From 9acab9646608da5e76b11cd15beeeb63ebd4c622 Mon Sep 17 00:00:00 2001 From: Jeremy Besson Date: Tue, 27 May 2025 12:43:47 +0300 Subject: [PATCH 1/4] Fix null reference exception in TryToCompressRegular method in Span --- src/Elastic.Apm/Model/Span.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Elastic.Apm/Model/Span.cs b/src/Elastic.Apm/Model/Span.cs index 2fbe2db54..b22dfddfe 100644 --- a/src/Elastic.Apm/Model/Span.cs +++ b/src/Elastic.Apm/Model/Span.cs @@ -645,8 +645,11 @@ private bool TryToCompressRegular(Span sibling) { Composite ??= new Composite(); Composite.CompressionStrategy = "same_kind"; - if (_context.IsValueCreated && Context.Service?.Target != null) + if (_context.IsValueCreated && Context?.Service?.Target != null) + { Name = "Calls to " + Context.Service.Target.ToDestinationServiceResource(); + } + return true; } From 470cb7b8bada7eeb0bb1f36f7b28707f88687986 Mon Sep 17 00:00:00 2001 From: Jeremy Besson Date: Fri, 20 Jun 2025 09:43:06 +0300 Subject: [PATCH 2/4] Avoid that a shallow exception got thrown when trying to set a parent to an activity when a parent already exists. --- src/Elastic.Apm/Model/Transaction.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Elastic.Apm/Model/Transaction.cs b/src/Elastic.Apm/Model/Transaction.cs index 3558d7a56..92f9bf034 100644 --- a/src/Elastic.Apm/Model/Transaction.cs +++ b/src/Elastic.Apm/Model/Transaction.cs @@ -270,10 +270,14 @@ internal Transaction( // This is so that the distributed tracing data will flow to any child activities try { - _activity.SetParentId( - ActivityTraceId.CreateFromString(distributedTracingData.TraceId.AsSpan()), - ActivitySpanId.CreateFromString(distributedTracingData.ParentId.AsSpan()), - distributedTracingData.FlagRecorded ? ActivityTraceFlags.Recorded : ActivityTraceFlags.None); + // Only if the parent does not already exists + if (_activity.ParentId != null && _activity.Parent != null) + { + _activity.SetParentId( + ActivityTraceId.CreateFromString(distributedTracingData.TraceId.AsSpan()), + ActivitySpanId.CreateFromString(distributedTracingData.ParentId.AsSpan()), + distributedTracingData.FlagRecorded ? ActivityTraceFlags.Recorded : ActivityTraceFlags.None); + } if (distributedTracingData.HasTraceState) _activity.TraceStateString = distributedTracingData.TraceState.ToTextHeader(); From fed1b5f6afeb290de9eb0584cfd32d19ff6e7219 Mon Sep 17 00:00:00 2001 From: Jeremy Besson Date: Fri, 20 Jun 2025 09:45:27 +0300 Subject: [PATCH 3/4] Fix --- src/Elastic.Apm/Model/Transaction.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Elastic.Apm/Model/Transaction.cs b/src/Elastic.Apm/Model/Transaction.cs index 92f9bf034..d29fac4a8 100644 --- a/src/Elastic.Apm/Model/Transaction.cs +++ b/src/Elastic.Apm/Model/Transaction.cs @@ -270,7 +270,7 @@ internal Transaction( // This is so that the distributed tracing data will flow to any child activities try { - // Only if the parent does not already exists + // Only if the parent does not already exist if (_activity.ParentId != null && _activity.Parent != null) { _activity.SetParentId( From f57a1eb185c69dbb5a9393085fa25aadb564afc2 Mon Sep 17 00:00:00 2001 From: Jeremy Besson Date: Fri, 20 Jun 2025 14:30:26 +0300 Subject: [PATCH 4/4] Fix --- src/Elastic.Apm/Model/Transaction.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Elastic.Apm/Model/Transaction.cs b/src/Elastic.Apm/Model/Transaction.cs index d29fac4a8..4e504fbef 100644 --- a/src/Elastic.Apm/Model/Transaction.cs +++ b/src/Elastic.Apm/Model/Transaction.cs @@ -271,7 +271,7 @@ internal Transaction( try { // Only if the parent does not already exist - if (_activity.ParentId != null && _activity.Parent != null) + if (_activity.ParentId == null && _activity.Parent == null) { _activity.SetParentId( ActivityTraceId.CreateFromString(distributedTracingData.TraceId.AsSpan()),