Repository navigation
feat(otel)!: upgrade to OpenTelemetry JS SDK 3 and fix span parenting - #126
Merged
Merged
Conversation
Move @opentelemetry/core to 3.x and @opentelemetry/instrumentation to 0.301.x, make @opentelemetry/api a ^1.10.0 peer dependency and require Node.js >=22.15.0. Tests now run against the SDK 3 TracerProvider from @opentelemetry/sdk-trace. Amp-Thread-ID: https://ampcode.com/threads/T-01a1cc89-88ff-735a-b0e6-546b99965804
Parent spans were resolved through a map keyed by store and key, so operations from concurrent requests on the same key were attached to another request's getOrSet span, and spans created inside a factory were not children of the factory span. Attach the operation span with context.attach() on the tracing channel start event and dispose it on the synchronous end event instead. Also report the package version as the instrumentation version, warn when the BentoCache constructor cannot be patched, and make the test helper patch a mutable copy of the module so suppressInternalOperations is covered. Amp-Thread-ID: https://ampcode.com/threads/T-01a1cc89-88ff-735a-b0e6-546b99965804
🦋 Changeset detectedLatest commit: 0dc91c5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Summary
Two commits:
feat(otel)!: upgrade@bentocache/otelto OpenTelemetry JS SDK 3.@opentelemetry/coremoves to^3.1.1and@opentelemetry/instrumentationto^0.301.1.@opentelemetry/apibecomes a^1.10.0peer dependency, as in the upstream SDK 3 instrumentations. The package now requires Node.js>=22.15.0. Tests useTracerProviderfrom@opentelemetry/sdk-traceinstead ofsdk-trace-base. The instrumentation source needed no changes for SDK 3.fix(otel): make cache operation spans the active context. Parent spans used to be resolved through a map keyed bystore:key, which caused these problems:getOrSetspan, so they ended up in another trace.getOrSet) were not children ofcache.factory.The span is now attached with
context.attach()(@opentelemetry/api1.10) on the tracing channelstartevent, and the token is disposed on the synchronousendevent. This commit also:0.1.0);manuallyRegister()cannot patch the read-only ESM namespace;suppressInternalOperationswas untested.Breaking change
The two SDK lines cannot share one release. SDK 2 packages require
@opentelemetry/api <1.10.0, and SDK 3 packages require>=1.10.0 <1.11.0. With npm, an SDK 2 app now fails withERESOLVEon the@opentelemetry/apipeer. The changesets release this as0.2.0, so^0.1.xconsumers stay on SDK 2.Verification
pnpm build,typecheck,oxlint --deny-warningsandoxfmt --checkpass. Tests: 11/11.getOrSetimport-in-the-middlehook, produced correctly parented spans and suppressed L2 spans.Not included
playground/still lists SDK 2 dependencies. They are unused, and itsdevscript imports a missingsrc/instrumentation.ts.suppressInternalOperationscannot work withmanuallyRegister()on ESM. Making it work would need a new exportedinternalOperationWrapperhelper.