def test_export_not_retryable(self): exporter = self._exporter test_span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557338, is_remote=False, ), ) test_span.start() test_span.end() with mock.patch( "azure_monitor.export.trace.AzureMonitorSpanExporter._transmit" ) as transmit: # noqa: E501 transmit.return_value = ExportResult.FAILED_NOT_RETRYABLE result = exporter.export([test_span]) self.assertEqual(result, SpanExportResult.FAILED_NOT_RETRYABLE)
def test_export_failure(self): exporter = self._exporter with mock.patch( "azure_monitor.export.trace.AzureMonitorSpanExporter._transmit" ) as transmit: # noqa: E501 test_span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557338, is_remote=False, ), ) test_span.start() test_span.end() transmit.return_value = ExportResult.FAILED_RETRYABLE exporter.export([test_span]) self.assertEqual(len(os.listdir(exporter.storage.path)), 1) self.assertIsNone(exporter.storage.get())
def test_export_exception(self, logger_mock): test_span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557338, is_remote=False, ), ) test_span.start() test_span.end() exporter = self._exporter with mock.patch( "azure_monitor.export.trace.AzureMonitorSpanExporter._transmit", throw(Exception), ): # noqa: E501 result = exporter.export([test_span]) self.assertEqual(result, SpanExportResult.FAILED_NOT_RETRYABLE) self.assertEqual(logger_mock.exception.called, True)
def test_export_failure(self, span_to_envelope_mock): span_to_envelope_mock.return_value = ["bar"] exporter = AzureMonitorSpanExporter( storage_path=os.path.join(TEST_FOLDER, self.id())) with mock.patch( "azure_monitor.trace.AzureMonitorSpanExporter._transmit" ) as transmit: # noqa: E501 test_span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557338, ), ) test_span.start() test_span.end() transmit.return_value = ExportResult.FAILED_RETRYABLE exporter.export([test_span]) self.assertEqual(len(os.listdir(exporter.storage.path)), 1) self.assertIsNone(exporter.storage.get())
def test_export_success(self): exporter = self._exporter test_span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557338, is_remote=False, ), ) test_span.start() test_span.end() with mock.patch( "azure_monitor.export.trace.AzureMonitorSpanExporter._transmit" ) as transmit: # noqa: E501 transmit.return_value = ExportResult.SUCCESS storage_mock = mock.Mock() exporter._transmit_from_storage = storage_mock exporter.export([test_span]) self.assertEqual(storage_mock.call_count, 1) self.assertEqual(len(os.listdir(exporter.storage.path)), 0)
class TestOTLPSpanExporter(TestCase): def setUp(self): tracer_provider = TracerProvider() self.exporter = OTLPSpanExporter() tracer_provider.add_span_processor( SimpleExportSpanProcessor(self.exporter) ) self.tracer = tracer_provider.get_tracer(__name__) self.server = server(ThreadPoolExecutor(max_workers=10)) self.server.add_insecure_port("[::]:55678") self.server.start() event_mock = Mock( **{ "timestamp": 1591240820506462784, "attributes": OrderedDict([("a", 1), ("b", False)]), } ) type(event_mock).name = PropertyMock(return_value="a") self.span = Span( "a", context=Mock( **{ "trace_state": OrderedDict([("a", "b"), ("c", "d")]), "span_id": 10217189687419569865, "trace_id": 67545097771067222548457157018666467027, } ), resource=SDKResource(OrderedDict([("a", 1), ("b", False)])), parent=Mock(**{"span_id": 12345}), attributes=OrderedDict([("a", 1), ("b", True)]), events=[event_mock], links=[ Mock( **{ "context.trace_id": 1, "context.span_id": 2, "attributes": OrderedDict([("a", 1), ("b", False)]), "kind": SpanKind.INTERNAL, } ) ], ) self.span.start() self.span.end() def tearDown(self): self.server.stop(None) @patch("opentelemetry.ext.otlp.trace_exporter.expo") @patch("opentelemetry.ext.otlp.trace_exporter.sleep") def test_unavailable(self, mock_sleep, mock_expo): mock_expo.configure_mock(**{"return_value": [1]}) add_TraceServiceServicer_to_server( TraceServiceServicerUNAVAILABLE(), self.server ) self.assertEqual( self.exporter.export([self.span]), SpanExportResult.FAILURE ) mock_sleep.assert_called_with(1) @patch("opentelemetry.ext.otlp.trace_exporter.expo") @patch("opentelemetry.ext.otlp.trace_exporter.sleep") def test_unavailable_delay(self, mock_sleep, mock_expo): mock_expo.configure_mock(**{"return_value": [1]}) add_TraceServiceServicer_to_server( TraceServiceServicerUNAVAILABLEDelay(), self.server ) self.assertEqual( self.exporter.export([self.span]), SpanExportResult.FAILURE ) mock_sleep.assert_called_with(4) def test_success(self): add_TraceServiceServicer_to_server( TraceServiceServicerSUCCESS(), self.server ) self.assertEqual( self.exporter.export([self.span]), SpanExportResult.SUCCESS ) def test_translate_spans(self): expected = ExportTraceServiceRequest( resource_spans=[ ResourceSpans( resource=CollectorResource( attributes=[ AttributeKeyValue(key="a", int_value=1), AttributeKeyValue(key="b", bool_value=False), ] ), instrumentation_library_spans=[ InstrumentationLibrarySpans( spans=[ CollectorSpan( # pylint: disable=no-member name="a", start_time_unix_nano=self.span.start_time, end_time_unix_nano=self.span.end_time, trace_state="a=b,c=d", span_id=int.to_bytes( 10217189687419569865, 8, "big" ), trace_id=int.to_bytes( 67545097771067222548457157018666467027, 16, "big", ), parent_span_id=( b"\000\000\000\000\000\00009" ), kind=CollectorSpan.SpanKind.INTERNAL, attributes=[ AttributeKeyValue( key="a", int_value=1 ), AttributeKeyValue( key="b", bool_value=True ), ], events=[ CollectorSpan.Event( name="a", time_unix_nano=1591240820506462784, attributes=[ AttributeKeyValue( key="a", int_value=1 ), AttributeKeyValue( key="b", int_value=False ), ], ) ], status=Status(code=0, message=""), links=[ CollectorSpan.Link( trace_id=int.to_bytes( 1, 16, "big" ), span_id=int.to_bytes(2, 8, "big"), attributes=[ AttributeKeyValue( key="a", int_value=1 ), AttributeKeyValue( key="b", bool_value=False ), ], ) ], ) ] ) ], ), ] ) # pylint: disable=protected-access self.assertEqual(expected, self.exporter._translate_spans([self.span]))
def test_span_to_envelope(self): options = { "instrumentation_key": "12345678-1234-5678-abcd-12345678abcd" } exporter = AzureMonitorSpanExporter(**options) parent_span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557338, ), ) start_time = 1575494316027613500 end_time = start_time + 1001000000 # SpanKind.CLIENT HTTP span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557337, ), parent=parent_span, sampler=None, trace_config=None, resource=None, attributes={ "component": "http", "http.method": "GET", "http.url": "https://www.wikipedia.org/wiki/Rabbit", "http.status_code": 200, }, events=None, links=[], kind=SpanKind.CLIENT, ) span.start(start_time=start_time) span.end(end_time=end_time) span.status = Status(canonical_code=StatusCanonicalCode.OK) envelope = exporter.span_to_envelope(span) self.assertEqual(envelope.ikey, "12345678-1234-5678-abcd-12345678abcd") self.assertEqual(envelope.name, "Microsoft.ApplicationInsights.RemoteDependency") self.assertEqual(envelope.tags["ai.operation.parentId"], "a6f5d48acb4d31da") self.assertEqual( envelope.tags["ai.operation.id"], "1bbd944a73a05d89eab5d3740a213ee7", ) self.assertEqual(envelope.time, "2019-12-04T21:18:36.027613Z") self.assertEqual(envelope.data.base_data.name, "GET//wiki/Rabbit") self.assertEqual( envelope.data.base_data.data, "https://www.wikipedia.org/wiki/Rabbit", ) self.assertEqual(envelope.data.base_data.target, "www.wikipedia.org") self.assertEqual(envelope.data.base_data.id, "a6f5d48acb4d31d9") self.assertEqual(envelope.data.base_data.result_code, "200") self.assertEqual(envelope.data.base_data.duration, "0.00:00:01.001") self.assertEqual(envelope.data.base_data.type, "HTTP") self.assertEqual(envelope.data.base_type, "RemoteDependencyData") # SpanKind.CLIENT unknown type span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557337, ), parent=parent_span, sampler=None, trace_config=None, resource=None, attributes={}, events=None, links=[], kind=SpanKind.CLIENT, ) span.status = Status(canonical_code=StatusCanonicalCode.OK) span.start(start_time=start_time) span.end(end_time=end_time) envelope = exporter.span_to_envelope(span) self.assertEqual(envelope.ikey, "12345678-1234-5678-abcd-12345678abcd") self.assertEqual(envelope.name, "Microsoft.ApplicationInsights.RemoteDependency") self.assertEqual(envelope.tags["ai.operation.parentId"], "a6f5d48acb4d31da") self.assertEqual( envelope.tags["ai.operation.id"], "1bbd944a73a05d89eab5d3740a213ee7", ) self.assertEqual(envelope.time, "2019-12-04T21:18:36.027613Z") self.assertEqual(envelope.data.base_data.name, "test") self.assertEqual(envelope.data.base_data.id, "a6f5d48acb4d31d9") self.assertEqual(envelope.data.base_data.duration, "0.00:00:01.001") self.assertEqual(envelope.data.base_data.type, None) self.assertEqual(envelope.data.base_type, "RemoteDependencyData") # SpanKind.CLIENT missing method span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557337, ), parent=parent_span, sampler=None, trace_config=None, resource=None, attributes={ "component": "http", "http.url": "https://www.wikipedia.org/wiki/Rabbit", "http.status_code": 200, }, events=None, links=[], kind=SpanKind.CLIENT, ) span.status = Status(canonical_code=StatusCanonicalCode.OK) span.start(start_time=start_time) span.end(end_time=end_time) envelope = exporter.span_to_envelope(span) self.assertEqual(envelope.ikey, "12345678-1234-5678-abcd-12345678abcd") self.assertEqual(envelope.name, "Microsoft.ApplicationInsights.RemoteDependency") self.assertEqual(envelope.tags["ai.operation.parentId"], "a6f5d48acb4d31da") self.assertEqual( envelope.tags["ai.operation.id"], "1bbd944a73a05d89eab5d3740a213ee7", ) self.assertEqual(envelope.time, "2019-12-04T21:18:36.027613Z") self.assertEqual(envelope.data.base_data.name, "test") self.assertEqual( envelope.data.base_data.data, "https://www.wikipedia.org/wiki/Rabbit", ) self.assertEqual(envelope.data.base_data.target, "www.wikipedia.org") self.assertEqual(envelope.data.base_data.id, "a6f5d48acb4d31d9") self.assertEqual(envelope.data.base_data.result_code, "200") self.assertEqual(envelope.data.base_data.duration, "0.00:00:01.001") self.assertEqual(envelope.data.base_data.type, "HTTP") self.assertEqual(envelope.data.base_type, "RemoteDependencyData") # SpanKind.SERVER HTTP - 200 request span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557337, ), parent=parent_span, sampler=None, trace_config=None, resource=None, attributes={ "component": "http", "http.method": "GET", "http.path": "/wiki/Rabbit", "http.route": "/wiki/Rabbit", "http.url": "https://www.wikipedia.org/wiki/Rabbit", "http.status_code": 200, }, events=None, links=[], kind=SpanKind.SERVER, ) span.status = Status(canonical_code=StatusCanonicalCode.OK) span.start(start_time=start_time) span.end(end_time=end_time) envelope = exporter.span_to_envelope(span) self.assertEqual(envelope.ikey, "12345678-1234-5678-abcd-12345678abcd") self.assertEqual(envelope.name, "Microsoft.ApplicationInsights.Request") self.assertEqual(envelope.tags["ai.operation.parentId"], "a6f5d48acb4d31da") self.assertEqual( envelope.tags["ai.operation.id"], "1bbd944a73a05d89eab5d3740a213ee7", ) self.assertEqual(envelope.tags["ai.operation.name"], "GET /wiki/Rabbit") self.assertEqual(envelope.time, "2019-12-04T21:18:36.027613Z") self.assertEqual(envelope.data.base_data.id, "a6f5d48acb4d31d9") self.assertEqual(envelope.data.base_data.duration, "0.00:00:01.001") self.assertEqual(envelope.data.base_data.response_code, "200") self.assertEqual(envelope.data.base_data.name, "GET /wiki/Rabbit") self.assertEqual(envelope.data.base_data.success, True) self.assertEqual( envelope.data.base_data.url, "https://www.wikipedia.org/wiki/Rabbit", ) self.assertEqual(envelope.data.base_type, "RequestData") # SpanKind.SERVER HTTP - Failed request span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557337, ), parent=parent_span, sampler=None, trace_config=None, resource=None, attributes={ "component": "http", "http.method": "GET", "http.path": "/wiki/Rabbit", "http.route": "/wiki/Rabbit", "http.url": "https://www.wikipedia.org/wiki/Rabbit", "http.status_code": 400, }, events=None, links=[], kind=SpanKind.SERVER, ) span.status = Status(canonical_code=StatusCanonicalCode.OK) span.start(start_time=start_time) span.end(end_time=end_time) envelope = exporter.span_to_envelope(span) self.assertEqual(envelope.ikey, "12345678-1234-5678-abcd-12345678abcd") self.assertEqual(envelope.name, "Microsoft.ApplicationInsights.Request") self.assertEqual(envelope.tags["ai.operation.parentId"], "a6f5d48acb4d31da") self.assertEqual( envelope.tags["ai.operation.id"], "1bbd944a73a05d89eab5d3740a213ee7", ) self.assertEqual(envelope.tags["ai.operation.name"], "GET /wiki/Rabbit") self.assertEqual(envelope.time, "2019-12-04T21:18:36.027613Z") self.assertEqual(envelope.data.base_data.id, "a6f5d48acb4d31d9") self.assertEqual(envelope.data.base_data.duration, "0.00:00:01.001") self.assertEqual(envelope.data.base_data.response_code, "400") self.assertEqual(envelope.data.base_data.name, "GET /wiki/Rabbit") self.assertEqual(envelope.data.base_data.success, False) self.assertEqual( envelope.data.base_data.url, "https://www.wikipedia.org/wiki/Rabbit", ) self.assertEqual(envelope.data.base_type, "RequestData") # SpanKind.SERVER unknown type span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557337, ), parent=parent_span, sampler=None, trace_config=None, resource=None, attributes={ "component": "http", "http.method": "GET", "http.path": "/wiki/Rabbit", "http.route": "/wiki/Rabbit", "http.url": "https://www.wikipedia.org/wiki/Rabbit", "http.status_code": 400, }, events=None, links=[], kind=SpanKind.SERVER, ) span.status = Status(canonical_code=StatusCanonicalCode.OK) span.start(start_time=start_time) span.end(end_time=end_time) envelope = exporter.span_to_envelope(span) self.assertEqual(envelope.ikey, "12345678-1234-5678-abcd-12345678abcd") self.assertEqual(envelope.name, "Microsoft.ApplicationInsights.Request") self.assertEqual(envelope.tags["ai.operation.parentId"], "a6f5d48acb4d31da") self.assertEqual( envelope.tags["ai.operation.id"], "1bbd944a73a05d89eab5d3740a213ee7", ) self.assertEqual(envelope.time, "2019-12-04T21:18:36.027613Z") self.assertEqual(envelope.data.base_data.id, "a6f5d48acb4d31d9") self.assertEqual(envelope.data.base_data.duration, "0.00:00:01.001") self.assertEqual(envelope.data.base_type, "RequestData") # SpanKind.INTERNAL span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557337, ), parent=None, sampler=None, trace_config=None, resource=None, attributes={"key1": "value1"}, events=None, links=[], kind=SpanKind.INTERNAL, ) span.status = Status(canonical_code=StatusCanonicalCode.OK) span.start(start_time=start_time) span.end(end_time=end_time) envelope = exporter.span_to_envelope(span) self.assertEqual(envelope.ikey, "12345678-1234-5678-abcd-12345678abcd") self.assertEqual(envelope.name, "Microsoft.ApplicationInsights.RemoteDependency") self.assertRaises(KeyError, lambda: envelope.tags["ai.operation.parentId"]) self.assertEqual( envelope.tags["ai.operation.id"], "1bbd944a73a05d89eab5d3740a213ee7", ) self.assertEqual(envelope.time, "2019-12-04T21:18:36.027613Z") self.assertEqual(envelope.data.base_data.name, "test") self.assertEqual(envelope.data.base_data.duration, "0.00:00:01.001") self.assertEqual(envelope.data.base_data.id, "a6f5d48acb4d31d9") self.assertEqual(envelope.data.base_data.type, "InProc") self.assertEqual(envelope.data.base_type, "RemoteDependencyData") # Attributes span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557337, ), parent=parent_span, sampler=None, trace_config=None, resource=None, attributes={ "component": "http", "http.method": "GET", "http.url": "https://www.wikipedia.org/wiki/Rabbit", "http.status_code": 200, "test": "asd", }, events=None, links=[], kind=SpanKind.CLIENT, ) span.status = Status(canonical_code=StatusCanonicalCode.OK) span.start(start_time=start_time) span.end(end_time=end_time) envelope = exporter.span_to_envelope(span) self.assertEqual(len(envelope.data.base_data.properties), 2) self.assertEqual(envelope.data.base_data.properties["component"], "http") self.assertEqual(envelope.data.base_data.properties["test"], "asd") # Links links = [] links.append( Link(context=SpanContext( trace_id=36873507687745823477771305566750195432, span_id=12030755672171557338, ))) span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557337, ), parent=parent_span, sampler=None, trace_config=None, resource=None, attributes={ "component": "http", "http.method": "GET", "http.url": "https://www.wikipedia.org/wiki/Rabbit", "http.status_code": 200, }, events=None, links=links, kind=SpanKind.CLIENT, ) span.status = Status(canonical_code=StatusCanonicalCode.OK) span.start(start_time=start_time) span.end(end_time=end_time) envelope = exporter.span_to_envelope(span) self.assertEqual(len(envelope.data.base_data.properties), 2) json_dict = json.loads( envelope.data.base_data.properties["_MS.links"])[0] self.assertEqual(json_dict["id"], "a6f5d48acb4d31da") # Status span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557337, ), parent=parent_span, sampler=None, trace_config=None, resource=None, attributes={ "component": "http", "http.method": "GET", "http.url": "https://www.wikipedia.org/wiki/Rabbit", "http.status_code": 500, }, events=None, links=[], kind=SpanKind.SERVER, ) span.status = Status(canonical_code=StatusCanonicalCode.OK) span.start(start_time=start_time) span.end(end_time=end_time) envelope = exporter.span_to_envelope(span) self.assertEqual(envelope.data.base_data.response_code, "500") self.assertFalse(envelope.data.base_data.success) span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557337, ), parent=parent_span, sampler=None, trace_config=None, resource=None, attributes={ "component": "http", "http.method": "GET", "http.url": "https://www.wikipedia.org/wiki/Rabbit", "http.status_code": 500, }, events=None, links=[], kind=SpanKind.CLIENT, ) span.status = Status(canonical_code=StatusCanonicalCode.OK) span.start(start_time=start_time) span.end(end_time=end_time) envelope = exporter.span_to_envelope(span) self.assertEqual(envelope.data.base_data.result_code, "500") self.assertFalse(envelope.data.base_data.success) span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557337, ), parent=parent_span, sampler=None, trace_config=None, resource=None, attributes={ "component": "http", "http.method": "GET", "http.url": "https://www.wikipedia.org/wiki/Rabbit", }, events=None, links=[], kind=SpanKind.SERVER, ) span.status = Status(canonical_code=StatusCanonicalCode.OK) span.start(start_time=start_time) span.end(end_time=end_time) envelope = exporter.span_to_envelope(span) self.assertEqual(envelope.data.base_data.response_code, "0") self.assertTrue(envelope.data.base_data.success) span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557337, ), parent=parent_span, sampler=None, trace_config=None, resource=None, attributes={ "component": "http", "http.method": "GET", "http.url": "https://www.wikipedia.org/wiki/Rabbit", }, events=None, links=[], kind=SpanKind.CLIENT, ) span.status = Status(canonical_code=StatusCanonicalCode.OK) span.start(start_time=start_time) span.end(end_time=end_time) envelope = exporter.span_to_envelope(span) self.assertEqual(envelope.data.base_data.result_code, "0") self.assertTrue(envelope.data.base_data.success) span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557337, ), parent=parent_span, sampler=None, trace_config=None, resource=None, attributes={ "component": "http", "http.method": "GET", "http.url": "https://www.wikipedia.org/wiki/Rabbit", }, events=None, links=[], kind=SpanKind.SERVER, ) span.start(start_time=start_time) span.end(end_time=end_time) span.status = Status(canonical_code=StatusCanonicalCode.UNKNOWN) envelope = exporter.span_to_envelope(span) self.assertEqual(envelope.data.base_data.response_code, "2") self.assertFalse(envelope.data.base_data.success) span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557337, ), parent=parent_span, sampler=None, trace_config=None, resource=None, attributes={ "component": "http", "http.method": "GET", "http.url": "https://www.wikipedia.org/wiki/Rabbit", }, events=None, links=[], kind=SpanKind.CLIENT, ) span.start(start_time=start_time) span.end(end_time=end_time) span.status = Status(canonical_code=StatusCanonicalCode.UNKNOWN) envelope = exporter.span_to_envelope(span) self.assertEqual(envelope.data.base_data.result_code, "2") self.assertFalse(envelope.data.base_data.success) # Server route attribute span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557337, ), parent=parent_span, sampler=None, trace_config=None, resource=None, attributes={ "component": "HTTP", "http.method": "GET", "http.route": "/wiki/Rabbit", "http.path": "/wiki/Rabbitz", "http.url": "https://www.wikipedia.org/wiki/Rabbit", "http.status_code": 400, }, events=None, links=[], kind=SpanKind.SERVER, ) span.start(start_time=start_time) span.end(end_time=end_time) span.status = Status(canonical_code=StatusCanonicalCode.OK) envelope = exporter.span_to_envelope(span) self.assertEqual( envelope.data.base_data.properties["request.name"], "GET /wiki/Rabbit", ) self.assertEqual( envelope.data.base_data.properties["request.url"], "https://www.wikipedia.org/wiki/Rabbit", ) # Server method attribute missing span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557337, ), parent=parent_span, sampler=None, trace_config=None, resource=None, attributes={ "component": "HTTP", "http.path": "/wiki/Rabbitz", "http.url": "https://www.wikipedia.org/wiki/Rabbit", "http.status_code": 400, }, events=None, links=[], kind=SpanKind.SERVER, ) span.start(start_time=start_time) span.end(end_time=end_time) span.status = Status(canonical_code=StatusCanonicalCode.OK) envelope = exporter.span_to_envelope(span) self.assertIsNone(envelope.data.base_data.name) # Server route attribute missing span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557337, ), parent=parent_span, sampler=None, trace_config=None, resource=None, attributes={ "component": "HTTP", "http.method": "GET", "http.path": "/wiki/Rabbitz", "http.url": "https://www.wikipedia.org/wiki/Rabbit", "http.status_code": 400, }, events=None, links=[], kind=SpanKind.SERVER, ) span.start(start_time=start_time) span.end(end_time=end_time) span.status = Status(canonical_code=StatusCanonicalCode.OK) envelope = exporter.span_to_envelope(span) self.assertEqual(envelope.data.base_data.name, "GET") self.assertEqual( envelope.data.base_data.properties["request.name"], "GET /wiki/Rabbitz", ) self.assertEqual( envelope.data.base_data.properties["request.url"], "https://www.wikipedia.org/wiki/Rabbit", ) # Server route and path attribute missing span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557337, ), parent=parent_span, sampler=None, trace_config=None, resource=None, attributes={ "component": "HTTP", "http.method": "GET", "http.url": "https://www.wikipedia.org/wiki/Rabbit", "http.status_code": 400, }, events=None, links=[], kind=SpanKind.SERVER, ) span.start(start_time=start_time) span.end(end_time=end_time) span.status = Status(canonical_code=StatusCanonicalCode.OK) envelope = exporter.span_to_envelope(span) self.assertIsNone( envelope.data.base_data.properties.get("request.name")) self.assertEqual( envelope.data.base_data.properties["request.url"], "https://www.wikipedia.org/wiki/Rabbit", ) # Server http.url missing span = Span( name="test", context=SpanContext( trace_id=36873507687745823477771305566750195431, span_id=12030755672171557337, ), parent=parent_span, sampler=None, trace_config=None, resource=None, attributes={ "component": "HTTP", "http.method": "GET", "http.route": "/wiki/Rabbit", "http.path": "/wiki/Rabbitz", "http.status_code": 400, }, events=None, links=[], kind=SpanKind.SERVER, ) span.start(start_time=start_time) span.end(end_time=end_time) span.status = Status(canonical_code=StatusCanonicalCode.OK) envelope = exporter.span_to_envelope(span) self.assertIsNone(envelope.data.base_data.url) self.assertIsNone( envelope.data.base_data.properties.get("request.url"))