Skip to content

feat(node): Use @opentelemetry/instrumentation-undici for fetch tracing #13485

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

Merged
merged 21 commits into from
Sep 9, 2024

Conversation

timfish
Copy link
Collaborator

@timfish timfish commented Aug 27, 2024

This PR migrates the nativeNodeFetchIntegration to use @opentelemetry/instrumentation-undici instead of opentelemetry-instrumentation-fetch-node.

The instrumentation is still exported as nativeNodeFetchIntegration and is named NodeFetch to ensure backwards compatibility and the tests pass without changes.

Note: One nextjs-14 e2e test did need a change due to the new/differing attribute names.

It's worth noting that @opentelemetry/instrumentation-undici uses different attributes from the latest semantic convention version vs what we are using and what's used by opentelemetry-instrumentation-fetch-node. It looks like the http instrumentation is migrating to these too so some of the changes in this PR will ensure that the http instrumentation continues to work after these updates.

Outstanding issues:

  • For the outgoing fetch > outgoing sampled fetch requests without active span are correctly instrumented tests, the sentry-trace header has an extra -1 on the end. I have no idea what causes this!

  • For /api/v3 portion of the fetch-unsampled/test.ts and fetch-sampled-no-active-span/test.ts, it fails because the baggage header is not undefined as expected. As far as I can tell, SentryPropagator should be excluding these from header injection but it's not. I guess this is because @opentelemetry/instrumentation-undici is not setting the SEMATTRS_HTTP_URL attribute (http.url). Should the otel instrumentation be setting this or should we also be checking for SemanticAttributes.URL_FULL attribute (url.full) which it already sets? Here are the attributes it is already setting.

@timfish timfish requested review from mydea and AbhiPrasad August 27, 2024 22:20
Copy link
Contributor

github-actions bot commented Aug 27, 2024

size-limit report 📦

Path Size % Change Change
@sentry/browser 22.52 KB - -
@sentry/browser - with treeshaking flags 21.3 KB - -
@sentry/browser (incl. Tracing) 34.78 KB - -
@sentry/browser (incl. Tracing, Replay) 71.23 KB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 61.67 KB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 75.57 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 88.3 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback, metrics) 90.14 KB - -
@sentry/browser (incl. metrics) 26.83 KB - -
@sentry/browser (incl. Feedback) 39.6 KB - -
@sentry/browser (incl. sendFeedback) 27.19 KB - -
@sentry/browser (incl. FeedbackAsync) 31.9 KB - -
@sentry/react 25.28 KB - -
@sentry/react (incl. Tracing) 37.74 KB - -
@sentry/vue 26.67 KB - -
@sentry/vue (incl. Tracing) 36.61 KB - -
@sentry/svelte 22.65 KB - -
CDN Bundle 23.77 KB - -
CDN Bundle (incl. Tracing) 36.49 KB - -
CDN Bundle (incl. Tracing, Replay) 70.91 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 76.22 KB - -
CDN Bundle - uncompressed 69.63 KB - -
CDN Bundle (incl. Tracing) - uncompressed 108.21 KB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 219.87 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 233.07 KB - -
@sentry/nextjs (client) 37.51 KB - -
@sentry/sveltekit (client) 35.35 KB - -
@sentry/node 126.36 KB +1.11% +1.38 KB 🔺
@sentry/node - without tracing 98.84 KB +3.5% +3.34 KB 🔺
@sentry/aws-serverless 109.1 KB +1.47% +1.58 KB 🔺

View base workflow run

@timfish
Copy link
Collaborator Author

timfish commented Aug 27, 2024

@timfish timfish marked this pull request as ready for review September 5, 2024 09:45
@@ -45,8 +47,8 @@ export function wrapRequestHandler(
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.cloudflare',
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.server',
['http.request.method']: request.method,
['url.full']: request.url,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I replaced these in a couple of places since I just added temporary constants for them

name: 'NodeFetch',
setupOnce() {
const instrumentation = new UndiciInstrumentation({
requireParentforSpans: false,
Copy link
Member

Choose a reason for hiding this comment

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

is this a typo in our config or upstream, seems like it should be requireParentForSpans 😅

Copy link
Collaborator Author

@timfish timfish Sep 5, 2024

Choose a reason for hiding this comment

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

@timfish
Copy link
Collaborator Author

timfish commented Sep 5, 2024

One nextjs-14 e2e test did need a change due to the differing attributes

mydea added a commit that referenced this pull request Sep 5, 2024
…13587)

This bumps all our internal OTEL instrumentation to their latest
version.

Mainly, this fixes two things:

* Mongoose now supports v7 & v8
open-telemetry/opentelemetry-js-contrib#2353
* A variety of bug fixes, including a problem with http.get in ESM mode
open-telemetry/opentelemetry-js#4857 - See:
https://github.com/open-telemetry/opentelemetry-js/releases/tag/experimental%2Fv0.53.0

Related:

* open-telemetry/opentelemetry-js#4975 Issue
about relaxing deps in "core" instrumentation packages
* PR to bump deps in `@prisma/instrumentation`:
prisma/prisma#25160
* PR to bump deps in `opentelemetry-instrument-remix`:
justindsmith/opentelemetry-instrumentations-js#52
* PR to bump deps in `opentelemetry-instrumentation-fetch-node`:
gas-buddy/opentelemetry-instrumentation-fetch-node#17
(which will also be superseded by
#13485 eventually)

* Closes #11499
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.

Use @opentelemetry/instrumentation-undici Unhandled Promise Rejection in debugger on Node startup
3 participants