Skip to content

Commit

Permalink
When batching, same object is mutated destroying exception information (
Browse files Browse the repository at this point in the history
  • Loading branch information
calleo committed Feb 8, 2023
1 parent 7db21dd commit b85e476
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
3 changes: 3 additions & 0 deletions contrib/opencensus-ext-azure/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- Fix export of exception information in traces
([#1187](https://github.com/census-instrumentation/opencensus-python/pull/1187))

## 1.1.8

Released 2023-01-18
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def span_data_to_envelope(self, sd):
)
if sd.span_kind == SpanKind.SERVER:
if ERROR_MESSAGE in sd.attributes:
envelope.name = 'Microsoft.ApplicationInsights.Exception'
exc_env = Envelope(**envelope)
exc_env.name = 'Microsoft.ApplicationInsights.Exception'
data = ExceptionData(
exceptions=[{
'id': 1,
Expand All @@ -107,8 +108,8 @@ def span_data_to_envelope(self, sd):
'parsedStack': sd.attributes.get(STACKTRACE, None)
}],
)
envelope.data = Data(baseData=data, baseType='ExceptionData')
yield envelope
exc_env.data = Data(baseData=data, baseType='ExceptionData')
yield exc_env

envelope.name = 'Microsoft.ApplicationInsights.Request'
data = Request(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def test_span_data_to_envelope(self):
'RequestData')

# SpanKind.SERVER HTTP - with exceptions
envelopes = exporter.span_data_to_envelope(SpanData(
envelopes = list(exporter.span_data_to_envelope(SpanData(
name='test',
context=SpanContext(
trace_id='6e0c63257de34c90bf9efcd03927272e',
Expand Down Expand Up @@ -529,9 +529,10 @@ def test_span_data_to_envelope(self):
same_process_as_parent_span=None,
child_span_count=None,
span_kind=SpanKind.SERVER,
))
)))
self.assertEqual(len(envelopes), 2)

envelope = next(envelopes)
envelope = envelopes[0]
self.assertEqual(
envelope.iKey,
'12345678-1234-5678-abcd-12345678abcd')
Expand All @@ -551,7 +552,7 @@ def test_span_data_to_envelope(self):
envelope.data.baseType,
'ExceptionData')

envelope = next(envelopes)
envelope = envelopes[1]
self.assertEqual(
envelope.iKey,
'12345678-1234-5678-abcd-12345678abcd')
Expand Down

0 comments on commit b85e476

Please sign in to comment.