From 7d8bed806087777165fe73f9275447e485161301 Mon Sep 17 00:00:00 2001 From: Peter <34331512+pmaytak@users.noreply.github.com> Date: Thu, 4 Jan 2024 01:27:57 -0800 Subject: [PATCH 1/3] Downgrade System.Diagnostics.DiagnosticSource to v6. --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index b8b977b6f3..3c246a996a 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -15,7 +15,7 @@ - + From 153757f37e604e8d03444eb27149068d58af2021 Mon Sep 17 00:00:00 2001 From: Peter <34331512+pmaytak@users.noreply.github.com> Date: Mon, 8 Jan 2024 18:51:33 -0800 Subject: [PATCH 2/3] Adds a check if OpenTelemetry instrumentation can be used. (#4486) * Adds a check if OTel can be used. * Comments. More specific error type. --- .../Features/OpenTelemetry/OtelInstrumentation.cs | 6 ++++++ .../PlatformsCommon/Shared/AbstractPlatformProxy.cs | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) 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 From a4b473544ee458ca32059075e77ae317fc394bae Mon Sep 17 00:00:00 2001 From: Peter <34331512+pmaytak@users.noreply.github.com> Date: Mon, 8 Jan 2024 18:59:10 -0800 Subject: [PATCH 3/3] Add comment --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 3c246a996a..32d9133eac 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -15,7 +15,7 @@ - +