-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
ref(opentelemetry): Remove usage of parseUrl
#15954
Open
AbhiPrasad
wants to merge
1
commit into
develop
Choose a base branch
from
abhi-otel-parseurl
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+38
−208
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,9 @@ import { | |
SEMANTIC_ATTRIBUTE_SENTRY_OP, | ||
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, | ||
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, | ||
getSanitizedUrlString, | ||
parseUrl, | ||
stripUrlQueryAndFragment, | ||
parseStringToURLObject, | ||
getSanitizedUrlStringFromUrlObject, | ||
isURLObjectRelative, | ||
} from '@sentry/core'; | ||
import { SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION } from '../semanticAttributes'; | ||
import type { AbstractSpan } from '../types'; | ||
|
@@ -156,16 +156,16 @@ export function descriptionForHttpMethod( | |
opParts.push('prefetch'); | ||
} | ||
|
||
const { urlPath, url, query, fragment, hasRoute } = getSanitizedUrl(attributes, kind); | ||
const [parsedUrl, httpRoute] = getParsedUrl(attributes); | ||
|
||
if (!urlPath) { | ||
if (!parsedUrl) { | ||
return { ...getUserUpdatedNameAndSource(name, attributes), op: opParts.join('.') }; | ||
} | ||
|
||
const graphqlOperationsAttribute = attributes[SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION]; | ||
|
||
// Ex. GET /api/users | ||
const baseDescription = `${httpMethod} ${urlPath}`; | ||
const baseDescription = `${httpMethod} ${httpRoute || getSanitizedUrlStringFromUrlObject(parsedUrl)}`; | ||
|
||
// When the http span has a graphql operation, append it to the description | ||
// We add these in the graphqlIntegration | ||
|
@@ -174,18 +174,16 @@ export function descriptionForHttpMethod( | |
: baseDescription; | ||
|
||
// If `httpPath` is a root path, then we can categorize the transaction source as route. | ||
const inferredSource: TransactionSource = hasRoute || urlPath === '/' ? 'route' : 'url'; | ||
const inferredSource: TransactionSource = httpRoute || parsedUrl.pathname === '/' ? 'route' : 'url'; | ||
|
||
const data: Record<string, string> = {}; | ||
|
||
if (url) { | ||
data.url = url; | ||
data.url = isURLObjectRelative(parsedUrl) ? parsedUrl.pathname : parsedUrl.toString(); | ||
if (parsedUrl.search) { | ||
data['http.query'] = parsedUrl.search; | ||
} | ||
if (query) { | ||
data['http.query'] = query; | ||
} | ||
if (fragment) { | ||
data['http.fragment'] = fragment; | ||
if (parsedUrl.hash) { | ||
data['http.fragment'] = parsedUrl.hash; | ||
} | ||
|
||
// If the span kind is neither client nor server, we use the original name | ||
|
@@ -234,48 +232,31 @@ function getGraphqlOperationNamesFromAttribute(attr: AttributeValue): string { | |
} | ||
|
||
/** Exported for tests only */ | ||
export function getSanitizedUrl( | ||
export function getParsedUrl( | ||
attributes: Attributes, | ||
kind: SpanKind, | ||
): { | ||
url: string | undefined; | ||
urlPath: string | undefined; | ||
query: string | undefined; | ||
fragment: string | undefined; | ||
hasRoute: boolean; | ||
} { | ||
): [parsedUrl: ReturnType<typeof parseStringToURLObject>, httpRoute: string | undefined] { | ||
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. can we get the httpRoute logic out of here somehow? It seems like all we do is read the http.route attribute and return it. |
||
// This is the relative path of the URL, e.g. /sub | ||
// eslint-disable-next-line deprecation/deprecation | ||
const httpTarget = attributes[SEMATTRS_HTTP_TARGET]; | ||
const possibleRelativeUrl = attributes[SEMATTRS_HTTP_TARGET]; | ||
// This is the full URL, including host & query params etc., e.g. https://example.com/sub?foo=bar | ||
// eslint-disable-next-line deprecation/deprecation | ||
const httpUrl = attributes[SEMATTRS_HTTP_URL] || attributes[ATTR_URL_FULL]; | ||
const possibleFullUrl = attributes[SEMATTRS_HTTP_URL] || attributes[ATTR_URL_FULL]; | ||
// This is the normalized route name - may not always be available! | ||
const httpRoute = attributes[ATTR_HTTP_ROUTE]; | ||
|
||
const parsedUrl = typeof httpUrl === 'string' ? parseUrl(httpUrl) : undefined; | ||
const url = parsedUrl ? getSanitizedUrlString(parsedUrl) : undefined; | ||
const query = parsedUrl?.search || undefined; | ||
const fragment = parsedUrl?.hash || undefined; | ||
const httpRoute = attributes[ATTR_HTTP_ROUTE] as string | undefined; | ||
|
||
if (typeof httpRoute === 'string') { | ||
return { urlPath: httpRoute, url, query, fragment, hasRoute: true }; | ||
} | ||
|
||
if (kind === SpanKind.SERVER && typeof httpTarget === 'string') { | ||
return { urlPath: stripUrlQueryAndFragment(httpTarget), url, query, fragment, hasRoute: false }; | ||
} | ||
const parsedHttpUrl = typeof possibleFullUrl === 'string' ? parseStringToURLObject(possibleFullUrl) : undefined; | ||
const parsedHttpTarget = | ||
typeof possibleRelativeUrl === 'string' ? parseStringToURLObject(possibleRelativeUrl) : undefined; | ||
|
||
if (parsedUrl) { | ||
return { urlPath: url, url, query, fragment, hasRoute: false }; | ||
if (parsedHttpUrl) { | ||
return [parsedHttpUrl, httpRoute]; | ||
} | ||
|
||
// fall back to target even for client spans, if no URL is present | ||
if (typeof httpTarget === 'string') { | ||
return { urlPath: stripUrlQueryAndFragment(httpTarget), url, query, fragment, hasRoute: false }; | ||
if (parsedHttpTarget) { | ||
return [parsedHttpTarget, httpRoute]; | ||
} | ||
|
||
return { urlPath: undefined, url, query, fragment, hasRoute: false }; | ||
return [undefined, httpRoute]; | ||
} | ||
|
||
/** | ||
|
This file contains 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
This file contains 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
Oops, something went wrong.
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.
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.
h: If we have an httpRoute but no parsedUrl we would return the original name here. I don't know if that is desired.