From c5a838ffed4bc9b279a2432a109cbd8760c07f64 Mon Sep 17 00:00:00 2001
From: Pavol Loffay
Date: Thu, 17 Jun 2021 17:44:44 +0200
Subject: [PATCH 1/3] Move agent config and its deps into agent classloader
Signed-off-by: Pavol Loffay
---
.gitmodules | 2 +-
.../agent/filter/FilterRegistry.java | 20 ++--
.../v4_0/ApacheHttpClientUtils.java | 16 ++--
instrumentation/build.gradle.kts | 6 --
.../v1_5/client/GrpcClientInterceptor.java | 15 +--
.../v1_5/server/GrpcServerInterceptor.java | 15 +--
.../grpc/v1_5/GrpcInstrumentationTest.java | 4 +-
.../v2_0/JaxrsClientBodyCaptureFilter.java | 11 +--
.../v2_0/JaxrsClientEntityInterceptor.java | 11 +--
.../HttpClientRequestTracingHandler.java | 12 +--
.../HttpClientResponseTracingHandler.java | 12 +--
.../HttpServerRequestTracingHandler.java | 12 +--
.../HttpServerResponseTracingHandler.java | 12 +--
.../HttpClientRequestTracingHandler.java | 12 +--
.../HttpClientResponseTracingHandler.java | 12 +--
.../HttpServerRequestTracingHandler.java | 12 +--
.../HttpServerResponseTracingHandler.java | 12 +--
.../okhttp/v3_0/OkHttpTracingInterceptor.java | 14 +--
.../nowrapping/BodyCaptureAsyncListener.java | 14 +--
.../Servlet30AndFilterInstrumentation.java | 18 ++--
.../ServletResponseInstrumentation.java | 11 +--
.../HttpRequestHandleInstrumentation.java | 9 +-
.../vertx/HttpRequestInstrumentation.java | 14 ++-
javaagent-core/build.gradle.kts | 28 +-----
.../core/config/InstrumentationConfig.java | 84 ++++++++++++++++
.../buffer/BoundedBuffersFactory.java | 5 +-
javaagent/build.gradle.kts | 11 ---
otel-extensions/build.gradle.kts | 29 ++++++
.../HypertraceResourceProvider.java | 2 +-
.../extensions}/config/EnvironmentConfig.java | 2 +-
.../HypertraceAgentConfiguration.java | 5 +-
.../extensions}/config/HypertraceConfig.java | 48 +---------
.../config/InstrumentationConfigImpl.java | 95 +++++++++++++++++++
.../InstrumentationConfigInstaller.java | 32 +++++++
.../src/main/proto | 0
.../HypertraceAgentConfigurationTest.java | 1 +
.../config/EnvironmentConfigTest.java | 2 +-
.../config/HypertraceConfigTest.java | 2 +-
.../src/test/resources/config.yaml | 0
.../src/test/resources/emptyconfig.yaml | 0
40 files changed, 391 insertions(+), 231 deletions(-)
create mode 100644 javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java
rename {javaagent-core/src/main/java/org/hypertrace/agent/core => otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions}/config/EnvironmentConfig.java (99%)
rename otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/{ => config}/HypertraceAgentConfiguration.java (94%)
rename {javaagent-core/src/main/java/org/hypertrace/agent/core => otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions}/config/HypertraceConfig.java (80%)
create mode 100644 otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/InstrumentationConfigImpl.java
create mode 100644 otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/InstrumentationConfigInstaller.java
rename {javaagent-core => otel-extensions}/src/main/proto (100%)
rename {javaagent-core/src/test/java/org/hypertrace/agent/core => otel-extensions/src/test/java/org/hypertrace/agent/otel/extensions}/config/EnvironmentConfigTest.java (98%)
rename {javaagent-core/src/test/java/org/hypertrace/agent/core => otel-extensions/src/test/java/org/hypertrace/agent/otel/extensions}/config/HypertraceConfigTest.java (99%)
rename {javaagent-core => otel-extensions}/src/test/resources/config.yaml (100%)
rename {javaagent-core => otel-extensions}/src/test/resources/emptyconfig.yaml (100%)
diff --git a/.gitmodules b/.gitmodules
index 30e7d38a4..bd38ff0a5 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,3 @@
[submodule "javaagent-core/src/main/proto"]
- path = javaagent-core/src/main/proto
+ path = otel-extensions/src/main/proto
url = https://github.com/hypertrace/agent-config.git
diff --git a/filter-api/src/main/java/org/hypertrace/agent/filter/FilterRegistry.java b/filter-api/src/main/java/org/hypertrace/agent/filter/FilterRegistry.java
index 91fe76976..d80df0555 100644
--- a/filter-api/src/main/java/org/hypertrace/agent/filter/FilterRegistry.java
+++ b/filter-api/src/main/java/org/hypertrace/agent/filter/FilterRegistry.java
@@ -16,15 +16,13 @@
package org.hypertrace.agent.filter;
-import com.google.protobuf.StringValue;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
-import org.hypertrace.agent.core.config.EnvironmentConfig;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
import org.hypertrace.agent.filter.api.Filter;
import org.hypertrace.agent.filter.spi.FilterProvider;
import org.slf4j.Logger;
@@ -70,8 +68,7 @@ private static Filter load() {
ServiceLoader providers = ServiceLoader.load(FilterProvider.class, cl);
List filters = new ArrayList<>();
for (FilterProvider provider : providers) {
- String disabled =
- EnvironmentConfig.getProperty(getProviderDisabledPropertyName(provider.getClass()));
+ String disabled = getProperty(getProviderDisabledPropertyName(provider.getClass()));
if ("true".equalsIgnoreCase(disabled)) {
continue;
}
@@ -82,17 +79,16 @@ private static Filter load() {
}
private static ClassLoader loadJars() {
- List jarPaths = HypertraceConfig.get().getJavaagent().getFilterJarPathsList();
+ List jarPaths = InstrumentationConfig.ConfigProvider.get().jarPaths();
URL[] urls = new URL[jarPaths.size()];
int i = 0;
- for (StringValue jarPath : jarPaths) {
+ for (String jarPath : jarPaths) {
try {
- URL url = new URL("file", "", -1, jarPath.getValue());
+ URL url = new URL("file", "", -1, jarPath);
urls[i] = url;
i++;
} catch (MalformedURLException e) {
- logger.warn(
- String.format("Malformed URL exception for jar on path: %s", jarPath.getValue()), e);
+ logger.warn(String.format("Malformed URL exception for jar on path: %s", jarPath), e);
}
}
return new URLClassLoader(urls, Thread.currentThread().getContextClassLoader());
@@ -101,4 +97,8 @@ private static ClassLoader loadJars() {
public static String getProviderDisabledPropertyName(Class> clazz) {
return String.format("ht.filter.provider.%s.disabled", clazz.getSimpleName());
}
+
+ public static String getProperty(String name) {
+ return System.getProperty(name, System.getenv(name.replaceAll("\\.", "_").toUpperCase()));
+ }
}
diff --git a/instrumentation/apache-httpclient-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/apachehttpclient/v4_0/ApacheHttpClientUtils.java b/instrumentation/apache-httpclient-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/apachehttpclient/v4_0/ApacheHttpClientUtils.java
index abc5a75d5..83c02d2ac 100644
--- a/instrumentation/apache-httpclient-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/apachehttpclient/v4_0/ApacheHttpClientUtils.java
+++ b/instrumentation/apache-httpclient-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/apachehttpclient/v4_0/ApacheHttpClientUtils.java
@@ -29,8 +29,8 @@
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpMessage;
import org.apache.http.HttpResponse;
-import org.hypertrace.agent.config.Config.AgentConfig;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig.ConfigProvider;
import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedBuffersFactory;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedByteArrayOutputStream;
@@ -42,6 +42,8 @@
public class ApacheHttpClientUtils {
private ApacheHttpClientUtils() {}
+ private static InstrumentationConfig instrumentationConfig = ConfigProvider.get();
+
private static final Logger log = LoggerFactory.getLogger(ApacheHttpClientUtils.class);
public static void addResponseHeaders(Span span, HeaderIterator headerIterator) {
@@ -63,12 +65,11 @@ private static void addHeaders(
}
public static void traceRequest(Span span, HttpMessage request) {
- AgentConfig agentConfig = HypertraceConfig.get();
- if (agentConfig.getDataCapture().getHttpHeaders().getRequest().getValue()) {
+ if (instrumentationConfig.httpHeaders().request()) {
ApacheHttpClientUtils.addRequestHeaders(span, request.headerIterator());
}
- if (agentConfig.getDataCapture().getHttpBody().getRequest().getValue()
+ if (instrumentationConfig.httpBody().request()
&& request instanceof HttpEntityEnclosingRequest) {
HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) request;
HttpEntity entity = entityRequest.getEntity();
@@ -78,12 +79,11 @@ public static void traceRequest(Span span, HttpMessage request) {
}
public static void traceResponse(Span span, HttpResponse response) {
- AgentConfig agentConfig = HypertraceConfig.get();
- if (agentConfig.getDataCapture().getHttpHeaders().getResponse().getValue()) {
+ if (instrumentationConfig.httpHeaders().response()) {
ApacheHttpClientUtils.addResponseHeaders(span, response.headerIterator());
}
- if (agentConfig.getDataCapture().getHttpBody().getResponse().getValue()) {
+ if (instrumentationConfig.httpBody().response()) {
HttpEntity entity = response.getEntity();
ApacheHttpClientUtils.traceEntity(
span, HypertraceSemanticAttributes.HTTP_RESPONSE_BODY, entity);
diff --git a/instrumentation/build.gradle.kts b/instrumentation/build.gradle.kts
index f4a98b9b5..4e50d8907 100644
--- a/instrumentation/build.gradle.kts
+++ b/instrumentation/build.gradle.kts
@@ -53,12 +53,6 @@ tasks {
mergeServiceFiles()
- relocate("com.fasterxml.jackson", "io.opentelemetry.javaagent.shaded.org.hypertrace.shaded.com.fasterxml.jackson")
- relocate("com.google", "io.opentelemetry.javaagent.shaded.org.hypertrace.shaded.com.google")
- relocate("google.protobuf", "io.opentelemetry.javaagent.shaded.org.hypertrace.shaded.google.protobuf")
- relocate("org.checkerframework", "io.opentelemetry.javaagent.shaded.org.hypertrace.shaded.com.checkerframework")
- relocate("org.yaml", "io.opentelemetry.javaagent.shaded.org.hypertrace.shaded.org.yaml")
-
relocate("com.blogspot.mydailyjava.weaklockfree", "io.opentelemetry.instrumentation.api.internal.shaded.weaklockfree")
exclude("**/module-info.class")
diff --git a/instrumentation/grpc-1.5/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/client/GrpcClientInterceptor.java b/instrumentation/grpc-1.5/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/client/GrpcClientInterceptor.java
index 90142b5b4..6112f2c29 100644
--- a/instrumentation/grpc-1.5/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/client/GrpcClientInterceptor.java
+++ b/instrumentation/grpc-1.5/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/client/GrpcClientInterceptor.java
@@ -28,15 +28,18 @@
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.javaagent.instrumentation.hypertrace.grpc.v1_5.GrpcInstrumentationName;
import io.opentelemetry.javaagent.instrumentation.hypertrace.grpc.v1_5.GrpcSpanDecorator;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes;
public class GrpcClientInterceptor implements ClientInterceptor {
+ private static final InstrumentationConfig instrumentationConfig =
+ InstrumentationConfig.ConfigProvider.get();
+
@Override
public ClientCall interceptCall(
MethodDescriptor method, CallOptions callOptions, Channel next) {
- if (!HypertraceConfig.isInstrumentationEnabled(
+ if (!instrumentationConfig.isInstrumentationEnabled(
GrpcInstrumentationName.PRIMARY, GrpcInstrumentationName.OTHER)) {
return next.newCall(method, callOptions);
}
@@ -59,7 +62,7 @@ static final class TracingClientCall
@Override
public void start(Listener responseListener, Metadata headers) {
super.start(new TracingClientCallListener<>(responseListener, span), headers);
- if (HypertraceConfig.get().getDataCapture().getRpcMetadata().getRequest().getValue()) {
+ if (instrumentationConfig.rpcMetadata().request()) {
GrpcSpanDecorator.addMetadataAttributes(
headers, span, HypertraceSemanticAttributes::rpcRequestMetadata);
}
@@ -68,7 +71,7 @@ public void start(Listener responseListener, Metadata headers) {
@Override
public void sendMessage(ReqT message) {
super.sendMessage(message);
- if (HypertraceConfig.get().getDataCapture().getRpcBody().getRequest().getValue()) {
+ if (instrumentationConfig.rpcBody().request()) {
GrpcSpanDecorator.addMessageAttribute(
message, span, HypertraceSemanticAttributes.RPC_REQUEST_BODY);
}
@@ -87,7 +90,7 @@ static final class TracingClientCallListener
@Override
public void onMessage(RespT message) {
delegate().onMessage(message);
- if (HypertraceConfig.get().getDataCapture().getRpcBody().getResponse().getValue()) {
+ if (instrumentationConfig.rpcBody().response()) {
GrpcSpanDecorator.addMessageAttribute(
message, span, HypertraceSemanticAttributes.RPC_RESPONSE_BODY);
}
@@ -96,7 +99,7 @@ public void onMessage(RespT message) {
@Override
public void onHeaders(Metadata headers) {
super.onHeaders(headers);
- if (HypertraceConfig.get().getDataCapture().getRpcMetadata().getResponse().getValue()) {
+ if (instrumentationConfig.rpcMetadata().response()) {
GrpcSpanDecorator.addMetadataAttributes(
headers, span, HypertraceSemanticAttributes::rpcResponseMetadata);
}
diff --git a/instrumentation/grpc-1.5/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/server/GrpcServerInterceptor.java b/instrumentation/grpc-1.5/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/server/GrpcServerInterceptor.java
index b6e4f1fc3..870fcf7ad 100644
--- a/instrumentation/grpc-1.5/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/server/GrpcServerInterceptor.java
+++ b/instrumentation/grpc-1.5/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/server/GrpcServerInterceptor.java
@@ -28,16 +28,19 @@
import io.opentelemetry.javaagent.instrumentation.hypertrace.grpc.v1_5.GrpcInstrumentationName;
import io.opentelemetry.javaagent.instrumentation.hypertrace.grpc.v1_5.GrpcSpanDecorator;
import java.util.Map;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes;
import org.hypertrace.agent.filter.FilterRegistry;
public class GrpcServerInterceptor implements ServerInterceptor {
+ private static final InstrumentationConfig instrumentationConfig =
+ InstrumentationConfig.ConfigProvider.get();
+
@Override
public ServerCall.Listener interceptCall(
ServerCall call, Metadata headers, ServerCallHandler next) {
- if (!HypertraceConfig.isInstrumentationEnabled(
+ if (!instrumentationConfig.isInstrumentationEnabled(
GrpcInstrumentationName.PRIMARY, GrpcInstrumentationName.OTHER)) {
return next.startCall(call, headers);
}
@@ -46,7 +49,7 @@ public ServerCall.Listener interceptCall(
Map mapHeaders = GrpcSpanDecorator.metadataToMap(headers);
- if (HypertraceConfig.get().getDataCapture().getRpcMetadata().getRequest().getValue()) {
+ if (instrumentationConfig.rpcMetadata().request()) {
GrpcSpanDecorator.addMetadataAttributes(mapHeaders, currentSpan);
}
@@ -75,7 +78,7 @@ static final class TracingServerCall
@Override
public void sendMessage(RespT message) {
super.sendMessage(message);
- if (HypertraceConfig.get().getDataCapture().getRpcBody().getResponse().getValue()) {
+ if (instrumentationConfig.rpcBody().response()) {
GrpcSpanDecorator.addMessageAttribute(
message, span, HypertraceSemanticAttributes.RPC_RESPONSE_BODY);
}
@@ -84,7 +87,7 @@ public void sendMessage(RespT message) {
@Override
public void sendHeaders(Metadata headers) {
super.sendHeaders(headers);
- if (HypertraceConfig.get().getDataCapture().getRpcMetadata().getResponse().getValue()) {
+ if (instrumentationConfig.rpcMetadata().response()) {
GrpcSpanDecorator.addMetadataAttributes(
headers, span, HypertraceSemanticAttributes::rpcResponseMetadata);
}
@@ -104,7 +107,7 @@ static final class TracingServerCallListener
@Override
public void onMessage(ReqT message) {
delegate().onMessage(message);
- if (HypertraceConfig.get().getDataCapture().getRpcBody().getRequest().getValue()) {
+ if (instrumentationConfig.rpcBody().request()) {
GrpcSpanDecorator.addMessageAttribute(
message, span, HypertraceSemanticAttributes.RPC_REQUEST_BODY);
}
diff --git a/instrumentation/grpc-1.5/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/GrpcInstrumentationTest.java b/instrumentation/grpc-1.5/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/GrpcInstrumentationTest.java
index abb3047bd..e08d4e4dd 100644
--- a/instrumentation/grpc-1.5/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/GrpcInstrumentationTest.java
+++ b/instrumentation/grpc-1.5/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/GrpcInstrumentationTest.java
@@ -35,9 +35,9 @@
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeoutException;
-import org.hypertrace.agent.core.config.EnvironmentConfig;
-import org.hypertrace.agent.core.config.HypertraceConfig;
import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes;
+import org.hypertrace.agent.otel.extensions.config.EnvironmentConfig;
+import org.hypertrace.agent.otel.extensions.config.HypertraceConfig;
import org.hypertrace.agent.testing.AbstractInstrumenterTest;
import org.hypertrace.example.GreeterGrpc;
import org.hypertrace.example.GreeterGrpc.GreeterBlockingStub;
diff --git a/instrumentation/jaxrs-client-2.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/jaxrs/v2_0/JaxrsClientBodyCaptureFilter.java b/instrumentation/jaxrs-client-2.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/jaxrs/v2_0/JaxrsClientBodyCaptureFilter.java
index 0a912e479..ca902a56a 100644
--- a/instrumentation/jaxrs-client-2.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/jaxrs/v2_0/JaxrsClientBodyCaptureFilter.java
+++ b/instrumentation/jaxrs-client-2.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/jaxrs/v2_0/JaxrsClientBodyCaptureFilter.java
@@ -28,8 +28,7 @@
import javax.ws.rs.client.ClientResponseContext;
import javax.ws.rs.client.ClientResponseFilter;
import javax.ws.rs.core.MultivaluedMap;
-import org.hypertrace.agent.config.Config.AgentConfig;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,6 +36,8 @@
public class JaxrsClientBodyCaptureFilter implements ClientRequestFilter, ClientResponseFilter {
private static final Logger log = LoggerFactory.getLogger(JaxrsClientBodyCaptureFilter.class);
+ private static final InstrumentationConfig instrumentationConfig =
+ InstrumentationConfig.ConfigProvider.get();
@Override
public void filter(ClientRequestContext requestContext) {
@@ -47,10 +48,9 @@ public void filter(ClientRequestContext requestContext) {
Context currentContext = (Context) contextObj;
Span currentSpan = Span.fromContext(currentContext);
- AgentConfig agentConfig = HypertraceConfig.get();
try {
- if (agentConfig.getDataCapture().getHttpHeaders().getRequest().getValue()) {
+ if (instrumentationConfig.httpHeaders().request()) {
captureHeaders(
currentSpan,
HypertraceSemanticAttributes::httpRequestHeader,
@@ -70,10 +70,9 @@ public void filter(ClientRequestContext requestContext, ClientResponseContext re
Context currentContext = (Context) contextObj;
Span currentSpan = Span.fromContext(currentContext);
- AgentConfig agentConfig = HypertraceConfig.get();
try {
- if (agentConfig.getDataCapture().getHttpHeaders().getResponse().getValue()) {
+ if (instrumentationConfig.httpHeaders().response()) {
captureHeaders(
currentSpan,
HypertraceSemanticAttributes::httpResponseHeader,
diff --git a/instrumentation/jaxrs-client-2.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/jaxrs/v2_0/JaxrsClientEntityInterceptor.java b/instrumentation/jaxrs-client-2.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/jaxrs/v2_0/JaxrsClientEntityInterceptor.java
index 31c8df4e3..d3c5a6b8d 100644
--- a/instrumentation/jaxrs-client-2.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/jaxrs/v2_0/JaxrsClientEntityInterceptor.java
+++ b/instrumentation/jaxrs-client-2.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/jaxrs/v2_0/JaxrsClientEntityInterceptor.java
@@ -31,8 +31,7 @@
import javax.ws.rs.ext.ReaderInterceptorContext;
import javax.ws.rs.ext.WriterInterceptor;
import javax.ws.rs.ext.WriterInterceptorContext;
-import org.hypertrace.agent.config.Config.AgentConfig;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes;
import org.hypertrace.agent.core.instrumentation.SpanAndBuffer;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedBuffersFactory;
@@ -46,6 +45,8 @@
public class JaxrsClientEntityInterceptor implements ReaderInterceptor, WriterInterceptor {
private static final Logger log = LoggerFactory.getLogger(JaxrsClientEntityInterceptor.class);
+ private static final InstrumentationConfig instrumentationConfig =
+ InstrumentationConfig.ConfigProvider.get();
private final ContextStore inputStreamContextStore;
private final ContextStore outputStreamContextStore;
@@ -63,10 +64,9 @@ public Object aroundReadFrom(ReaderInterceptorContext responseContext)
throws IOException, WebApplicationException {
MediaType mediaType = responseContext.getMediaType();
- AgentConfig agentConfig = HypertraceConfig.get();
if (mediaType == null
|| !ContentTypeUtils.shouldCapture(mediaType.toString())
- || !agentConfig.getDataCapture().getHttpBody().getResponse().getValue()) {
+ || !instrumentationConfig.httpBody().response()) {
return responseContext.proceed();
}
@@ -125,8 +125,7 @@ public void aroundWriteTo(WriterInterceptorContext requestContext)
Context context = (Context) contextObj;
Span currentSpan = Span.fromContext(context);
- AgentConfig agentConfig = HypertraceConfig.get();
- if (agentConfig.getDataCapture().getHttpBody().getRequest().getValue()) {
+ if (instrumentationConfig.httpBody().request()) {
MediaType mediaType = requestContext.getMediaType();
if (mediaType == null || !ContentTypeUtils.shouldCapture(mediaType.toString())) {
requestContext.proceed();
diff --git a/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/client/HttpClientRequestTracingHandler.java b/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/client/HttpClientRequestTracingHandler.java
index 78cefc1c2..79dea62e0 100644
--- a/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/client/HttpClientRequestTracingHandler.java
+++ b/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/client/HttpClientRequestTracingHandler.java
@@ -33,8 +33,7 @@
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
-import org.hypertrace.agent.config.Config.AgentConfig;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedBuffersFactory;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedByteArrayOutputStream;
@@ -44,7 +43,8 @@
public class HttpClientRequestTracingHandler extends ChannelOutboundHandlerAdapter {
- private final AgentConfig agentConfig = HypertraceConfig.get();
+ private static final InstrumentationConfig instrumentationConfig =
+ InstrumentationConfig.ConfigProvider.get();
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise prm) {
@@ -64,12 +64,12 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise prm) {
HttpRequest httpRequest = (HttpRequest) msg;
Map headersMap = headersToMap(httpRequest);
- if (agentConfig.getDataCapture().getHttpHeaders().getRequest().getValue()) {
+ if (instrumentationConfig.httpHeaders().request()) {
headersMap.forEach((key, value) -> span.setAttribute(key, value));
}
CharSequence contentType = DataCaptureUtils.getContentType(httpRequest);
- if (agentConfig.getDataCapture().getHttpBody().getRequest().getValue()
+ if (instrumentationConfig.httpBody().request()
&& contentType != null
&& ContentTypeUtils.shouldCapture(contentType.toString())) {
@@ -88,7 +88,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise prm) {
}
if ((msg instanceof HttpContent || msg instanceof ByteBuf)
- && agentConfig.getDataCapture().getHttpBody().getRequest().getValue()) {
+ && instrumentationConfig.httpBody().request()) {
DataCaptureUtils.captureBody(span, channel, AttributeKeys.REQUEST_BODY_BUFFER, msg);
}
diff --git a/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/client/HttpClientResponseTracingHandler.java b/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/client/HttpClientResponseTracingHandler.java
index ea1ce001a..9b7db4072 100644
--- a/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/client/HttpClientResponseTracingHandler.java
+++ b/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/client/HttpClientResponseTracingHandler.java
@@ -36,8 +36,7 @@
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.nio.charset.Charset;
import java.util.Map;
-import org.hypertrace.agent.config.Config.AgentConfig;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedBuffersFactory;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedByteArrayOutputStream;
@@ -47,7 +46,8 @@
public class HttpClientResponseTracingHandler extends ChannelInboundHandlerAdapter {
- private final AgentConfig agentConfig = HypertraceConfig.get();
+ private static final InstrumentationConfig instrumentationConfig =
+ InstrumentationConfig.ConfigProvider.get();
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
@@ -65,12 +65,12 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
if (msg instanceof HttpResponse) {
HttpResponse httpResponse = (HttpResponse) msg;
- if (agentConfig.getDataCapture().getHttpHeaders().getResponse().getValue()) {
+ if (instrumentationConfig.httpHeaders().response()) {
captureHeaders(span, httpResponse);
}
CharSequence contentType = DataCaptureUtils.getContentType(httpResponse);
- if (agentConfig.getDataCapture().getHttpBody().getResponse().getValue()
+ if (instrumentationConfig.httpBody().response()
&& contentType != null
&& ContentTypeUtils.shouldCapture(contentType.toString())) {
@@ -89,7 +89,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
}
if ((msg instanceof HttpContent || msg instanceof ByteBuf)
- && agentConfig.getDataCapture().getHttpBody().getResponse().getValue()) {
+ && instrumentationConfig.httpBody().response()) {
DataCaptureUtils.captureBody(span, ctx.channel(), AttributeKeys.RESPONSE_BODY_BUFFER, msg);
}
diff --git a/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/server/HttpServerRequestTracingHandler.java b/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/server/HttpServerRequestTracingHandler.java
index 439a358e6..fd143cc59 100644
--- a/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/server/HttpServerRequestTracingHandler.java
+++ b/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/server/HttpServerRequestTracingHandler.java
@@ -33,8 +33,7 @@
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
-import org.hypertrace.agent.config.Config.AgentConfig;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedBuffersFactory;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedByteArrayOutputStream;
@@ -44,7 +43,8 @@
public class HttpServerRequestTracingHandler extends ChannelInboundHandlerAdapter {
- private final AgentConfig agentConfig = HypertraceConfig.get();
+ private static final InstrumentationConfig instrumentationConfig =
+ InstrumentationConfig.ConfigProvider.get();
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
@@ -60,14 +60,14 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
HttpRequest httpRequest = (HttpRequest) msg;
Map headersMap = headersToMap(httpRequest);
- if (agentConfig.getDataCapture().getHttpHeaders().getRequest().getValue()) {
+ if (instrumentationConfig.httpHeaders().request()) {
headersMap.forEach((key, value) -> span.setAttribute(key, value));
}
// used by blocking handler
channel.attr(AttributeKeys.REQUEST_HEADERS).set(headersMap);
CharSequence contentType = DataCaptureUtils.getContentType(httpRequest);
- if (agentConfig.getDataCapture().getHttpBody().getRequest().getValue()
+ if (instrumentationConfig.httpBody().request()
&& contentType != null
&& ContentTypeUtils.shouldCapture(contentType.toString())) {
@@ -86,7 +86,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
}
if ((msg instanceof HttpContent || msg instanceof ByteBuf)
- && agentConfig.getDataCapture().getHttpBody().getRequest().getValue()) {
+ && instrumentationConfig.rpcBody().request()) {
DataCaptureUtils.captureBody(span, channel, AttributeKeys.REQUEST_BODY_BUFFER, msg);
}
diff --git a/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/server/HttpServerResponseTracingHandler.java b/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/server/HttpServerResponseTracingHandler.java
index e8d2319a8..7e3f72660 100644
--- a/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/server/HttpServerResponseTracingHandler.java
+++ b/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/server/HttpServerResponseTracingHandler.java
@@ -38,8 +38,7 @@
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.nio.charset.Charset;
import java.util.Map;
-import org.hypertrace.agent.config.Config.AgentConfig;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedBuffersFactory;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedByteArrayOutputStream;
@@ -49,7 +48,8 @@
public class HttpServerResponseTracingHandler extends ChannelOutboundHandlerAdapter {
- private final AgentConfig agentConfig = HypertraceConfig.get();
+ private static final InstrumentationConfig instrumentationConfig =
+ InstrumentationConfig.ConfigProvider.get();
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise prm) {
@@ -62,12 +62,12 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise prm) {
if (msg instanceof HttpResponse) {
HttpResponse httpResponse = (HttpResponse) msg;
- if (agentConfig.getDataCapture().getHttpHeaders().getResponse().getValue()) {
+ if (instrumentationConfig.httpHeaders().response()) {
captureHeaders(span, httpResponse);
}
CharSequence contentType = DataCaptureUtils.getContentType(httpResponse);
- if (agentConfig.getDataCapture().getHttpBody().getResponse().getValue()
+ if (instrumentationConfig.httpBody().response()
&& contentType != null
&& ContentTypeUtils.shouldCapture(contentType.toString())) {
@@ -86,7 +86,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise prm) {
}
if ((msg instanceof HttpContent || msg instanceof ByteBuf)
- && agentConfig.getDataCapture().getHttpBody().getResponse().getValue()) {
+ && instrumentationConfig.httpBody().response()) {
DataCaptureUtils.captureBody(span, ctx.channel(), AttributeKeys.RESPONSE_BODY_BUFFER, msg);
}
diff --git a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/client/HttpClientRequestTracingHandler.java b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/client/HttpClientRequestTracingHandler.java
index 1496aafe1..82624fd9f 100644
--- a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/client/HttpClientRequestTracingHandler.java
+++ b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/client/HttpClientRequestTracingHandler.java
@@ -33,8 +33,7 @@
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
-import org.hypertrace.agent.config.Config.AgentConfig;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedBuffersFactory;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedByteArrayOutputStream;
@@ -44,7 +43,8 @@
public class HttpClientRequestTracingHandler extends ChannelOutboundHandlerAdapter {
- private final AgentConfig agentConfig = HypertraceConfig.get();
+ private static final InstrumentationConfig instrumentationConfig =
+ InstrumentationConfig.ConfigProvider.get();
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise prm) {
@@ -63,12 +63,12 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise prm) {
HttpRequest httpRequest = (HttpRequest) msg;
Map headersMap = headersToMap(httpRequest);
- if (agentConfig.getDataCapture().getHttpHeaders().getRequest().getValue()) {
+ if (instrumentationConfig.httpHeaders().request()) {
headersMap.forEach((key, value) -> span.setAttribute(key, value));
}
CharSequence contentType = DataCaptureUtils.getContentType(httpRequest);
- if (agentConfig.getDataCapture().getHttpBody().getRequest().getValue()
+ if (instrumentationConfig.httpBody().request()
&& contentType != null
&& ContentTypeUtils.shouldCapture(contentType.toString())) {
@@ -87,7 +87,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise prm) {
}
if ((msg instanceof HttpContent || msg instanceof ByteBuf)
- && agentConfig.getDataCapture().getHttpBody().getRequest().getValue()) {
+ && instrumentationConfig.httpBody().request()) {
DataCaptureUtils.captureBody(span, channel, AttributeKeys.REQUEST_BODY_BUFFER, msg);
}
diff --git a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/client/HttpClientResponseTracingHandler.java b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/client/HttpClientResponseTracingHandler.java
index a4ccc6443..3656267af 100644
--- a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/client/HttpClientResponseTracingHandler.java
+++ b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/client/HttpClientResponseTracingHandler.java
@@ -36,8 +36,7 @@
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.nio.charset.Charset;
import java.util.Map;
-import org.hypertrace.agent.config.Config.AgentConfig;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedBuffersFactory;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedByteArrayOutputStream;
@@ -47,7 +46,8 @@
public class HttpClientResponseTracingHandler extends ChannelInboundHandlerAdapter {
- private final AgentConfig agentConfig = HypertraceConfig.get();
+ private static final InstrumentationConfig instrumentationConfig =
+ InstrumentationConfig.ConfigProvider.get();
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
@@ -64,12 +64,12 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
if (msg instanceof HttpResponse) {
HttpResponse httpResponse = (HttpResponse) msg;
- if (agentConfig.getDataCapture().getHttpHeaders().getResponse().getValue()) {
+ if (instrumentationConfig.httpHeaders().response()) {
captureHeaders(span, httpResponse);
}
CharSequence contentType = DataCaptureUtils.getContentType(httpResponse);
- if (agentConfig.getDataCapture().getHttpBody().getResponse().getValue()
+ if (instrumentationConfig.httpBody().response()
&& contentType != null
&& ContentTypeUtils.shouldCapture(contentType.toString())) {
@@ -88,7 +88,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
}
if ((msg instanceof HttpContent || msg instanceof ByteBuf)
- && agentConfig.getDataCapture().getHttpBody().getResponse().getValue()) {
+ && instrumentationConfig.httpBody().response()) {
DataCaptureUtils.captureBody(span, ctx.channel(), AttributeKeys.RESPONSE_BODY_BUFFER, msg);
}
diff --git a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/HttpServerRequestTracingHandler.java b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/HttpServerRequestTracingHandler.java
index d3bbc582c..8a9451f65 100644
--- a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/HttpServerRequestTracingHandler.java
+++ b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/HttpServerRequestTracingHandler.java
@@ -33,8 +33,7 @@
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
-import org.hypertrace.agent.config.Config.AgentConfig;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedBuffersFactory;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedByteArrayOutputStream;
@@ -44,7 +43,8 @@
public class HttpServerRequestTracingHandler extends ChannelInboundHandlerAdapter {
- private final AgentConfig agentConfig = HypertraceConfig.get();
+ private static final InstrumentationConfig instrumentationConfig =
+ InstrumentationConfig.ConfigProvider.get();
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
@@ -60,14 +60,14 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
HttpRequest httpRequest = (HttpRequest) msg;
Map headersMap = headersToMap(httpRequest);
- if (agentConfig.getDataCapture().getHttpHeaders().getRequest().getValue()) {
+ if (instrumentationConfig.httpHeaders().request()) {
headersMap.forEach((key, value) -> span.setAttribute(key, value));
}
// used by blocking handler
channel.attr(AttributeKeys.REQUEST_HEADERS).set(headersMap);
CharSequence contentType = DataCaptureUtils.getContentType(httpRequest);
- if (agentConfig.getDataCapture().getHttpBody().getRequest().getValue()
+ if (instrumentationConfig.httpBody().request()
&& contentType != null
&& ContentTypeUtils.shouldCapture(contentType.toString())) {
@@ -86,7 +86,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
}
if ((msg instanceof HttpContent || msg instanceof ByteBuf)
- && agentConfig.getDataCapture().getHttpBody().getRequest().getValue()) {
+ && instrumentationConfig.httpBody().request()) {
DataCaptureUtils.captureBody(span, channel, AttributeKeys.REQUEST_BODY_BUFFER, msg);
}
diff --git a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/HttpServerResponseTracingHandler.java b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/HttpServerResponseTracingHandler.java
index 34fc53800..831eace4b 100644
--- a/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/HttpServerResponseTracingHandler.java
+++ b/instrumentation/netty/netty-4.1/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/HttpServerResponseTracingHandler.java
@@ -36,8 +36,7 @@
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.nio.charset.Charset;
import java.util.Map;
-import org.hypertrace.agent.config.Config.AgentConfig;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedBuffersFactory;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedByteArrayOutputStream;
@@ -47,7 +46,8 @@
public class HttpServerResponseTracingHandler extends ChannelOutboundHandlerAdapter {
- private final AgentConfig agentConfig = HypertraceConfig.get();
+ private static final InstrumentationConfig instrumentationConfig =
+ InstrumentationConfig.ConfigProvider.get();
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise prm) {
@@ -60,12 +60,12 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise prm) {
if (msg instanceof HttpResponse) {
HttpResponse httpResponse = (HttpResponse) msg;
- if (agentConfig.getDataCapture().getHttpHeaders().getResponse().getValue()) {
+ if (instrumentationConfig.httpHeaders().response()) {
captureHeaders(span, httpResponse);
}
CharSequence contentType = DataCaptureUtils.getContentType(httpResponse);
- if (agentConfig.getDataCapture().getHttpBody().getResponse().getValue()
+ if (instrumentationConfig.httpBody().response()
&& contentType != null
&& ContentTypeUtils.shouldCapture(contentType.toString())) {
@@ -84,7 +84,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise prm) {
}
if ((msg instanceof HttpContent || msg instanceof ByteBuf)
- && agentConfig.getDataCapture().getHttpBody().getResponse().getValue()) {
+ && instrumentationConfig.httpBody().response()) {
DataCaptureUtils.captureBody(span, ctx.channel(), AttributeKeys.RESPONSE_BODY_BUFFER, msg);
}
diff --git a/instrumentation/okhttp/okhttp-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/okhttp/v3_0/OkHttpTracingInterceptor.java b/instrumentation/okhttp/okhttp-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/okhttp/v3_0/OkHttpTracingInterceptor.java
index c5990a39a..d2546a7da 100644
--- a/instrumentation/okhttp/okhttp-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/okhttp/v3_0/OkHttpTracingInterceptor.java
+++ b/instrumentation/okhttp/okhttp-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/okhttp/v3_0/OkHttpTracingInterceptor.java
@@ -28,7 +28,7 @@
import okhttp3.Response;
import okhttp3.ResponseBody;
import okio.Buffer;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes;
import org.hypertrace.agent.core.instrumentation.utils.ContentTypeUtils;
import org.slf4j.Logger;
@@ -36,10 +36,12 @@
public class OkHttpTracingInterceptor implements Interceptor {
private static final Logger log = LoggerFactory.getLogger(OkHttpTracingInterceptor.class);
+ private static final InstrumentationConfig instrumentationConfig =
+ InstrumentationConfig.ConfigProvider.get();
@Override
public Response intercept(Chain chain) throws IOException {
- if (!HypertraceConfig.isInstrumentationEnabled(
+ if (!instrumentationConfig.isInstrumentationEnabled(
Okhttp3InstrumentationName.PRIMARY, Okhttp3InstrumentationName.OTHER)) {
return chain.proceed(chain.request());
}
@@ -47,20 +49,20 @@ public Response intercept(Chain chain) throws IOException {
Span span = Span.current();
Request request = chain.request();
- if (HypertraceConfig.get().getDataCapture().getHttpHeaders().getRequest().getValue()) {
+ if (instrumentationConfig.httpHeaders().request()) {
captureHeaders(span, request.headers(), HypertraceSemanticAttributes::httpRequestHeader);
}
captureRequestBody(span, request.body());
Response response = chain.proceed(request);
- if (HypertraceConfig.get().getDataCapture().getHttpHeaders().getResponse().getValue()) {
+ if (instrumentationConfig.httpHeaders().response()) {
captureHeaders(span, response.headers(), HypertraceSemanticAttributes::httpResponseHeader);
}
return captureResponseBody(span, response);
}
private static void captureRequestBody(Span span, RequestBody requestBody) {
- if (!HypertraceConfig.get().getDataCapture().getHttpBody().getRequest().getValue()) {
+ if (!instrumentationConfig.httpBody().request()) {
return;
}
if (requestBody == null) {
@@ -80,7 +82,7 @@ private static void captureRequestBody(Span span, RequestBody requestBody) {
}
private static Response captureResponseBody(Span span, final Response response) {
- if (!HypertraceConfig.get().getDataCapture().getHttpBody().getResponse().getValue()) {
+ if (!instrumentationConfig.httpBody().response()) {
return response;
}
if (response.body() == null) {
diff --git a/instrumentation/servlet/servlet-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v3_0/nowrapping/BodyCaptureAsyncListener.java b/instrumentation/servlet/servlet-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v3_0/nowrapping/BodyCaptureAsyncListener.java
index cb12cdc53..7747cc849 100644
--- a/instrumentation/servlet/servlet-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v3_0/nowrapping/BodyCaptureAsyncListener.java
+++ b/instrumentation/servlet/servlet-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v3_0/nowrapping/BodyCaptureAsyncListener.java
@@ -29,8 +29,7 @@
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.hypertrace.agent.config.Config.AgentConfig;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes;
import org.hypertrace.agent.core.instrumentation.SpanAndObjectPair;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedByteArrayOutputStream;
@@ -41,6 +40,9 @@
public class BodyCaptureAsyncListener implements AsyncListener {
+ private static final InstrumentationConfig instrumentationConfig =
+ InstrumentationConfig.ConfigProvider.get();
+
private final AtomicBoolean responseHandled;
private final Span span;
@@ -52,8 +54,6 @@ public class BodyCaptureAsyncListener implements AsyncListener {
private final ContextStore inputStreamContextStore;
private final ContextStore readerContextStore;
- private final AgentConfig agentConfig = HypertraceConfig.get();
-
public BodyCaptureAsyncListener(
AtomicBoolean responseHandled,
Span span,
@@ -100,13 +100,13 @@ private void captureResponseDataAndClearRequestBuffer(
if (servletResponse instanceof HttpServletResponse) {
HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;
- if (agentConfig.getDataCapture().getHttpBody().getResponse().getValue()
+ if (instrumentationConfig.httpBody().response()
&& ContentTypeUtils.shouldCapture(httpResponse.getContentType())) {
Utils.captureResponseBody(
span, httpResponse, responseContextStore, streamContextStore, writerContextStore);
}
- if (agentConfig.getDataCapture().getHttpHeaders().getResponse().getValue()) {
+ if (instrumentationConfig.httpHeaders().response()) {
for (String headerName : httpResponse.getHeaderNames()) {
String headerValue = httpResponse.getHeader(headerName);
span.setAttribute(
@@ -118,7 +118,7 @@ private void captureResponseDataAndClearRequestBuffer(
HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
// remove request body buffers from context stores, otherwise they might get reused
- if (agentConfig.getDataCapture().getHttpBody().getRequest().getValue()
+ if (instrumentationConfig.httpBody().request()
&& ContentTypeUtils.shouldCapture(httpRequest.getContentType())) {
Utils.resetRequestBodyBuffers(
httpRequest, requestContextStore, inputStreamContextStore, readerContextStore);
diff --git a/instrumentation/servlet/servlet-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v3_0/nowrapping/Servlet30AndFilterInstrumentation.java b/instrumentation/servlet/servlet-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v3_0/nowrapping/Servlet30AndFilterInstrumentation.java
index a58d7dad7..b7e553830 100644
--- a/instrumentation/servlet/servlet-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v3_0/nowrapping/Servlet30AndFilterInstrumentation.java
+++ b/instrumentation/servlet/servlet-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v3_0/nowrapping/Servlet30AndFilterInstrumentation.java
@@ -47,8 +47,7 @@
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatcher.Junction;
-import org.hypertrace.agent.config.Config.AgentConfig;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes;
import org.hypertrace.agent.core.instrumentation.SpanAndObjectPair;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedByteArrayOutputStream;
@@ -102,9 +101,10 @@ public static boolean start(
HttpServletResponse httpResponse = (HttpServletResponse) response;
currentSpan = Java8BytecodeBridge.currentSpan();
- AgentConfig agentConfig = HypertraceConfig.get();
+ InstrumentationConfig instrumentationConfig = InstrumentationConfig.ConfigProvider.get();
+
String contentType = httpRequest.getContentType();
- if (agentConfig.getDataCapture().getHttpBody().getRequest().getValue()
+ if (instrumentationConfig.httpBody().request()
&& ContentTypeUtils.shouldCapture(contentType)) {
// The HttpServletRequest instrumentation uses this to
// enable the instrumentation
@@ -123,7 +123,7 @@ public static boolean start(
AttributeKey attributeKey =
HypertraceSemanticAttributes.httpRequestHeader(headerName);
- if (HypertraceConfig.get().getDataCapture().getHttpHeaders().getRequest().getValue()) {
+ if (instrumentationConfig.httpHeaders().request()) {
currentSpan.setAttribute(attributeKey, headerValue);
}
headers.put(attributeKey.getKey(), headerValue);
@@ -155,7 +155,7 @@ public static void exit(
HttpServletResponse httpResponse = (HttpServletResponse) response;
HttpServletRequest httpRequest = (HttpServletRequest) request;
- AgentConfig agentConfig = HypertraceConfig.get();
+ InstrumentationConfig instrumentationConfig = InstrumentationConfig.ConfigProvider.get();
// response context to capture body and clear the context
ContextStore responseContextStore =
@@ -195,7 +195,7 @@ public static void exit(
}
if (!request.isAsyncStarted() && responseHandled.compareAndSet(false, true)) {
- if (agentConfig.getDataCapture().getHttpHeaders().getResponse().getValue()) {
+ if (instrumentationConfig.httpHeaders().response()) {
for (String headerName : httpResponse.getHeaderNames()) {
String headerValue = httpResponse.getHeader(headerName);
currentSpan.setAttribute(
@@ -204,7 +204,7 @@ public static void exit(
}
// capture response body
- if (agentConfig.getDataCapture().getHttpBody().getResponse().getValue()
+ if (instrumentationConfig.httpBody().response()
&& ContentTypeUtils.shouldCapture(httpResponse.getContentType())) {
Utils.captureResponseBody(
currentSpan,
@@ -215,7 +215,7 @@ public static void exit(
}
// remove request body buffers from context stores, otherwise they might get reused
- if (agentConfig.getDataCapture().getHttpBody().getRequest().getValue()
+ if (instrumentationConfig.httpBody().request()
&& ContentTypeUtils.shouldCapture(httpRequest.getContentType())) {
Utils.resetRequestBodyBuffers(
httpRequest, requestContextStore, inputStreamContextStore, readerContextStore);
diff --git a/instrumentation/servlet/servlet-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v3_0/nowrapping/response/ServletResponseInstrumentation.java b/instrumentation/servlet/servlet-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v3_0/nowrapping/response/ServletResponseInstrumentation.java
index d8ce9d908..b827073d1 100644
--- a/instrumentation/servlet/servlet-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v3_0/nowrapping/response/ServletResponseInstrumentation.java
+++ b/instrumentation/servlet/servlet-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/servlet/v3_0/nowrapping/response/ServletResponseInstrumentation.java
@@ -39,8 +39,7 @@
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatcher.Junction;
-import org.hypertrace.agent.config.Config.AgentConfig;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
import org.hypertrace.agent.core.instrumentation.SpanAndObjectPair;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedBuffersFactory;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedByteArrayOutputStream;
@@ -116,9 +115,9 @@ public static void exit(
}
// do not capture if data capture is disabled or not supported content type
- AgentConfig agentConfig = HypertraceConfig.get();
+ InstrumentationConfig instrumentationConfig = InstrumentationConfig.ConfigProvider.get();
String contentType = httpServletResponse.getContentType();
- if (agentConfig.getDataCapture().getHttpBody().getResponse().getValue()
+ if (instrumentationConfig.httpBody().response()
&& ContentTypeUtils.shouldCapture(contentType)) {
String charsetStr = httpServletResponse.getCharacterEncoding();
@@ -175,9 +174,9 @@ public static void exit(
}
// do not capture if data capture is disabled or not supported content type
- AgentConfig agentConfig = HypertraceConfig.get();
+ InstrumentationConfig instrumentationConfig = InstrumentationConfig.ConfigProvider.get();
String contentType = httpServletResponse.getContentType();
- if (agentConfig.getDataCapture().getHttpBody().getResponse().getValue()
+ if (instrumentationConfig.httpBody().response()
&& ContentTypeUtils.shouldCapture(contentType)) {
BoundedCharArrayWriter writer = BoundedBuffersFactory.createWriter();
diff --git a/instrumentation/vertx-web-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/vertx/HttpRequestHandleInstrumentation.java b/instrumentation/vertx-web-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/vertx/HttpRequestHandleInstrumentation.java
index 46e7e7d75..b4dfe966e 100644
--- a/instrumentation/vertx-web-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/vertx/HttpRequestHandleInstrumentation.java
+++ b/instrumentation/vertx-web-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/vertx/HttpRequestHandleInstrumentation.java
@@ -33,7 +33,7 @@
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes;
import org.hypertrace.agent.core.instrumentation.utils.ContentTypeUtils;
@@ -72,14 +72,15 @@ public static void handleResponseEnter(
}
Span span = Span.fromContext(contexts.context);
- if (HypertraceConfig.get().getDataCapture().getHttpHeaders().getRequest().getValue()) {
+ InstrumentationConfig instrumentationConfig = InstrumentationConfig.ConfigProvider.get();
+ if (instrumentationConfig.httpHeaders().request()) {
for (Map.Entry entry : request.headers()) {
span.setAttribute(
HypertraceSemanticAttributes.httpRequestHeader(entry.getKey()), entry.getValue());
}
}
- if (HypertraceConfig.get().getDataCapture().getHttpHeaders().getResponse().getValue()) {
+ if (instrumentationConfig.httpHeaders().response()) {
for (Map.Entry entry : response.headers()) {
span.setAttribute(
HypertraceSemanticAttributes.httpResponseHeader(entry.getKey()), entry.getValue());
@@ -87,7 +88,7 @@ public static void handleResponseEnter(
}
String contentType = response.getHeader("Content-Type");
- if (HypertraceConfig.get().getDataCapture().getHttpBody().getResponse().getValue()
+ if (instrumentationConfig.httpBody().response()
&& ContentTypeUtils.shouldCapture(contentType)) {
InstrumentationContext.get(HttpClientResponse.class, Span.class).put(response, span);
}
diff --git a/instrumentation/vertx-web-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/vertx/HttpRequestInstrumentation.java b/instrumentation/vertx-web-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/vertx/HttpRequestInstrumentation.java
index 094c5fc5d..7714844da 100644
--- a/instrumentation/vertx-web-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/vertx/HttpRequestInstrumentation.java
+++ b/instrumentation/vertx-web-3.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/vertx/HttpRequestInstrumentation.java
@@ -41,7 +41,7 @@
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedBuffersFactory;
import org.hypertrace.agent.core.instrumentation.buffer.BoundedCharArrayWriter;
@@ -140,7 +140,8 @@ public static void enter(
Span span = Span.fromContext(contexts.context);
String contentType = request.headers().get("Content-Type");
- if (HypertraceConfig.get().getDataCapture().getHttpBody().getRequest().getValue()
+ InstrumentationConfig instrumentationConfig = InstrumentationConfig.ConfigProvider.get();
+ if (instrumentationConfig.httpBody().request()
&& ContentTypeUtils.shouldCapture(contentType)) {
BoundedCharArrayWriter buffer =
InstrumentationContext.get(MultiMap.class, BoundedCharArrayWriter.class)
@@ -179,7 +180,8 @@ public static void enter(
Span span = Span.fromContext(contexts.context);
String contentType = request.headers().get("Content-Type");
- if (HypertraceConfig.get().getDataCapture().getHttpBody().getRequest().getValue()
+ InstrumentationConfig instrumentationConfig = InstrumentationConfig.ConfigProvider.get();
+ if (instrumentationConfig.httpBody().request()
&& ContentTypeUtils.shouldCapture(contentType)) {
BoundedCharArrayWriter buffer =
@@ -214,7 +216,8 @@ public static void enter(
}
String contentType = request.headers().get("Content-Type");
- if (HypertraceConfig.get().getDataCapture().getHttpBody().getRequest().getValue()
+ InstrumentationConfig instrumentationConfig = InstrumentationConfig.ConfigProvider.get();
+ if (instrumentationConfig.httpBody().request()
&& ContentTypeUtils.shouldCapture(contentType)) {
ContextStore contextStore =
@@ -246,7 +249,8 @@ public static void enter(
}
String contentType = request.headers().get("Content-Type");
- if (HypertraceConfig.get().getDataCapture().getHttpBody().getRequest().getValue()
+ InstrumentationConfig instrumentationConfig = InstrumentationConfig.ConfigProvider.get();
+ if (instrumentationConfig.httpBody().request()
&& ContentTypeUtils.shouldCapture(contentType)) {
ContextStore contextStore =
diff --git a/javaagent-core/build.gradle.kts b/javaagent-core/build.gradle.kts
index 9be8ec96d..5932022f3 100644
--- a/javaagent-core/build.gradle.kts
+++ b/javaagent-core/build.gradle.kts
@@ -1,29 +1,8 @@
-import com.google.protobuf.gradle.*
-
plugins {
`java-library`
- idea
- id("com.google.protobuf") version "0.8.13"
id("org.hypertrace.publish-maven-central-plugin")
}
-val protobufVersion = "3.15.8"
-
-protobuf {
- protoc {
- // The artifact spec for the Protobuf Compiler
- artifact = "com.google.protobuf:protoc:$protobufVersion"
- }
- generateProtoTasks {
- }
-}
-
-idea {
- module {
- sourceDirs.add(file("${projectDir}/build/generated/source/proto/main/proto"))
- }
-}
-
val versions: Map by extra
dependencies {
@@ -32,11 +11,6 @@ dependencies {
implementation("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-caching:${versions["opentelemetry_java_agent"]}")
implementation("org.slf4j:slf4j-api:${versions["slf4j"]}")
- api(platform("com.google.protobuf:protobuf-bom:$protobufVersion"))
- api("com.google.protobuf:protobuf-java")
- api("com.google.protobuf:protobuf-java-util")
- // convert yaml to json, since java protobuf impl supports only json
- implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.11.3")
-
+ // TODO (pavolloffay) remove
implementation("com.blogspot.mydailyjava:weak-lock-free:0.17")
}
diff --git a/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java b/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java
new file mode 100644
index 000000000..3eb41208a
--- /dev/null
+++ b/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright The Hypertrace Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.hypertrace.agent.core.config;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.ServiceLoader;
+
+/** Instrumentation config holds configuration for the instrumentation. */
+public interface InstrumentationConfig {
+
+ int maxBodySizeBytes();
+
+ List jarPaths();
+
+ Message httpHeaders();
+
+ Message httpBody();
+
+ Message rpcMetadata();
+
+ Message rpcBody();
+
+ interface Message {
+ boolean request();
+
+ boolean response();
+ }
+
+ default boolean isInstrumentationEnabled(String primaryName, String[] otherNames) {
+ // the instNames is not used because the config does not support it at the moment.
+
+ // disabled if all is disabled
+ if (!httpBody().request()
+ && !httpBody().response()
+ && !httpHeaders().request()
+ && !httpHeaders().response()
+ && !rpcMetadata().request()
+ && !rpcMetadata().response()) {
+ return false;
+ }
+ return true;
+ }
+
+ class ConfigProvider {
+ private static volatile InstrumentationConfig instrumentationConfig;
+
+ static InstrumentationConfig load() {
+ ServiceLoader configs =
+ ServiceLoader.load(InstrumentationConfig.class);
+ Iterator iterator = configs.iterator();
+ if (!iterator.hasNext()) {
+ return null;
+ }
+ // TODO consider returning noop
+ return iterator.next();
+ }
+
+ public static InstrumentationConfig get() {
+ if (instrumentationConfig == null) {
+ synchronized (ConfigProvider.class) {
+ if (instrumentationConfig == null) {
+ instrumentationConfig = load();
+ }
+ }
+ }
+ return instrumentationConfig;
+ }
+ }
+}
diff --git a/javaagent-core/src/main/java/org/hypertrace/agent/core/instrumentation/buffer/BoundedBuffersFactory.java b/javaagent-core/src/main/java/org/hypertrace/agent/core/instrumentation/buffer/BoundedBuffersFactory.java
index 5756fee92..c7ca69e02 100644
--- a/javaagent-core/src/main/java/org/hypertrace/agent/core/instrumentation/buffer/BoundedBuffersFactory.java
+++ b/javaagent-core/src/main/java/org/hypertrace/agent/core/instrumentation/buffer/BoundedBuffersFactory.java
@@ -17,12 +17,11 @@
package org.hypertrace.agent.core.instrumentation.buffer;
import java.nio.charset.Charset;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
public class BoundedBuffersFactory {
- public static final int MAX_SIZE =
- HypertraceConfig.get().getDataCapture().getBodyMaxSizeBytes().getValue();
+ public static final int MAX_SIZE = InstrumentationConfig.ConfigProvider.get().maxBodySizeBytes();
public static BoundedByteArrayOutputStream createStream(Charset charset) {
return new BoundedByteArrayOutputStream(MAX_SIZE, charset);
diff --git a/javaagent/build.gradle.kts b/javaagent/build.gradle.kts
index dd1342253..ca8ae1061 100644
--- a/javaagent/build.gradle.kts
+++ b/javaagent/build.gradle.kts
@@ -30,17 +30,6 @@ tasks {
}
shadowJar {
- // config in javaagent-core uses protobuf and jackson
- // shade to the same location as OTEL, because the package prefix is used in classloader instrumentation
- // https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/master/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/Constants.java#L25
- // Consider changing the prefix once https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/1594 is fixed.
- relocate("com.fasterxml.jackson", "io.opentelemetry.javaagent.shaded.org.hypertrace.shaded.com.fasterxml.jackson")
- relocate("com.google", "io.opentelemetry.javaagent.shaded.org.hypertrace.shaded.com.google")
- relocate("google.protobuf", "io.opentelemetry.javaagent.shaded.org.hypertrace.shaded.google.protobuf")
- relocate("javax", "io.opentelemetry.javaagent.shaded.org.hypertrace.shaded.javax")
- relocate("org.checkerframework", "io.opentelemetry.javaagent.shaded.org.hypertrace.shaded.com.checkerframework")
- relocate("org.yaml", "io.opentelemetry.javaagent.shaded.org.hypertrace.shaded.org.yaml")
-
relocate("com.blogspot.mydailyjava.weaklockfree", "io.opentelemetry.instrumentation.api.internal.shaded.weaklockfree")
dependencies {
diff --git a/otel-extensions/build.gradle.kts b/otel-extensions/build.gradle.kts
index ef8420aee..165ddbc26 100644
--- a/otel-extensions/build.gradle.kts
+++ b/otel-extensions/build.gradle.kts
@@ -1,5 +1,27 @@
+import com.google.protobuf.gradle.*
+
plugins {
`java-library`
+ idea
+ id("com.google.protobuf") version "0.8.13"
+}
+
+
+val protobufVersion = "3.15.8"
+
+protobuf {
+ protoc {
+ // The artifact spec for the Protobuf Compiler
+ artifact = "com.google.protobuf:protoc:$protobufVersion"
+ }
+ generateProtoTasks {
+ }
+}
+
+idea {
+ module {
+ sourceDirs.add(file("${projectDir}/build/generated/source/proto/main/proto"))
+ }
}
val versions: Map by extra
@@ -18,6 +40,13 @@ dependencies {
implementation("net.bytebuddy:byte-buddy:${versions["byte_buddy"]}")
annotationProcessor("com.google.auto.service:auto-service:1.0")
+
+ api(platform("com.google.protobuf:protobuf-bom:$protobufVersion"))
+ api("com.google.protobuf:protobuf-java")
+ api("com.google.protobuf:protobuf-java-util")
+ // convert yaml to json, since java protobuf impl supports only json
+ implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.11.3")
+
testImplementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:${versions["opentelemetry"]}-alpha")
testImplementation("io.opentelemetry:opentelemetry-sdk:${versions["opentelemetry"]}")
}
diff --git a/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/HypertraceResourceProvider.java b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/HypertraceResourceProvider.java
index 458efcff2..d4abf0ad9 100644
--- a/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/HypertraceResourceProvider.java
+++ b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/HypertraceResourceProvider.java
@@ -24,7 +24,7 @@
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
import org.hypertrace.agent.config.Config.AgentConfig;
-import org.hypertrace.agent.core.config.HypertraceConfig;
+import org.hypertrace.agent.otel.extensions.config.HypertraceConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/javaagent-core/src/main/java/org/hypertrace/agent/core/config/EnvironmentConfig.java b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/EnvironmentConfig.java
similarity index 99%
rename from javaagent-core/src/main/java/org/hypertrace/agent/core/config/EnvironmentConfig.java
rename to otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/EnvironmentConfig.java
index c207193cf..2b4e5ff17 100644
--- a/javaagent-core/src/main/java/org/hypertrace/agent/core/config/EnvironmentConfig.java
+++ b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/EnvironmentConfig.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.hypertrace.agent.core.config;
+package org.hypertrace.agent.otel.extensions.config;
import com.google.protobuf.BoolValue;
import com.google.protobuf.Int32Value;
diff --git a/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/HypertraceAgentConfiguration.java b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/HypertraceAgentConfiguration.java
similarity index 94%
rename from otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/HypertraceAgentConfiguration.java
rename to otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/HypertraceAgentConfiguration.java
index cf596f967..5e96be475 100644
--- a/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/HypertraceAgentConfiguration.java
+++ b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/HypertraceAgentConfiguration.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.hypertrace.agent.otel.extensions;
+package org.hypertrace.agent.otel.extensions.config;
import com.google.auto.service.AutoService;
import com.google.common.annotations.VisibleForTesting;
@@ -26,7 +26,6 @@
import org.hypertrace.agent.config.Config.AgentConfig;
import org.hypertrace.agent.config.Config.PropagationFormat;
import org.hypertrace.agent.config.Config.TraceReporterType;
-import org.hypertrace.agent.core.config.HypertraceConfig;
@AutoService(PropertySource.class)
public class HypertraceAgentConfiguration implements PropertySource {
@@ -72,7 +71,7 @@ public Map getProperties() {
}
@VisibleForTesting
- static String toOtelPropagators(List propagationFormats) {
+ public static String toOtelPropagators(List propagationFormats) {
return propagationFormats.stream()
.map(v -> v.name().toLowerCase())
.collect(Collectors.joining(","));
diff --git a/javaagent-core/src/main/java/org/hypertrace/agent/core/config/HypertraceConfig.java b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/HypertraceConfig.java
similarity index 80%
rename from javaagent-core/src/main/java/org/hypertrace/agent/core/config/HypertraceConfig.java
rename to otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/HypertraceConfig.java
index 55b3f3ca6..ed85ab88f 100644
--- a/javaagent-core/src/main/java/org/hypertrace/agent/core/config/HypertraceConfig.java
+++ b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/HypertraceConfig.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.hypertrace.agent.core.config;
+package org.hypertrace.agent.otel.extensions.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
@@ -48,10 +48,6 @@ private HypertraceConfig() {}
private static final Logger log = LoggerFactory.getLogger(HypertraceConfig.class);
- // we could use a Set but that would need to be synchronized
- // so avoiding for perf reasons
- private static volatile boolean servletCausingException;
-
// volatile field in order to properly handle lazy initialization with double-checked locking
private static volatile AgentConfig agentConfig;
@@ -80,48 +76,6 @@ public static AgentConfig get() {
return agentConfig;
}
- public static boolean isInstrumentationEnabled(String primaryName, String[] otherNames) {
- // the instNames is not used because the config does not support it at the moment.
-
- AgentConfig agentConfig = get();
- // disabled if all is disabled
- if (!agentConfig.getDataCapture().getHttpBody().getRequest().getValue()
- && !agentConfig.getDataCapture().getHttpBody().getResponse().getValue()
- && !agentConfig.getDataCapture().getHttpHeaders().getRequest().getValue()
- && !agentConfig.getDataCapture().getHttpHeaders().getResponse().getValue()
- && !agentConfig.getDataCapture().getRpcMetadata().getRequest().getValue()
- && !agentConfig.getDataCapture().getRpcMetadata().getResponse().getValue()) {
- return false;
- }
- return true;
- }
-
- public static boolean disableServletWrapperTypes() {
- return servletCausingException;
- }
-
- /** Record any exception. This can result in disabling instrumentations. */
- public static void recordException(Throwable throwable) {
- if (!(throwable instanceof ClassCastException)) {
- return;
- }
- String message = throwable.getMessage();
- if (message == null || message.isEmpty() || !isHypertraceType(message)) {
- return;
- }
- message = message.toLowerCase();
- if (message.contains("servlet")) {
- log.error(
- "Hypertrace servlet type caused class cast exception. Disabling wrapping of servlet types",
- throwable);
- servletCausingException = true;
- }
- }
-
- private static boolean isHypertraceType(String message) {
- return message.contains("hypertrace");
- }
-
/** Reset the config, use only in tests. */
@VisibleForTesting
public static void reset() {
diff --git a/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/InstrumentationConfigImpl.java b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/InstrumentationConfigImpl.java
new file mode 100644
index 000000000..2ea737dd0
--- /dev/null
+++ b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/InstrumentationConfigImpl.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright The Hypertrace Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.hypertrace.agent.otel.extensions.config;
+
+import com.google.auto.service.AutoService;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.hypertrace.agent.config.Config;
+import org.hypertrace.agent.config.Config.AgentConfig;
+import org.hypertrace.agent.config.Config.DataCapture;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
+
+@AutoService(InstrumentationConfig.class)
+public class InstrumentationConfigImpl implements InstrumentationConfig {
+
+ private final AgentConfig agentConfig = HypertraceConfig.get();
+
+ private final Message httpHeaders;
+ private final Message httpBody;
+ private final Message rpcMetadata;
+ private final Message rpcBody;
+
+ public InstrumentationConfigImpl() {
+ DataCapture dataCapture = agentConfig.getDataCapture();
+ this.httpHeaders = new MessageImpl(dataCapture.getHttpHeaders());
+ this.httpBody = new MessageImpl(dataCapture.getHttpBody());
+ this.rpcMetadata = new MessageImpl(dataCapture.getRpcMetadata());
+ this.rpcBody = new MessageImpl(dataCapture.getRpcBody());
+ }
+
+ @Override
+ public int maxBodySizeBytes() {
+ return agentConfig.getDataCapture().getBodyMaxSizeBytes().getValue();
+ }
+
+ @Override
+ public List jarPaths() {
+ return agentConfig.getJavaagent().getFilterJarPathsList().stream()
+ .map(r -> r.getValue())
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public Message httpHeaders() {
+ return this.httpHeaders;
+ }
+
+ @Override
+ public Message httpBody() {
+ return this.httpBody;
+ }
+
+ @Override
+ public Message rpcMetadata() {
+ return this.rpcMetadata;
+ }
+
+ @Override
+ public Message rpcBody() {
+ return this.rpcBody;
+ }
+
+ private class MessageImpl implements Message {
+
+ private final Config.Message message;
+
+ public MessageImpl(Config.Message message) {
+ this.message = message;
+ }
+
+ @Override
+ public boolean request() {
+ return message.getRequest().getValue();
+ }
+
+ @Override
+ public boolean response() {
+ return message.getResponse().getValue();
+ }
+ }
+}
diff --git a/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/InstrumentationConfigInstaller.java b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/InstrumentationConfigInstaller.java
new file mode 100644
index 000000000..4d18ead15
--- /dev/null
+++ b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/InstrumentationConfigInstaller.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright The Hypertrace Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.hypertrace.agent.otel.extensions.config;
+
+import com.google.auto.service.AutoService;
+import io.opentelemetry.instrumentation.api.config.Config;
+import io.opentelemetry.javaagent.spi.ComponentInstaller;
+import org.hypertrace.agent.core.config.InstrumentationConfig.ConfigProvider;
+
+@AutoService(ComponentInstaller.class)
+public class InstrumentationConfigInstaller implements ComponentInstaller {
+
+ @Override
+ public void beforeByteBuddyAgent(Config config) {
+ // get initializes singleton
+ ConfigProvider.get();
+ }
+}
diff --git a/javaagent-core/src/main/proto b/otel-extensions/src/main/proto
similarity index 100%
rename from javaagent-core/src/main/proto
rename to otel-extensions/src/main/proto
diff --git a/otel-extensions/src/test/java/org/hypertrace/agent/otel/extensions/HypertraceAgentConfigurationTest.java b/otel-extensions/src/test/java/org/hypertrace/agent/otel/extensions/HypertraceAgentConfigurationTest.java
index 80853e88c..ce245fd6c 100644
--- a/otel-extensions/src/test/java/org/hypertrace/agent/otel/extensions/HypertraceAgentConfigurationTest.java
+++ b/otel-extensions/src/test/java/org/hypertrace/agent/otel/extensions/HypertraceAgentConfigurationTest.java
@@ -19,6 +19,7 @@
import java.util.Arrays;
import java.util.List;
import org.hypertrace.agent.config.Config.PropagationFormat;
+import org.hypertrace.agent.otel.extensions.config.HypertraceAgentConfiguration;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
diff --git a/javaagent-core/src/test/java/org/hypertrace/agent/core/config/EnvironmentConfigTest.java b/otel-extensions/src/test/java/org/hypertrace/agent/otel/extensions/config/EnvironmentConfigTest.java
similarity index 98%
rename from javaagent-core/src/test/java/org/hypertrace/agent/core/config/EnvironmentConfigTest.java
rename to otel-extensions/src/test/java/org/hypertrace/agent/otel/extensions/config/EnvironmentConfigTest.java
index 73300f9dd..4b3edbcc9 100644
--- a/javaagent-core/src/test/java/org/hypertrace/agent/core/config/EnvironmentConfigTest.java
+++ b/otel-extensions/src/test/java/org/hypertrace/agent/otel/extensions/config/EnvironmentConfigTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.hypertrace.agent.core.config;
+package org.hypertrace.agent.otel.extensions.config;
import com.google.protobuf.StringValue;
import java.util.Arrays;
diff --git a/javaagent-core/src/test/java/org/hypertrace/agent/core/config/HypertraceConfigTest.java b/otel-extensions/src/test/java/org/hypertrace/agent/otel/extensions/config/HypertraceConfigTest.java
similarity index 99%
rename from javaagent-core/src/test/java/org/hypertrace/agent/core/config/HypertraceConfigTest.java
rename to otel-extensions/src/test/java/org/hypertrace/agent/otel/extensions/config/HypertraceConfigTest.java
index 81dbee374..452d39111 100644
--- a/javaagent-core/src/test/java/org/hypertrace/agent/core/config/HypertraceConfigTest.java
+++ b/otel-extensions/src/test/java/org/hypertrace/agent/otel/extensions/config/HypertraceConfigTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.hypertrace.agent.core.config;
+package org.hypertrace.agent.otel.extensions.config;
import com.google.protobuf.StringValue;
import com.google.protobuf.util.JsonFormat;
diff --git a/javaagent-core/src/test/resources/config.yaml b/otel-extensions/src/test/resources/config.yaml
similarity index 100%
rename from javaagent-core/src/test/resources/config.yaml
rename to otel-extensions/src/test/resources/config.yaml
diff --git a/javaagent-core/src/test/resources/emptyconfig.yaml b/otel-extensions/src/test/resources/emptyconfig.yaml
similarity index 100%
rename from javaagent-core/src/test/resources/emptyconfig.yaml
rename to otel-extensions/src/test/resources/emptyconfig.yaml
From 0fd2fd0c3068ef7f713a1ddcc14091733aae0eed Mon Sep 17 00:00:00 2001
From: Pavol Loffay
Date: Fri, 18 Jun 2021 09:39:01 +0200
Subject: [PATCH 2/3] fix grpc
Signed-off-by: Pavol Loffay
---
.../grpc/v1_5/client/GrpcClientInterceptor.java | 13 ++++++++++---
.../grpc/v1_5/server/GrpcServerInterceptor.java | 11 ++++++++---
.../grpc/v1_5/GrpcInstrumentationTest.java | 2 ++
.../agent/core/config/InstrumentationConfig.java | 7 +++++++
4 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/instrumentation/grpc-1.5/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/client/GrpcClientInterceptor.java b/instrumentation/grpc-1.5/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/client/GrpcClientInterceptor.java
index 6112f2c29..cb823a0e6 100644
--- a/instrumentation/grpc-1.5/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/client/GrpcClientInterceptor.java
+++ b/instrumentation/grpc-1.5/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/client/GrpcClientInterceptor.java
@@ -33,12 +33,11 @@
public class GrpcClientInterceptor implements ClientInterceptor {
- private static final InstrumentationConfig instrumentationConfig =
- InstrumentationConfig.ConfigProvider.get();
-
@Override
public ClientCall interceptCall(
MethodDescriptor method, CallOptions callOptions, Channel next) {
+
+ InstrumentationConfig instrumentationConfig = InstrumentationConfig.ConfigProvider.get();
if (!instrumentationConfig.isInstrumentationEnabled(
GrpcInstrumentationName.PRIMARY, GrpcInstrumentationName.OTHER)) {
return next.newCall(method, callOptions);
@@ -62,6 +61,8 @@ static final class TracingClientCall
@Override
public void start(Listener responseListener, Metadata headers) {
super.start(new TracingClientCallListener<>(responseListener, span), headers);
+
+ InstrumentationConfig instrumentationConfig = InstrumentationConfig.ConfigProvider.get();
if (instrumentationConfig.rpcMetadata().request()) {
GrpcSpanDecorator.addMetadataAttributes(
headers, span, HypertraceSemanticAttributes::rpcRequestMetadata);
@@ -71,6 +72,8 @@ public void start(Listener responseListener, Metadata headers) {
@Override
public void sendMessage(ReqT message) {
super.sendMessage(message);
+
+ InstrumentationConfig instrumentationConfig = InstrumentationConfig.ConfigProvider.get();
if (instrumentationConfig.rpcBody().request()) {
GrpcSpanDecorator.addMessageAttribute(
message, span, HypertraceSemanticAttributes.RPC_REQUEST_BODY);
@@ -90,6 +93,8 @@ static final class TracingClientCallListener
@Override
public void onMessage(RespT message) {
delegate().onMessage(message);
+
+ InstrumentationConfig instrumentationConfig = InstrumentationConfig.ConfigProvider.get();
if (instrumentationConfig.rpcBody().response()) {
GrpcSpanDecorator.addMessageAttribute(
message, span, HypertraceSemanticAttributes.RPC_RESPONSE_BODY);
@@ -99,6 +104,8 @@ public void onMessage(RespT message) {
@Override
public void onHeaders(Metadata headers) {
super.onHeaders(headers);
+
+ InstrumentationConfig instrumentationConfig = InstrumentationConfig.ConfigProvider.get();
if (instrumentationConfig.rpcMetadata().response()) {
GrpcSpanDecorator.addMetadataAttributes(
headers, span, HypertraceSemanticAttributes::rpcResponseMetadata);
diff --git a/instrumentation/grpc-1.5/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/server/GrpcServerInterceptor.java b/instrumentation/grpc-1.5/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/server/GrpcServerInterceptor.java
index 870fcf7ad..23d1b0bc5 100644
--- a/instrumentation/grpc-1.5/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/server/GrpcServerInterceptor.java
+++ b/instrumentation/grpc-1.5/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/server/GrpcServerInterceptor.java
@@ -34,12 +34,11 @@
public class GrpcServerInterceptor implements ServerInterceptor {
- private static final InstrumentationConfig instrumentationConfig =
- InstrumentationConfig.ConfigProvider.get();
-
@Override
public ServerCall.Listener interceptCall(
ServerCall call, Metadata headers, ServerCallHandler next) {
+
+ InstrumentationConfig instrumentationConfig = InstrumentationConfig.ConfigProvider.get();
if (!instrumentationConfig.isInstrumentationEnabled(
GrpcInstrumentationName.PRIMARY, GrpcInstrumentationName.OTHER)) {
return next.startCall(call, headers);
@@ -78,6 +77,8 @@ static final class TracingServerCall
@Override
public void sendMessage(RespT message) {
super.sendMessage(message);
+
+ InstrumentationConfig instrumentationConfig = InstrumentationConfig.ConfigProvider.get();
if (instrumentationConfig.rpcBody().response()) {
GrpcSpanDecorator.addMessageAttribute(
message, span, HypertraceSemanticAttributes.RPC_RESPONSE_BODY);
@@ -87,6 +88,8 @@ public void sendMessage(RespT message) {
@Override
public void sendHeaders(Metadata headers) {
super.sendHeaders(headers);
+
+ InstrumentationConfig instrumentationConfig = InstrumentationConfig.ConfigProvider.get();
if (instrumentationConfig.rpcMetadata().response()) {
GrpcSpanDecorator.addMetadataAttributes(
headers, span, HypertraceSemanticAttributes::rpcResponseMetadata);
@@ -107,6 +110,8 @@ static final class TracingServerCallListener
@Override
public void onMessage(ReqT message) {
delegate().onMessage(message);
+
+ InstrumentationConfig instrumentationConfig = InstrumentationConfig.ConfigProvider.get();
if (instrumentationConfig.rpcBody().request()) {
GrpcSpanDecorator.addMessageAttribute(
message, span, HypertraceSemanticAttributes.RPC_REQUEST_BODY);
diff --git a/instrumentation/grpc-1.5/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/GrpcInstrumentationTest.java b/instrumentation/grpc-1.5/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/GrpcInstrumentationTest.java
index e08d4e4dd..441e05028 100644
--- a/instrumentation/grpc-1.5/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/GrpcInstrumentationTest.java
+++ b/instrumentation/grpc-1.5/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_5/GrpcInstrumentationTest.java
@@ -35,6 +35,7 @@
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeoutException;
+import org.hypertrace.agent.core.config.InstrumentationConfig;
import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes;
import org.hypertrace.agent.otel.extensions.config.EnvironmentConfig;
import org.hypertrace.agent.otel.extensions.config.HypertraceConfig;
@@ -190,6 +191,7 @@ public void disabledInstrumentation_dynamicConfig()
URL configUrl = getClass().getClassLoader().getResource("ht-config-all-disabled.yaml");
System.setProperty(EnvironmentConfig.CONFIG_FILE_PROPERTY, configUrl.getPath());
HypertraceConfig.reset();
+ InstrumentationConfig.ConfigProvider.reset();
GreeterBlockingStub blockingStub = GreeterGrpc.newBlockingStub(CHANNEL);
Response response = blockingStub.sayHello(REQUEST);
diff --git a/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java b/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java
index 3eb41208a..201aaf878 100644
--- a/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java
+++ b/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java
@@ -59,6 +59,13 @@ default boolean isInstrumentationEnabled(String primaryName, String[] otherNames
class ConfigProvider {
private static volatile InstrumentationConfig instrumentationConfig;
+ /** Reset the config, use only in tests. */
+ public static void reset() {
+ synchronized (ConfigProvider.class) {
+ instrumentationConfig = null;
+ }
+ }
+
static InstrumentationConfig load() {
ServiceLoader configs =
ServiceLoader.load(InstrumentationConfig.class);
From 70889fa764be522554b8efa16f3bd272075ca7b7 Mon Sep 17 00:00:00 2001
From: Pavol Loffay
Date: Mon, 21 Jun 2021 13:15:18 +0200
Subject: [PATCH 3/3] Fix issue with loading the filter
Signed-off-by: Pavol Loffay
---
.../agent/filter/FilterRegistry.java | 25 ++++++++++++++-----
.../HttpServerRequestTracingHandler.java | 2 +-
.../core/config/InstrumentationConfig.java | 19 ++++++++++----
.../extensions/FilterComponentInstaller.java | 11 +++++++-
.../config/InstrumentationConfigImpl.java | 9 -------
5 files changed, 44 insertions(+), 22 deletions(-)
diff --git a/filter-api/src/main/java/org/hypertrace/agent/filter/FilterRegistry.java b/filter-api/src/main/java/org/hypertrace/agent/filter/FilterRegistry.java
index d80df0555..285f6f894 100644
--- a/filter-api/src/main/java/org/hypertrace/agent/filter/FilterRegistry.java
+++ b/filter-api/src/main/java/org/hypertrace/agent/filter/FilterRegistry.java
@@ -20,9 +20,9 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.ServiceLoader;
-import org.hypertrace.agent.core.config.InstrumentationConfig;
import org.hypertrace.agent.filter.api.Filter;
import org.hypertrace.agent.filter.spi.FilterProvider;
import org.slf4j.Logger;
@@ -53,7 +53,7 @@ public static Filter getFilter() {
synchronized (FilterRegistry.class) {
if (filter == null) {
try {
- filter = load();
+ filter = load(Collections.emptyList());
} catch (Throwable t) {
logger.error("Throwable thrown while loading filter jars", t);
}
@@ -63,8 +63,22 @@ public static Filter getFilter() {
return filter;
}
- private static Filter load() {
- ClassLoader cl = loadJars();
+ /**
+ * Initializes the registry by loading the filters. This method should be called only once at
+ * javaagent startup.
+ *
+ * @param jarPaths paths to filter jar files.
+ */
+ public static void initialize(List jarPaths) {
+ try {
+ filter = load(jarPaths);
+ } catch (Throwable t) {
+ logger.error("Throwable thrown while loading filter jars", t);
+ }
+ }
+
+ private static Filter load(List jarPaths) {
+ ClassLoader cl = loadJars(jarPaths);
ServiceLoader providers = ServiceLoader.load(FilterProvider.class, cl);
List filters = new ArrayList<>();
for (FilterProvider provider : providers) {
@@ -78,8 +92,7 @@ private static Filter load() {
return new MultiFilter(filters);
}
- private static ClassLoader loadJars() {
- List jarPaths = InstrumentationConfig.ConfigProvider.get().jarPaths();
+ private static ClassLoader loadJars(List jarPaths) {
URL[] urls = new URL[jarPaths.size()];
int i = 0;
for (String jarPath : jarPaths) {
diff --git a/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/server/HttpServerRequestTracingHandler.java b/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/server/HttpServerRequestTracingHandler.java
index fd143cc59..f8079c5f9 100644
--- a/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/server/HttpServerRequestTracingHandler.java
+++ b/instrumentation/netty/netty-4.0/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/server/HttpServerRequestTracingHandler.java
@@ -86,7 +86,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
}
if ((msg instanceof HttpContent || msg instanceof ByteBuf)
- && instrumentationConfig.rpcBody().request()) {
+ && instrumentationConfig.httpBody().request()) {
DataCaptureUtils.captureBody(span, channel, AttributeKeys.REQUEST_BODY_BUFFER, msg);
}
diff --git a/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java b/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java
index 201aaf878..9aec3fe57 100644
--- a/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java
+++ b/javaagent-core/src/main/java/org/hypertrace/agent/core/config/InstrumentationConfig.java
@@ -17,24 +17,29 @@
package org.hypertrace.agent.core.config;
import java.util.Iterator;
-import java.util.List;
import java.util.ServiceLoader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/** Instrumentation config holds configuration for the instrumentation. */
public interface InstrumentationConfig {
+ /** Maximum capture body size in bytes. */
int maxBodySizeBytes();
- List jarPaths();
-
+ /** Data capture for HTTP headers. */
Message httpHeaders();
+ /** Data capture for HTTP body. */
Message httpBody();
+ /** Data capture for RPC metadata. */
Message rpcMetadata();
+ /** Data capture for RPC body */
Message rpcBody();
+ /** Message holds data capture configuration for various entities. */
interface Message {
boolean request();
@@ -49,6 +54,8 @@ default boolean isInstrumentationEnabled(String primaryName, String[] otherNames
&& !httpBody().response()
&& !httpHeaders().request()
&& !httpHeaders().response()
+ && !rpcBody().request()
+ && !rpcBody().response()
&& !rpcMetadata().request()
&& !rpcMetadata().response()) {
return false;
@@ -57,6 +64,8 @@ default boolean isInstrumentationEnabled(String primaryName, String[] otherNames
}
class ConfigProvider {
+ private static final Logger logger = LoggerFactory.getLogger(ConfigProvider.class);
+
private static volatile InstrumentationConfig instrumentationConfig;
/** Reset the config, use only in tests. */
@@ -66,14 +75,14 @@ public static void reset() {
}
}
- static InstrumentationConfig load() {
+ private static InstrumentationConfig load() {
ServiceLoader configs =
ServiceLoader.load(InstrumentationConfig.class);
Iterator iterator = configs.iterator();
if (!iterator.hasNext()) {
+ logger.error("Failed to load instrumentation config");
return null;
}
- // TODO consider returning noop
return iterator.next();
}
diff --git a/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/FilterComponentInstaller.java b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/FilterComponentInstaller.java
index 3d0b51cb1..390a095a7 100644
--- a/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/FilterComponentInstaller.java
+++ b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/FilterComponentInstaller.java
@@ -19,15 +19,24 @@
import com.google.auto.service.AutoService;
import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.javaagent.spi.ComponentInstaller;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.hypertrace.agent.config.Config.AgentConfig;
import org.hypertrace.agent.filter.FilterRegistry;
+import org.hypertrace.agent.otel.extensions.config.HypertraceConfig;
@AutoService(ComponentInstaller.class)
public class FilterComponentInstaller implements ComponentInstaller {
@Override
public void beforeByteBuddyAgent(Config config) {
+ AgentConfig agentConfig = HypertraceConfig.get();
+ List jarPaths =
+ agentConfig.getJavaagent().getFilterJarPathsList().stream()
+ .map(r -> r.getValue())
+ .collect(Collectors.toList());
// resolves filter via service loader resolution
- FilterRegistry.getFilter();
+ FilterRegistry.initialize(jarPaths);
}
@Override
diff --git a/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/InstrumentationConfigImpl.java b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/InstrumentationConfigImpl.java
index 2ea737dd0..6859b5ffc 100644
--- a/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/InstrumentationConfigImpl.java
+++ b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/config/InstrumentationConfigImpl.java
@@ -17,8 +17,6 @@
package org.hypertrace.agent.otel.extensions.config;
import com.google.auto.service.AutoService;
-import java.util.List;
-import java.util.stream.Collectors;
import org.hypertrace.agent.config.Config;
import org.hypertrace.agent.config.Config.AgentConfig;
import org.hypertrace.agent.config.Config.DataCapture;
@@ -47,13 +45,6 @@ public int maxBodySizeBytes() {
return agentConfig.getDataCapture().getBodyMaxSizeBytes().getValue();
}
- @Override
- public List jarPaths() {
- return agentConfig.getJavaagent().getFilterJarPathsList().stream()
- .map(r -> r.getValue())
- .collect(Collectors.toList());
- }
-
@Override
public Message httpHeaders() {
return this.httpHeaders;