From ce6738984910b5c7b8847cc71f1ba313528d2c98 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Mon, 30 Sep 2024 11:33:15 +0100 Subject: [PATCH] Skip Azure storage in OTel bridge when Elastic library is present --- .../OpenTelemetry/ElasticActivityListener.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Elastic.Apm/OpenTelemetry/ElasticActivityListener.cs b/src/Elastic.Apm/OpenTelemetry/ElasticActivityListener.cs index e288e13b4..0ebbe1fdc 100644 --- a/src/Elastic.Apm/OpenTelemetry/ElasticActivityListener.cs +++ b/src/Elastic.Apm/OpenTelemetry/ElasticActivityListener.cs @@ -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; @@ -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);