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

[Console Exporter] Partial output when Activity has a link without any tags due to NullReferenceException #3863

Closed
spanglerco opened this issue Nov 3, 2022 · 1 comment · Fixed by #3932
Labels
bug Something isn't working

Comments

@spanglerco
Copy link

Bug Report

<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.4.0-beta.2" />
<TargetFramework>net6.0</TargetFramework>

Symptom

With an Activity that includes an ActivityLink without any tags, the console exporter throws a NullReferenceException when stopping/disposing the Activity.

What is the expected behavior?

The console output shows all activity information including the "Resource associated with Activity".

What is the actual behavior?

The link is included in the output, but not the "Resource associated with Activity" afterwards. A NullReferenceException is thrown, which is caught by the SDK and included in the diagnostics log:

2022-11-03T15:44:00.6954123Z:Unknown error in SpanProcessor event '{0}': '{1}'.{OnExport}{System.NullReferenceException: Object reference not set to an instance of an object.
   at OpenTelemetry.Exporter.ConsoleActivityExporter.Export(Batch`1& batch)
   at OpenTelemetry.SimpleExportProcessor`1.OnExport(T data)}

Visual Studio breaks for the exception by default, but execution can be resumed (this is configurable).

Reproduce

using System.Diagnostics;
using OpenTelemetry;
using OpenTelemetry.Trace;

var source = new ActivitySource("Testing");
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .AddSource("Testing")
    .AddConsoleExporter()
    .Build();

ActivityContext context;
using (var first = source.StartActivity("first"))
{
    context = first!.Context;
}

var links = new[] { new ActivityLink(context) };
using var second = source.StartActivity(ActivityKind.Internal, links: links, name: "Second");

Additional Context

The problem is in ConsoleActivityExporter.cs where it has a foreach to enumerate the tags without first checking for null. In the same file, it looks like it may also have an issue with events that don't have any tags, but I haven't testing that case. The code should probably switch to using activityLink.EnumerateTags() (like in #3580).

@spanglerco spanglerco added the bug Something isn't working label Nov 3, 2022
@TimothyMothra
Copy link
Contributor

I'm looking into this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants