-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(core): Ensure url, http.query and http.fragment are directly added
#22547
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
base: develop
Are you sure you want to change the base?
Changes from all commits
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,8 +24,8 @@ export function addOutgoingRequestBreadcrumb( | |||||||||
| status_code: statusCode, | ||||||||||
| url: getSanitizedUrlString(parsedUrl), | ||||||||||
| 'http.method': request.method || 'GET', | ||||||||||
| ...(parsedUrl.search ? { 'http.query': parsedUrl.search } : {}), | ||||||||||
| ...(parsedUrl.hash ? { 'http.fragment': parsedUrl.hash } : {}), | ||||||||||
| ...(parsedUrl.search ? { 'http.query': parsedUrl.search.slice(1) || undefined } : {}), | ||||||||||
| ...(parsedUrl.hash ? { 'http.fragment': parsedUrl.hash.slice(1) || undefined } : {}), | ||||||||||
|
Comment on lines
+27
to
+28
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. These get serialized with
Suggested change
|
||||||||||
| }, | ||||||||||
| type: 'http', | ||||||||||
| level, | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,8 +7,10 @@ import { RPCType, setRPCMetadata } from '@opentelemetry/core'; | |||||||||
| import { | ||||||||||
| HTTP_CLIENT_IP, | ||||||||||
| HTTP_FLAVOR, | ||||||||||
| HTTP_FRAGMENT, | ||||||||||
| HTTP_HOST, | ||||||||||
| HTTP_METHOD, | ||||||||||
| HTTP_QUERY, | ||||||||||
| HTTP_RESPONSE_STATUS_CODE, | ||||||||||
| HTTP_ROUTE, | ||||||||||
| HTTP_SCHEME, | ||||||||||
|
|
@@ -51,6 +53,7 @@ import { | |||||||||
| bindScopeToEmitter, | ||||||||||
| startInactiveSpan, | ||||||||||
| withActiveSpan, | ||||||||||
| getSanitizedUrlStringFromUrlObject, | ||||||||||
| SPAN_KIND, | ||||||||||
| } from '@sentry/core'; | ||||||||||
| import { DEBUG_BUILD } from '../../debug-build'; | ||||||||||
|
|
@@ -152,6 +155,7 @@ const _httpServerSpansIntegration = ((options: HttpServerSpansIntegrationOptions | |||||||||
|
|
||||||||||
| const fullUrl = normalizedRequest.url || request.url || '/'; | ||||||||||
| const urlObj = parseStringToURLObject(fullUrl); | ||||||||||
| const sanitizedUrl = urlObj ? getSanitizedUrlStringFromUrlObject(urlObj) : undefined; | ||||||||||
|
|
||||||||||
| const headers = request.headers; | ||||||||||
| const userAgent = headers['user-agent']; | ||||||||||
|
|
@@ -166,6 +170,9 @@ const _httpServerSpansIntegration = ((options: HttpServerSpansIntegrationOptions | |||||||||
| const httpTargetWithoutQueryFragment = urlObj ? urlObj.pathname : stripUrlQueryAndFragment(fullUrl); | ||||||||||
| const bestEffortTransactionName = `${method} ${httpTargetWithoutQueryFragment}`; | ||||||||||
|
|
||||||||||
| const query = urlObj?.search ? urlObj.search.slice(1) || undefined : undefined; | ||||||||||
| const fragment = urlObj?.hash ? urlObj.hash.slice(1) || undefined : undefined; | ||||||||||
|
Comment on lines
+173
to
+174
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. Same here
Suggested change
|
||||||||||
|
|
||||||||||
| const span = startInactiveSpan({ | ||||||||||
| name: bestEffortTransactionName, | ||||||||||
| kind: SPAN_KIND.SERVER, | ||||||||||
|
|
@@ -179,7 +186,10 @@ const _httpServerSpansIntegration = ((options: HttpServerSpansIntegrationOptions | |||||||||
| // Old Semantic Conventions attributes - added for compatibility with what `@opentelemetry/instrumentation-http` output before | ||||||||||
| /* eslint-disable typescript/no-deprecated */ | ||||||||||
| [HTTP_URL]: fullUrl, | ||||||||||
| url: sanitizedUrl, | ||||||||||
| [HTTP_METHOD]: normalizedRequest.method, | ||||||||||
| [HTTP_QUERY]: query, | ||||||||||
| [HTTP_FRAGMENT]: fragment, | ||||||||||
| [HTTP_TARGET]: urlObj ? `${urlObj.pathname}${urlObj.search}` : httpTargetWithoutQueryFragment, | ||||||||||
| [HTTP_HOST]: host, | ||||||||||
| [NET_HOST_NAME]: hostname, | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split HTTP query fragment formats
Medium Severity
This commit normalizes
http.queryandhttp.fragmentby stripping leading?and#in core fetch, HTTP breadcrumbs, URL span helpers, and Node server spans, but browser XHR and Node undici fetch breadcrumbs still emit the rawURL.search/URL.hashvalues with those prefixes. The same app can therefore report different query and fragment shapes onhttp.clientspans and HTTP breadcrumbs depending on the API used.Reviewed by Cursor Bugbot for commit d6bc9b0. Configure here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed. Need to update the following as well to match:
Also found these:
Also, there are
TODO(v11)comments about this in packages/opentelemetry/src/utils/parseSpanDescription.ts line 202 and packages/opentelemetry/src/spanExporter.ts line 456 that seem related, and I think can be dropped, since the todo will be to-done after this PR.Might want to verify that the stripping happening in the otel lib isn't going to double-strip these fields, since the field set in
packages/core/src/integrations/requestdata.tsis stripped already. I think it's actually behaving properly, stripping it only where it needs to and not anywhere else (apart from the handful of locations noted above), and it'd likely fail a bunch of tests if it was double-stripping. In which case theTODO(v11)comments are definitely a bit of a hazard.