-
Notifications
You must be signed in to change notification settings - Fork 969
Add NATS instrumentation #13999
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
base: main
Are you sure you want to change the base?
Add NATS instrumentation #13999
Conversation
🔧 The result from spotlessApply was committed to the PR branch. |
@laurit is it you I should ask a review from? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently there is a build failure, and a test failure.
.../io/opentelemetry/javaagent/instrumentation/nats/v2_21/ConnectionRequestInstrumentation.java
Outdated
Show resolved
Hide resolved
...in/java/io/opentelemetry/javaagent/instrumentation/nats/v2_21/NatsInstrumentationModule.java
Outdated
Show resolved
Hide resolved
...in/java/io/opentelemetry/javaagent/instrumentation/nats/v2_21/NatsInstrumentationModule.java
Outdated
Show resolved
Hide resolved
.../java/io/opentelemetry/javaagent/instrumentation/nats/v2_21/SubscriptionInstrumentation.java
Outdated
Show resolved
Hide resolved
...ts-2.21/library/src/main/java/io/opentelemetry/instrumentation/nats/v2_21/NatsTelemetry.java
Show resolved
Hide resolved
...brary/src/main/java/io/opentelemetry/instrumentation/nats/v2_21/OpenTelemetryConnection.java
Outdated
Show resolved
Hide resolved
.../main/java/io/opentelemetry/instrumentation/nats/v2_21/internal/NatsInstrumenterFactory.java
Outdated
Show resolved
Hide resolved
.../java/io/opentelemetry/instrumentation/nats/v2_21/internal/NatsRequestContextCustomizer.java
Outdated
Show resolved
Hide resolved
...y/src/test/java/io/opentelemetry/instrumentation/nats/v2_21/NatsTelemetryDispatcherTest.java
Outdated
Show resolved
Hide resolved
fcb32fb
to
487dffb
Compare
import io.opentelemetry.instrumentation.api.internal.Timer; | ||
import io.opentelemetry.instrumentation.nats.v2_21.internal.NatsRequest; | ||
|
||
final class OpenTelemetryMessageHandler implements MessageHandler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the only one class I didn't proxy as it's a single method interface and it should be pretty stable
40e1913
to
7d1b355
Compare
89cd845
to
360a21f
Compare
@@ -29,6 +29,9 @@ for dir in $(find instrumentation -name "*.java" | grep library/src/main/java | | |||
if [[ "$dir" == "instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/lettuce/core/protocol" ]]; then | |||
continue | |||
fi | |||
if [[ "$dir" == "instrumentation/nats/nats-2.21/library/src/main/java/io/nats/client/impl" ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to put OpenTelemetryDispatcherFactory
in this package because it relies on NatsConnection
and NatsDispatcher
which are package scoped. See this comment
} | ||
|
||
/** Returns a {@link Options.Builder} with instrumented {@link DispatcherFactory}. */ | ||
public Options.Builder wrap(Options.Builder options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not really sure about this, as I have to rely on a build
. I think it would be better to let users do options.dispatcherFactory(...)
as OpenTelemetryDispatcherFactory
is now exposed
hey @laurit could you have a second look at this one when you have the time? muzzle passes locally and on previous builds, so I guess the error is transient. |
@@ -691,6 +691,12 @@ targets: | |||
- type: gradle | |||
path: ./ | |||
target: ':instrumentation:mongo:mongo-async-3.3:javaagent' | |||
- type: gradle | |||
path: ./ | |||
target: ':instrumentation:nats:nats-2.21:javaagent' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since it passes for 2.17.2+, should I change 2.21 to 2.17.2 everywhere? (library included)
might be worth checking if this needs to be applied before merging |
First, sorry for the review of 5000 rows, that's not very nice.
This PR aims at instrumenting NATS for both library and java agent, using the messaging conventions.
I identified three blocks,
publish
,subscribe
andrequest
. The two first ones are classic pub-sub operations. The latter is a request-reply pattern, out of the box using NATS. It basically combines publish and subscribe over a unique and temporary subject(topic).Few things:
request
. I used a CLIENT instrumenter and played with the Context to group the publish/subscribe under the same trace. Ideally, for my usage at work, I'd like everything to be in the same trace. I guess we could control this with an option.What it looks like (only tested the library part):
Publish & Subscribe
Two different traces.


subscribe
follows_frompublish
with a reference/linkRequest
Unique trace.

subscribe
child_ofpublish
as the code calls forrequest