-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(instrumentation): add ability to filter span by PrismaLayerType
#20113
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(instrumentation): add ability to filter span by PrismaLayerType
#20113
Conversation
(The failing test in CI is unrelated) |
@janpio all tests are passing now after sync this branch with |
The code changes look good, thanks so much for the contribution! This definitely needs to be tested, would you be able to add some tests, or do you need help with this? |
@aqrln I could add some unit tests but I'm not sure what is the strategy here. The only other tests are pretty basic. Any suggestions? Otherwise I'm happy if you guys want to add specific tests. |
@aqrln tests added. There are failing tests in the ci but they shouldn't be related to these changes |
(Retriggered a run for the failing tests) |
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.
This looks very solid, thank you for adding the tests! What I was having in mind was rather adding some integration tests in packages/client/test/functional/tracing
(sorry for not making this clear, it's not easy to navigate our test structure) but these unit tests should also be very useful. We can add the integration tests ourselves because I don't want to burden you with more work and I'd like to merge this PR soon — but if you are interested and want to, feel free to look into adding them, just let me know!
Co-authored-by: Joël Galeran <[email protected]> Co-authored-by: Pierre-Antoine Mills <[email protected]>
…ensions (prisma#20438) * fix(client): Ensure result extensions are applied after all query extensions Fix prisma#20437 * Move recursive `applyExtensions` into it's own module
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@overbit sorry for not bringing this to the finish line in time for 5.1.0 but this will land in 5.2.0 — I'll make sure to review and merge it soon. |
Any progress? |
@SevInf apologies but I haven't got any time to proceed and resolve your comments. Feel free to take over from here |
For people who got here like me after a while, as it seems Prisma team won't implement any filtering on their own, you can achieve what you want by creating a custom SpanProcessor(/BatchSpanProcessor) like this: import {
ReadableSpan,
SpanExporter,
BatchSpanProcessor,
} from '@opentelemetry/sdk-trace-base';
export class FilteringSpanProcessor extends BatchSpanProcessor {
private spansToFilterOut: RegExp;
constructor(exporter: SpanExporter, spanPatternToFilterOut: string) {
super(exporter);
this.spansToFilterOut = new RegExp(spanPatternToFilterOut);
}
onEnd(span: ReadableSpan): void {
// Filter out spans based on custom criteria
if (this.shouldExport(span)) {
super.onEnd(span);
}
}
private shouldExport(span: ReadableSpan): boolean {
return !this.spansToFilterOut.test(span.name);
}
} and registering it with NodeSdk: new FilteringSpanProcessor(
traceExporter,
// this will filter out anything that starts with prisma: but is not prisma:client:operation or prisma:engine:query/db_query spans
'^(prisma:(?!client:operation|engine:(query|db_query)).*)',
), or filter it out directly in your OTel agent that ingests spans but that often is not possible if you use some paid services. |
Thanks again @overbit for this nice PR! I took the liberty to apply the suggested changes, improve the test suite and slightly updated the functionality to now also support regex based filtering. ;) Filters can be supplied on the new PrismaInstrumentation({
ignoreSpanTypes: [
/prisma:client:ser.*/,
'prisma:client:connect',
'prisma:engine:query',
],
}) Note that if you filter out a parent span all its child spans will also be filtered out. E.g. Tracing docs can be found here: https://www.prisma.io/docs/orm/prisma-client/observability-and-logging/opentelemetry-tracing |
Add ability to filter out some of the instrumentation span generated by prisma
Related #14640
#14640 (comment)