Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3abc109
Add Entra auth to Durable tracing
YunchuWang Aug 6, 2026
c4fd90a
Merge branch 'dev' into yunchuwang-fix-3497-entra-tracing
YunchuWang Aug 6, 2026
5405752
Fix Entra credential reuse in Functions host
YunchuWang Aug 6, 2026
5fa4182
Harden host credential reuse validation
YunchuWang Aug 6, 2026
8b1b987
Test Durable credential selection branches
YunchuWang Aug 6, 2026
cddec93
Warn when host telemetry credential cannot be read
YunchuWang Aug 10, 2026
3d58aa6
Address review: upgrade logging package and cover the DI credential path
YunchuWang Aug 13, 2026
b170f32
Align remaining System.Drawing.Common pins with 6.0.0
YunchuWang Aug 13, 2026
47c0f5f
Raise WorkerExtensions System.Drawing.Common pin to 6.0.0
YunchuWang Aug 13, 2026
7a43548
Reuse the host telemetry channel instead of reading its credential
YunchuWang Aug 13, 2026
e5d5bc3
Fix telemetry shutdown flush lifecycle
YunchuWang Aug 13, 2026
77ff790
Update src/WebJobs.Extensions.DurableTask/Correlation/TelemetryActiva…
YunchuWang Aug 17, 2026
7de20d9
Merge branch 'dev' into yunchuwang-fix-3497-entra-tracing
YunchuWang Aug 17, 2026
fffc980
Clarify invalid authentication warning
YunchuWang Aug 17, 2026
bcbad7a
Merge branch 'dev' into yunchuwang-fix-3497-entra-tracing
YunchuWang Aug 18, 2026
c046003
Consolidate tracing warning logging
YunchuWang Aug 18, 2026
579419d
Merge branch 'dev' into yunchuwang-fix-3497-entra-tracing
YunchuWang Aug 18, 2026
30718c0
Merge branch 'dev' into yunchuwang-fix-3497-entra-tracing
YunchuWang Aug 19, 2026
1a11607
Merge branch 'dev' into yunchuwang-fix-3497-entra-tracing
YunchuWang Aug 20, 2026
2c27ccb
Merge branch 'dev' into yunchuwang-fix-3497-entra-tracing
YunchuWang Aug 21, 2026
516cff3
Merge branch 'dev' into yunchuwang-fix-3497-entra-tracing
YunchuWang Aug 21, 2026
fa8fc03
Align WorkerExtensions pin comments with the 6.0.0 override
YunchuWang Aug 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<PackageVersion Include="Microsoft.Azure.WebJobs" Version="3.0.45" />
<PackageVersion Include="Microsoft.Azure.WebJobs.Extensions.DurableTask.Analyzers" Version="0.5.0" />
<PackageVersion Include="Microsoft.Azure.WebJobs.Extensions.Rpc" Version="3.0.39" />
<PackageVersion Include="Microsoft.Azure.WebJobs.Logging.ApplicationInsights" Version="3.0.41" />
Comment thread
YunchuWang marked this conversation as resolved.
Resolved
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="10.0.2" />
<PackageVersion Include="Microsoft.Bcl.Memory" Version="10.0.5" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ You will also need to specify an Application Insights resource in the environmen

Next, you'll need to copy the connection string or instrumentation key for that resource to add in the environment variables. We recommend adding the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable, but you can also add `APPINSIGHTS_INSTRUMENTATIONKEY`. If you are running your app locally, then add this environment variable in `local.settings.json`. If you are running the app in Azure, then add it under `Configuration` as an application setting.

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.

#### Run the sample
The sample shows how Distributed Tracing V2 improves the observability of some flagship Durable Functions patterns.

Expand Down
110 changes: 110 additions & 0 deletions src/WebJobs.Extensions.DurableTask/Correlation/TelemetryActivator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Reflection;
using System.Security.Authentication;
using System.Threading.Tasks;
using Azure.Identity;
using DurableTask.ApplicationInsights;
using DurableTask.Core;
using DurableTask.Core.Settings;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Azure.WebJobs.Logging.ApplicationInsights;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using ApplicationInsightsTokenCredentialOptions = Microsoft.Azure.WebJobs.Logging.ApplicationInsights.TokenCredentialOptions;

