Repository navigation
Add Entra authentication to Durable distributed tracing - #3512
wangbill (YunchuWang) merged 22 commits into
Conversation
Reuse the WebJobs Application Insights authentication-string parser and apply the selected managed identity credential to Durable's owned telemetry configuration. Keep the existing lifecycle so host telemetry processors cannot filter Durable spans. Add system/user identity parsing coverage, malformed-setting warnings, and a V2 request/dependency parent-chain regression test. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 01711e67-44d5-4e79-915a-a9e6d7dafe26
There was a problem hiding this comment.
Pull request overview
This PR enables Microsoft Entra (AAD) authentication for Durable Functions’ private Application Insights telemetry pipeline used by Distributed Tracing, by honoring APPLICATIONINSIGHTS_AUTHENTICATION_STRING and configuring a managed-identity TokenCredential on the TelemetryConfiguration. This addresses missing Durable V2 spans when the App Insights resource has DisableLocalAuth=true.
Changes:
- Update
TelemetryActivatorto parseAPPLICATIONINSIGHTS_AUTHENTICATION_STRING(using WebJobs’ parser semantics) and apply aManagedIdentityCredentialviaTelemetryConfiguration.SetAzureTokenCredential(...), with a safe warning on invalid strings. - Add E2E/activation tests covering valid/invalid authentication strings and verifying that V2 module span parent/child chains are preserved under Entra auth.
- Add the necessary WebJobs Application Insights logging package reference and document Entra-only setup in the V2 tracing sample.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/WebJobs.Extensions.DurableTask/Correlation/TelemetryActivator.cs |
Reads and parses APPLICATIONINSIGHTS_AUTHENTICATION_STRING, applies a managed-identity credential to Durable’s owned AI telemetry pipeline, and logs success/warning without exposing configured values. |
src/WebJobs.Extensions.DurableTask/WebJobs.Extensions.DurableTask.csproj |
Adds a runtime package reference needed to reuse WebJobs’ authentication-string parsing semantics. |
Directory.Packages.props |
Centralizes the Microsoft.Azure.WebJobs.Logging.ApplicationInsights version for consistent dependency management. |
test/Directory.Packages.props |
Removes the redundant per-test package version entry now that it is centrally managed. |
test/FunctionsV2/Tests/E2E/CorrelationEndToEndTests.cs |
Adds coverage for Entra auth enablement/warnings and validates V2 telemetry span chaining with Entra auth enabled. |
samples/distributed-tracing/v2/DistributedTracingSample/README.md |
Documents Entra-only App Insights setup (APPLICATIONINSIGHTS_AUTHENTICATION_STRING) for Distributed Tracing V2. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Reuse the host-configured Application Insights credential when available so Durable's private telemetry pipeline uses the Functions host assembly-load context. Retain the standalone fallback and cover credential extraction and DI construction. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 00d274e1-e73b-45f4-9592-18fa90d81936
Verify dependency injection selects the host-aware constructor and distinguish malformed authentication strings from credentials that cannot be applied. Document why the host credential must be reused across Functions load contexts. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 01711e67-44d5-4e79-915a-a9e6d7dafe26
Extract the host-reuse and standalone-fallback decision into a focused helper. Verify the host credential is applied to Durable's owned telemetry configuration and both managed identity authentication forms retain their fallback. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 00d274e1-e73b-45f4-9592-18fa90d81936
ApplyAzureTokenCredential now reports whether the Functions host credential was reused. When a host TelemetryConfiguration is present but the credential cannot be read, Durable falls back to creating its own managed identity credential, which the host Application Insights SDK rejects when the host and the function app load different Azure.Core versions. That failure was silent and reproduced the original missing-span symptom. It is now logged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 01711e67-44d5-4e79-915a-a9e6d7dafe26
Microsoft.Azure.WebJobs.Logging.ApplicationInsights 3.0.41 transitively resolved System.Drawing.Common 4.7.0 (GHSA-rxg9-xrhp-64gj, Critical) on both target frameworks. Move to 3.0.45 so it lines up with the existing Microsoft.Azure.WebJobs 3.0.45 reference; the transitive graph now resolves System.Drawing.Common 6.0.0 and the audit is clean. That newer graph also raises the transitive requirement above the test-side pin of 4.7.3, so raise that pin to 6.0.0 to keep central pinning consistent. The correlation E2E test asserted on an activator the test helper built by hand with the two-argument constructor, so it never exercised the host-aware constructor that the fix depends on. Let the container build the activator and only attach the OnSend hook, register a host TelemetryConfiguration the way the Functions host does, and assert the credential Durable applies to its own configuration is the very same instance the host owns. The fallback case is covered too: no host credential means a standalone managed identity credential plus the warning. Reverting the reuse logic fails both new assertions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 01711e67-44d5-4e79-915a-a9e6d7dafe26
Upgrading Microsoft.Azure.WebJobs.Logging.ApplicationInsights to 3.0.45 changes the transitive graph so Microsoft.Data.SqlClient's System.Configuration.ConfigurationManager 6.0.0 chain now requires System.Drawing.Common >= 6.0.0. Two remaining 4.7.3 pins were lower than that and failed restore with NU1605/NU1109 (warnings are errors). Verified by control: with 3.0.41 both restore clean, with 3.0.45 both fail; after raising the pins all 25 projects that reference the Durable extension restore clean. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 01711e67-44d5-4e79-915a-a9e6d7dafe26
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/WebJobs.Extensions.DurableTask/Correlation/TelemetryActivator.cs:270
APPLICATIONINSIGHTS_CONNECTION_STRINGis required for Microsoft Entra ingestion, but this branch also runs when onlyAPPINSIGHTS_INSTRUMENTATIONKEYis present. That unsupported configuration receives a credential and the “authentication enabled” success log even though its Durable spans cannot be ingested. Gate authentication onconnectionStringProvidedand emit a sanitized warning when the authentication string is configured without a connection string.
if (!string.IsNullOrWhiteSpace(resolvedAuthenticationString))
samples/distributed-tracing/v2/DistributedTracingSample/README.md:31
- The preceding paragraph permits either a connection string or instrumentation key, so “also configure” incorrectly presents
APPINSIGHTS_INSTRUMENTATIONKEYplus this authentication string as supported. Microsoft Entra ingestion requiresAPPLICATIONINSIGHTS_CONNECTION_STRING; make that prerequisite explicit here.
If the Application Insights resource has local authentication disabled, also configure `APPLICATIONINSIGHTS_AUTHENTICATION_STRING`. Use `Authorization=AAD` for the function app's system-assigned managed identity, or `Authorization=AAD;ClientId=<USER_ASSIGNED_CLIENT_ID>` for a user-assigned managed identity. The selected identity needs the `Monitoring Metrics Publisher` role on the Application Insights resource. Microsoft Entra authentication for Application Insights isn't supported by the Functions host during local development.
|
query_data.csv |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/WebJobs.Extensions.DurableTask/Correlation/HostForwardingTelemetryChannel.cs:97
HostForwardingTelemetryChanneladvertises theIAsyncFlushablecontract, wherefalsemeans the telemetry transfer failed (or was cancelled), but this path returnsfalseafterFlush()completes successfully. Consequently,TelemetryClient.FlushAsyncreports a failure for every synchronous host channel even though no failure occurred. Returntrueafter the successful synchronous flush (and update the corresponding assertion inTelemetryActivatorTests).
this.hostChannel.Flush();
return Task.FromResult(false);
Directory.Build.props pins System.Drawing.Common 6.0.0 for the generated WorkerExtensions.csproj, but two companion comments still described a 4.7.3 override. Update them so future maintenance reflects the actual pin. Comment-only change; no MSBuild behavior is affected. The repo-root Directory.Packages.props 4.7.3 CPM pin is intentionally unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: bb9b7efb-7caf-485a-bc72-5eeee04310b8
Summary
APPLICATIONINSIGHTS_AUTHENTICATION_STRINGto Durable's private Application Insights pipelineAzure.CoretypeFixes #3497
Root cause
Durable distributed tracing creates a private
TelemetryConfiguration. It copied the Application Insights instrumentation key or connection string, but not the Microsoft Entra credential configured by the Functions host. WithDisableLocalAuth=true, host telemetry stayed authenticated while Durable Request/Dependency telemetry was rejected at ingestion.The obvious fix — construct a
ManagedIdentityCredentialand callSetAzureTokenCredentialon Durable's configuration — does not work inside the Functions host. Application Insights 2.22 resolvesAzure.Core.TokenCredentialthroughReflectionCredentialEnvelope, which binds the type in the host/default load context. A credential constructed in the function app load context is a different type identity and is rejected withArgumentException. This was confirmed on a live Function App, not inferred.Implementation
Durable does not obtain a credential at all. It wraps the host's
ITelemetryChanneland forwards its own telemetry through it. The host channel already holds the credential envelope and the Entra ingestion endpoint, so the authentication problem disappears without Durable ever touching anAzure.Coretype — no reflection, and no coupling to the host's load context or to Application Insights internals.Authorization=AADAuthorization=AAD;ClientId=<CLIENT_ID>TelemetryActivatorconstructor while retaining the existing two-argument public constructorHostForwardingTelemetryChannel, which forwardsSend/Flushto the host channelManagedIdentityCredentialfallback behavior for standalone WebJobs hosts, where there is no host channel to reuseMonitoring Metrics PublisherroleThree properties of the Application Insights SDK make the wrapper safe, and they are structural rather than conventions this code has to uphold:
ISupportCredentialEnvelopeisinternal, so an external wrapper cannot implement it. TheTelemetryChannelsetter's call toSetTelemetryChannelCredentialEnvelopeis therefore a no-op on the wrapper, and Durable's credential-free configuration cannot clear the host's credential.SetTelemetryChannelEndpointonly writesEndpointAddressforInMemoryChannelandServerTelemetryChannel. A custom channel is never written to, so configuring Durable's connection string cannot downgrade the host to the non-Entra endpoint.Disposeis intentionally empty. The host owns the channel's lifetime, and Durable's configuration must not be able to stop host telemetry.The host
TelemetryConfigurationitself is still intentionally not reused for telemetry. Host telemetry processors include operation filtering that is incompatible with Durable operations that do not carry the hostCategoryproperty; retaining the private configuration avoids the missing-span behavior that led to the earlier revert in #3053. Only the channel — the transport — is shared.Real Azure-hosted validation
All runs used temporary Azure Functions v4 Windows Consumption apps, real Azure Storage, workspace-based Application Insights with
DisableLocalAuth=true, and real managed identities. Exactly one identity at a time hadMonitoring Metrics Publisherscoped to the Application Insights component. No application code usedAzureCliCredential.Current head
7a435487— channel forwarding, .NET 8 in-processA diagnostic endpoint resolved the production-registered
ITelemetryActivatorfrom the live host and reported the wiring:{ "activatorType": "...DurableTask.Correlation.TelemetryActivator", "durableChannelType": "...DurableTask.Correlation.HostForwardingTelemetryChannel", "hostChannelType": "Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.ServerTelemetryChannel", "hostChannelAssembly": "Microsoft.AI.ServerTelemetryChannel", "wrappedIsHostChannel": true, "durableConfigurationIsHostConfiguration": false }The wrapper holds the host's real
ServerTelemetryChannelinstance, and Durable's configuration is still its own — so the isolated processor/module pipeline that #3053 depended on is intact.Ingested span chain, identical in both runs (user-assigned shown):
Initialization logged the expected identity type for each run, and the host-channel-unavailable warning never fired. Ordinary host telemetry continued to flow throughout, confirming the shared channel was not disturbed.
Earlier heads
The same harness previously reproduced the bug and validated the credential-reuse approach. Those results still establish the failure mode and the breadth of the fix.
The isolated and Node.js runs confirm the fix applies to host-generated Durable spans independently of the language worker. Worker-direct Application Insights/OpenTelemetry remains a separate pipeline. Normal non-.NET rollout still requires a Durable extension release followed by an extension-bundle release.
Automated validation
TelemetryActivatorTests: 10/10 on net8.0 and net10.0CorrelationEndToEndTests: 37/37 on net8.0 and net10.0New coverage for this design:
OnSendtest channel is preserved rather than replacedCleanup and security
Configuration
The connection string remains required:
Choose one authentication form:
The selected identity needs
Monitoring Metrics Publisheron the Application Insights component.Official references:
APPLICATIONINSIGHTS_AUTHENTICATION_STRING