-
Notifications
You must be signed in to change notification settings - Fork 17
fix(otel): Use id generator fallback #467
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
Merged
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,11 +5,11 @@ | |
| import hashlib | ||
| import os | ||
| import re | ||
| from datetime import datetime, UTC | ||
| from datetime import UTC, datetime | ||
|
|
||
| from opentelemetry.sdk.trace import IdGenerator, RandomIdGenerator | ||
|
|
||
| from opentelemetry.sdk.trace import RandomIdGenerator | ||
|
|
||
| HASH_LENGTH = 16 | ||
| HASHED_ID_PATTERN = re.compile(r"^[0-9a-f]{16}$") | ||
|
|
||
|
|
||
|
|
@@ -67,19 +67,25 @@ def operation_id_to_span_id(operation_id: str) -> int: | |
|
|
||
| class DeterministicIdGenerator(RandomIdGenerator): | ||
| """An ID generator that produces deterministic span IDs when a pending | ||
| operation ID is set, and random IDs otherwise. | ||
| operation ID is set, and falls back to the provided generator otherwise. | ||
|
|
||
| Trace IDs are deterministic when an execution ARN is set, ensuring all | ||
| invocations of the same durable execution share a single trace. | ||
| invocations of the same durable execution share a single trace. When no | ||
| deterministic ID is available, generation is delegated to the fallback | ||
| generator (the tracer provider's original ID generator by default). | ||
|
|
||
| Trace IDs embed a real timestamp so they satisfy the X-Ray format | ||
| requirement (first 8 hex chars = Unix epoch seconds). | ||
|
|
||
| Args: | ||
| fallback_id_generator: Generator used when no deterministic ID is | ||
| available. Defaults to a new ``RandomIdGenerator``. | ||
| """ | ||
|
|
||
| def __init__(self) -> None: | ||
| def __init__(self, fallback_id_generator: IdGenerator | None = None) -> None: | ||
| self._next_span_id: int | None = None | ||
| self._execution_trace_id: int | None = None | ||
| self._random_id_generator = RandomIdGenerator() | ||
| self._fallback_id_generator = fallback_id_generator or RandomIdGenerator() | ||
|
|
||
| def set_next_span_id(self, span_id: int | None) -> None: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will the threading issue be addressed in a separate PR?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, threading issue is tracked here: #428 |
||
| """Set the operation ID to use for the next span's ID. | ||
|
|
@@ -101,9 +107,11 @@ def set_trace_id( | |
|
|
||
| def generate_trace_id(self) -> int: | ||
| """Generate a 128-bit trace ID.""" | ||
| return self._execution_trace_id or self._random_id_generator.generate_trace_id() | ||
| return ( | ||
| self._execution_trace_id or self._fallback_id_generator.generate_trace_id() | ||
| ) | ||
|
|
||
| def generate_span_id(self) -> int: | ||
| """Generate a 64-bit span ID.""" | ||
| span_id, self._next_span_id = self._next_span_id, None | ||
| return span_id or self._random_id_generator.generate_span_id() | ||
| return span_id or self._fallback_id_generator.generate_span_id() | ||
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
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.
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.
The base class was to make type checker happy. But I feel it's not correct
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 think the reason is the checker is complaining this like
self._provider.id_generator = self._id_generatorThe provider's id_generator should use the base class, but they are using the
RandomIdGeneratorclassThere 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.
Can you find a way to fix this?