Skip to content

Conversation

@TimothyMothra
Copy link

@TimothyMothra TimothyMothra commented Nov 22, 2022

Fixes #3863 .

ConsoleExporter fails silently when exporting an ActivityLink without Tags.

Changes

  • added null check to ConsoleActivityExporter
  • added new test class ConsoleActivityExporterTest to reproduce reported issue
  • fix "CS8602 Dereference of a possibly null reference." in Utils.cs
    Because the new test project has nullable enable, the Utils class needed to be fixed.
    I used Debug.Assert to check for null and used the null-forgiving operator to dismiss the build error.

Please provide a brief description of the changes here.

For significant contributions please make sure you have completed the following items:

  • Appropriate CHANGELOG.md updated for non-trivial changes
  • Design discussion issue #
  • Changes in public API reviewed

@TimothyMothra TimothyMothra requested a review from a team November 22, 2022 19:19
reyang
reyang previously requested changes Nov 22, 2022
Copy link
Member

@reyang reyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnitTestEventListener is beyond the scope of the issue/PR.

foreach (var activityLink in activity.Links)
{
this.WriteLine($" {activityLink.Context.TraceId} {activityLink.Context.SpanId}");
foreach (var attribute in activityLink.Tags)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TimothyMothra FYI you could re-write this as:

foreach (ref readonly var attribute in activityLink.EnumerateTagObjects())

More efficient and it will handle the null case for you 😄

Might be worth re-writing all of the foreach loops in here to use the newer pattern just to have a good reference doing it correctly. Follow-up thing if you are interested 😉

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take this as a follow up after this PR merges. :)

@codecov
Copy link

codecov bot commented Nov 22, 2022

Codecov Report

Merging #3932 (ddf9cf2) into main (44d2fe2) will increase coverage by 0.19%.
The diff coverage is 84.21%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3932      +/-   ##
==========================================
+ Coverage   85.30%   85.50%   +0.19%     
==========================================
  Files         287      288       +1     
  Lines       11026    11059      +33     
==========================================
+ Hits         9406     9456      +50     
+ Misses       1620     1603      -17     
Impacted Files Coverage Δ
...AspNetCore/Implementation/HttpInMetricsListener.cs 74.35% <57.14%> (-9.65%) ⬇️
...emetry.Exporter.Console/ConsoleActivityExporter.cs 48.27% <100.00%> (+48.27%) ⬆️
...ry.Instrumentation.AspNetCore/AspNetCoreMetrics.cs 100.00% <100.00%> (ø)
...NetCore/AspNetCoreMetricsInstrumentationOptions.cs 100.00% <100.00%> (ø)
...ation.AspNetCore/MeterProviderBuilderExtensions.cs 100.00% <100.00%> (ø)
...lemetry/Internal/SelfDiagnosticsConfigRefresher.cs 86.53% <0.00%> (-5.77%) ⬇️
...lementation/SqlClientInstrumentationEventSource.cs 70.83% <0.00%> (-4.17%) ⬇️
...emetry.Api/Internal/OpenTelemetryApiEventSource.cs 79.41% <0.00%> (-2.95%) ⬇️
...nTelemetry/Internal/OpenTelemetrySdkEventSource.cs 80.15% <0.00%> (-2.39%) ⬇️
src/OpenTelemetry/BatchExportProcessor.cs 82.24% <0.00%> (-1.87%) ⬇️
... and 4 more

@reyang reyang dismissed their stale review November 22, 2022 22:22

blocker removed

@TimothyMothra

This comment was marked as resolved.


## Unreleased

* Bug fix, ConsoleExporter fails silently when exporting an `ActivityLink`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Reword this to something like:
Bug fix to prevent ConsoleExporter from failing when exporting an ActivityLink without tags.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

5 participants