Skip to content

ref: Add hub.startTransaction extension #2626

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
merged 8 commits into from
Jun 2, 2020

Conversation

rhcarvalho
Copy link
Contributor

@rhcarvalho rhcarvalho commented May 29, 2020

This probably replaces #2625.

  • Remove Transaction._isTransaction because the only way this was used is equivalent to calling Hub.startTransaction.
  • Instead of warning of missing name when starting a transaction, move the warning to right before the transaction is sent to Sentry, because it is a valid use case to start without a name and set it later (e.g. when the final name is not known until after the transaction is started).
  • Extract code that starts transactions from startSpan. The recommended way to start transactions is through Sentry.startTransaction or Hub.startTransaction, and to start spans call Transaction.startChild.

Moving the check to the func where it matters eliminates the need for
the internal field _isTransaction and the downstream logic in startSpan.
Shorter message equals smaller bundle size.
Limit ourselves to a single warning line.

The fix to eliminate the warning is to call
  startTransaction({name: "some name"})
so the setName advice is misplaced.
Extract code that starts transactions from startSpan and deprecate
startSpan.

Move check of empty transaction name to right before sending the
transaction, because it is valid to start the transaction without a name
and set the name later with Transaction.setName().
@rhcarvalho rhcarvalho requested review from HazAT and kamilogorek May 29, 2020 09:27
Copy link
Member

@HazAT HazAT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logger.warn('Will fall back to <unlabeled transaction>, use `transaction.setName()` to change it.');
(context as TransactionContext).name = '<unlabeled transaction>';
}
logger.warn('Deprecated: Use startTransaction to start transactions and Transaction.startChild to start spans.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only log this in case of an transaction

* with the transaction poperty set.
*/
if ((context as any).transaction !== undefined) {
logger.warn(`Use \`Sentry.startTransaction({name: ${(context as any).transaction}})\` to start a Transaction.`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a confusing syntax :3

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

y? ^^

@HazAT HazAT mentioned this pull request Jun 2, 2020
@HazAT HazAT changed the title ref: Add hub.startTransaction extension and deprecate startSpan ref: Add hub.startTransaction extension Jun 2, 2020
@kamilogorek kamilogorek self-requested a review June 2, 2020 09:26
@HazAT HazAT merged commit 727da28 into master Jun 2, 2020
@HazAT HazAT deleted the rhcarvalho/start-transaction-on-hub branch June 2, 2020 09:49
rhcarvalho added a commit that referenced this pull request Jun 8, 2020
Follow up on #2626.

Now that startTransaction exists, replace usages of startSpan where the intention is to create a transaction.

Additionally, documentation updates and some refactoring to minimize type castings and linter flag usage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants