-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: id generator with separate source of randomness (#1010)
- Loading branch information
1 parent
5bc4100
commit ac8cce1
Showing
2 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
25 changes: 25 additions & 0 deletions
25
python/openinference-instrumentation/tests/test_id_generator.py
This file contains 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,25 @@ | ||
from random import seed | ||
|
||
from opentelemetry.sdk.trace import TracerProvider | ||
from opentelemetry.sdk.trace.export import SimpleSpanProcessor | ||
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter | ||
|
||
from openinference.instrumentation import OITracer, TraceConfig | ||
|
||
|
||
def test_id_generator_is_unaffected_by_seed() -> None: | ||
in_memory_span_exporter = InMemorySpanExporter() | ||
tracer_provider = TracerProvider() | ||
tracer_provider.add_span_processor(SimpleSpanProcessor(in_memory_span_exporter)) | ||
tracer = tracer_provider.get_tracer(__name__) | ||
oi_tracer = OITracer(tracer, TraceConfig()) | ||
n = 10 | ||
for tr in (tracer, oi_tracer): | ||
for _ in range(n): | ||
seed(42) | ||
with tr.start_as_current_span("parent"): | ||
tr.start_span("child").end() | ||
spans = in_memory_span_exporter.get_finished_spans() | ||
assert len(spans) == n * 2 * 2 | ||
assert len(set(span.context.trace_id for span in spans)) == (n + 1) | ||
assert len(set(span.context.span_id for span in spans)) == (n + 1) * 2 |