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

Commit 432a378

Browse files
authored
Fix missing/none fields in exceptiondetails (#1232)
1 parent aa1b4ee commit 432a378

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
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 missing/None fields in `ExceptionDetails`
6+
([#1232](https://github.com/census-instrumentation/opencensus-python/pull/1232))
7+
58
## 1.1.11
69

710
Released 2023-10-12

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ def log_record_to_envelope(self, record):
231231
if exctype is not None:
232232
exc_type = exctype.__name__
233233

234+
if not exc_type:
235+
exc_type = "Exception"
236+
if not message:
237+
message = "Exception"
238+
234239
envelope.name = 'Microsoft.ApplicationInsights.Exception'
235240

236241
data = ExceptionData(

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,22 @@ def span_data_to_envelope(self, sd):
9696
)
9797
if sd.span_kind == SpanKind.SERVER:
9898
if ERROR_MESSAGE in sd.attributes:
99+
message = sd.attributes.get(ERROR_MESSAGE)
100+
if not message:
101+
message = "Exception"
102+
stack_trace = sd.attributes.get(STACKTRACE, [])
103+
if not hasattr(stack_trace, '__iter__'):
104+
stack_trace = []
99105
exc_env = Envelope(**envelope)
100106
exc_env.name = 'Microsoft.ApplicationInsights.Exception'
101107
data = ExceptionData(
102108
exceptions=[{
103109
'id': 1,
104110
'outerId': 0,
105111
'typeName': sd.attributes.get(ERROR_NAME, ''),
106-
'message': sd.attributes[ERROR_MESSAGE],
112+
'message': message,
107113
'hasFullStack': STACKTRACE in sd.attributes,
108-
'parsedStack': sd.attributes.get(STACKTRACE, None)
114+
'parsedStack': stack_trace
109115
}],
110116
)
111117
exc_env.data = Data(baseData=data, baseType='ExceptionData')

0 commit comments

Comments
 (0)