Skip to content

Commit

Permalink
Add test case for trace_context
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Nov 13, 2020
1 parent fbcd55c commit 19ee9fa
Showing 1 changed file with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import typing
import unittest
from unittest.mock import Mock, patch

from opentelemetry import trace
from opentelemetry.trace.propagation import tracecontext
Expand Down Expand Up @@ -232,7 +233,8 @@ def test_tracestate_keys(self):
carrier_getter,
{
"traceparent": [
"00-12345678901234567890123456789012-1234567890123456-00"
"00-12345678901234567890123456789012-"
"1234567890123456-00"
],
"tracestate": [tracestate_value],
},
Expand All @@ -248,3 +250,33 @@ def test_tracestate_keys(self):
self.assertEqual(
span.get_span_context().trace_state["foo-_*/bar"], "bar4"
)

@patch("opentelemetry.trace.INVALID_SPAN_CONTEXT")
@patch("opentelemetry.trace.get_current_span")
def test_fields(self, mock_get_current_span, mock_invalid_span_context):

mock_span_context = Mock(
**{
"trace_id": 1,
"span_id": 2,
"trace_flags": 3,
"trace_state": {"a": "b"}
}
)

mock_span = Mock(
**{"get_span_context.return_value": mock_span_context}
)

mock_get_current_span.configure_mock(return_value=mock_span)

mock_set_in_carrier = Mock()

FORMAT.inject(mock_set_in_carrier, {})

inject_fields = set()

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

self.assertEqual(inject_fields, FORMAT.fields)

0 comments on commit 19ee9fa

Please sign in to comment.