fix(otel): Use id generator fallback#467
Open
wangyb-A wants to merge 2 commits into
Open
Conversation
c5166fe to
a200401
Compare
zhongkechen
previously approved these changes
Jun 11, 2026
a0c53e9 to
577905a
Compare
Import TracerProvider from opentelemetry.sdk.trace instead of the API base class so id_generator and sampler attributes resolve correctly under mypy. Make DeterministicIdGenerator subclass RandomIdGenerator for type compatibility with the provider's id_generator attribute. Change DeterministicIdGenerator to fall back to the tracer provider's original id generator rather than always creating a new RandomIdGenerator. The plugin now captures the provider's existing generator and passes it as the fallback before overwriting it. Add unit tests covering the fallback behavior and update existing tests to reference the renamed _fallback_id_generator attribute.
zhongkechen
approved these changes
Jun 12, 2026
| @@ -67,19 +67,25 @@ def operation_id_to_span_id(operation_id: str) -> int: | |||
|
|
|||
| class DeterministicIdGenerator(RandomIdGenerator): | |||
Contributor
There was a problem hiding this comment.
The base class was to make type checker happy. But I feel it's not correct
| 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.
Will the threading issue be addressed in a separate PR?
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Import TracerProvider from opentelemetry.sdk.trace instead of the API
base class so id_generator and sampler attributes resolve correctly
under mypy. Make DeterministicIdGenerator subclass RandomIdGenerator
for type compatibility with the provider's id_generator attribute.
Change DeterministicIdGenerator to fall back to the tracer provider's
original id generator rather than always creating a new
RandomIdGenerator. The plugin now captures the provider's existing
generator and passes it as the fallback before overwriting it.
Add unit tests covering the fallback behavior and update existing
tests to reference the renamed _fallback_id_generator attribute.
Issue #, if available: close #426
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.