Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure we capture baggage when capturing Errors during unsampled transactions #2427

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Mpdreamz marked this conversation as resolved.
Show resolved Hide resolved

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