12
12
OTLPUdpMetricExporter ,
13
13
OTLPUdpSpanExporter ,
14
14
UdpExporter ,
15
+ FORMAT_OTEL_SAMPLED_TRACES_BINARY_PREFIX ,
15
16
FORMAT_OTEL_UNSAMPLED_TRACES_BINARY_PREFIX ,
16
17
)
17
18
from opentelemetry .sdk .metrics ._internal .export import MetricExportResult
@@ -99,7 +100,7 @@ class TestOTLPUdpSpanExporter(unittest.TestCase):
99
100
100
101
@patch ("amazon.opentelemetry.distro.otlp_udp_exporter.encode_spans" )
101
102
@patch ("amazon.opentelemetry.distro.otlp_udp_exporter.UdpExporter" )
102
- def test_export (self , mock_udp_exporter , mock_encode_spans ):
103
+ def test_export_unsampled_span (self , mock_udp_exporter , mock_encode_spans ):
103
104
mock_udp_exporter_instance = mock_udp_exporter .return_value
104
105
mock_encoded_data = MagicMock ()
105
106
mock_encode_spans .return_value .SerializeToString .return_value = mock_encoded_data
@@ -110,6 +111,19 @@ def test_export(self, mock_udp_exporter, mock_encode_spans):
110
111
)
111
112
self .assertEqual (result , SpanExportResult .SUCCESS )
112
113
114
+ @patch ("amazon.opentelemetry.distro.otlp_udp_exporter.encode_spans" )
115
+ @patch ("amazon.opentelemetry.distro.otlp_udp_exporter.UdpExporter" )
116
+ def test_export_sampled_span (self , mock_udp_exporter , mock_encode_spans ):
117
+ mock_udp_exporter_instance = mock_udp_exporter .return_value
118
+ mock_encoded_data = MagicMock ()
119
+ mock_encode_spans .return_value .SerializeToString .return_value = mock_encoded_data
120
+ exporter = OTLPUdpSpanExporter ()
121
+ result = exporter .export (MagicMock ())
122
+ mock_udp_exporter_instance .send_data .assert_called_once_with (
123
+ data = mock_encoded_data , signal_format_prefix = FORMAT_OTEL_SAMPLED_TRACES_BINARY_PREFIX
124
+ )
125
+ self .assertEqual (result , SpanExportResult .SUCCESS )
126
+
113
127
@patch ("amazon.opentelemetry.distro.otlp_udp_exporter.encode_spans" )
114
128
@patch ("amazon.opentelemetry.distro.otlp_udp_exporter.UdpExporter" )
115
129
def test_export_with_exception (self , mock_udp_exporter , mock_encode_spans ):
0 commit comments