Repository navigation
chore(deps): replace the unmaintained uptrace opentelemetry-go-extra modules - #1753
Conversation
…modules FSC depended on three github.com/uptrace/opentelemetry-go-extra modules: otelzap and otelsql directly, otelutil transitively. Upstream's last commit is 2024-11-18 and v0.3.2 is its newest tag, so the suite no longer tracks the OpenTelemetry Go API. That came due in hyperledger-labs#1747. go.opentelemetry.io/otel/log v0.21.0 deleted keyvalue.go, and with it log.Value and every log.XxxValue constructor. otelutil v0.3.2 still calls them, so bumping otel/log past v0.20.0 stops the module compiling: otelutil@v0.3.2/attribute.go:68:38: undefined: log.Value otelutil@v0.3.2/attribute.go:71:14: undefined: log.StringValue Pinning otel/log at v0.20.0 would work, and would have to hold forever. otelzap turns out not to be needed at all. It was configured with a LoggerProvider wrapping noop.NewLoggerProvider(), and spanLogger.Emit discarded every part of the record it received except the body: trace.SpanFromContext(ctx).AddEvent(record.Body().AsString(), ...) So each context-aware call built a log.Record, set its severity, ran otelutil.LogValue over the fields -- the code path that needs the removed API -- and looked up runtime.Caller, and all of it was thrown away to keep one string. Only two behaviours were ever consumed: - span.AddEvent(msg, logger.name=...) at or above the logger's level - span.SetStatus(codes.Error, msg) for Error and above Both are now produced directly in ctxFieldLogger over a plain zap.SugaredLogger, and the log-signal plumbing -- spanLoggerProvider, spanLogger, sanitizedSpanLogger -- is gone along with the otel/log dependency itself. Nothing is computed when the span in ctx is not recording, so fmt.Sprintf and the sanitizer no longer run on the common untraced path: InfowContext, enabled, no fields before 1378 ns/op 1785 B/op 11 allocs/op after 453 ns/op 1221 B/op 3 allocs/op contrib/bridges/otelzap is not the replacement: it is a zapcore.Core emitting real log records to a LoggerProvider, with no *Context methods and no span events, so adopting it would mean writing more code to get something FSC does not want. It is the right choice only if FSC later wants the log signal. otelsql has no contrib counterpart -- the suite carries no database/sql instrumentation -- so it moves to github.com/XSAM/otelsql, the implementation the OpenTelemetry registry lists, whose Open and WithAttributes signatures are identical. Its otel v1.46.0 requirement pulls the root module's otel core along with it. Dropping one wrapper frame from the call chain takes the otel logger's caller skip from 2 to 1, which TestContextLogFields_CallerAccuracy covers. The span event path had no test at all, so otel_test.go adds one per behaviour, over tracetest.SpanRecorder and the real trace SDK. Signed-off-by: Marcus Brandenburger <bur@zurich.ibm.com>
|
Hey @mbrandenburger 👋 thanks for the PR! This comment updates automatically as you push changes -- think of it as your PR's live scoreboard! PR Checks✅ DCO Sign-off -- All commits have valid sign-offs. Nice work! ✅ GPG Signature -- All commits have verified GPG signatures. Locked and loaded! ✅ Merge Conflicts -- No merge conflicts detected. Smooth sailing! ❌ Issue Link -- Almost there! You are not assigned to the following linked issues: #1747. Please ensure you are assigned to all linked issues before opening a PR. You can comment ⏳ All checks must pass before this PR can be reviewed. You've got this! |
adecaro
left a comment
There was a problem hiding this comment.
Review: does this address #1752?
Checked out at 59458e167dd8c240c525e0665bd7c5531e21d868 (up to date with main).
$ go build ./... && go vet ./platform/common/services/logging/... ./platform/view/services/storage/driver/sql/{postgres,sqlite}/...
(clean)
$ go test -count=1 --skip '(Postgres)' ./platform/common/services/logging/... ./platform/view/services/storage/driver/sql/{postgres,sqlite}/...
ok .../platform/common/services/logging
ok .../platform/common/services/logging/testlogger
ok .../platform/view/services/storage/driver/sql/postgres
ok .../platform/view/services/storage/driver/sql/sqlite
$ golangci-lint run ./platform/common/services/logging/... ./platform/view/services/storage/driver/sql/{postgres,sqlite}/...
0 issues.
$ grep -rn "uptrace\|otel/log" (every go.mod/go.sum in the repo)
(no matches — fully removed)
go mod tidy in a scratch copy of all four affected modules (., integration/, libp2p/, cc/query/) produced zero diff.
What it fixes / adds
| Claim | Verified how |
|---|---|
otelzap was only ever used for AddEvent/SetStatus(codes.Error,...), nothing else |
Read pre-PR otel.go + vendored otelzap@v0.3.2 source (otelzap.go:161-168) — confirmed the new ctxFieldLogger.addEvent reproduces both effects with the same sanitize/status ordering |
XSAM/otelsql's Open/WithAttributes are drop-in for uptrace/otelsql |
Both call sites unchanged except import path; builds and tests clean |
otel 1.45→1.46 / testify 1.12.0→1.12.1 are pulled in by XSAM/otelsql, not chosen |
Confirmed in the go.mod diff — no other version changes present |
New otel_test.go covers the issue's stated gap (event name+attr, printf formatting, error status, level suppression, sanitize path, no-span-in-ctx) |
One test per item, all pass |
Blocking
None.
Non-blocking
- The bot's Issue Link check currently FAILs (
status: needs revision) because the PR body mentions#1747in prose (as the PR this unblocks) without a closing keyword, andcheckIssueLinkrequires assignment on every mentioned issue, not just the one actually being closed (Fixes #1752, which the author is assigned to). That's a known bot limitation, not something to fix in this PR's code.
Recommendation
Merge after the Issue Link check is resolved (get assigned to #1747, or drop/rephrase the mention) — the code itself is clean: build/vet/lint/tests all pass, go mod tidy is a no-op everywhere, and every claim in the PR description checked out against the diff and the removed library's source.
|
Tick the box to add this pull request to the merge queue (same as
|
What and why
FSC depended on three
github.com/uptrace/opentelemetry-go-extramodules —otelzapandotelsqldirectly,otelutiltransitively. The suite is unmaintained:v0.3.2is its newest tag and upstream's last commit is 2024-11-18.That became blocking in #1747.
go.opentelemetry.io/otel/logv0.21.0 deletedkeyvalue.go, and with itlog.Valueand everylog.XxxValueconstructor.otelutil@v0.3.2still calls them, so the v0.20.0 → v0.22.0 bump in that PR stops the root module compiling — which is whyAnalyze, all threegolangcijobs, everyutest-*and everyitest-*are red there:Pinning
otel/logat v0.20.0 fixes #1747, and would have to hold forever. This removes the constraint instead.otelzapturns out not to have been needed at all. It was configured with aLoggerProviderwrappingnoop.NewLoggerProvider(), andspanLogger.Emitdiscarded every part of the record except the body:So each context-aware call built a
log.Record, set its severity, ranotelutil.LogValueover the fields — the code path that needs the removed API — and did aruntime.Callerlookup, and all of it was thrown away to keep one string. Only two behaviours were ever consumed, and both are now produced directly inctxFieldLoggerover a plain*zap.SugaredLogger:span.AddEvent(msg, logger.name=…)at or above the logger's levelspan.SetStatus(codes.Error, msg)for Error and abovespanLoggerProvider,spanLoggerandsanitizedSpanLoggerare gone, and with them thego.opentelemetry.io/otel/logdependency. Because nothing is computed when the span in ctx is not recording,fmt.Sprintfand the sanitizer no longer run on the untraced path — the common case in production:go.opentelemetry.io/contrib/bridges/otelzapis deliberately not used: it is azapcore.Coreemitting real log records to aLoggerProvider, with no*Contextmethods and no span events, so it would be more code for something FSC does not want. It is the right choice only if FSC later wants the log signal rather than span events.otelsqlhas no contrib counterpart — the suite carries nodatabase/sqlinstrumentation — so it moves togithub.com/XSAM/otelsql, the implementation the OpenTelemetry registry lists.OpenandWithAttributesare signature-identical, so it is a one-line import swap in each of the two call sites.Closes #1752
How it was verified
go build ./...in all four buildable modulesmake unit-tests-root— passgo test ./platform/view/services/storage/... ./platform/common/services/logging/...— 14 packages, passmake tidyclean; nouptraceand nootel/logleft in any of the fivego.modfilesgolangci-lint runon both changed package trees — 0 issuesgo test -bench 'Infow|Infof|Debugf' ./platform/common/services/logging/New tests, since the span-event path had no coverage before:
otel_test.goasserts the event name andlogger.nameattribute, printf message formatting,SetStatuson error, suppression below level, theOtelSanitizepath, and no-span-in-ctx — overtracetest.SpanRecorderand the real trace SDK.Postgres-backed tests need Docker and were not run locally;
utest-postgrescovers them.Notes for reviewers
platform/common/services/logging/otel.go:spanEvent,spanEventfandaddEventare the ~25 lines that replace both dependencies.logger.godrops the otel logger's caller skip from 2 to 1, because one wrapper frame leaves the call chain. The pre-existingTestContextLogFields_CallerAccuracycatches this if it is wrong — it did, before the adjustment.otel1.45 → 1.46 andtestify1.12.0 → 1.12.1 in the rootgo.modare pulled in byXSAM/otelsql@v0.44.0's own requirement, not chosen here. chore(deps): bump the go-dependencies group across 3 directories with 22 updates #1747 bumps both anyway.otel/loggone from every module, nothing in that batch is breaking, and no Dependabotignoreentry is needed.make tidydirtiness on chore(deps): bump the go-dependencies group across 3 directories with 22 updates #1747 (integration/go.sum,libp2p/go.mod,libp2p/go.sum). Dependabot updates each directory independently and cannot run the repo's cross-module tidy, so that PR still needs amake tidycommit.