From cfd92bc9cb1e28350836c064003d97c30eac3ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Mon, 9 Dec 2024 12:56:50 +0100 Subject: [PATCH] Fix SqlClientInitializer Handles changes from https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2305 --- .../Loading/Initializers/SqlClientInitializer.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.AutoInstrumentation/Loading/Initializers/SqlClientInitializer.cs b/src/OpenTelemetry.AutoInstrumentation/Loading/Initializers/SqlClientInitializer.cs index 08bdbdac9a..887b4fe87a 100644 --- a/src/OpenTelemetry.AutoInstrumentation/Loading/Initializers/SqlClientInitializer.cs +++ b/src/OpenTelemetry.AutoInstrumentation/Loading/Initializers/SqlClientInitializer.cs @@ -1,6 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +using System.Reflection; using OpenTelemetry.AutoInstrumentation.Configurations; using OpenTelemetry.AutoInstrumentation.Plugins; @@ -41,8 +42,14 @@ private void InitializeOnFirstCall(ILifespanManager lifespanManager) }; _pluginManager.ConfigureTracesOptions(options); - var instrumentation = Activator.CreateInstance(instrumentationType, options)!; + var propertyInfo = instrumentationType.GetProperty("TracingOptions", BindingFlags.Static | BindingFlags.Public); + propertyInfo?.SetValue(null, options); - lifespanManager.Track(instrumentation); + var instrumentation = instrumentationType.InvokeMember("AddTracingHandle", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static, Type.DefaultBinder, null, []); + + if (instrumentation != null) + { + lifespanManager.Track(instrumentation); + } } }