From 440a343f05c2bcb44149781f4283fe721eea47a1 Mon Sep 17 00:00:00 2001 From: Matthew Hensley Date: Fri, 8 Nov 2024 15:04:17 -0500 Subject: [PATCH] skip recording w/o metric handles --- .../Implementation/SqlClientDiagnosticListener.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs index ba6a0fa66d..8a91e103cf 100644 --- a/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs +++ b/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs @@ -248,6 +248,11 @@ public override void OnEventWritten(string name, object? payload) private void RecordDuration(Activity? activity, object? payload, bool hasError = false) { + if (SqlClientInstrumentation.MetricHandles == 0) + { + return; + } + TagList tags = default(TagList); if (activity != null && activity.IsAllDataRequested)