azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

OpenTelemetry not logging messages with exception details to Application Insights from python code

Open sbfrancies-onyx opened this issue 1 year ago • 1 comments

  • Package Name: azure-monitor-opentelemetry
  • Package Version: 1.1.1
  • Operating System: Linux
  • Python Version: 3.10

Describe the bug I am in process of migrating a python 3.10 project from OpenCensus to OpenTelemetry as the former is being sunsetted this year.

Application Insights logs are working correctly for standard info, warning, error, etc logging but I am having an issue with logging exceptions.

Take the following example code:

from azure.monitor.opentelemetry import configure_azure_monitor
import logging

configure_azure_monitor(
     connection_string="MY_APPINSIGHTS_CONNECTION_STRING",
)

try:
    logging.info("My INFO message")
    logging.warning("My WARNING message")
    logging.error("My ERROR message")
    raise Exception("My EXCEPTION message")
except Exception:
    logging.exception('My CUSTOM message')
    logging.error('My CUSTOM message', stack_info=True, exc_info=True)

The logs before the exception is raised work as expected. What for the logs in the except block is that an Application insights log would be created with an outerMessage or details..message of "My CUSTOM message" or at least "My CUSTOM message" somewhere in the record. What I am seeing when I check though is the following:

exceptions
| order by timestamp desc 

image

"My CUSTOM message" is nowhere to be found. I asked on StackOverflow about configuration options for this but apparently it is the current behaviour of the package which seems like a bug.

To Reproduce Steps to reproduce the behaviour:

  1. Use the code sample above replacing "MY_APPINSIGHTS_CONNECTION_STRING" with your Application Insights connection string.

Expected behaviour

  1. logging.exception("Something") creates an Application Insights record containing "Something"

Screenshots image

sbfrancies-onyx avatar Jan 11 '24 12:01 sbfrancies-onyx

Thank you for the feedback @sbfrancies-onyx. We will investigate and get back to you asap.

kashifkhan avatar Jan 11 '24 14:01 kashifkhan

Hi @kashifkhan - just wondering was there any update on this?

jdudleyonyxtech avatar Jan 25 '24 10:01 jdudleyonyxtech

@jdudleyonyxtech

Thanks for your patience. I've create a PR to address this issue: https://github.com/Azure/azure-sdk-for-python/pull/34020

lzchen avatar Jan 25 '24 22:01 lzchen