diff --git a/Directory.Packages.props b/Directory.Packages.props index b8b977b6f3..32d9133eac 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -15,7 +15,7 @@ - + diff --git a/src/client/Microsoft.Identity.Client/Platforms/Features/OpenTelemetry/OtelInstrumentation.cs b/src/client/Microsoft.Identity.Client/Platforms/Features/OpenTelemetry/OtelInstrumentation.cs index 3593e2d7df..a0986b2d41 100644 --- a/src/client/Microsoft.Identity.Client/Platforms/Features/OpenTelemetry/OtelInstrumentation.cs +++ b/src/client/Microsoft.Identity.Client/Platforms/Features/OpenTelemetry/OtelInstrumentation.cs @@ -80,6 +80,12 @@ internal class OtelInstrumentation : IOtelInstrumentation unit: "ms", description: "Performance of token acquisition calls network latency")); + public OtelInstrumentation() + { + // Needed to fail fast if the runtime, like in-process Azure Functions, doesn't support OpenTelemetry + _ = Meter.Version; + } + // Aggregates the successful requests based on token source and cache refresh reason. void IOtelInstrumentation.LogSuccessMetrics( string platform, diff --git a/src/client/Microsoft.Identity.Client/PlatformsCommon/Shared/AbstractPlatformProxy.cs b/src/client/Microsoft.Identity.Client/PlatformsCommon/Shared/AbstractPlatformProxy.cs index 85c8a22ce8..1d6d69a8fb 100644 --- a/src/client/Microsoft.Identity.Client/PlatformsCommon/Shared/AbstractPlatformProxy.cs +++ b/src/client/Microsoft.Identity.Client/PlatformsCommon/Shared/AbstractPlatformProxy.cs @@ -2,7 +2,7 @@ // Licensed under the MIT License. using System; -using System.Security.Cryptography.X509Certificates; +using System.IO; using System.Threading.Tasks; using Microsoft.Identity.Client.AuthScheme.PoP; using Microsoft.Identity.Client.Cache; @@ -55,7 +55,15 @@ protected AbstractPlatformProxy(ILoggerAdapter logger) private IOtelInstrumentation InternalGetOtelInstrumentation() { #if SUPPORTS_OTEL - return new OtelInstrumentation(); + try + { + return new OtelInstrumentation(); + } catch (FileNotFoundException ex) + { + // Can happen in in-process Azure Functions: https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/4456 + Logger.Warning("Failed instantiating OpenTelemetry instrumentation. Exception: " + ex.Message); + return new NullOtelInstrumentation(); + } #else return new NullOtelInstrumentation(); #endif