Skip to content

Commit 89cd845

Browse files
committed
fix dispatcher in library instrumentation
1 parent 7d1b355 commit 89cd845

File tree

6 files changed

+48
-84
lines changed

6 files changed

+48
-84
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.nats.client.impl;
7+
8+
import io.nats.client.MessageHandler;
9+
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
10+
import io.opentelemetry.instrumentation.nats.v2_21.OpenTelemetryMessageHandler;
11+
import io.opentelemetry.instrumentation.nats.v2_21.internal.NatsRequest;
12+
13+
/**
14+
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
15+
* any time.
16+
*/
17+
public final class OpenTelemetryDispatcherFactory extends DispatcherFactory {
18+
19+
private final DispatcherFactory delegate;
20+
private final Instrumenter<NatsRequest, Void> consumerReceiveInstrumenter;
21+
private final Instrumenter<NatsRequest, Void> consumerProcessInstrumenter;
22+
23+
public OpenTelemetryDispatcherFactory(
24+
DispatcherFactory delegate,
25+
Instrumenter<NatsRequest, Void> consumerReceiveInstrumenter,
26+
Instrumenter<NatsRequest, Void> consumerProcessInstrumenter) {
27+
this.delegate = delegate;
28+
this.consumerReceiveInstrumenter = consumerReceiveInstrumenter;
29+
this.consumerProcessInstrumenter = consumerProcessInstrumenter;
30+
}
31+
32+
@Override
33+
NatsDispatcher createDispatcher(NatsConnection natsConnection, MessageHandler messageHandler) {
34+
return delegate.createDispatcher(
35+
natsConnection,
36+
new OpenTelemetryMessageHandler(
37+
messageHandler, consumerReceiveInstrumenter, consumerProcessInstrumenter));
38+
}
39+
}

instrumentation/nats/nats-2.21/library/src/main/java/io/opentelemetry/instrumentation/nats/v2_21/NatsTelemetry.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.nats.client.Connection;
99
import io.nats.client.Options;
1010
import io.nats.client.impl.DispatcherFactory;
11+
import io.nats.client.impl.OpenTelemetryDispatcherFactory;
1112
import io.opentelemetry.api.OpenTelemetry;
1213
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
1314
import io.opentelemetry.instrumentation.nats.v2_21.internal.NatsRequest;
@@ -54,7 +55,7 @@ public Options.Builder wrap(Options.Builder options) {
5455
}
5556

5657
return options.dispatcherFactory(
57-
OpenTelemetryDispatcherFactory.wrap(
58+
new OpenTelemetryDispatcherFactory(
5859
factory, consumerReceiveInstrumenter, consumerProcessInstrumenter));
5960
}
6061
}

instrumentation/nats/nats-2.21/library/src/main/java/io/opentelemetry/instrumentation/nats/v2_21/OpenTelemetryDispatcherFactory.java

Lines changed: 0 additions & 76 deletions
This file was deleted.

instrumentation/nats/nats-2.21/library/src/main/java/io/opentelemetry/instrumentation/nats/v2_21/OpenTelemetryMessageHandler.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
import io.opentelemetry.instrumentation.api.internal.Timer;
1515
import io.opentelemetry.instrumentation.nats.v2_21.internal.NatsRequest;
1616

17-
final class OpenTelemetryMessageHandler implements MessageHandler {
17+
/**
18+
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
19+
* any time. Exposed for {@link io.nats.client.impl.OpenTelemetryDispatcherFactory}.
20+
*/
21+
public final class OpenTelemetryMessageHandler implements MessageHandler {
1822

1923
private final MessageHandler delegate;
2024
private final Instrumenter<NatsRequest, Void> consumerReceiveInstrumenter;

instrumentation/nats/nats-2.21/library/src/main/java/io/opentelemetry/instrumentation/nats/v2_21/internal/NatsInstrumenterFactory.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717

1818
/**
1919
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
20-
* any time.", or "This class is internal and experimental. Its APIs are unstable and can change at
21-
* any time. Its APIs (or a version of them) may be promoted to the public stable API in the future,
22-
* but no guarantees are made.
20+
* any time.
2321
*/
2422
public final class NatsInstrumenterFactory {
2523
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.nats-2.21";

instrumentation/nats/nats-2.21/library/src/main/java/io/opentelemetry/instrumentation/nats/v2_21/internal/NatsRequest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313

1414
/**
1515
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
16-
* any time.", or "This class is internal and experimental. Its APIs are unstable and can change at
17-
* any time. Its APIs (or a version of them) may be promoted to the public stable API in the future,
18-
* but no guarantees are made.
16+
* any time.
1917
*/
2018
@AutoValue
2119
public abstract class NatsRequest {

0 commit comments

Comments
 (0)