-
Notifications
You must be signed in to change notification settings - Fork 651
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
Add instrumentor and auto instrumentation support for aiohttp #1075
Conversation
* add an instrumentor for aiohttp client sessions * the instrumentor will wrap the ClientSession constructor and automatically a TraceConfig on construction
""" | ||
# pylint:disable=unused-argument | ||
def instrumented_init(wrapped, instance, args, kwargs): | ||
if context_api.get_value("suppress_instrumentation"): |
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.
We also have this check in instrumented methods. Does this exist to prevent instrumenting libraries in the first place or to prevent generating spans for certain code paths? I think it's the later. In other words, I think we should still instrument the libraries but instrumentation itself should check for this for each request and skip generating spans in case.
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.
once AioHttpClientInstrumentor().instrument()
is called, the library is always instrumented. this check just supresses instrumentation for a single ClientSession
.
aiohttp
already comes with built in hooks for instrumenting certain aspects. To make use of these hooks one has to pass one or more TraceConfig
objects to the ClientSession
constructor. The AioHttpClientInstrumentor
piggybacks on this mechanism by wrapping the ClientSession
constructor to automatically add a TraceConfig
with the respective hooks every time a ClientSession
is created. The suppress_instrumentation
is to exclude single ClientSession
s from being instrumented.
span_name=span_name, | ||
tracer_provider=tracer_provider, | ||
) | ||
trace_config.opentelemetry_aiohttp_trace_config = True |
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.
Perhaps something like trace_config.opentelemetry_aiohttp_instrumented
is more descriptive?
Description
Current
aiohttp-client
instrumentation requires to explicitly create aTraceConfig
and pass it to the constructor of aClientSession
.This PR introduces an instrumentor for aiohttp
ClientSession
s which automatically adds aTraceConfig
when aClientSession
is created.Also adds the entry point for auto-instrumenting aiohttp client sessions.
Type of change
How Has This Been Tested?
Manual tests + additional unit tests
Checklist: