Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Late OpenTelemetry context propagation in _handle__invocation_request #1626

Open
MatteoMeil opened this issue Jan 7, 2025 · 0 comments

Comments

@MatteoMeil
Copy link

MatteoMeil commented Jan 7, 2025

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:

  1. self.configure_opentelemetry(fi_context) should be executed in _handle__invocation_request right before first log is emitted at line 617
  2. consequently, fi_context initialization 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

  1. Create a new Azure Function
  2. Create a new trigger and write code to emit some logs
  3. In local.settings.json add PYTHON_ENABLE_OPENTELEMETRY=1 and APPLICATIONINSIGHTS_CONNECTION_STRING=your-connection-string
  4. Run the trigger created at step 2.
  5. Check in Application Insights that first log emitted by function invocation (i.e.: Received function invocation request ...) has a blank operation_id

requirements.txt file

azure-functions
azure-monitor-opentelemetry

Where are you facing this problem?

Local - Core Tools

@MatteoMeil MatteoMeil changed the title [Bug] Late context propagation in _handle__invocation_request [Bug] Late OpenTelemetry context propagation in _handle__invocation_request Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant