azure-functions-python-worker
azure-functions-python-worker copied to clipboard
[Bug] Late OpenTelemetry context propagation in _handle__invocation_request
Expected Behavior
Context should be propagated as soon as possible to make all logs generated by function invocation have a valid Operation Id in Application Insights. Thus:
self.configure_opentelemetry(fi_context)should be executed in_handle__invocation_requestright before first log is emitted at line 617- consequently,
fi_contextinitialization should be moved up, ideally at line 602
Actual Behavior
If OpenTelemetry is available and initialized, first log emitted by _handle__invocation_request is not properly recorded as part of function workflow, i.e.: in Application Insights has a blank Operation Id.
This is because of late context propagation (at line 666) which happens after first log is emitted at line 617
Steps to Reproduce
- Create a new Azure Function
- Create a new trigger and write code to emit some logs
- In
local.settings.jsonaddPYTHON_ENABLE_OPENTELEMETRY=1andAPPLICATIONINSIGHTS_CONNECTION_STRING=your-connection-string - Run the trigger created at step 2.
- Check in Application Insights that first log emitted by function invocation (i.e.:
Received function invocation request ...) has a blankoperation_id
requirements.txt file
azure-functions
azure-monitor-opentelemetry
Where are you facing this problem?
Local - Core Tools