-
Notifications
You must be signed in to change notification settings - Fork 8
Added OTEL tracing #196
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
Open
davidigandan
wants to merge
14
commits into
main
Choose a base branch
from
dev
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Added OTEL tracing #196
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
722bf3e
Add basic tracing middleware and global control
davidigandan 52cb04d
Instrument on subscribe and add dcid to span attributes
davidigandan cc9ee12
Add spanid and traceid metadata to greylog
davidigandan f7cc658
Add recipe_id to spans
davidigandan 8b2a2f1
Add dev and prod dependencies
davidigandan 0686e28
Remove dcid extract from message and inject to span logic. Will be ad…
davidigandan 2d9e21c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3a5283a
Use plugin configurations to configure connection to OTELCollector
davidigandan 4b999f1
Remove vestigial dcid handling and unnecessary debug statements
davidigandan 4b86715
remove unhelpful docstring
davidigandan 9c13d07
Merge branch 'dev' of https://github.com/DiamondLightSource/python-wo…
davidigandan 3e0b902
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d446e80
imported OTEL config class to common_service
davidigandan 16b0e10
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import functools | ||
| from collections.abc import Callable | ||
|
|
||
| from opentelemetry import trace | ||
| from opentelemetry.propagate import extract | ||
|
|
||
| from workflows.transport.middleware import BaseTransportMiddleware | ||
|
|
||
|
|
||
| class OTELTracingMiddleware(BaseTransportMiddleware): | ||
| def __init__(self, tracer: trace.Tracer, service_name: str): | ||
| self.tracer = tracer | ||
| self.service_name = service_name | ||
|
|
||
| def subscribe(self, call_next: Callable, channel, callback, **kwargs) -> int: | ||
| @functools.wraps(callback) | ||
| def wrapped_callback(header, message): | ||
| # Extract trace context from message headers | ||
| ctx = extract(header) if header else None | ||
|
|
||
| # Start a new span with the extracted context | ||
| with self.tracer.start_as_current_span( | ||
| "transport.subscribe", context=ctx | ||
| ) as span: | ||
| span.set_attribute("service_name", self.service_name) | ||
| span.set_attribute("channel", channel) | ||
|
|
||
| # Call the original callback | ||
| return callback(header, message) | ||
|
|
||
| # Call the next middleware with the wrapped callback | ||
| return call_next(channel, wrapped_callback, **kwargs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Potentially uninitialized local variable Error