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

OTLP exporter: Standardize handling of attributes #3262

Merged
merged 22 commits into from
May 11, 2022

Conversation

alanwest
Copy link
Member

@alanwest alanwest commented May 9, 2022

Related to #2010.

This PR is specifically in the context of the OTLP exporter but my purpose is to drive the more general conversation for what datatypes all SDK components should handle.

I've taken a pretty broad stance to begin with. This PR ensures that the OTLP exporter handles strings and nearly all .NET built-in value types. Arrays of these types are handled as well (partially addresses #3229 for OTLP exporter).

The ToOtlpAttribute method handles attributes on logs, metrics, and resources. Attributes on trace data is handled in a different part of the code and has not yet been expanded to handle the same set of datatypes. I'll wait until we settle on the set of datatypes we want to handle to fix traces.

@alanwest alanwest requested a review from a team May 9, 2022 19:19
// case ulong: May throw an exception on overflow.
// case decimal: Converting to double produces rounding errors.
default:
return null;
Copy link
Member

Choose a reason for hiding this comment

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

this would be a breaking change? as we were doing ToString() before, and now we ignore the value? should we retain the current behavior?
(Or we treat current behavior as a unintentional bug, and this is indeed the fix)

Either way - please add to changelog entry as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Or we treat current behavior as a unintentional bug, and this is indeed the fix

This is where I'm leaning but want to hear other opinions. While unusual, I have seen a ToString overload be susceptible to exceptions, mutating state, and even deadlock.

As an end user, I'd prefer to have to be intentional about how I'm ToStringing my attributes that are not just simple numeric types or strings.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is the right change.

One thing to note is - do we log anywhere about this? i.e if I miss some values, and i enable self-diagnostics, would there be something that tells me exporter is dropping things?

Copy link
Member Author

Choose a reason for hiding this comment

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

At one point, I thought the Jaeger and Zipkin exporters did not ToString arbitrary attributes. I guess they do now. So, I'm ok ToStringing everything else if that's what folks prefer.

Copy link
Member Author

Choose a reason for hiding this comment

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

One thing to note is - do we log anywhere about this? i.e if I miss some values, and i enable self-diagnostics, would there be something that tells me exporter is dropping things?

No logging at the moment - will add.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is the right change.

In that case, we should update Zipkin, Jaeger, Console, Prometheus to behave the same. Maybe there's some way to unify this logic, but I haven't put my mind to this yet.

Copy link
Member

Choose a reason for hiding this comment

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

From SIG meet: revert to use ToString(), and explore IFormattable in a follow up.

Copy link
Member

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

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

LGTM. Need changelog before merge

@alanwest alanwest force-pushed the alanwest/otlp-attributes branch from 2f4d235 to 8624117 Compare May 10, 2022 20:05
@codecov
Copy link

codecov bot commented May 10, 2022

Codecov Report

Merging #3262 (55979bf) into main (5c168a3) will increase coverage by 0.16%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3262      +/-   ##
==========================================
+ Coverage   85.48%   85.65%   +0.16%     
==========================================
  Files         262      263       +1     
  Lines        9502     9515      +13     
==========================================
+ Hits         8123     8150      +27     
+ Misses       1379     1365      -14     
Impacted Files Coverage Δ
...metryProtocol/Implementation/ActivityExtensions.cs 93.05% <ø> (+1.24%) ⬆️
...tation/OpenTelemetryProtocolExporterEventSource.cs 86.36% <100.00%> (+1.36%) ⬆️
...tryProtocol/Implementation/OtlpCommonExtensions.cs 100.00% <100.00%> (ø)
...ter.ZPages/Implementation/ZPagesActivityTracker.cs 97.14% <0.00%> (-2.86%) ⬇️
...nTelemetry/Internal/OpenTelemetrySdkEventSource.cs 76.72% <0.00%> (+2.58%) ⬆️
...lemetry/Internal/SelfDiagnosticsConfigRefresher.cs 92.30% <0.00%> (+5.76%) ⬆️
...emetry.Api/Internal/OpenTelemetryApiEventSource.cs 82.35% <0.00%> (+5.88%) ⬆️

@alanwest alanwest requested a review from cijothomas May 11, 2022 00:43
@alanwest
Copy link
Member Author

@cijothomas I think this is good to go now. As discussed in the SIG meeting, I've restored the behavior of calling ToString on all other types not explicitly supported.

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.

3 participants