fix: keep OpenTelemetry running when resource detection is incomplete - #2
Merged
Merged
Conversation
The runtime image sets USER 65532:65532 but never creates a matching account, so the process owner detector's user.Current call fails and resource.New returns an error. Init treated that as fatal, which disabled OpenTelemetry entirely in every container. resource.New still returns the attributes its other detectors produced, so an incomplete resource is a degraded one, not an invalid one. Log the detection failure and carry on. Checking errors.Is(err, resource.ErrPartialResource) would not have helped here: the process owner detector returns user.Current's error verbatim, unwrapped. Also create the nonroot account the numeric USER refers to, so the lookup succeeds and process.owner is populated instead of merely tolerated. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
The runtime image runs as
USER 65532:65532, butdebian:bookworm-slimhas no account at that UID:So OTel's
processOwnerDetectorcallsuser.Current(), which fails,resource.Newreturns that error, andInittreated it as fatal — disabling telemetry in every container.Why the obvious guard would not have worked
The SDK's own documented pattern is
errors.Is(err, resource.ErrPartialResource). That does not catch this case —processOwnerDetector.Detectreturnsuser.Current()'s error verbatim, unwrapped:detect()joins the error but still merges every other detector, so the resource keeps env, PID, executable, command args, runtime, host andservice.name— onlyprocess.owneris missing. An incomplete resource is a degraded one, not an invalid one.Changes
internal/telemetry/otel.go— log detection failures as a warning and continue with the resource, instead of aborting startup.Dockerfile— create thenonrootaccount the numericUSERrefers to, so the lookup actually succeeds andprocess.owneris populated rather than merely tolerated.USERstays numeric so KubernetesrunAsNonRootcan verify it.Verification
End-to-end, real binary under
--user 65532:65532withOTEL_EXPORTER_OTLP_ENDPOINTset:application stopped with an error: initialize telemetry failedWARN incomplete telemetry resource→INFO telemetry initialized→ startup continuesINFO telemetry initialized, no warning — owner resolvesConfirmed the image change works with
CGO_ENABLED=0(pure-Goos/userreads/etc/passwd), which is how this binary ships.Added
TestInitKeepsPartialResourceWhenDetectionFails, written first and watched fail with the exact production error before the fix.go vet ./...,go test -race ./...,go build ./cmd/app, andgofmtare all clean.🤖 Generated with Claude Code