Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit b85e476

Browse files
authored
When batching, same object is mutated destroying exception information (#1187)
1 parent 7db21dd commit b85e476

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

contrib/opencensus-ext-azure/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
- Fix export of exception information in traces
6+
([#1187](https://github.com/census-instrumentation/opencensus-python/pull/1187))
7+
58
## 1.1.8
69

710
Released 2023-01-18

contrib/opencensus-ext-azure/opencensus/ext/azure/trace_exporter/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ def span_data_to_envelope(self, sd):
9696
)
9797
if sd.span_kind == SpanKind.SERVER:
9898
if ERROR_MESSAGE in sd.attributes:
99-
envelope.name = 'Microsoft.ApplicationInsights.Exception'
99+
exc_env = Envelope(**envelope)
100+
exc_env.name = 'Microsoft.ApplicationInsights.Exception'
100101
data = ExceptionData(
101102
exceptions=[{
102103
'id': 1,
@@ -107,8 +108,8 @@ def span_data_to_envelope(self, sd):
107108
'parsedStack': sd.attributes.get(STACKTRACE, None)
108109
}],
109110
)
110-
envelope.data = Data(baseData=data, baseType='ExceptionData')
111-
yield envelope
111+
exc_env.data = Data(baseData=data, baseType='ExceptionData')
112+
yield exc_env
112113

113114
envelope.name = 'Microsoft.ApplicationInsights.Request'
114115
data = Request(

contrib/opencensus-ext-azure/tests/test_azure_trace_exporter.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ def test_span_data_to_envelope(self):
498498
'RequestData')
499499

500500
# SpanKind.SERVER HTTP - with exceptions
501-
envelopes = exporter.span_data_to_envelope(SpanData(
501+
envelopes = list(exporter.span_data_to_envelope(SpanData(
502502
name='test',
503503
context=SpanContext(
504504
trace_id='6e0c63257de34c90bf9efcd03927272e',
@@ -529,9 +529,10 @@ def test_span_data_to_envelope(self):
529529
same_process_as_parent_span=None,
530530
child_span_count=None,
531531
span_kind=SpanKind.SERVER,
532-
))
532+
)))
533+
self.assertEqual(len(envelopes), 2)
533534

534-
envelope = next(envelopes)
535+
envelope = envelopes[0]
535536
self.assertEqual(
536537
envelope.iKey,
537538
'12345678-1234-5678-abcd-12345678abcd')
@@ -551,7 +552,7 @@ def test_span_data_to_envelope(self):
551552
envelope.data.baseType,
552553
'ExceptionData')
553554

554-
envelope = next(envelopes)
555+
envelope = envelopes[1]
555556
self.assertEqual(
556557
envelope.iKey,
557558
'12345678-1234-5678-abcd-12345678abcd')

0 commit comments

Comments
 (0)