From d732fed91fd285732a28289d7e9e68db0660f41e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Bienh=C3=BCls?= Date: Fri, 8 Mar 2024 17:15:20 +0100 Subject: [PATCH] Fixed NullReferenceException --- MySQL.Data/src/MySQLActivitySource.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/MySQL.Data/src/MySQLActivitySource.cs b/MySQL.Data/src/MySQLActivitySource.cs index 069a3bc3d..efe99cfac 100644 --- a/MySQL.Data/src/MySQLActivitySource.cs +++ b/MySQL.Data/src/MySQLActivitySource.cs @@ -74,9 +74,12 @@ internal static Activity CommandStart(MySqlCommand command) var settings = command.Connection.Settings; var activity = Activity.Current != null ? Source.StartActivity("SQL Statement", ActivityKind.Client, Activity.Current.Context) : Source.StartActivity("SQL Statement", ActivityKind.Client); - // passing through this attribute will propagate the context into the server - string query_attr = $"00-{Activity.Current.Context.TraceId}-{Activity.Current.Context.SpanId}-00"; - command.Attributes.SetAttribute("traceparent", query_attr); + if (Activity.Current != null) + { + // passing through this attribute will propagate the context into the server + string query_attr = $"00-{Activity.Current.Context.TraceId}-{Activity.Current.Context.SpanId}-00"; + command.Attributes.SetAttribute("traceparent", query_attr); + } activity?.SetTag("db.system", "mysql"); activity?.SetTag("db.name", command.Connection.Database);