diff --git a/docs/examples/opentelemetry-example-app/tests/test_flask_example.py b/docs/examples/opentelemetry-example-app/tests/test_flask_example.py index bc903a9c60c..40c7091fa6f 100644 --- a/docs/examples/opentelemetry-example-app/tests/test_flask_example.py +++ b/docs/examples/opentelemetry-example-app/tests/test_flask_example.py @@ -21,7 +21,7 @@ import opentelemetry_example_app.flask_example as flask_example from opentelemetry import trace -from opentelemetry.sdk import trace as trace_sdk +from opentelemetry.sdk.trace.random_ids_generator import RandomIdsGenerator class TestFlaskExample(unittest.TestCase): @@ -46,7 +46,8 @@ def tearDown(self): self.send_patcher.stop() def test_full_path(self): - trace_id = trace_sdk.generate_trace_id() + ids_generator = RandomIdsGenerator() + trace_id = ids_generator.generate_trace_id() # We need to use the Werkzeug test app because # The headers are injected at the wsgi layer. # The flask test app will not include these, and @@ -58,7 +59,7 @@ def test_full_path(self): headers={ "traceparent": "00-{:032x}-{:016x}-{:02x}".format( trace_id, - trace_sdk.generate_span_id(), + ids_generator.generate_span_id(), trace.TraceFlags.SAMPLED, ) }, diff --git a/exporter/opentelemetry-exporter-datadog/tests/test_datadog_format.py b/exporter/opentelemetry-exporter-datadog/tests/test_datadog_format.py index 1a398745b8d..e4b8e720be0 100644 --- a/exporter/opentelemetry-exporter-datadog/tests/test_datadog_format.py +++ b/exporter/opentelemetry-exporter-datadog/tests/test_datadog_format.py @@ -17,6 +17,7 @@ from opentelemetry import trace as trace_api from opentelemetry.exporter.datadog import constants, propagator from opentelemetry.sdk import trace +from opentelemetry.sdk.trace.random_ids_generator import RandomIdsGenerator from opentelemetry.trace import get_current_span, set_span_in_context FORMAT = propagator.DatadogFormat() @@ -30,11 +31,12 @@ def get_as_list(dict_object, key): class TestDatadogFormat(unittest.TestCase): @classmethod def setUpClass(cls): + ids_generator = RandomIdsGenerator() cls.serialized_trace_id = propagator.format_trace_id( - trace.generate_trace_id() + ids_generator.generate_trace_id() ) cls.serialized_parent_id = propagator.format_span_id( - trace.generate_span_id() + ids_generator.generate_span_id() ) cls.serialized_origin = "origin-service" @@ -103,11 +105,13 @@ def test_context_propagation(self): ) self.assertTrue(parent_context.is_remote) + ids_generator = RandomIdsGenerator() + child = trace.Span( "child", trace_api.SpanContext( parent_context.trace_id, - trace.generate_span_id(), + ids_generator.generate_span_id(), is_remote=False, trace_flags=parent_context.trace_flags, trace_state=parent_context.trace_state, @@ -148,11 +152,13 @@ def test_sampling_priority_auto_reject(self): self.assertEqual(parent_context.trace_flags, constants.AUTO_REJECT) + ids_generator = RandomIdsGenerator() + child = trace.Span( "child", trace_api.SpanContext( parent_context.trace_id, - trace.generate_span_id(), + ids_generator.generate_span_id(), is_remote=False, trace_flags=parent_context.trace_flags, trace_state=parent_context.trace_state, diff --git a/opentelemetry-sdk/tests/trace/propagation/test_b3_format.py b/opentelemetry-sdk/tests/trace/propagation/test_b3_format.py index 77834adec97..2c9ccb5bc44 100644 --- a/opentelemetry-sdk/tests/trace/propagation/test_b3_format.py +++ b/opentelemetry-sdk/tests/trace/propagation/test_b3_format.py @@ -17,6 +17,7 @@ import opentelemetry.sdk.trace as trace import opentelemetry.sdk.trace.propagation.b3_format as b3_format +from opentelemetry.sdk.trace.random_ids_generator import RandomIdsGenerator import opentelemetry.trace as trace_api from opentelemetry.context import get_current @@ -34,11 +35,12 @@ def get_child_parent_new_carrier(old_carrier): parent_context = trace_api.get_current_span(ctx).get_context() parent = trace.Span("parent", parent_context) + ids_generator = RandomIdsGenerator() child = trace.Span( "child", trace_api.SpanContext( parent_context.trace_id, - trace.generate_span_id(), + ids_generator.generate_span_id(), is_remote=False, trace_flags=parent_context.trace_flags, trace_state=parent_context.trace_state, @@ -56,14 +58,15 @@ def get_child_parent_new_carrier(old_carrier): class TestB3Format(unittest.TestCase): @classmethod def setUpClass(cls): + ids_generator = RandomIdsGenerator() cls.serialized_trace_id = b3_format.format_trace_id( - trace.generate_trace_id() + ids_generator.generate_trace_id() ) cls.serialized_span_id = b3_format.format_span_id( - trace.generate_span_id() + ids_generator.generate_span_id() ) cls.serialized_parent_id = b3_format.format_span_id( - trace.generate_span_id() + ids_generator.generate_span_id() ) def test_extract_multi_header(self):