Skip to content

[Monitor OpenTelemetry] Replace Az Fns Hook with Instrumentation#37591

Merged
JacksonWeber merged 16 commits intoAzure:mainfrom
JacksonWeber:jacksonweber/use-az-fns-instrumentation
Mar 20, 2026
Merged

[Monitor OpenTelemetry] Replace Az Fns Hook with Instrumentation#37591
JacksonWeber merged 16 commits intoAzure:mainfrom
JacksonWeber:jacksonweber/use-az-fns-instrumentation

Conversation

@JacksonWeber
Copy link
Copy Markdown
Member

Packages impacted by this PR

@azure/monitor-opentelemetry

Issues associated with this PR

Describe the problem that is addressed by this PR

This pull request updates the Azure Monitor OpenTelemetry SDK to replace the custom AzureFunctionsHook with the officially supported @azure/functions-opentelemetry-instrumentation package for Azure Functions context propagation. This change simplifies the codebase, removes custom module loading logic, and ensures the latest Azure Functions instrumentation features are available. Related tests have been updated to reflect the new approach.

Key changes include:

Azure Functions Instrumentation Modernization:

  • Replaced the custom AzureFunctionsHook implementation with the @azure/functions-opentelemetry-instrumentation package, which is now always included as an instrumentation. This package is maintained by the Azure Functions team and adds capabilities such as log forwarding and support for WorkerOpenTelemetryEnabled. (sdk/monitor/monitor-opentelemetry/CHANGELOG.md, sdk/monitor/monitor-opentelemetry/package.json, sdk/monitor/monitor-opentelemetry/src/traces/handler.ts, [1] [2] [3] [4] [5] [6] [7]

Codebase Simplification and Cleanup:

  • Removed the custom Azure Functions hook implementation and associated module loader utilities, cleaning up both CommonJS and ESM-specific code. (sdk/monitor/monitor-opentelemetry/src/traces/azureFnHook.ts, sdk/monitor/monitor-opentelemetry/src/shared/module.ts, sdk/monitor/monitor-opentelemetry/src/shared/module-cjs.cts, [1] [2] [3]

Test Updates:

  • Updated and simplified unit tests to verify that AzureFunctionsInstrumentation is always registered, and removed tests specific to the old custom hook logic. (sdk/monitor/monitor-opentelemetry/test/internal/unit/traces/azureFnHook.test.ts, sdk/monitor/monitor-opentelemetry/test/internal/unit/traces/traceHandler.test.ts, [1] [2] [3] [4]

Minor Code Comments:

Checklists

  • Added impacted package name to the issue description
  • Does this PR needs any fixes in the SDK Generator?** (If so, create an Issue in the Autorest/typescript repository and link it here)
  • Added a changelog (if necessary)

Copilot AI review requested due to automatic review settings March 11, 2026 19:50
@JacksonWeber JacksonWeber changed the title Jacksonweber/use az fns instrumentation [Monitor OpenTelemetry] Replace Az Fns Hook with Instrumentation Mar 11, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes Azure Functions context propagation in @azure/monitor-opentelemetry by replacing the custom AzureFunctionsHook with the officially supported @azure/functions-opentelemetry-instrumentation, and removes now-unneeded custom module-loading utilities.

Changes:

  • Always registers AzureFunctionsInstrumentation as part of TraceHandler instrumentation initialization.
  • Removes the custom Azure Functions hook implementation (azureFnHook.ts) and the ESM/CJS loaders previously used to conditionally load @azure/functions-core.
  • Updates unit tests and package metadata (dependency + changelog) to reflect the new Azure Functions instrumentation approach.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
sdk/monitor/monitor-opentelemetry/src/traces/handler.ts Replaces custom hook usage with AzureFunctionsInstrumentation and always adds it to the instrumentation list.
sdk/monitor/monitor-opentelemetry/src/traces/azureFnHook.ts Removes the custom AzureFunctionsHook implementation entirely.
sdk/monitor/monitor-opentelemetry/src/shared/module.ts Removes ESM loader helper that loaded @azure/functions-core.
sdk/monitor/monitor-opentelemetry/src/shared/module-cjs.cts Removes CJS loader helper that loaded @azure/functions-core.
sdk/monitor/monitor-opentelemetry/test/internal/unit/traces/azureFnHook.test.ts Updates tests to validate AzureFunctionsInstrumentation registration instead of custom hook behavior.
sdk/monitor/monitor-opentelemetry/test/internal/unit/traces/traceHandler.test.ts Updates expectation to account for always-on AzureFunctionsInstrumentation.
sdk/monitor/monitor-opentelemetry/package.json Adds dependency on @azure/functions-opentelemetry-instrumentation.
sdk/monitor/monitor-opentelemetry/CHANGELOG.md Documents the replacement of the custom hook with the new instrumentation package.
sdk/monitor/monitor-opentelemetry/src/metrics/quickpulse/export/sender.ts Clarifies a @ts-expect-error comment used for tests accessing a private field.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread sdk/monitor/monitor-opentelemetry/test/internal/unit/traces/traceHandler.test.ts Outdated
Comment thread sdk/monitor/monitor-opentelemetry/src/traces/handler.ts Outdated
@JacksonWeber JacksonWeber requested a review from hectorhdzg March 18, 2026 20:55
Comment thread sdk/ai/ai-agents/test/public/agents/agents.spec.ts
Copy link
Copy Markdown
Member

@hectorhdzg hectorhdzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like some git merge issues, but monitor opentelemetry package changes look good

These files were accidentally included in the PR and are outside
the scope of monitor-opentelemetry changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JacksonWeber JacksonWeber requested a review from hectorhdzg March 19, 2026 23:25
Copy link
Copy Markdown
Member

@jeremymeng jeremymeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lock file changes look good

@JacksonWeber JacksonWeber merged commit d87374f into Azure:main Mar 20, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants