Add test case for DataDog fields and AWS SDK Extension (#231)

This commit is contained in:
Diego Hurtado
2020-12-11 14:48:01 -06:00
committed by GitHub
parent 91bfc9afe5
commit e5a0153794
4 changed files with 69 additions and 1 deletions

View File

@ -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`.

View File

@ -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
)