You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If an ASP.NET Core application processes a HTTP request with distributed tracing headers (traceparent and baggage) AND an exception occurs in the controller, then the Elastic.Apm logger writes the following log entry.
fail: Elastic.Apm[0]
{AspNetCoreDiagnosticListener} Failed capturing DiagnosticSource event
System.NullReferenceException: Object reference not set to an instance of an object.
at Elastic.Apm.Model.Error.CheckAndCaptureBaggage() in C:\Users\oufaev\source\repos\apm-agent-dotnet\src\Elastic.Apm\Model\Error.cs:line 77
at Elastic.Apm.Model.Error..ctor(Transaction transaction, String parentId, IApmLogger loggerArg, Dictionary`2 labels) in C:\Users\oufaev\source\repos\apm-agent-dotnet\src\Elastic.Apm\Model\Error.cs:line 58
at Elastic.Apm.Model.Error..ctor(CapturedException capturedException, Transaction transaction, String parentId, IApmLogger loggerArg, Dictionary`2 labels) in C:\Users\oufaev\source\repos\apm-agent-dotnet\src\Elastic.Apm\Model\Error.cs:line 25
at Elastic.Apm.Model.ExecutionSegmentCommon.CaptureException(Exception exception, IApmLogger logger, IPayloadSender payloadSender, IExecutionSegment executionSegment, IConfigurationReader configurationReader, Transaction transaction, IApmServerInfo apmServerInfo, String culprit, Boolean isHandled, String parentId, Dictionary`2 labels) in C:\Users\oufaev\source\repos\apm-agent-dotnet\src\Elastic.Apm\Model\ExecutionSegmentCommon.cs:line 203
at Elastic.Apm.Model.Transaction.CaptureException(Exception exception, String culprit, Boolean isHandled, String parentId, Dictionary`2 labels) in C:\Users\oufaev\source\repos\apm-agent-dotnet\src\Elastic.Apm\Model\Transaction.cs:line 779
at Elastic.Apm.AspNetCore.DiagnosticListener.AspNetCoreDiagnosticListener.HandleOnNext(KeyValuePair`2 kv) in C:\Users\oufaev\source\repos\apm-agent-dotnet\src\integrations\Elastic.Apm.AspNetCore\DiagnosticListener\AspNetCoreDiagnosticListener.cs:line 89
at Elastic.Apm.DiagnosticListeners.DiagnosticListenerBase.OnNext(KeyValuePair`2 kv) in C:\Users\oufaev\source\repos\apm-agent-dotnet\src\Elastic.Apm\DiagnosticListeners\DiagnosticListenerBase.cs:line 53
Then do HTTP request. To reproduce the problem it is really important to send the baggage header, and in the traceparent header the field with the sampled flag should be 00.
private void CheckAndCaptureBaggage()
{
if (Activity.Current == null || !Activity.Current.Baggage.Any())
return;
foreach (var baggage in Activity.Current.Baggage)
{
if (!WildcardMatcher.IsAnyMatch(Configuration.BaggageToAttach, baggage.Key))
continue;
var newKey = $"baggage.{baggage.Key}";
var labels = Context.InternalLabels.Value; // Here Context is null, so the error occurs
labels[newKey] = baggage.Value;
}
}
The text was updated successfully, but these errors were encountered:
Thanks for reporting this @OlegUfaev, this sounds like a nasty issue. This didn't make the cutoff for the several bug fix releases we did this week but I put this at the top of my queue on Monday.
APM Agent version
Elastic.Apm.AspNetCore v1.28.0
Environment
Operating system and version:
Windows 10
.NET Framework/Core name and version (e.g. .NET 4.6.2, NET Core 3.1.100) :
.NET 8
Application Target Framework(s) (e.g. net462, netcoreapp3.1):
.net8.0
Describe the bug
If an ASP.NET Core application processes a HTTP request with distributed tracing headers (
traceparent
andbaggage
) AND an exception occurs in the controller, then theElastic.Apm
logger writes the following log entry.To Reproduce
Steps to reproduce the behavior:
WebApiExample
baggage
header, and in thetraceparent
header the field with the sampled flag should be00
.Expected behavior
The System.NullReferenceException error does not occur.
Actual behavior
System.NullReferenceException error occurs.
The problem occurs in this method: Error.cs
The text was updated successfully, but these errors were encountered: