Skip to content

Commit

Permalink
Downgrade System.Diagnostics.DiagnosticSource to v6 and add a check i…
Browse files Browse the repository at this point in the history
…f OpenTelemetry instrumentation can be used (#4487)

* Downgrade System.Diagnostics.DiagnosticSource to v6.

* Adds a check if OpenTelemetry instrumentation can be used. (#4486)

* Adds a check if OTel can be used.

* Comments. More specific error type.

* Add comment
  • Loading branch information
pmaytak authored Jan 10, 2024
1 parent 75dce4e commit ea376b4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageVersion Include="Microsoft.IdentityModel.Abstractions" Version="6.22.0" />
<PackageVersion Include="Microsoft.Web.WebView2" Version="1.0.864.35" />
<PackageVersion Include="System.ComponentModel.TypeConverter" Version="4.3.0" />
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="7.0.2" />
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="6.0.1" /> <!-- Should match Azure Functions runtime: https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/4456 -->
<PackageVersion Include="System.IO.FileSystem.AccessControl" Version="5.0.0" />
<PackageVersion Include="System.Net.NameResolution" Version="4.3.0" />
<PackageVersion Include="System.Runtime.Serialization.Formatters" Version="4.3.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ea376b4

Please sign in to comment.