sentry-docs
sentry-docs copied to clipboard
Document how to associate `sentry-trace` with manual instrumentation
We need to document how to associate the sentry-trace
if using manual instrumentation for Java, .NET, React Native and other SDKs if possible.
just a Java example:
// assume there's a span/transaction or just create a new one
final ISpan activeSpan = hub.getSpan();
final SentryTraceHeader sentryTraceHeader = activeSpan.toSentryTrace();
// assume you can intercept the request call and add its spans header
request.getHeaders().add(sentryTraceHeader.getName(), sentryTraceHeader.getValue());
activeSpan.finish();
cc @bruno-garcia @jennmueng @maciejwalkowiak @Tyrrrz @brustolin
@marandaneto Let's sync on this before you do it. My work on the dynamic sampling/tracestate headers will likely come into play.
.NET example:
using var httpClient = new HttpClient(new SentryHttpMessageHandler());
I think this is pretty unique to .NET though.
One can also do this fully manually:
var span = hub.GetSpan();
var traceHeader = span.GetTraceHeader();
using var request = new HttpRequestMessage(HttpMethod.Get, "...");
request.Headers.Add("sentry-trace", traceHeader.ToString());
span.Finish();
@maciejwalkowiak how would we do it on Java right now? is my code snippet accurate?
If the snippet is about creating a span around HTTP call, it think we should also show how to start a child span, set the status and finish. Like its done here: https://github.com/getsentry/sentry-java/blob/main/sentry-spring/src/main/java/io/sentry/spring/tracing/SentrySpanClientHttpRequestInterceptor.java#L38
that makes total sense, I just wanted to be sure that the important bits are correct which is:
final SentryTraceHeader sentryTraceHeader = activeSpan.toSentryTrace();
request.getHeaders().add(sentryTraceHeader.getName(), sentryTraceHeader.getValue());
FYI - IDK how soon it will be released, but once my dynamic sampling work on the tracestate
header goes out, toSentryTrace
will be deprecated in favor of getTraceHeaders
, which will return both the sentry-trace
and tracestate
headers.
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog
or Status: In Progress
, I will leave it alone ... forever!
"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀
It's not clear to me how to instantiate a trace from a request with the SentryTraceHeader - is there any documentation on this?
@crummy indeed, thanks for reporting this, subscribe to this issue please https://github.com/getsentry/sentry-java/issues/1346
@lobsterkatie mind reviewing https://github.com/getsentry/sentry-docs/pull/3324 ? we've got questions from multiple people already so we need to tackle this at least for the Java SDK
Wanna implement manual passing trace_id for Python Sanic requests (sentry's integration do nothing here), but can't find any info about header name to pass trace_id. What's the name of default sentry trace header?
@Olegt0rr it's the PR's title, sentry-trace
Keeping it open as a placeholder for other platforms, it's still not documented for the other SDKs other than Java/Android afaik.
This should be common content and just the code snippet would change per platform, only relevant for server-side SDKs. Java is already done but should adapt to the common content.
Would be great to see some info about this in the node
and serverless (node)
docs. I've been digging into the code for days trying to figure out how to get traces to be passed from one lambda through into another when calling them via the AWS SDK instead of HTTP.
:+1: me too. I've got the sentry trace-id header going from my SPA to graphql backend but unable to make use of it in the backend. I'm seeing it in my console.logs() but doing stuff like the below is doing nothing (yes, the value is being retrieved correctly). Tried a bunch of different ways of using it besides that. There are no docs on how to do this properly.
context.transaction = Sentry.startTransaction({
op: 'gql',
name: request.operationName,
traceId: request.http.headers.get('sentry-trace')
})
Edit: actually finally got this working after taking a break and coming back and reading what the Express integration does.
import { extractTraceparentData } from '@sentry/tracing'
...
const traceparentData = extractTraceparentData(request.http.headers.get('sentry-trace'))
context.transaction = Sentry.startTransaction({
op: 'gql',
name: 'GraphQLTransaction',
...traceparentData
})
Then it worked. Very easy, but some docs would have prevented hours of digging.
knowing how to get the current sentry-trace id would also be helpful.
Once use case i have is for not rest calls
It seems like the docs at https://docs.sentry.io/platforms/node/guides/aws-lambda/performance/connect-services/ have been updated with instructions for generating a header via span.toTraceparent
… I assume this includes both sentry-trace
and the poorly-documented baggage
header but I haven't had a chance to test this or figure out how to it will affect things if I start a transaction inside of another (as there is no way to pass this info at the request level for things like AWS lambda invocations, e.g. https://github.com/getsentry/sentry-javascript/issues/7701).
👍 me too. I've got the sentry trace-id header going from my SPA to graphql backend but unable to make use of it in the backend. I'm seeing it in my console.logs() but doing stuff like the below is doing nothing (yes, the value is being retrieved correctly). Tried a bunch of different ways of using it besides that. There are no docs on how to do this properly.
context.transaction = Sentry.startTransaction({ op: 'gql', name: request.operationName, traceId: request.http.headers.get('sentry-trace') })
Edit: actually finally got this working after taking a break and coming back and reading what the Express integration does.
import { extractTraceparentData } from '@sentry/tracing' ... const traceparentData = extractTraceparentData(request.http.headers.get('sentry-trace')) context.transaction = Sentry.startTransaction({ op: 'gql', name: 'GraphQLTransaction', ...traceparentData })
Then it worked. Very easy, but some docs would have prevented hours of digging.
👍 me too. I've got the sentry trace-id header going from my SPA to graphql backend but unable to make use of it in the backend. I'm seeing it in my console.logs() but doing stuff like the below is doing nothing (yes, the value is being retrieved correctly). Tried a bunch of different ways of using it besides that. There are no docs on how to do this properly.
context.transaction = Sentry.startTransaction({ op: 'gql', name: request.operationName, traceId: request.http.headers.get('sentry-trace') })
Edit: actually finally got this working after taking a break and coming back and reading what the Express integration does.
import { extractTraceparentData } from '@sentry/tracing' ... const traceparentData = extractTraceparentData(request.http.headers.get('sentry-trace')) context.transaction = Sentry.startTransaction({ op: 'gql', name: 'GraphQLTransaction', ...traceparentData })
Then it worked. Very easy, but some docs would have prevented hours of digging.
Thanks bro! You saved my time! Would be good to have some examples of using custom instrumentation in the sentry docs