Skip to content

Commit

Permalink
Ensure we capture baggage when capturing Errors during unsampled tran…
Browse files Browse the repository at this point in the history
…sactions (#2427)
  • Loading branch information
Mpdreamz authored Aug 19, 2024
1 parent eae543f commit 824a5b4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Elastic.Apm/Model/Error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private Error(Transaction transaction, string parentId, IApmLogger loggerArg, Di

ParentId = parentId;

if (transaction != null && transaction.IsSampled)
if (transaction is { IsSampled: true })
{
Context = transaction.Context.DeepCopy();

Expand All @@ -55,19 +55,23 @@ private Error(Transaction transaction, string parentId, IApmLogger loggerArg, Di
}
}

CheckAndCaptureBaggage();
CheckAndCaptureBaggage(transaction);

IApmLogger logger = loggerArg?.Scoped($"{nameof(Error)}.{Id}");
logger.Trace()
?.Log("New Error instance created: {Error}. Time: {Time} (as timestamp: {Timestamp})",
this, TimeUtils.FormatTimestampForLog(Timestamp), Timestamp);
}

private void CheckAndCaptureBaggage()
private void CheckAndCaptureBaggage(Transaction transaction)
{
if (Activity.Current == null || !Activity.Current.Baggage.Any())
return;

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

foreach (var baggage in Activity.Current.Baggage)
{
if (!WildcardMatcher.IsAnyMatch(Configuration.BaggageToAttach, baggage.Key))
Expand Down

0 comments on commit 824a5b4

Please sign in to comment.