-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat(am): Introduce startTransaction #2600
Conversation
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.
I'm excited we're doing this - I think it will make using tracing a lot easier! 🎉
First pass, just a bunch of suggestions wordsmithing docstrings and comments.
Co-authored-by: Katie Byers <katie.byers@sentry.io>
Co-authored-by: Katie Byers <katie.byers@sentry.io>
❤️ |
Thinking a bit about how those two arguments interact together and how people will use them. active.finish(undefined, /*trimEnd*/ true); IMHO that's a bit too smart code. The reason to have Could we use the same explicit |
Agree with Rodolfo. What I'd use instead is the options object (changing it for |
I'd be interested in alternatives to modifying transaction events if they're no longer reaching The use case for this is in getsentry/sentry#18822 |
I don't want to go too much off-topic, but I also don't like this PR becoming a huge amount of changes all at once. If this PR is changing the behavior of I suspect the second option is easier.
There are other mechanisms in the SDKs that take in a raw "event".
(consider all those rhetorical questions for now, I'd rather discuss them separately instead of condensing all into one XXL PR) |
@dashed there is a solution to this problem. The thing is exactly for that reason we do not want to expose it so ppl don't rely on it. Otherwise we can probably never move to individual Span ingestion. @rhcarvalho Then let's finish reviewing it so I can merge ^^
|
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.
The PR as is in the current state is ready to be merged. We can further discuss any changes once we merge it, so that we don't prevent other work from happening.
I don't quite follow. 🤔 How does changing the |
@dashed I will add you to the PR in Sentry. |
Motivation
The current SDK API can be very confusing when it comes to usage and it wasn't clear what the difference between a
Transaction
andSpan
is. This PR should align with the clarity and descriptions we now use in the AM docs getsentry/sentry-docs#1667tl;dr
Transaction
/Span
startSpan
with some properties)Public API:
Sentry.startTransaction()
→ returnsTransaction
objecttransactionObj.startChild()
for a child span of the root orspanObj.startChild()
for a child span of a lower-level span→ returnsSpan
objectspanObj.finish()
transactionObj.finish()
transactionObj.setX()
orspanObj.setX()
ApmIntegrations.Tracing()
Integrations.VueIntegration({ Vue, tracing: true })
Integrations.Http({ tracing: true })
Apm.Integrations.Express({ app })
User Entry Point
Sentry.startTransaction
A span on the Scope
Previously it was the case that if a Span was on the Scope it was considered to be the Transaction / an entry point for
hub.startSpan
calls to add children to the span on the Scope.This is a very magic and breaking behavior (what if there is suddenly no more span on the scope, what if it changes).
The way this PR utilizes this is that it considers whatever span is on Scope to take as the Trace / parent_span_id for newly created Transactions.
Right now the TracingIntegration starts a trace and sets an empty Span on the Scope (as the "trace"). With that, we make sure all succeeding Transactions are part of the same trace. The Integration keeps track of any ongoing Transaction itself. The Transaction and all children will have the same Trace ID.
Users should never interact with
hub.startSpan
*Unless they really know what they are doing
The Entrypoint is meant to be
Sentry.startTransaction
only. From there they create child Spans. After theyfinish()
the Transaction we flush it.Node Usage
Can be found in this example https://github.com/kamilogorek/express-apm-playground
tl;dr for Express. User needs to import and use the
@sentry/apm
package.We create a transaction and set it on the Scope and set a function on the Response called
getTransaction
. Users usegetTransaction
if they want to add child Spans to it.Code:
Few other fixes
contexts.trace
TracingIntegration
: RenameddiscardBackgroundSpans
tomarkBackgroundTransactions
span.finish(endTimestamp?: number): void
finish
method receives optional endTimestamp (to be able to have another finish point than call time of the function [helpful in integrations])TransactionContext
receives atrimEnd?: boolean
property that is helpful for Browser and the IdleTransaction. This will be used to tell the Transaction to use the timestamp of the last Span instead of the timestamp of whenfinish()
was called.Span
to reflect what they really aretimestamp
->endTimestamp
(JSON payload still looks the same)Transaction
events no longer go throughbeforeSend
-> Motivation: This shouldn't have been there in the first place. If we ever want to move to individual Span ingestion, we can't users rely on using this forTransaction
. Since Tracing is still considered beta, we are ok "breaking" this for now if users relied on that.