Skip to content

Conversation

tammy-baylis-swi
Copy link
Contributor

@tammy-baylis-swi tammy-baylis-swi commented Mar 10, 2023

PoC: Adds request_hook kwarg to instrument(**kwargs) of all loaded instrumentation libraries at custom distro startup. Not for any ticket in particular and just for visualization. This might mean we have more opportunities for manipulating span creation in addition to what I've written in the doc section How do OTel Python spans get created!

Some but not all OTel Python instrumentation libraries call its received request_hook method "right after a span is created for a request". For Django at least, the span at time of request_hook is mutable _Span and we can change its attributes!

Example stdout, where attributes include the arbitrary request-hook-foo as well as KVs we use for transaction name calculation while the span is still mutable:

Updated span attributes is BoundedAttributes({'request-hook-foo': 'some-bar-value', 'BucketCapacity': '6.800000000000001', 'BucketRate': '0.37400000000000005', 'SampleRate': 1000000, 'SampleSource': 6, 'http.method': 'GET', 'http.server_name': '8e4548baae98', 'http.scheme': 'http', 'net.host.port': 8002, 'http.host': '0.0.0.0:8002', 'http.url': 'http://0.0.0.0:8002/home_a_reentry/', 'net.peer.ip': '192.168.0.1', 'http.user_agent': 'curl/7.86.0', 'http.flavor': '1.1'}, maxlen=128)

Example trace, where the home_a_reentry/, another/, and home_b/ server spans include the arbitrary request-hook-foo attribute added to them by our request_hook method: https://my.na-01.cloud.solarwinds.com/140638900734749696/traces/42FA5A3869B78465B239FAD568A76BCC/04A0226E0217181C/details/breakdown

I don't think this can be used for transaction filtering by way of early DROP because (a) the span has already been created, and (b) anything a request_hook method returns won't be used (how Django calls it here). So returning a NonRecordingSpan can't drop the trace (I've tried this and we still get the same full trace).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant