-
Notifications
You must be signed in to change notification settings - Fork 601
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
allow a user-defined function for providing span attributes on engine/connect span begin #2733
base: main
Are you sure you want to change the base?
allow a user-defined function for providing span attributes on engine/connect span begin #2733
Conversation
…/connect span begin
hey @shalevr - do you think you'd be able to review this sometime soon? Happy to create an issue if you need additional context |
I'm a bit confused with the behavior of this custom sampler. Would you be able to provide a specific example? Can't you achieve this behavior with a custom ParentBased sampler? |
hey @lzchen sorry I missed this. Yes, I am getting the behavior with a custom ParentBased sampler, but the sample decision depends on the attributes, and I currently can't provide attributes to the OTEL-sqlalchemy spans. The sampler code looks like this:
And the idea is that I want to sample X% of the time in general but if I pass in the relevant attributes I can force record and sample or force drop. This is generally helpful for hot library code where I don't want to pay the overhead of tracing unless a span is already active via app code. Currently I'm somewhat blocked on sqlalchemy instrumentation because I don't want to pay that overhead cost on 5% of all sqlalchemy function calls (which is what the ratio is set at in production). |
Description
Add
attrs_provider
as an optional kwarg forSQLAlchemyInstrumentor().instrument
. Ifattrs_provider
(a 0 argument callable) is provided, it will be evaluated before any calls to start_current_span within the engine or connection instrumentation. This allows users who have an attribute aware sampler to inject attributes into the sampler to control sample behavior.Specifically, for my usecase, I have a subclass of the
ParentBasedTraceIdRatio
calledOverrideableParentBasedTraceIdRatio
which allows passing of an 'x-ignore-sample' attribute which forces the sampler to emit a DROP decision when the parent is not already sampled. I would like to force all SqlAlchemy spans to be dropped unless the parent is sampled, which necessitates this change.Fixes #2788
Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.