Swifting
Swifting

Reputation: 479

How to set operation id for custom application insight events?

We have running on Azure a Python Web App (flask). It processes requests and also logs some results in the end via a custom event to Application Insights.

However inside Application Insights our end-to-end transaction Operation ID for our Custom Events is 0.

enter image description here

Other event types such as Requests, do have the operation id. How can we get the same operation id in here as the Request event?

import logging
from opencensus.ext.azure.log_exporter import AzureEventHandler, AzureLogHandler

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

logger.addHandler(AzureEventHandler(
    connection_string='InstrumentationKey=00000000-0000-0000-0000-000000000000'))

def track_result(result):
    properties = {'result': result}
    logger.info('Result log', extra={'custom_dimensions': properties})
    return None

Upvotes: 1

Views: 1224

Answers (1)

Mohit Ganorkar
Mohit Ganorkar

Reputation: 2069

  • Here using openCensus and AzureEventHandler the operation ID was populated in application insights using the following code :
import  logging
from opencensus.trace import config_integration
from  opencensus.ext.azure.log_exporter  import  AzureEventHandler
config_integration.trace_integrations(['logging'])

logger = logging.getLogger(__name__)

handler = AzureEventHandler(connection_string='Connection String from portal')

logger.addHandler(handler)


# Now we can log like this 

logger.warning('Before the span')
  • Here the operation Id is filled every time I make a get request to my flask api

enter image description here

Upvotes: 1

Related Questions