Skip to content
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

Prevent duplicate telemetry when using both library and auto instrumentation #2661

Merged

Conversation

mateuszrzeszutek
Copy link
Member

Fixes #903

I've removed the library instrumentation shading (io.opentelemetry.instrumentation.*); instrumentation-api is still shaded though (io.opentelemetry.instrumentation.api.*).
Since now the agent will disable the javaagent instrumentation when it encounters a library class I think that this offers a similar level of safety as shading everything.

Comment on lines +190 to +193
// TODO: optimization: refactor matcher caching, only the matcher returned by this method should
// cache results, the intermediary ones don't need to cache anything
// right now every matcher returned from ClassLoaderMatcher caches separately
// this will also make those "Skipping ..." logs appear less
Copy link
Member Author

Choose a reason for hiding this comment

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

Will be done in next PR

@mateuszrzeszutek mateuszrzeszutek force-pushed the prevent-duplicate-telemetry branch from 443b7c7 to 6fb98a5 Compare March 31, 2021 08:45
return classLoaderMatcher().and(not(libraryMatcher));
}

private void logLibraryInstrumentationDetected() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Mmm, if we don't shade library instrumentations, we will detect those classes from within our javaagent jar, no? Or am I asking nonsense?

Copy link
Member Author

Choose a reason for hiding this comment

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

We won't, because they're in the agent classloader.

@mateuszrzeszutek mateuszrzeszutek force-pushed the prevent-duplicate-telemetry branch from 6fb98a5 to 4083520 Compare March 31, 2021 15:14
@mateuszrzeszutek
Copy link
Member Author

(Rebasing to make those context-leak-failing tests pass)

@mateuszrzeszutek
Copy link
Member Author

There's also the matter of testing this: I thought of adding a testSet that contains the library instrumentation and basically running the same test as the library instrumentation module - any duplicate telemetry would fail the tests.

Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

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

nice 👍

@trask trask merged commit 3043469 into open-telemetry:main Mar 31, 2021
@mateuszrzeszutek mateuszrzeszutek deleted the prevent-duplicate-telemetry branch March 31, 2021 17:58
@anuraaga
Copy link
Contributor

anuraaga commented Apr 1, 2021

Sorry for very late review - are we confident classpath is a good enough signal to back off? For example, I might depend on a library which uses gRPC, and actually initializes gRPC library instrumentation itself as part of its own best practices, but that doesn't mean my own handlers will have it applied. So I thought we were going to need to go with an approach where the agent detects whether the library instrumentation is actually being used, not just the class presence.

@trask
Copy link
Member

trask commented Apr 1, 2021

ah, that's a good point

@mateuszrzeszutek
Copy link
Member Author

Oh, that is an excellent point...

And the worst thing is that there's no reasonable workaround for that scenario: you can't exclude the grpc library instrumentation because the library that uses it will break.

Hmm, I'll probably revert this and go back to the drawing board.

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.

Prevent duplicate telemetry when using both library and auto instrumentation
4 participants