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

Resource Attributes allow Primitive Arrays #1852

Merged
merged 13 commits into from
Mar 4, 2021
Merged

Resource Attributes allow Primitive Arrays #1852

merged 13 commits into from
Mar 4, 2021

Conversation

Austin-Tan
Copy link
Member

Fixes #1652

Changes

Previously would throw exceptions upon string[], bool[], long[], double[]. Accepts now.
Also, throws exception on null KEYs as well, not just null VALUEs

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

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

@Austin-Tan Austin-Tan requested a review from a team February 25, 2021 07:49
@@ -93,8 +93,7 @@ public Resource Merge(Resource other)
string sanitizedKey;
if (attribute.Key == null)
{
OpenTelemetrySdkEventSource.Log.InvalidArgument("Create resource", "attribute key", "Attribute key should be non-null string.");
sanitizedKey = string.Empty;
throw new System.ArgumentException("Resource's attributes contains a null key");
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

The message might be misleading since it is talking about "attributes on the resource" but the method is only focusing on one attribute.
One possible way is to put something like nameof(attribute) has a null key here.

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 might be misunderstanding but each attribute is just a key and value, so a null key makes it impossible to do that right? I could print the Value instead since Key is null, but it may also be null and would then require checking and formatting

Copy link
Member Author

Choose a reason for hiding this comment

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

Found out C# prevents you from instantiating any dictionary where the key is null, it'll throw its own ArgumentNullException. Might be the reason we originally didn't check for key == null, and I'm happy to just remove this change if that makes sense.

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.

LGTM.

@codecov
Copy link

codecov bot commented Feb 25, 2021

Codecov Report

Merging #1852 (1b3e1aa) into main (cb066cb) will increase coverage by 0.24%.
The diff coverage is 99.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1852      +/-   ##
==========================================
+ Coverage   83.77%   84.02%   +0.24%     
==========================================
  Files         187      187              
  Lines        5967     6004      +37     
==========================================
+ Hits         4999     5045      +46     
+ Misses        968      959       -9     
Impacted Files Coverage Δ
src/OpenTelemetry/Logs/OpenTelemetryLogger.cs 71.42% <ø> (ø)
src/OpenTelemetry/Trace/TracerProviderSdk.cs 95.16% <98.64%> (+4.38%) ⬆️
...metryProtocol/Implementation/ActivityExtensions.cs 86.89% <100.00%> (+0.05%) ⬆️
...ry.Instrumentation.AspNet/AspNetInstrumentation.cs 100.00% <100.00%> (ø)
...umentation.AspNet/Implementation/HttpInListener.cs 89.10% <100.00%> (ø)
...entation.AspNet/TracerProviderBuilderExtensions.cs 100.00% <100.00%> (ø)
...umentation.AspNetCore/AspNetCoreInstrumentation.cs 100.00% <100.00%> (ø)
...tation.AspNetCore/Implementation/HttpInListener.cs 86.56% <100.00%> (ø)
...tion.AspNetCore/TracerProviderBuilderExtensions.cs 100.00% <100.00%> (ø)
...ntation.GrpcNetClient/GrpcClientInstrumentation.cs 100.00% <100.00%> (+12.50%) ⬆️
... and 16 more

@CodeBlanch
Copy link
Member

Doesn't have to be done on this PR, but we also need to make sure exporters support this. For example, this...

process.Tags[key] = label.ToJaegerTag();

...only supports the primitives. It needs to do something like what ProcessJaegerTagArray does:

private static void ProcessJaegerTagArray(ref PooledList<JaegerTag> tags, KeyValuePair<string, object> activityTag)

But can't call that exactly (I don't think) because Process doesn't have the PooledList. A dash of refactoring first.

@cijothomas cijothomas merged commit a071d4d into open-telemetry:main Mar 4, 2021
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.

Allow arrays of primitives in Resource Attribute Values
5 participants