Skip to content

Commit

Permalink
Fix missing/none fields in exceptiondetails (#1232)
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen authored Nov 2, 2023
1 parent aa1b4ee commit 432a378
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 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 missing/None fields in `ExceptionDetails`
([#1232](https://github.com/census-instrumentation/opencensus-python/pull/1232))

## 1.1.11

Released 2023-10-12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ def log_record_to_envelope(self, record):
if exctype is not None:
exc_type = exctype.__name__

if not exc_type:
exc_type = "Exception"
if not message:
message = "Exception"

envelope.name = 'Microsoft.ApplicationInsights.Exception'

data = ExceptionData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,22 @@ def span_data_to_envelope(self, sd):
)
if sd.span_kind == SpanKind.SERVER:
if ERROR_MESSAGE in sd.attributes:
message = sd.attributes.get(ERROR_MESSAGE)
if not message:
message = "Exception"
stack_trace = sd.attributes.get(STACKTRACE, [])
if not hasattr(stack_trace, '__iter__'):
stack_trace = []
exc_env = Envelope(**envelope)
exc_env.name = 'Microsoft.ApplicationInsights.Exception'
data = ExceptionData(
exceptions=[{
'id': 1,
'outerId': 0,
'typeName': sd.attributes.get(ERROR_NAME, ''),
'message': sd.attributes[ERROR_MESSAGE],
'message': message,
'hasFullStack': STACKTRACE in sd.attributes,
'parsedStack': sd.attributes.get(STACKTRACE, None)
'parsedStack': stack_trace
}],
)
exc_env.data = Data(baseData=data, baseType='ExceptionData')
Expand Down

0 comments on commit 432a378

Please sign in to comment.