namespace Microsoft.Azure.WebJobs.Extensions.DurableTask.Correlation
{
Expand All @@ -21,6 +26,7 @@ public class TelemetryActivator : ITelemetryActivator, IAsyncDisposable, IDispos
{
private readonly DurableTaskOptions options;
private readonly INameResolver nameResolver;
private readonly TelemetryConfiguration hostTelemetryConfiguration;
private EndToEndTraceHelper endToEndTraceHelper;
private TelemetryClient telemetryClient;

Expand All @@ -30,9 +36,24 @@ public class TelemetryActivator : ITelemetryActivator, IAsyncDisposable, IDispos
/// <param name="options">DurableTask options.</param>
/// <param name="nameResolver">Name resolver used for environment variables.</param>
public TelemetryActivator(IOptions<DurableTaskOptions> options, INameResolver nameResolver)
: this(options, nameResolver, hostTelemetryConfiguration: null)
{
}

/// <summary>
/// Constructor for initializing Distributed Tracing with the host telemetry configuration.
/// </summary>
/// <param name="options">DurableTask options.</param>
/// <param name="nameResolver">Name resolver used for environment variables.</param>
/// <param name="hostTelemetryConfiguration">Application Insights configuration owned by the host.</param>
public TelemetryActivator(
IOptions<DurableTaskOptions> options,
INameResolver nameResolver,
TelemetryConfiguration hostTelemetryConfiguration)
{
this.options = options.Value;
this.nameResolver = nameResolver;
this.hostTelemetryConfiguration = hostTelemetryConfiguration;
}

/// <summary>
Expand Down Expand Up @@ -190,6 +211,7 @@ private TelemetryConfiguration SetupTelemetryConfiguration()

string resolvedInstrumentationKey = this.nameResolver.Resolve("APPINSIGHTS_INSTRUMENTATIONKEY");
string resolvedConnectionString = this.nameResolver.Resolve("APPLICATIONINSIGHTS_CONNECTION_STRING");
string resolvedAuthenticationString = this.nameResolver.Resolve("APPLICATIONINSIGHTS_AUTHENTICATION_STRING");

bool instrumentationKeyProvided = !string.IsNullOrEmpty(resolvedInstrumentationKey);
bool connectionStringProvided = !string.IsNullOrEmpty(resolvedConnectionString);
Expand Down Expand Up @@ -238,7 +260,95 @@ private TelemetryConfiguration SetupTelemetryConfiguration()
config.ConnectionString = resolvedConnectionString;
}

if (!string.IsNullOrWhiteSpace(resolvedAuthenticationString))
{
try
{
ApplicationInsightsTokenCredentialOptions tokenCredentialOptions =
ApplicationInsightsTokenCredentialOptions.ParseAuthenticationString(resolvedAuthenticationString);
bool userAssignedIdentity = tokenCredentialOptions.ClientId != null;
ApplyAzureTokenCredential(config, this.hostTelemetryConfiguration, tokenCredentialOptions);
this.endToEndTraceHelper.ExtensionInformationalEvent(
hubName: this.options.HubName,
functionName: string.Empty,
instanceId: string.Empty,
message:
"Microsoft Entra authentication enabled for Durable distributed tracing using the "
+ $"{(userAssignedIdentity ? "user-assigned" : "system-assigned")} managed identity.",
writeToUserLogs: true);
}
catch (AuthenticationException)
{
this.LogInvalidAuthenticationString();
}
catch (FormatException)
{
this.LogInvalidAuthenticationString();
}
catch (ArgumentException)
{
this.LogAuthenticationStringCouldNotBeApplied();
}
}

return config;
}

internal static void ApplyAzureTokenCredential(
TelemetryConfiguration durableConfiguration,
TelemetryConfiguration hostConfiguration,
ApplicationInsightsTokenCredentialOptions tokenCredentialOptions)
{
object tokenCredential = GetAzureTokenCredential(hostConfiguration);
if (tokenCredential == null)
{
ManagedIdentityId managedIdentityId = tokenCredentialOptions.ClientId != null
? ManagedIdentityId.FromUserAssignedClientId(tokenCredentialOptions.ClientId)
: ManagedIdentityId.SystemAssigned;
tokenCredential = new ManagedIdentityCredential(managedIdentityId);
}

durableConfiguration.SetAzureTokenCredential(tokenCredential);
}

