Skip to content

Commit

Permalink
Skip Azure storage in OTel bridge when Elastic library is present
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejgordon committed Sep 30, 2024
1 parent 221ee85 commit ce67389
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Elastic.Apm/OpenTelemetry/ElasticActivityListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ internal ElasticActivityListener(IApmAgent agent, HttpTraceConfiguration httpTra
AppDomain.CurrentDomain.GetAssemblies().SingleOrDefault(assembly =>
assembly.GetName().Name == "Elastic.Apm.Azure.ServiceBus") != null;

private static readonly bool HasStorageInstrumentation =
AppDomain.CurrentDomain.GetAssemblies().SingleOrDefault(assembly =>
assembly.GetName().Name == "Elastic.Apm.Azure.Storage") != null;

private readonly IApmLogger _logger;
private Tracer _tracer;
private readonly HttpTraceConfiguration _httpTraceConfiguration;
Expand Down Expand Up @@ -80,8 +84,22 @@ internal void Start(Tracer tracerInternal)
return;
}
if (HasStorageInstrumentation && activity.Tags.Any(kvp =>
kvp.Key.Equals("az.namespace", StringComparison.Ordinal) && kvp.Value.Equals("Microsoft.Storage", StringComparison.Ordinal)))
{
_logger.Debug()?.Log("ActivityStarted: name:{DisplayName} id:{ActivityId} traceId:{TraceId} skipped 'Microsoft.Storage' " +
"activity because 'Elastic.Apm.Azure.Storage' is present in the application.",
activity.DisplayName, activity.Id, activity.TraceId);
return;
}
if (KnownListeners.SkippedActivityNamesSet.Contains(activity.DisplayName))
{
_logger.Trace()?.Log("ActivityStarted: name:{DisplayName} id:{ActivityId} traceId:{TraceId} skipped because it matched " +
"a skipped activity name defined in KnownListeners.");
return;
}
_logger.Trace()?.Log("ActivityStarted: name:{DisplayName} id:{ActivityId} traceId:{TraceId}",
activity.DisplayName, activity.Id, activity.TraceId);
Expand Down

0 comments on commit ce67389

Please sign in to comment.