-
Notifications
You must be signed in to change notification settings - Fork 849
feat: add commenter_for_all_spans option to enable SQLCommenter for non-recording spans
#4090
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
base: main
Are you sure you want to change the base?
Conversation
…enter for non-recording spans
...tion/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py
Outdated
Show resolved
Hide resolved
...tion/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py
Outdated
Show resolved
Hide resolved
| and (span.is_recording() or self._commenter_for_all_spans) | ||
| ) | ||
|
|
||
| if should_comment: |
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.
Is there a way to make these nested if-else blocks (here and in sqlalchemy) more concise? If the original code gets chopped up a bit then it's fine as long as the tests continue to pass 🙂
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.
I refactored it a little bit, let me know if it is better
|
This is looking good and I really appreciate the docs updates and comments so far. Just left one minor suggestion. |
commenter_for_nonrecording_spans option to enable SQLCommenter for non-recording spanscommenter_for_all_spans option to enable SQLCommenter for non-recording spans
Description
Add
commenter_for_all_spansoption to SQLAlchemy and DBAPI instrumentations, enabling SQLCommenter to add SQL comments (includingtraceparent) for not sampled spans.Motivation: By default, SQLCommenter only adds comments when
span.is_recording()isTrue. This means not sampled spans (e.g., when using a sampling rate < 100%) don't get SQL comments. However, some users wanttraceparentpropagated in SQL comments for all requests regardless of sampling decision, enabling database-side correlation with distributed traces.Changes:
commenter_for_all_spansparameter (default:False) to both SQLAlchemy and DBAPI instrumentationsspan.is_recording()isTrue(existing behavior preserved)Type of change
How Has This Been Tested?
Added unit tests for both instrumentations: