-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ref(core): Remove transaction name extraction from requestDataIntegration
#11513
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
lforst
merged 7 commits into
develop
from
lms/feat-remove-transactionName-from-requestDataIntegration
Apr 25, 2024
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f5c0816
feat(core): Remove transaction name extraction from requestDataIntegr…
Lms24 65e07a1
format
Lms24 f12aa7f
remove another event.transaction assignment
Lms24 3e94c5e
Merge remote-tracking branch 'origin/develop' into lms/feat-remove-tr…
lforst d76edc6
Remove incorrect assertions
lforst 2d61a45
Fix nextjs transaction names
lforst 49baed5
review comment
lforst 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 hidden or 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 |
---|---|---|
@@ -1,8 +1,7 @@ | ||
import type { Client, IntegrationFn, Span } from '@sentry/types'; | ||
import type { IntegrationFn } from '@sentry/types'; | ||
import type { AddRequestDataToEventOptions, TransactionNamingScheme } from '@sentry/utils'; | ||
import { addRequestDataToEvent, extractPathForTransaction } from '@sentry/utils'; | ||
import { addRequestDataToEvent } from '@sentry/utils'; | ||
import { defineIntegration } from '../integration'; | ||
import { spanToJSON } from '../utils/spanUtils'; | ||
|
||
export type RequestDataIntegrationOptions = { | ||
/** | ||
|
@@ -67,12 +66,11 @@ const _requestDataIntegration = ((options: RequestDataIntegrationOptions = {}) = | |
|
||
return { | ||
name: INTEGRATION_NAME, | ||
processEvent(event, _hint, client) { | ||
processEvent(event, _hint, _client) { | ||
// Note: In the long run, most of the logic here should probably move into the request data utility functions. For | ||
// the moment it lives here, though, until https://github.com/getsentry/sentry-javascript/issues/5718 is addressed. | ||
// (TL;DR: Those functions touch many parts of the repo in many different ways, and need to be clened up. Once | ||
// that's happened, it will be easier to add this logic in without worrying about unexpected side effects.) | ||
const { transactionNamingScheme } = _options; | ||
|
||
const { sdkProcessingMetadata = {} } = event; | ||
const req = sdkProcessingMetadata.request; | ||
|
@@ -83,38 +81,7 @@ const _requestDataIntegration = ((options: RequestDataIntegrationOptions = {}) = | |
|
||
const addRequestDataOptions = convertReqDataIntegrationOptsToAddReqDataOpts(_options); | ||
|
||
const processedEvent = addRequestDataToEvent(event, req, addRequestDataOptions); | ||
|
||
// Transaction events already have the right `transaction` value | ||
if (event.type === 'transaction' || transactionNamingScheme === 'handler') { | ||
return processedEvent; | ||
} | ||
|
||
// In all other cases, use the request's associated transaction (if any) to overwrite the event's `transaction` | ||
// value with a high-quality one | ||
const reqWithTransaction = req as { _sentryTransaction?: Span }; | ||
const transaction = reqWithTransaction._sentryTransaction; | ||
if (transaction) { | ||
const name = spanToJSON(transaction).description || ''; | ||
|
||
// TODO (v8): Remove the nextjs check and just base it on `transactionNamingScheme` for all SDKs. (We have to | ||
// keep it the way it is for the moment, because changing the names of transactions in Sentry has the potential | ||
// to break things like alert rules.) | ||
const shouldIncludeMethodInTransactionName = | ||
getSDKName(client) === 'sentry.javascript.nextjs' | ||
? name.startsWith('/api') | ||
: transactionNamingScheme !== 'path'; | ||
|
||
const [transactionValue] = extractPathForTransaction(req, { | ||
path: true, | ||
method: shouldIncludeMethodInTransactionName, | ||
customRoute: name, | ||
}); | ||
|
||
processedEvent.transaction = transactionValue; | ||
} | ||
|
||
return processedEvent; | ||
return addRequestDataToEvent(event, req, addRequestDataOptions); | ||
}, | ||
}; | ||
}) satisfies IntegrationFn; | ||
|
@@ -166,15 +133,3 @@ function convertReqDataIntegrationOptsToAddReqDataOpts( | |
}, | ||
}; | ||
} | ||
|
||
function getSDKName(client: Client): string | undefined { | ||
try { | ||
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. Why did we even do this before here 😅 but I guess it is just not needed because we always set this directly now, right? |
||
// For a long chain like this, it's fewer bytes to combine a try-catch with assuming everything is there than to | ||
// write out a long chain of `a && a.b && a.b.c && ...` | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
return client.getOptions()._metadata!.sdk!.name; | ||
} catch (err) { | ||
// In theory we should never get here | ||
return undefined; | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.