fix: early OpenTelemetry context propagation in invocation - #1882
Open
hallvictoria wants to merge 10 commits into
Open
fix: early OpenTelemetry context propagation in invocation#1882hallvictoria wants to merge 10 commits into
hallvictoria wants to merge 10 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses late OpenTelemetry context propagation during function invocation handling so that invocation logs are correlated with the proper trace context (Operation Id) in Application Insights.
Changes:
- Move OpenTelemetry context initialization/configuration earlier in the invocation request handlers (worker dispatcher + v1/v2 runtimes).
- Remove the later (async-only) OpenTelemetry configuration points after args/bindings setup.
- Add a unit test intended to validate that OpenTelemetry is configured before the first invocation log in the worker dispatcher.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| workers/tests/unittests/test_opentelemetry.py | Adds tests to validate OpenTelemetry context propagation occurs before the first invocation log. |
| workers/azure_functions_worker/dispatcher.py | Moves _get_context + configure_opentelemetry() before the first logger.info in _handle__invocation_request. |
| runtimes/v2/azure_functions_runtime/handle_event.py | Moves context creation + OpenTelemetry configuration before the first invocation logger.info. |
| runtimes/v1/azure_functions_runtime_v1/handle_event.py | Moves context creation + OpenTelemetry configuration before the first invocation logger.info. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
hallvictoria
marked this pull request as ready for review
August 10, 2026 20:20
hallvictoria
requested review from
Gavin Aguiar (gavin-aguiar) and
Varad Meru (vrdmr)
as code owners
August 10, 2026 20:20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #1626
Move OpenTelemetry context propagation earlier in
_handle__invocation_requestto ensure all logs have proper trace context (Operation Id) in Application Insights.Problem: When OpenTelemetry is enabled, the first log emitted in
_handle__invocation_requesthad a blank Operation Id becauseconfigure_opentelemetry()was called after the first log was emitted.Solution: Move
fi_contextinitialization andconfigure_opentelemetry()call to immediately afterFunctionInfois retrieved, before any logging occurs.Pull Request Checklist
Host-Worker Contract
Worker Execution Logic
If yes, please answer the following:
Python Version Coverage
Programming Model Compatibility (for Python 3.13+)