Skip to content

Commit 09ded4c

Browse files
Add a null check on transaction for Error (#2618)
Add a null check on transaction for Error' For issue: #2553
1 parent d3de22c commit 09ded4c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Elastic.Apm/Model/Error.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5-
using System;
65
using System.Collections.Generic;
76
using System.Diagnostics;
87
using System.Linq;
@@ -66,13 +65,16 @@ private void CheckAndCaptureBaggage(Transaction transaction)
6665

6766
//if context was not set prior we set it now to ensure we capture baggage for errors
6867
//occuring during unsampled transactions
69-
Context ??= transaction.Context.DeepCopy();
68+
Context ??= transaction?.Context.DeepCopy();
7069

7170
foreach (var baggage in Activity.Current.Baggage)
7271
{
7372
if (!WildcardMatcher.IsAnyMatch(Configuration.BaggageToAttach, baggage.Key))
7473
continue;
7574

75+
// The context is created only if there is a baggage value to insert.
76+
Context ??= new Context();
77+
7678
var newKey = $"baggage.{baggage.Key}";
7779
var labels = Context.InternalLabels.Value;
7880
labels[newKey] = baggage.Value;

0 commit comments

Comments
 (0)