Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions azure_monitor/src/azure_monitor/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,13 @@ def span_to_envelope(self, span): # noqa pylint: disable=too-many-branches
if "http.route" in span.attributes:
data.name = data.name + " " + span.attributes["http.route"]
envelope.tags["ai.operation.name"] = data.name
data.properties["request.name"] = data.name
elif 'http.path' in span.attributes:
data.properties['request.name'] = data.name + \
' ' + span.attributes['http.path']
if "http.url" in span.attributes:
data.url = span.attributes["http.url"]
data.properties['request.url'] = span.attributes['http.url']
if "http.status_code" in span.attributes:
status_code = span.attributes["http.status_code"]
data.responseCode = str(status_code)
Expand Down Expand Up @@ -146,6 +151,7 @@ def span_to_envelope(self, span): # noqa pylint: disable=too-many-branches
data.success = True
else: # SpanKind.INTERNAL
data.type = "InProc"
data.success = True
for key in span.attributes:
# This removes redundant data from ApplicationInsights
if key.startswith('http.'):
Expand Down
96 changes: 96 additions & 0 deletions azure_monitor/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ def test_span_to_envelope(self):
self.assertEqual(
envelope.data.baseData.type,
'InProc')
self.assertEqual(
envelope.data.baseData.success,
True)
self.assertEqual(
envelope.data.baseType,
'RemoteDependencyData')
Expand Down Expand Up @@ -687,3 +690,96 @@ def test_span_to_envelope(self):
self.assertEqual(
envelope.data.baseData.resultCode, '2')
self.assertFalse(envelope.data.baseData.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=None,
kind=SpanKind.SERVER
)
span.start_time = start_time
span.end_time = end_time
span.status = StatusCanonicalCode.OK
envelope = exporter.span_to_envelope(span)
self.assertEqual(
envelope.data.baseData.properties['request.name'], 'GET /wiki/Rabbit')
self.assertEqual(
envelope.data.baseData.properties['request.url'], 'https://www.wikipedia.org/wiki/Rabbit')

# 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=None,
kind=SpanKind.SERVER
)
span.start_time = start_time
span.end_time = end_time
span.status = StatusCanonicalCode.OK
envelope = exporter.span_to_envelope(span)
self.assertEqual(
envelope.data.baseData.properties['request.name'], 'GET /wiki/Rabbitz')
self.assertEqual(
envelope.data.baseData.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=None,
kind=SpanKind.SERVER
)
span.start_time = start_time
span.end_time = end_time
span.status = StatusCanonicalCode.OK
envelope = exporter.span_to_envelope(span)
self.assertIsNone(
envelope.data.baseData.properties.get('request.name'))
self.assertEqual(
envelope.data.baseData.properties['request.url'], 'https://www.wikipedia.org/wiki/Rabbit')