Closed goleary closed 4 months ago
It looks like the primsa instrumentation does not use that tracer that's passed in, but gets the tracer directly from the API. This does not look like it's a bug in registerInstrumentation()
.
Is there a specific reason why you want to sample traces that are created by the Prisma instrumentation, but not your own? The sampled flag is part of the trace context, as it's not common to sample part of a trace (dropping prisma spans sometimes, keeping all manually instrumented spans, if I understand correctly) - that's also one of the reasons why Span ID is not part of the sampling decision. Telemetry will be inconsistent this way and it'll always look like there's stuff missing.
Got it, yeah looks like a bug on Prisma's implementation, guess we can close this one. Thanks for the quick response and investigation!
The reason I have it set up this way is that I want to use sampling on Prisma traces because we generate tons of them and I do not want to affect the performance of our application, nor do we actually need all of the. I do NOT want to sample the manually instrumented traces because we only use them for certain key processes where we want as much visibility as possible.
Not sure I understand what you're suggesting. My assumption is that because the sampling is configured on the provider and that if I have two separate providers then I should be able to sample certain traces and not others. Is there some other way I can achieve this behavior?
hey @pichlermarc I closed the issue because I don't believe it's a problem with this repo, but I would still love you input on the above when you get a second 🙏
The reason I have it set up this way is that I want to use sampling on Prisma traces because we generate tons of them and I do not want to affect the performance of our application, nor do we actually need all of the. I do NOT want to sample the manually instrumented traces because we only use them for certain key processes where we want as much visibility as possible. Not sure I understand what you're suggesting. My assumption is that because the sampling is configured on the provider and that if I have two separate providers then I should be able to sample certain traces and not others. Is there some other way I can achieve this behavior?
The reason I have it set up this way is that I want to use sampling on Prisma traces because we generate tons of them and I do not want to affect the performance of our application, nor do we actually need all of the. I do NOT want to sample the manually instrumented traces because we only use them for certain key processes where we want as much visibility as possible.
Not sure I understand what you're suggesting. My assumption is that because the sampling is configured on the provider and that if I have two separate providers then I should be able to sample certain traces and not others. Is there some other way I can achieve this behavior?
Ah I see. The Sampler
is a user-implementable interface for that reason. You could implement a sampler that in essence delegates to a AlwaysOnSampler
for your own spans and a TraceIdBasedRatioSampler
for the others (you could distingush them by their attributes, or by span name).
Then you can combine that with a ParentBasedSampler
that will delegate the sampling decision to the your custom sampler if the span is a root span.
This way traces you started will always be kept, and traces you did not start will not be kept in n% of cases. This way you have one TracerProvider
with a custom sampler that will make a sampling decision based on your criteria (and respect previous sampling decisions to avoid broken traces).
mmm that makes a lot of sense, I'll look into doing that.
The reason I didn't see my setup as being problematic is that the Prisma traces and our manual traces are entirely separate, neither is a parent of the other, so we wouldn't get into a situation where part of a trace disappears, but it sounds like y'all have better way to deal with this type of situation.
Thanks!!
I implemented a Sampler
like you suggested and it works great, thanks again for the guidance!
Glad I could help :)
What happened?
Steps to Reproduce
Create an open telemetry setup with 2 providers. Register one globally and pass the other as
tracerProvider
toregisterInstrumentations
Then run a process which results in the instrumentation generating traces.
Expected Result
The instrumentation will only write to the provider passed as
tracerProvider
Actual Result
The instrumentation writes to the global provider (defaultProvider
Additional Details
Basically I want to sample the traces coming from from Prisma, but I do not want to sample the traces that we manually instrument via
wrapWithSpan
etc. Not sure if there is some other way to achieve this, but it's very confusing that the provider I pass in toregisterInstrumentaitons
is not used.OpenTelemetry Setup Code
package.json
Relevant log output