diff --git a/contrib/opencensus-ext-azure/CHANGELOG.md b/contrib/opencensus-ext-azure/CHANGELOG.md index f8c372645..76ee1dd12 100644 --- a/contrib/opencensus-ext-azure/CHANGELOG.md +++ b/contrib/opencensus-ext-azure/CHANGELOG.md @@ -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 diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py index f837779e3..14e228d06 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py @@ -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( diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/trace_exporter/__init__.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/trace_exporter/__init__.py index 26c07e6b1..31af8e05c 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/trace_exporter/__init__.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/trace_exporter/__init__.py @@ -96,6 +96,12 @@ 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( @@ -103,9 +109,9 @@ def span_data_to_envelope(self, sd): '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')