/// <summary>
/// Gets the host credential so the private Durable telemetry configuration uses the same
/// Azure.Core type loaded by the Functions host. Creating a new credential in the function
/// app load context can be rejected by the host's Application Insights SDK.
/// </summary>
internal static object GetAzureTokenCredential(TelemetryConfiguration configuration)
{
if (configuration == null)
{
return null;
}

PropertyInfo envelopeProperty = typeof(TelemetryConfiguration).GetProperty(
"CredentialEnvelope",
BindingFlags.Instance | BindingFlags.NonPublic);
object credentialEnvelope = envelopeProperty?.GetValue(configuration);
PropertyInfo credentialProperty = credentialEnvelope?.GetType().GetProperty(
"Credential",
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
return credentialProperty?.GetValue(credentialEnvelope);
}

private void LogInvalidAuthenticationString()
{
this.endToEndTraceHelper.ExtensionWarningEvent(
hubName: this.options.HubName,
functionName: string.Empty,
instanceId: string.Empty,
message: "APPLICATIONINSIGHTS_AUTHENTICATION_STRING is invalid and will not be used for Durable distributed tracing.");
Comment thread
YunchuWang marked this conversation as resolved.
Resolved
}

private void LogAuthenticationStringCouldNotBeApplied()
{
this.endToEndTraceHelper.ExtensionWarningEvent(
hubName: this.options.HubName,
functionName: string.Empty,
instanceId: string.Empty,
message: "APPLICATIONINSIGHTS_AUTHENTICATION_STRING could not be applied and will not be used for Durable distributed tracing.");
Comment thread
YunchuWang marked this conversation as resolved.
Resolved
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<ItemGroup>
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Microsoft.Azure.WebJobs" />
<PackageReference Include="Microsoft.Azure.WebJobs.Logging.ApplicationInsights" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Rpc" />
<PackageReference Include="Microsoft.Azure.DurableTask.Core" />
<PackageReference Include="Microsoft.Azure.DurableTask.AzureStorage" />
Expand Down
1 change: 0 additions & 1 deletion test/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<ItemGroup>
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="FluentAssertions" Version="4.19.4" />
<PackageVersion Include="Microsoft.Azure.WebJobs.Logging.ApplicationInsights" Version="3.0.41" />
<PackageVersion Include="Microsoft.Build" Version="17.8.43" />
<PackageVersion Include="Microsoft.Build.Framework" Version="17.8.43" />
<PackageVersion Include="Microsoft.Build.Locator" Version="1.4.1" />
Expand Down
93 changes: 93 additions & 0 deletions test/FunctionsV2/Helpers/TelemetryActivatorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Reflection;
using Azure.Identity;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask.Correlation;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
using ApplicationInsightsTokenCredentialOptions = Microsoft.Azure.WebJobs.Logging.ApplicationInsights.TokenCredentialOptions;

namespace Microsoft.Azure.WebJobs.Extensions.DurableTask.Tests
{
public class TelemetryActivatorTests
{
[Fact]
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
public void GetAzureTokenCredential_ReturnsCredentialFromHostConfiguration()
{
using TelemetryConfiguration hostConfiguration = TelemetryConfiguration.CreateDefault();
var credential = new ManagedIdentityCredential(ManagedIdentityId.SystemAssigned);
hostConfiguration.SetAzureTokenCredential(credential);

MethodInfo method = typeof(TelemetryActivator).GetMethod(
"GetAzureTokenCredential",
BindingFlags.NonPublic | BindingFlags.Static);

Assert.NotNull(method);
Assert.Same(credential, method.Invoke(obj: null, new object[] { hostConfiguration }));
}

[Fact]
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
public void ApplyAzureTokenCredential_ReusesHostCredential()
{
using TelemetryConfiguration hostConfiguration = TelemetryConfiguration.CreateDefault();
using TelemetryConfiguration durableConfiguration = TelemetryConfiguration.CreateDefault();
var credential = new ManagedIdentityCredential(ManagedIdentityId.SystemAssigned);
hostConfiguration.SetAzureTokenCredential(credential);
ApplicationInsightsTokenCredentialOptions options =
ApplicationInsightsTokenCredentialOptions.ParseAuthenticationString("Authorization=AAD");

TelemetryActivator.ApplyAzureTokenCredential(durableConfiguration, hostConfiguration, options);

Assert.Same(credential, TelemetryActivator.GetAzureTokenCredential(durableConfiguration));
}

[Theory]
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
[InlineData("Authorization=AAD")]
[InlineData("Authorization=AAD;ClientId=00000000-0000-0000-0000-000000000001")]
public void ApplyAzureTokenCredential_WithoutHostCredential_UsesManagedIdentity(string authenticationString)
{
using TelemetryConfiguration durableConfiguration = TelemetryConfiguration.CreateDefault();
ApplicationInsightsTokenCredentialOptions options =
ApplicationInsightsTokenCredentialOptions.ParseAuthenticationString(authenticationString);

TelemetryActivator.ApplyAzureTokenCredential(
durableConfiguration,
hostConfiguration: null,
options);

Assert.IsType<ManagedIdentityCredential>(
TelemetryActivator.GetAzureTokenCredential(durableConfiguration));
}

[Fact]
[Trait("Category", PlatformSpecificHelpers.TestCategory)]
public void DependencyInjection_SelectsHostTelemetryConfigurationConstructor()
{
using TelemetryConfiguration hostConfiguration = TelemetryConfiguration.CreateDefault();
var services = new ServiceCollection();
services.AddSingleton<IOptions<DurableTaskOptions>>(
Microsoft.Extensions.Options.Options.Create(new DurableTaskOptions()));
services.AddSingleton(Mock.Of<INameResolver>());
services.AddSingleton(hostConfiguration);
services.AddSingleton<ITelemetryActivator, TelemetryActivator>();

using ServiceProvider provider = services.BuildServiceProvider();
TelemetryActivator activator =
Assert.IsType<TelemetryActivator>(provider.GetRequiredService<ITelemetryActivator>());
FieldInfo field = typeof(TelemetryActivator).GetField(
"hostTelemetryConfiguration",
BindingFlags.Instance | BindingFlags.NonPublic);

Assert.NotNull(field);
Assert.Same(hostConfiguration, field.GetValue(activator));
}
}
}
Loading