Skip to content

Commit eea18a6

Browse files
authored
Add additional names to custom instrumentation so they can be disabled separately (#139)
* Add hypertrace specific names to instrumentations This will allow us to disable all or specific Hypertrace instrumentations. Signed-off-by: Pavol Loffay <[email protected]> * docs Signed-off-by: Pavol Loffay <[email protected]>
1 parent f3e2453 commit eea18a6

File tree

18 files changed

+57
-55
lines changed

18 files changed

+57
-55
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ The configuration precedence order
4848
2. environment variables, TODO add link to agent-config repo
4949
3. [configuration file](./example-config.yaml), specified `HT_CONFIG_FILE=example-config.yaml`
5050

51+
### Disable instrumentation at startup
52+
53+
Instrumentations can be disabled by `-Dotel.instrumentation.<instrumentation-name>.enabled=false`.
54+
55+
The following instrumentation names disable only Hypertrace instrumentations, not core OpenTelemetry:
56+
57+
* `ht` - all Hypertrace instrumentations
58+
* `servlet-ht` - Servlet, Spark Web
59+
* `okhttp-ht` - Okhttp
60+
* `grpc-ht` - Okhttp
61+
62+
The Hypertrace instrumentations use also the core OpenTelemetry instrumentation names so for example
63+
`-Dotel.instrumentation.servlet.enabled=false` disables all servlet instrumentations including core
64+
OpenTelemetry and Hypertrace.
65+
5166
## Test
5267

5368
Tests use docker via Testcontainers.org.

instrumentation/grpc-1.5/src/main/java/io/opentelemetry/instrumentation/hypertrace/grpc/v1_5/GrpcBodyInstrumentationModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
public class GrpcBodyInstrumentationModule extends InstrumentationModule {
2929

3030
public GrpcBodyInstrumentationModule() {
31-
super("grpc");
31+
super(GrpcInstrumentationName.PRIMARY, GrpcInstrumentationName.OTHER);
3232
}
3333

3434
@Override
@@ -40,7 +40,7 @@ public int getOrder() {
4040
public String[] helperClassNames() {
4141
return new String[] {
4242
"io.opentelemetry.instrumentation.hypertrace.grpc.v1_5.GrpcSpanDecorator",
43-
"io.opentelemetry.instrumentation.hypertrace.grpc.v1_5.InstrumentationName",
43+
"io.opentelemetry.instrumentation.hypertrace.grpc.v1_5.GrpcInstrumentationName",
4444
packageName + ".client.GrpcClientInterceptor",
4545
packageName + ".client.GrpcClientInterceptor$TracingClientCall",
4646
packageName + ".client.GrpcClientInterceptor$TracingClientCallListener",
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.opentelemetry.instrumentation.hypertrace.grpc.v1_5;
1818

19-
public class InstrumentationName {
20-
public static final String[] INSTRUMENTATION_NAME = {"grpc"};
19+
public class GrpcInstrumentationName {
20+
public static final String PRIMARY = "grpc";
21+
public static final String[] OTHER = {"ht", "grpc-ht"};
2122
}

instrumentation/grpc-1.5/src/main/java/io/opentelemetry/instrumentation/hypertrace/grpc/v1_5/client/GrpcClientInterceptor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import io.grpc.Metadata;
2727
import io.grpc.MethodDescriptor;
2828
import io.opentelemetry.api.trace.Span;
29+
import io.opentelemetry.instrumentation.hypertrace.grpc.v1_5.GrpcInstrumentationName;
2930
import io.opentelemetry.instrumentation.hypertrace.grpc.v1_5.GrpcSpanDecorator;
30-
import io.opentelemetry.instrumentation.hypertrace.grpc.v1_5.InstrumentationName;
3131
import org.hypertrace.agent.core.HypertraceConfig;
3232
import org.hypertrace.agent.core.HypertraceSemanticAttributes;
3333

@@ -36,7 +36,8 @@ public class GrpcClientInterceptor implements ClientInterceptor {
3636
@Override
3737
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
3838
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
39-
if (!HypertraceConfig.isInstrumentationEnabled(InstrumentationName.INSTRUMENTATION_NAME)) {
39+
if (!HypertraceConfig.isInstrumentationEnabled(
40+
GrpcInstrumentationName.PRIMARY, GrpcInstrumentationName.OTHER)) {
4041
return next.newCall(method, callOptions);
4142
}
4243

instrumentation/grpc-1.5/src/main/java/io/opentelemetry/instrumentation/hypertrace/grpc/v1_5/server/GrpcServerInterceptor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import io.grpc.ServerInterceptor;
2626
import io.grpc.Status;
2727
import io.opentelemetry.api.trace.Span;
28+
import io.opentelemetry.instrumentation.hypertrace.grpc.v1_5.GrpcInstrumentationName;
2829
import io.opentelemetry.instrumentation.hypertrace.grpc.v1_5.GrpcSpanDecorator;
29-
import io.opentelemetry.instrumentation.hypertrace.grpc.v1_5.InstrumentationName;
3030
import java.util.Map;
3131
import org.hypertrace.agent.core.HypertraceConfig;
3232
import org.hypertrace.agent.core.HypertraceSemanticAttributes;
@@ -38,7 +38,8 @@ public class GrpcServerInterceptor implements ServerInterceptor {
3838
@Override
3939
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
4040
ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
41-
if (!HypertraceConfig.isInstrumentationEnabled(InstrumentationName.INSTRUMENTATION_NAME)) {
41+
if (!HypertraceConfig.isInstrumentationEnabled(
42+
GrpcInstrumentationName.PRIMARY, GrpcInstrumentationName.OTHER)) {
4243
return next.startCall(call, headers);
4344
}
4445

instrumentation/okhttp/okhttp-3.0/src/main/java/io/opentelemetry/instrumentation/hypertrace/okhttp/v3_0/OkHttp3BodyInstrumentationModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
public class OkHttp3BodyInstrumentationModule extends InstrumentationModule {
3939

4040
public OkHttp3BodyInstrumentationModule() {
41-
super(InstrumentationName.INSTRUMENTATION_NAME[0], InstrumentationName.INSTRUMENTATION_NAME[1]);
41+
super(Okhttp3InstrumentationName.PRIMARY, Okhttp3InstrumentationName.OTHER);
4242
}
4343

4444
@Override
@@ -49,7 +49,7 @@ public int getOrder() {
4949
@Override
5050
public String[] helperClassNames() {
5151
return new String[] {
52-
packageName + ".InstrumentationName", packageName + ".OkHttpTracingInterceptor",
52+
packageName + ".Okhttp3InstrumentationName", packageName + ".OkHttpTracingInterceptor",
5353
};
5454
}
5555

instrumentation/okhttp/okhttp-3.0/src/main/java/io/opentelemetry/instrumentation/hypertrace/okhttp/v3_0/OkHttpTracingInterceptor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public class OkHttpTracingInterceptor implements Interceptor {
3939

4040
@Override
4141
public Response intercept(Chain chain) throws IOException {
42-
if (!HypertraceConfig.isInstrumentationEnabled(InstrumentationName.INSTRUMENTATION_NAME)) {
42+
if (!HypertraceConfig.isInstrumentationEnabled(
43+
Okhttp3InstrumentationName.PRIMARY, Okhttp3InstrumentationName.OTHER)) {
4344
return chain.proceed(chain.request());
4445
}
4546

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.opentelemetry.instrumentation.hypertrace.okhttp.v3_0;
1818

19-
public class InstrumentationName {
20-
public static final String[] INSTRUMENTATION_NAME = {"okhttp", "okhttp-3"};
19+
public class Okhttp3InstrumentationName {
20+
public static final String PRIMARY = "okhttp";
21+
public static final String[] OTHER = {"okhttp-3", "ht", "okhttp-ht", "okhttp-3-ht"};
2122
}

instrumentation/servlet/servlet-2.3/src/main/java/io/opentelemetry/instrumentation/hypertrace/servlet/v2_3/Servlet2BodyInstrumentationModule.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
public class Servlet2BodyInstrumentationModule extends InstrumentationModule {
5959

6060
public Servlet2BodyInstrumentationModule() {
61-
super(InstrumentationName.INSTRUMENTATION_NAME[0], InstrumentationName.INSTRUMENTATION_NAME[1]);
61+
super(Servlet2InstrumentationName.PRIMARY, Servlet2InstrumentationName.OTHER);
6262
}
6363

6464
@Override
@@ -89,7 +89,7 @@ public String[] helperClassNames() {
8989
"io.opentelemetry.instrumentation.hypertrace.servlet.common.BufferedWriterWrapper",
9090
"io.opentelemetry.instrumentation.hypertrace.servlet.common.BufferedReaderWrapper",
9191
"io.opentelemetry.instrumentation.hypertrace.servlet.common.ServletSpanDecorator",
92-
packageName + ".InstrumentationName",
92+
packageName + ".Servlet2InstrumentationName",
9393
packageName + ".BufferingHttpServletResponse",
9494
packageName + ".BufferingHttpServletResponse$BufferingServletOutputStream",
9595
packageName + ".BufferingHttpServletRequest",
@@ -131,7 +131,8 @@ public static Object start(
131131
@Advice.Argument(value = 1, readOnly = false) ServletResponse response,
132132
@Advice.Local("rootStart") Boolean rootStart) {
133133

134-
if (!HypertraceConfig.isInstrumentationEnabled(InstrumentationName.INSTRUMENTATION_NAME)) {
134+
if (!HypertraceConfig.isInstrumentationEnabled(
135+
Servlet2InstrumentationName.PRIMARY, Servlet2InstrumentationName.OTHER)) {
135136
return null;
136137
}
137138
if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) {
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.opentelemetry.instrumentation.hypertrace.servlet.v2_3;
1818

19-
public class InstrumentationName {
20-
public static final String[] INSTRUMENTATION_NAME = {"servlet", "servlet-2"};
19+
public class Servlet2InstrumentationName {
20+
public static final String PRIMARY = "servlet";
21+
public static final String[] OTHER = {"servlet-2", "ht", "servlet-ht", "servlet-2-ht"};
2122
}

0 commit comments

Comments
 (0)