Skip to content

Commit

Permalink
Update tests to use new ids generator
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanielRN committed Sep 24, 2020
1 parent 4da075c commit 4a643e0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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,
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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"

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 7 additions & 4 deletions opentelemetry-sdk/tests/trace/propagation/test_b3_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand All @@ -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):
Expand Down

0 comments on commit 4a643e0

Please sign in to comment.