mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-08-02 11:31:52 +08:00
Add test case for DataDog fields and AWS SDK Extension (#231)
This commit is contained in:
@ -275,6 +275,7 @@ class AwsXRayFormat(TextMapPropagator):
|
||||
carrier, TRACE_HEADER_KEY, trace_header,
|
||||
)
|
||||
|
||||
@property
|
||||
def fields(self):
|
||||
"""Returns a set with the fields set in `inject`.
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
import unittest
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from requests.structures import CaseInsensitiveDict
|
||||
|
||||
@ -165,7 +166,7 @@ class AwsXRayPropagatorTest(unittest.TestCase):
|
||||
injected_keys = set(carrier.keys())
|
||||
|
||||
self.assertEqual(
|
||||
injected_keys, AwsXRayPropagatorTest.XRAY_PROPAGATOR.fields()
|
||||
injected_keys, AwsXRayPropagatorTest.XRAY_PROPAGATOR.fields
|
||||
)
|
||||
|
||||
# Extract Tests
|
||||
@ -372,3 +373,35 @@ class AwsXRayPropagatorTest(unittest.TestCase):
|
||||
get_nested_span_context(context_with_extracted),
|
||||
INVALID_SPAN_CONTEXT,
|
||||
)
|
||||
|
||||
@patch(
|
||||
"opentelemetry.sdk.extension.aws.trace."
|
||||
"propagation.aws_xray_format.trace"
|
||||
)
|
||||
def test_fields(self, mock_trace):
|
||||
"""Make sure the fields attribute returns the fields used in inject"""
|
||||
|
||||
mock_trace.configure_mock(
|
||||
**{
|
||||
"get_current_span.return_value": Mock(
|
||||
**{
|
||||
"get_span_context.return_value": Mock(
|
||||
**{"is_valid": True, "trace_id": 1, "span_id": 1}
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
mock_set_in_carrier = Mock()
|
||||
|
||||
AwsXRayPropagatorTest.XRAY_PROPAGATOR.inject(mock_set_in_carrier, {})
|
||||
|
||||
inject_fields = set()
|
||||
|
||||
for call in mock_set_in_carrier.mock_calls:
|
||||
inject_fields.add(call[1][1])
|
||||
|
||||
self.assertEqual(
|
||||
AwsXRayPropagatorTest.XRAY_PROPAGATOR.fields, inject_fields
|
||||
)
|
||||
|
Reference in New Issue
Block a user