Skip to content

feat!: Bump to OpenTelemetry v2 #16872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from
Open

feat!: Bump to OpenTelemetry v2 #16872

wants to merge 28 commits into from

Conversation

andreiborza
Copy link
Member

@andreiborza andreiborza commented Jul 10, 2025

This PR

  • bumps all OpenTelemetry packages to v2 and equivalent (i.e. 0.202.0 for experimental and latest versions for all instrumentations).
  • removes our vendored express v5 instrumentation in favor of the OpenTelemetry instrumentation
  • adds polyfills for node utils to vercel-edge
  • removes the @sentry/opentelemetry OpenTelemetry v2 test dev-package as this is now covered by the package itself

Note: Once this PR is merged, the develop branch officially becomes the v10 branch and any releases for v9 have to happen on the v9 branch.

Copy link
Contributor

github-actions bot commented Jul 10, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.78 kB - -
@sentry/browser - with treeshaking flags 22.34 kB - -
@sentry/browser (incl. Tracing) 39.66 kB - -
@sentry/browser (incl. Tracing, Replay) 77.79 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 67.59 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 82.49 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 94.59 kB - -
@sentry/browser (incl. Feedback) 40.48 kB - -
@sentry/browser (incl. sendFeedback) 28.46 kB - -
@sentry/browser (incl. FeedbackAsync) 33.36 kB - -
@sentry/react 25.54 kB - -
@sentry/react (incl. Tracing) 41.62 kB - -
@sentry/vue 28.23 kB - -
@sentry/vue (incl. Tracing) 41.45 kB - -
@sentry/svelte 23.81 kB - -
CDN Bundle 25.18 kB - -
CDN Bundle (incl. Tracing) 39.42 kB - -
CDN Bundle (incl. Tracing, Replay) 75.42 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 80.89 kB - -
CDN Bundle - uncompressed 73.44 kB - -
CDN Bundle (incl. Tracing) - uncompressed 116.86 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 231 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 243.81 kB - -
@sentry/nextjs (client) 43.66 kB - -
@sentry/sveltekit (client) 40.08 kB - -
@sentry/node 142.66 kB -14.99% -25.15 kB 🔽
@sentry/node - without tracing 91.31 kB -8.88% -8.89 kB 🔽
@sentry/aws-serverless 102.75 kB -19.96% -25.61 kB 🔽
@sentry/node-core 47.24 kB added added

View base workflow run


// Access the span processors from the provider via _activeSpanProcessor
// Casted as any because _activeSpanProcessor is marked as readonly
const multiSpanProcessor = (provider as any)._activeSpanProcessor as
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure, but sometimes it also works to do provider['_activeSpanProcessor'] to make TS happy!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 worked, thanks!

@andreiborza andreiborza force-pushed the ab/bump-otel-v2 branch 11 times, most recently from 6de3296 to 957a4c8 Compare July 15, 2025 12:46
@andreiborza andreiborza marked this pull request as ready for review July 15, 2025 13:25
@andreiborza andreiborza force-pushed the ab/bump-otel-v2 branch 2 times, most recently from 8c43c8a to 213aa83 Compare July 16, 2025 09:29
Copy link
Member

@mydea mydea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work!

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I just had a couple of questions regarding changed attributes/data mostly. Otherwise LGTM!

@@ -65,7 +65,6 @@ test('Should record a transaction for route with parameters', async ({ request }
data: {
'express.name': 'query',
'express.type': 'middleware',
'http.route': '/',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logaf-l but our of curiosity: why was this attribute removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The express instrumentation doesn't add it anymore to middleware spans, I didn't find anything in their changelog regarding this tho so it's more of an observation after running it 😅.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this likely came from open-telemetry/opentelemetry-js-contrib#2843. Looks like it might be a bug in the instrumentation now because these spans are not for a 404 route..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@s1gr1d could you take a look at that please?

Copy link
Member

@s1gr1d s1gr1d Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bug before, as it was always attaching http.route. http.route should not be included when no route was matched (on 404).

The matched route, that is, the path template in the format used by the respective server framework.

Semantic Convention Docs: https://opentelemetry.io/docs/specs/semconv/registry/attributes/http/


But in this case it's not a 404 route 🤔

Copy link
Member

@s1gr1d s1gr1d Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checked: Middleware spans might not include the http.route attribute when it's not yet known at the time the middleware runs. And 'http.route': '/' is only added when there is an explicitly defined root route AND when when the route resolution is already done (middleware might run before that).

And why it was added before: Previously, the attribute ALWAYS defaulted to / but this was wrong. https://github.com/open-telemetry/opentelemetry-js-contrib/pull/2843/files#diff-81c3e13c3dac53e0dd6aabf6dc165305350eb522a85a2561f9ee51d9249011e7L198

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks so much for investigating and fixing this upstream @s1gr1d :)

}),
),
);
const provider = new NodeTracerProvider({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no action required: was this a breaking change in the provider class or simply a refactor?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking change, there's no more addSpanProcessor in v2.

@@ -31,7 +31,11 @@ test.describe('Trace propagation', () => {
const clientTx = await clientTxPromise;

expect(clientTx.contexts?.trace?.trace_id).toEqual(serverTx.contexts?.trace?.trace_id);
expect(clientTx.contexts?.trace?.parent_span_id).toBe(serverTx.contexts?.trace?.span_id);

const requestHandlerSpan = serverTx.spans?.find(span => span.op === 'request_handler.express');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no action required: looks like the parent span changed here. Any idea why? Is this a consequence of updated instrumenations?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, this came through the update in instrumentation. We no longer use our express v5 instrumentation.

@mydea mydea changed the title feat: Bump to OpenTelemetry v2 feat!: Bump to OpenTelemetry v2 Jul 16, 2025
Copy link
Member

@chargome chargome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇

"@opentelemetry/instrumentation-nestjs-core": "0.44.1",
"@opentelemetry/core": "^2.0.0",
"@opentelemetry/instrumentation": "^0.202.0",
"@opentelemetry/instrumentation-nestjs-core": "0.48.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can then switch this one in a separate PR (replacing our vendored instrumentation)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to switch anyway to match deps, it shouldn't affect our vendored instrumentation tho.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants