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

Migrate vertx HTTP client to Instrumenter API #4510

Merged
merged 3 commits into from
Oct 27, 2021

Conversation

mateuszrzeszutek
Copy link
Member

Part of #2713

Comment on lines +25 to +27
@Nullable
NetClientAttributesExtractor<HttpClientRequest, HttpClientResponse>
netAttributesExtractor) {
Copy link
Member

Choose a reason for hiding this comment

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

weird formatting from spotless 🤷‍♂️


private static final Instrumenter<HttpClientRequest, HttpClientResponse> INSTRUMENTER =
VertxClientInstrumenterFactory.create(
"io.opentelemetry.vertx-http-client-3.0", new Vertx3HttpAttributesExtractor(), null);
Copy link
Contributor

Choose a reason for hiding this comment

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

No net attributes 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.

That would require parsing the URL (which is exposed as a string by the library), so I decided not to do that.

import io.opentelemetry.context.propagation.TextMapSetter;
import io.vertx.core.http.HttpClientRequest;

public class HttpRequestHeaderSetter implements TextMapSetter<HttpClientRequest> {
Copy link
Contributor

Choose a reason for hiding this comment

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

make it enum?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, is there any point in doing so? Only one instance is created at a time, we don't have to worry about making it a singleton class.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, okay, I definitely agree that we should use enums (if possible) for implementing singletons. Is there any need to make this class a singleton in the first place?

Copy link
Contributor

Choose a reason for hiding this comment

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

Consistency? :)

@Override
Set<AttributeKey<?>> httpAttributes(URI uri) {
def attributes = super.httpAttributes(uri)
attributes.remove(SemanticAttributes.HTTP_FLAVOR)
Copy link
Contributor

Choose a reason for hiding this comment

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

A lot of the instrumenters return SemanticAttributes.HttpFlavorValues.HTTP_1_1 because that is the only version that the library supports. Would it make sense to use the same approach here. Or should we change other places to not fill it also when we can't extract accurate info from the instrumented library?

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 should we change other places to not fill it also when we can't extract accurate info from the instrumented library?

I think I prefer this option - if you can't extract something from the library, then just don't try to guess it.
In case of HTTP flavor, I guess that you could also use HTTP 1.0 and all those hard-coded 1.1 extractors would set false information.
I'll create an issue for cleaning this up in all instrumentations.

Copy link
Contributor

Choose a reason for hiding this comment

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

Vert.x 3.0.0 seems to hardcode it to 1.1 https://github.com/eclipse-vertx/vert.x/blob/187083cc2572afe82b5bf9c743fa4df868926a56/src/main/java/io/vertx/core/http/impl/HttpClientRequestImpl.java#L91 Though this part has changed in later version. I believe it is the same with other frameworks that the 1.1 we guessed really is the only option.

Copy link
Member Author

Choose a reason for hiding this comment

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

They changed it in 3.2, it does not have hard-coded version: https://github.com/eclipse-vertx/vert.x/blob/3.2.0/src/main/java/io/vertx/core/http/impl/HttpClientRequestImpl.java
This instrumentation also applies to >3.2, which makes me reluctant to set 1.1 for all possible cases.

def attributes = super.httpAttributes(uri)
attributes.remove(SemanticAttributes.HTTP_FLAVOR)
attributes.remove(SemanticAttributes.NET_PEER_NAME)
attributes.remove(SemanticAttributes.NET_PEER_PORT)
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess you chose not to fill peer port and name because it would require parsing them from the uri? An alternative would be to use reflection to get these.
One instrumentation strategy that I often used in a previous project in situations like this was to add an interface with methods like __getPort to implementation class and generate corresponding methods. Then when needed you could just instanceof + cast the request to get access to these. Unfortunately the only way to do this now would be to use asm which might be an overkill.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately the only way to do this now would be to use asm which might be an overkill.

Yep 😄

I think that we can leave it as it is until somebody creates a bug about it. Also, the newer 4.x Vertx version exposes host & port properly - so only users of an old Vertx version would not get net* attributes.

@trask trask merged commit bdb3511 into open-telemetry:main Oct 27, 2021
@mateuszrzeszutek mateuszrzeszutek deleted the vertx-instrumenter branch October 28, 2021 08:21
RashmiRam pushed a commit to RashmiRam/opentelemetry-auto-instr-java that referenced this pull request May 23, 2022
* Migrate vertx HTTP client to Instrumenter API

* Fix vertx-reactive tests

* Code review comments
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.

None yet

4 participants