Skip to content

Commit

Permalink
add extra test
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Stella committed Feb 14, 2021
1 parent 0f8b791 commit 9239938
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,40 @@ def test_fields(self, mock_get_current_span):
inject_fields.add(call[1][1])

self.assertEqual(FORMAT.fields, inject_fields)


@patch("opentelemetry.exporter.datadog.propagator.get_current_span")
def test_trace_state_not_none(self, mock_get_current_span):
"""Make sure the fields attribute returns the fields used in inject"""

tracer = trace.TracerProvider().get_tracer("sdk_tracer_provider")

mock_set_in_carrier = Mock()

mock_get_current_span.configure_mock(
**{
"return_value": Mock(
**{
"get_span_context.return_value": None,
"context.trace_flags": 0,
"context.trace_id": 1,
"context.trace_state": {constants.DD_ORIGIN: None},
}
)
}
)

with tracer.start_as_current_span("parent"):
with tracer.start_as_current_span("child"):
FORMAT.inject(mock_set_in_carrier, {})

inject_fields = set()

for call in mock_set_in_carrier.mock_calls:
inject_fields.add(call[1][1])

# verify 'x-datadog-origin' is not present, it was None
expected_fields = FORMAT.fields.copy()
expected_fields.discard('x-datadog-origin')

self.assertEqual(expected_fields, inject_fields)

0 comments on commit 9239938

Please sign in to comment.