fix(tracing): harden span export and telemetry semantics - #913
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughChangesTelemetry and build observability
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/tracing/tracing_test.go`:
- Around line 37-45: Update the test loop around spanLimits() to unset both
OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT and OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT
with cleanup before applying tc.spanEnv and tc.genEnv. Preserve the existing
conditional setup so empty table values remain truly unset and each case is
isolated from the test runner environment.
In `@pkg/tracing/tracing.go`:
- Around line 216-223: Prevent spans from being created during provider shutdown
and synchronize timing state: in pkg/tracing/tracing.go lines 216-223, call
timing.SetTracer with nil before provider.Shutdown; in pkg/timing/timing.go
lines 43-51, guard the paired parentCtx/tracer update and status read with a
mutex; and in pkg/timing/timing.go lines 98-111, copy both values under the same
read lock before starting a span.
- Around line 189-195: Update buildID to distinguish an empty readable
Dockerfile from an unreadable file by checking whether content is nil rather
than whether its length is nonzero. When content is non-nil, hash its contents
even when empty; retain the path fallback only for unreadable or absent content.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: c6de3485-63be-45ad-92e5-20bb65a96363
📒 Files selected for processing (7)
README.mdcmd/executor/cmd/root.gopkg/executor/build.gopkg/executor/build_timer_test.gopkg/timing/timing.gopkg/tracing/tracing.gopkg/tracing/tracing_test.go
2b7031c to
7590710
Compare
5a1b0cc to
41fad23
Compare
3d2d706 to
6868d5e
Compare
41fad23 to
1323e46
Compare
26c353d to
3b4e2ed
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
docs/telemetry.md (2)
11-11: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winDo not promise a span for every phase.
pkg/timing/timing.gosuppresses spans for several timing categories, so change this to “each traced phase” or document the exclusions. Otherwise missing phase spans may be mistaken for exporter loss.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@docs/telemetry.md` at line 11, Update the telemetry documentation’s build-span description to avoid promising a span for every build phase: say “each traced phase” or explicitly document the phase exclusions enforced by pkg/timing/timing.go. Preserve the existing descriptions of the root build span, Dockerfile command spans, span naming, and attributes.
9-9: 🔒 Security & Privacy | 🟡 Minor | ⚡ Quick winDocument the plaintext endpoint warning and opt-in contract.
pkg/tracing/tracing.gowarns whenKANIKO_TELEMETRY_ENDPOINTuseshttp://, and the standard OTEL endpoint alone does not enable tracing. This page presents HTTP without either warning, so add the same security and configuration guidance here.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@docs/telemetry.md` at line 9, Update the telemetry documentation describing the endpoint to warn that http:// sends data without transport encryption, and state that tracing requires explicit opt-in via KANIKO_TELEMETRY_ENABLED; setting only the standard OTEL endpoint does not enable it. Keep the existing OTLP/HTTP and authentication guidance intact.pkg/executor/build.go (1)
655-680: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winAttach core command attributes before fallible cache work.
The command span is started at Line 601, but
kaniko.command, phase, index, line, and stage are not attached until afterFilesUsedFromContextand cache-key generation. If either operation fails, the deferred stop preserves an otherwise anonymousCommandspan, undermining the failing-command trace objective. Attach the non-cache attributes immediately after starting the timer; add cache attributes once the key is available.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/executor/build.go` around lines 655 - 680, Move construction and attachment of the non-cache command span attributes from the current tracing block to immediately after the command timer starts, including kaniko.command, kaniko.command.hash, kaniko.phase, kaniko.instruction.index, kaniko.instruction.line, and kaniko.stage. Keep cache-specific attributes in the existing opts.Cache flow and append them only after cache-key generation succeeds, ensuring failures in FilesUsedFromContext or compositeKey.Hash still leave the command span identified.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/timing/timing.go`:
- Around line 109-115: Update the span creation flow around tracerMu and
tr.Start to keep tracerMu held through tr.Start, preventing Shutdown from
draining the provider between tracer snapshot and span creation. Preserve the
existing category check, span assignment, and attribute behavior while ensuring
tracer shutdown cannot overlap an in-flight start.
---
Outside diff comments:
In `@docs/telemetry.md`:
- Line 11: Update the telemetry documentation’s build-span description to avoid
promising a span for every build phase: say “each traced phase” or explicitly
document the phase exclusions enforced by pkg/timing/timing.go. Preserve the
existing descriptions of the root build span, Dockerfile command spans, span
naming, and attributes.
- Line 9: Update the telemetry documentation describing the endpoint to warn
that http:// sends data without transport encryption, and state that tracing
requires explicit opt-in via KANIKO_TELEMETRY_ENABLED; setting only the standard
OTEL endpoint does not enable it. Keep the existing OTLP/HTTP and authentication
guidance intact.
In `@pkg/executor/build.go`:
- Around line 655-680: Move construction and attachment of the non-cache command
span attributes from the current tracing block to immediately after the command
timer starts, including kaniko.command, kaniko.command.hash, kaniko.phase,
kaniko.instruction.index, kaniko.instruction.line, and kaniko.stage. Keep
cache-specific attributes in the existing opts.Cache flow and append them only
after cache-key generation succeeds, ensuring failures in FilesUsedFromContext
or compositeKey.Hash still leave the command span identified.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: c7ed2775-b5c6-425d-88fd-1942e2b31ed3
📒 Files selected for processing (9)
README.mdcmd/executor/cmd/root.godocs/telemetry.mdpkg/executor/build.gopkg/executor/build_timer_test.gopkg/timing/timing.gopkg/timing/timing_test.gopkg/tracing/tracing.gopkg/tracing/tracing_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
- pkg/executor/build_timer_test.go
- pkg/tracing/tracing_test.go
- pkg/tracing/tracing.go
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
- drop the global otel provider registration that silently enabled client spans in the GCS/GCR transports - cap attribute values at 64 KiB unless an OTEL length-limit env var is set (explicit -1 honored) - add KANIKO_TELEMETRY_OMIT_DOCKERFILE opt-out; warn on unparseable values and on plaintext http endpoints - derive kaniko.build_id from Dockerfile content, not mount path - strip the FF_KANIKO_ prefix from kaniko.ff.* keys - emit kaniko.cache.hit only when caching is on; classify phase by command type so cached RUNs are not "build"; kaniko.stage as int; stable "Command" span name (full text stays in kaniko.command) - let OTEL_SERVICE_NAME override the service.name default - guard tracing globals with a mutex; clear the timing tracer on Shutdown - document exported payload, protocol limits and the attribute set
- guard the timing tracer/context pair with a mutex and unwire span creation before draining the provider: Shutdown can run from the assertion hook while cache-push goroutines still start spans - content-address readable-but-empty Dockerfiles in build_id
3b4e2ed to
9aa6795
Compare
Follow-up to #902, addressing the review findings on the opt-in OpenTelemetry tracing. Stacked on
mz-otel-instrumentation.Span export correctness
--dryrun), so a failed build exports the span of the command that failed — previously exactly that span was dropped (unended spans never reach the processor). Pinned by a regression test that goes red without the fix.logrus.Fataldeaths (e.g. snapshot timeout) now flush via an exit handler; the exit-time flush is bounded to 5s so a dead collector can't stall teardown, and errors print to stderr before the flush.otel.SetTracerProvider: kaniko never consumed the global, but the vendored GCS/GCR transports do — it silently enabled orphan client spans.Shutdownunwires the timing tracer so nothing mints spans into a dead provider.Payload safety
OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT/OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIToverride, explicit-1honored.KANIKO_TELEMETRY_OMIT_DOCKERFILEopt-out for the Dockerfile-content attribute; warns when set to an unparseable boolean (fail-open would be silent otherwise) and when the endpoint is plaintexthttp://.--mount=type=secretids/env names — never values, FF values, cache keys), the HTTP-only protocol limit, and the full attribute reference.Attribute semantics
kaniko.build_idis content-addressed (sha256 of Dockerfile content + target) instead of hashing the mount path, which made it constant across a fleet.kaniko.ff.*keys lose the redundantFF_KANIKO_prefix; README documents that only explicitly-set flags are reported.kaniko.cache.hitis only emitted when caching is on (absence ≠ miss); phase is derived from the command type so a cached RUN is no longer labeledbuild;kaniko.stageis an int; span names are a stable"Command"(full text stays inkaniko.command;BENCHMARK_FILEkeys unchanged).OTEL_SERVICE_NAMEnow overrides theservice.namedefault (resource env applied last, via semconv).Deliberately not addressed here: trace start point (context fetch happens before
Init), inferred cross-stagecache.keyreporting, SIGTERM handling, category-map refactor — each noted in the README or code comments where relevant.Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Tests