-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Add helper for old api to guide users to startTransaction #2625
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 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 |
---|---|---|
|
@@ -20,20 +20,27 @@ function traceHeaders(this: Hub): { [key: string]: string } { | |
} | ||
|
||
/** | ||
* This functions starts a span. If there is already a `Span` on the Scope, | ||
* the created Span with the SpanContext will have a reference to it and become it's child. | ||
* Otherwise it'll crete a new `Span`. | ||
* | ||
* @param context Properties with which the span should be created | ||
* {@see Hub.startSpan} | ||
*/ | ||
function startSpan(this: Hub, context: SpanContext | TransactionContext): Transaction | Span { | ||
/** | ||
* @deprecated | ||
* We have this here as a fallback to not break users upgrading to the new API | ||
*/ | ||
if ((context as any).transaction !== undefined) { | ||
logger.warn(`Use \`Sentry.startTransaction({name: ${(context as any).transaction}})\` to start a Transaction.`); | ||
(context as TransactionContext).name = (context as any).transaction as string; | ||
(context as TransactionContext)._isTransaction = true; | ||
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 may not have fully understood this from previous PRs. What does it mean for a 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. We have another safeguard using when people call Since everything goes through |
||
} | ||
|
||
// This is our safeguard so people always get a Transaction in return. | ||
// We set `_isTransaction: true` in {@link Sentry.startTransaction} to have a runtime check | ||
// if the user really wanted to create a Transaction. | ||
if ((context as TransactionContext)._isTransaction && !(context as TransactionContext).name) { | ||
logger.warn('You are trying to start a Transaction but forgot to provide a `name` property.'); | ||
logger.warn('Will fall back to <unlabeled transaction>, use `transaction.setName()` to change it.'); | ||
(context as TransactionContext).name = '<unlabeled transaction>'; | ||
const name = '<unlabeled transaction>'; | ||
logger.warn(`Will fall back to \`${name}\``); | ||
(context as TransactionContext).name = name; | ||
} | ||
|
||
if ((context as TransactionContext).name) { | ||
|
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.
Does this work in the middle of the func body? Did you mean to put if above the func signature?
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.
It's more a marker for us once we have a major bump to delete this block and document the breaking change.