-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(core): Sanitize data URLs in http.client spans
#18896
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
Changes from 1 commit
2a7a6a4
73eca56
0c1772d
102ac46
79f63b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,15 @@ | ||
| import type { UndiciInstrumentationConfig } from '@opentelemetry/instrumentation-undici'; | ||
| import { UndiciInstrumentation } from '@opentelemetry/instrumentation-undici'; | ||
| import type { IntegrationFn } from '@sentry/core'; | ||
| import { defineIntegration, getClient, hasSpansEnabled, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core'; | ||
| import { | ||
| defineIntegration, | ||
| getClient, | ||
| hasSpansEnabled, | ||
| SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME, | ||
| SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, | ||
| SEMANTIC_ATTRIBUTE_URL_FULL, | ||
| stripDataUrlContent, | ||
| } from '@sentry/core'; | ||
| import type { NodeClient } from '@sentry/node-core'; | ||
| import { generateInstrumentOnce, SentryNodeFetchInstrumentation } from '@sentry/node-core'; | ||
| import type { NodeClientOptions } from '../types'; | ||
|
|
@@ -101,7 +109,20 @@ function getConfigWithDefaults(options: Partial<NodeFetchOptions> = {}): UndiciI | |
|
|
||
| return !!shouldIgnore; | ||
| }, | ||
| startSpanHook: () => { | ||
| startSpanHook: request => { | ||
| const url = getAbsoluteUrl(request.origin, request.path); | ||
|
|
||
| // Sanitize data URLs to prevent long base64 strings in span attributes | ||
| if (url.startsWith('data:')) { | ||
| const sanitizedUrl = stripDataUrlContent(url); | ||
| return { | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.node_fetch', | ||
| 'http.url': sanitizedUrl, | ||
| [SEMANTIC_ATTRIBUTE_URL_FULL]: sanitizedUrl, | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]: `${request.method || 'GET'} ${sanitizedUrl}`, | ||
|
Comment on lines
+119
to
+122
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. About the additional comment from @brunohaid: Maybe we could add the content of the first few bytes as an attribute here 🤔
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ended up adding the first 10 bytes to the span description and data. I went for adding this directly to the URL attributes/description because there isn't really a fitting attribute defined in SemConv for data url content. So I just stuck with the "url.full" one. |
||
| }; | ||
|
Lms24 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| return { | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.node_fetch', | ||
| }; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.