Skip to content

Commit f65ba70

Browse files
authored
Remove HT config from bootstrap and app classloader (#258)
* Fix remove HT config from bootstrap and app classloader Signed-off-by: Pavol Loffay <[email protected]> * Fix Signed-off-by: Pavol Loffay <[email protected]>
1 parent 8d67311 commit f65ba70

File tree

5 files changed

+71
-47
lines changed

5 files changed

+71
-47
lines changed

javaagent/build.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ dependencies {
1212
// https://oss.jfrog.org/artifactory/oss-snapshot-local/io/opentelemetry/instrumentation/auto/
1313
// https://dl.bintray.com/open-telemetry/maven/
1414
implementation("io.opentelemetry.javaagent", "opentelemetry-javaagent", version = "${versions["opentelemetry_java_agent"]}", classifier = "all")
15-
implementation(project(":javaagent-core"))
1615
implementation(project(":filter-api"))
1716
}
1817

@@ -50,8 +49,7 @@ tasks {
5049
}
5150

5251
relocate("org.slf4j", "io.opentelemetry.javaagent.slf4j")
53-
// TODO causes data not being reported
54-
// relocate("java.util.logging.Logger", "io.opentelemetry.javaagent.bootstrap.PatchLogger")
52+
relocate("java.util.logging.Logger", "io.opentelemetry.javaagent.bootstrap.PatchLogger")
5553

5654
// prevents conflict with library instrumentation
5755
relocate("io.opentelemetry.instrumentation.api", "io.opentelemetry.javaagent.shaded.instrumentation.api")

javaagent/src/main/java/org/hypertrace/agent/instrument/HypertraceAgent.java

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,13 @@
1616

1717
package org.hypertrace.agent.instrument;
1818

19-
import com.google.common.annotations.VisibleForTesting;
2019
import io.opentelemetry.javaagent.OpenTelemetryAgent;
2120
import java.lang.instrument.Instrumentation;
2221
import java.util.Collections;
2322
import java.util.HashMap;
24-
import java.util.List;
2523
import java.util.Map;
26-
import java.util.stream.Collectors;
27-
import org.hypertrace.agent.config.Config.AgentConfig;
28-
import org.hypertrace.agent.config.Config.PropagationFormat;
29-
import org.hypertrace.agent.core.config.HypertraceConfig;
3024

3125
public class HypertraceAgent {
32-
// https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/sdk-environment-variables.md
33-
private static final String OTEL_EXPORTER = "otel.exporter";
34-
private static final String OTEL_PROPAGATORS = "otel.propagators";
35-
private static final String OTEL_EXPORTER_ZIPKIN_ENDPOINT = "otel.exporter.zipkin.endpoint";
36-
private static final String OTEL_EXPORTER_ZIPKIN_SERVICE_NAME =
37-
"otel.exporter.zipkin.service.name";
38-
private static final String OTEL_PROCESSOR_BATCH_MAX_QUEUE = "otel.bsp.max.queue.size";
39-
private static final String OTEL_DEFAULT_LOG_LEVEL =
40-
"io.opentelemetry.javaagent.slf4j.simpleLogger.defaultLogLevel";
4126

4227
private static HypertraceAgent instance;
4328

@@ -64,34 +49,12 @@ public static void agentmain(String agentArgs, Instrumentation inst) {
6449
}
6550

6651
instance = new HypertraceAgent();
67-
setDefaultConfig();
6852
OpenTelemetryAgent.premain(agentArgs, inst);
6953
System.out.printf(
7054
"Hypertrace agent started, version: %s\n",
7155
HypertraceAgent.class.getPackage().getImplementationVersion());
7256
}
7357

74-
/** Set default values to OTEL config. OTEL config has a higher precedence. */
75-
private static void setDefaultConfig() {
76-
AgentConfig agentConfig = HypertraceConfig.get();
77-
OpenTelemetryConfig.setDefault(OTEL_EXPORTER, "zipkin");
78-
OpenTelemetryConfig.setDefault(
79-
OTEL_EXPORTER_ZIPKIN_SERVICE_NAME, agentConfig.getServiceName().getValue());
80-
OpenTelemetryConfig.setDefault(
81-
OTEL_PROPAGATORS, toOtelPropagators(agentConfig.getPropagationFormatsList()));
82-
OpenTelemetryConfig.setDefault(
83-
OTEL_EXPORTER_ZIPKIN_ENDPOINT, agentConfig.getReporting().getEndpoint().getValue());
84-
OpenTelemetryConfig.setDefault(
85-
OTEL_EXPORTER_ZIPKIN_SERVICE_NAME, agentConfig.getServiceName().getValue());
86-
}
87-
88-
@VisibleForTesting
89-
static String toOtelPropagators(List<PropagationFormat> propagationFormats) {
90-
return propagationFormats.stream()
91-
.map(v -> v.name().toLowerCase())
92-
.collect(Collectors.joining(","));
93-
}
94-
9558
// Expected format is "arg1=val1,arg2=val2,arg3=val3"
9659
private static Map<String, String> parseAgentArgs(String agentArgs) {
9760
if (agentArgs == null) {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright The Hypertrace Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.hypertrace.agent.otel.extensions;
18+
19+
import com.google.auto.service.AutoService;
20+
import com.google.common.annotations.VisibleForTesting;
21+
import io.opentelemetry.javaagent.spi.config.PropertySource;
22+
import java.util.HashMap;
23+
import java.util.List;
24+
import java.util.Map;
25+
import java.util.stream.Collectors;
26+
import org.hypertrace.agent.config.Config.AgentConfig;
27+
import org.hypertrace.agent.config.Config.PropagationFormat;
28+
import org.hypertrace.agent.core.config.HypertraceConfig;
29+
30+
@AutoService(PropertySource.class)
31+
public class HypertraceAgentConfiguration implements PropertySource {
32+
33+
// https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/sdk-environment-variables.md
34+
private static final String OTEL_EXPORTER = "otel.exporter";
35+
private static final String OTEL_PROPAGATORS = "otel.propagators";
36+
private static final String OTEL_EXPORTER_ZIPKIN_ENDPOINT = "otel.exporter.zipkin.endpoint";
37+
private static final String OTEL_EXPORTER_ZIPKIN_SERVICE_NAME =
38+
"otel.exporter.zipkin.service.name";
39+
private static final String OTEL_PROCESSOR_BATCH_MAX_QUEUE = "otel.bsp.max.queue.size";
40+
private static final String OTEL_DEFAULT_LOG_LEVEL =
41+
"io.opentelemetry.javaagent.slf4j.simpleLogger.defaultLogLevel";
42+
43+
@Override
44+
public Map<String, String> getProperties() {
45+
AgentConfig agentConfig = HypertraceConfig.get();
46+
47+
Map<String, String> configProperties = new HashMap<>();
48+
configProperties.put(OTEL_EXPORTER, "zipkin");
49+
configProperties.put(
50+
OTEL_EXPORTER_ZIPKIN_SERVICE_NAME, agentConfig.getServiceName().getValue());
51+
configProperties.put(
52+
OTEL_EXPORTER_ZIPKIN_ENDPOINT, agentConfig.getReporting().getEndpoint().getValue());
53+
configProperties.put(
54+
OTEL_PROPAGATORS, toOtelPropagators(agentConfig.getPropagationFormatsList()));
55+
56+
return configProperties;
57+
}
58+
59+
@VisibleForTesting
60+
static String toOtelPropagators(List<PropagationFormat> propagationFormats) {
61+
return propagationFormats.stream()
62+
.map(v -> v.name().toLowerCase())
63+
.collect(Collectors.joining(","));
64+
}
65+
}

otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/processor/HypertraceTracerCustomizer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ public class HypertraceTracerCustomizer implements TracerCustomizer {
3333

3434
@Override
3535
public void configure(SdkTracerManagement tracerManagement) {
36-
String exporter = System.getProperty("otel.exporter");
37-
if (exporter != null && exporter.contains("zipkin")) {
38-
tracerManagement.addSpanProcessor(new AddTagsSpanProcessor());
39-
}
36+
tracerManagement.addSpanProcessor(new AddTagsSpanProcessor());
4037
}
4138
}

javaagent/src/test/java/org/hypertrace/agent/instrument/HypertraceAgentTest.java renamed to otel-extensions/src/test/java/org/hypertrace/agent/otel/extensions/HypertraceAgentConfigurationTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.hypertrace.agent.instrument;
17+
package org.hypertrace.agent.otel.extensions;
1818

1919
import java.util.Arrays;
2020
import java.util.List;
2121
import org.hypertrace.agent.config.Config.PropagationFormat;
2222
import org.junit.jupiter.api.Assertions;
2323
import org.junit.jupiter.api.Test;
2424

25-
public class HypertraceAgentTest {
25+
public class HypertraceAgentConfigurationTest {
2626

2727
@Test
2828
public void propagationFormatList() {
2929
List<PropagationFormat> formats =
3030
Arrays.asList(PropagationFormat.B3, PropagationFormat.TRACECONTEXT);
31-
Assertions.assertEquals("b3,tracecontext", HypertraceAgent.toOtelPropagators(formats));
31+
Assertions.assertEquals(
32+
"b3,tracecontext", HypertraceAgentConfiguration.toOtelPropagators(formats));
3233
}
3334
}

0 commit comments

Comments
 (0)