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

Port opentelemetry-annotations-1.0 to Instrumenter API #3738

Merged
merged 6 commits into from
Aug 6, 2021

Conversation

HaloFour
Copy link
Contributor

@HaloFour HaloFour commented Jul 30, 2021

Ports the opentelemetry-annotations-1.0 project to using Instrumenter API in the tracing aspect.

Refactors some of the attribute binding code under the MethodSpanAttributesExtractor class. Removes the no-longer-used AsyncSpanEndStrategy/AsyncSpanEndStrategies implementations.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jul 31, 2021

CLA Signed

The committers are authorized under a signed CLA.

@HaloFour
Copy link
Contributor Author

HaloFour commented Jul 31, 2021

Looks like CopyOnWriteArrayList's iterator doesn't support remove so I had to rework the method to remove collected weak references.

@trask
Copy link
Member

trask commented Aug 2, 2021

/easycla

1 similar comment
@trask
Copy link
Member

trask commented Aug 2, 2021

/easycla

}

String[] attributeNames = parameterAttributeNamesExtractor.extract(method, parameters);
if (attributeNames == null || attributeNames.length != parameters.length) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can attributeNames be null? There are a few more null checks, if you can remove unnecessary ones it's good - we avoid them to make the code easier to read for someone that isn't familiar with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The definition of the functional interface allows for it, null indicating that the method has no parameters to map to attributes: https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation-api-annotation-support/src/main/java/io/opentelemetry/instrumentation/api/annotation/support/ParameterAttributeNamesExtractor.java#L26

I could change that to specify returning an empty array if preferred.

Copy link
Member

Choose a reason for hiding this comment

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

confusingly, I think @Nullable String[] means a non-null array of nullable strings, while String @Nullable [] means a nullable array of non-null strings

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's terrifying. I do defensively check for either the array being null or each element being null, so would that be @Nullable String @Nullable []?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll review the two implementations to see if it's possible that either will return null, if not I can change the annotation. Is it still worth having the defensive check even if the interface states that it shouldn't be null? I hate the idea of a bug in instrumentation leading to errors at runtime.

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 @anuraaga's point is that ParameterAttributeNamesExtractor.extract() returns @Nullable String[], so you don't need to check if the array is null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, so if the array itself can't be null (and that does seem to be the case) then the null check is unnecessary and I can leave the annotations as they are. Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

we are (slowly) rolling out NullAway checking, which will hopefully help (or maybe add to?) some of the confusion

Copy link
Member

Choose a reason for hiding this comment

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

(also, I could be wrong about how NullAway interprets @Nullable String[], my assumption is based on how Checker Framework works, it will be good to get confirmation here from @anuraaga)

Copy link
Member

Choose a reason for hiding this comment

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

I chatted with @anuraaga, NullAway (luckily) does not annotate the contents of the array (like the more powerful, but infinitely more confusing Checker Framework), so @Nullable String[] means what you thought it meant (Nullable applies to the array, not to the strings). Sorry for the confusion.

Copy link
Member

@mateuszrzeszutek mateuszrzeszutek left a comment

Choose a reason for hiding this comment

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

👍
Thanks!

@trask
Copy link
Member

trask commented Aug 5, 2021

@HaloFour when you have a chance to look at remaining comments, would love to merge this as we discovered this change will help with #3691

@HaloFour
Copy link
Contributor Author

HaloFour commented Aug 5, 2021

@trask

when you have a chance to look at remaining comments,

Will try to address tonight. Work has been a bit insane this week. 😅

@HaloFour HaloFour force-pushed the withspan-instrumenter branch from bb52b2e to 6c36c97 Compare August 6, 2021 00:20
@trask trask merged commit a5513a3 into open-telemetry:main Aug 6, 2021
@trask
Copy link
Member

trask commented Aug 6, 2021

thx ❤️

@HaloFour HaloFour deleted the withspan-instrumenter branch August 12, 2021 01:27
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.

4 participants