Skip to content

Commit 0aea1ff

Browse files
authored
Add reporter type config option (#274)
* Add reporter type config option Signed-off-by: Pavol Loffay <[email protected]> * Format Signed-off-by: Pavol Loffay <[email protected]> * fix Signed-off-by: Pavol Loffay <[email protected]>
1 parent bc28add commit 0aea1ff

File tree

6 files changed

+30
-4
lines changed

6 files changed

+30
-4
lines changed

javaagent-core/src/main/java/org/hypertrace/agent/core/config/EnvironmentConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.hypertrace.agent.config.Config.Opa.Builder;
2828
import org.hypertrace.agent.config.Config.PropagationFormat;
2929
import org.hypertrace.agent.config.Config.Reporting;
30+
import org.hypertrace.agent.config.Config.TraceReporterType;
3031

3132
public class EnvironmentConfig {
3233

@@ -42,6 +43,7 @@ private EnvironmentConfig() {}
4243

4344
private static final String REPORTING_PREFIX = HT_PREFIX + "reporting.";
4445
static final String REPORTING_ENDPOINT = REPORTING_PREFIX + "endpoint";
46+
static final String REPORTING_TRACE_TYPE = REPORTING_PREFIX + "trace.reporter.type";
4547
static final String REPORTING_SECURE = REPORTING_PREFIX + "secure";
4648

4749
private static final String OPA_PREFIX = REPORTING_PREFIX + "opa.";
@@ -109,6 +111,10 @@ private static Reporting.Builder applyReporting(Reporting.Builder builder) {
109111
if (reporterAddress != null) {
110112
builder.setEndpoint(StringValue.newBuilder().setValue(reporterAddress).build());
111113
}
114+
String traceReportingType = getProperty(REPORTING_TRACE_TYPE);
115+
if (traceReportingType != null) {
116+
builder.setTraceReporterType(TraceReporterType.valueOf(traceReportingType));
117+
}
112118
String secure = getProperty(REPORTING_SECURE);
113119
if (secure != null) {
114120
builder.setSecure(BoolValue.newBuilder().setValue(Boolean.valueOf(secure)).build());

javaagent-core/src/test/java/org/hypertrace/agent/core/config/EnvironmentConfigTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Arrays;
2121
import org.hypertrace.agent.config.Config.AgentConfig;
2222
import org.hypertrace.agent.config.Config.PropagationFormat;
23+
import org.hypertrace.agent.config.Config.TraceReporterType;
2324
import org.junit.jupiter.api.Assertions;
2425
import org.junit.jupiter.api.Test;
2526
import org.junitpioneer.jupiter.ClearSystemProperty;
@@ -29,6 +30,7 @@ class EnvironmentConfigTest {
2930
@Test
3031
@ClearSystemProperty(key = EnvironmentConfig.REPORTING_ENDPOINT)
3132
@ClearSystemProperty(key = EnvironmentConfig.REPORTING_SECURE)
33+
@ClearSystemProperty(key = EnvironmentConfig.REPORTING_TRACE_TYPE)
3234
@ClearSystemProperty(key = EnvironmentConfig.OPA_ENDPOINT)
3335
@ClearSystemProperty(key = EnvironmentConfig.OPA_POLL_PERIOD)
3436
@ClearSystemProperty(key = EnvironmentConfig.OPA_ENABLED)
@@ -41,6 +43,7 @@ public void systemProperties() {
4143
// when tests are run in parallel the env vars/sys props set it junit-pioneer are visible to
4244
// parallel tests
4345
System.setProperty(EnvironmentConfig.REPORTING_ENDPOINT, "http://:-)");
46+
System.setProperty(EnvironmentConfig.REPORTING_TRACE_TYPE, "OTLP");
4447
System.setProperty(EnvironmentConfig.REPORTING_SECURE, "true");
4548
System.setProperty(EnvironmentConfig.CAPTURE_HTTP_BODY_PREFIX + "request", "true");
4649
System.setProperty(EnvironmentConfig.OPA_ENDPOINT, "http://azkaban:9090");
@@ -61,6 +64,8 @@ public void systemProperties() {
6164
Arrays.asList(PropagationFormat.B3, PropagationFormat.TRACECONTEXT),
6265
agentConfig.getPropagationFormatsList());
6366
Assertions.assertEquals("http://:-)", agentConfig.getReporting().getEndpoint().getValue());
67+
Assertions.assertEquals(
68+
TraceReporterType.OTLP, agentConfig.getReporting().getTraceReporterType());
6469
Assertions.assertEquals(
6570
"http://azkaban:9090", agentConfig.getReporting().getOpa().getEndpoint().getValue());
6671
Assertions.assertEquals(true, agentConfig.getReporting().getOpa().getEnabled().getValue());

javaagent-core/src/test/java/org/hypertrace/agent/core/config/HypertraceConfigTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Arrays;
2626
import org.hypertrace.agent.config.Config.AgentConfig;
2727
import org.hypertrace.agent.config.Config.PropagationFormat;
28+
import org.hypertrace.agent.config.Config.TraceReporterType;
2829
import org.junit.jupiter.api.Assertions;
2930
import org.junit.jupiter.api.Test;
3031
import org.junit.jupiter.api.io.TempDir;
@@ -38,6 +39,8 @@ public void defaultValues() throws IOException {
3839
AgentConfig agentConfig = HypertraceConfig.load(resource.getPath());
3940
Assertions.assertTrue(agentConfig.getEnabled().getValue());
4041
Assertions.assertEquals("unknown", agentConfig.getServiceName().getValue());
42+
Assertions.assertEquals(
43+
TraceReporterType.ZIPKIN, agentConfig.getReporting().getTraceReporterType());
4144
Assertions.assertEquals(
4245
HypertraceConfig.DEFAULT_REPORTING_ENDPOINT,
4346
agentConfig.getReporting().getEndpoint().getValue());
@@ -100,6 +103,8 @@ private void assertConfig(AgentConfig agentConfig) {
100103
Assertions.assertEquals(false, agentConfig.getEnabled().getValue());
101104
Assertions.assertEquals(
102105
Arrays.asList(PropagationFormat.B3), agentConfig.getPropagationFormatsList());
106+
Assertions.assertEquals(
107+
TraceReporterType.OTLP, agentConfig.getReporting().getTraceReporterType());
103108
Assertions.assertEquals(
104109
"http://localhost:9411", agentConfig.getReporting().getEndpoint().getValue());
105110
Assertions.assertEquals(true, agentConfig.getReporting().getSecure().getValue());

javaagent-core/src/test/resources/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ propagationFormats:
66
reporting:
77
endpoint: http://localhost:9411
88
secure: true
9+
trace_reporter_type: OTLP
910
opa:
1011
endpoint: http://opa.localhost:8181/
1112
pollPeriodSeconds: 12

otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/HypertraceAgentConfiguration.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.stream.Collectors;
2626
import org.hypertrace.agent.config.Config.AgentConfig;
2727
import org.hypertrace.agent.config.Config.PropagationFormat;
28+
import org.hypertrace.agent.config.Config.TraceReporterType;
2829
import org.hypertrace.agent.core.config.HypertraceConfig;
2930

3031
@AutoService(PropertySource.class)
@@ -49,11 +50,19 @@ public Map<String, String> getProperties() {
4950

5051
Map<String, String> configProperties = new HashMap<>();
5152
configProperties.put(OTEL_ENABLED, String.valueOf(agentConfig.getEnabled().getValue()));
52-
configProperties.put(OTEL_TRACE_EXPORTER, "zipkin");
5353
configProperties.put(
54-
OTEL_EXPORTER_ZIPKIN_SERVICE_NAME, agentConfig.getServiceName().getValue());
54+
OTEL_TRACE_EXPORTER,
55+
agentConfig.getReporting().getTraceReporterType().name().toLowerCase());
5556
configProperties.put(
56-
OTEL_EXPORTER_ZIPKIN_ENDPOINT, agentConfig.getReporting().getEndpoint().getValue());
57+
OTEL_EXPORTER_ZIPKIN_SERVICE_NAME, agentConfig.getServiceName().getValue());
58+
if (agentConfig.getReporting().getTraceReporterType() == TraceReporterType.ZIPKIN) {
59+
configProperties.put(
60+
OTEL_EXPORTER_ZIPKIN_ENDPOINT, agentConfig.getReporting().getEndpoint().getValue());
61+
} else if (agentConfig.getReporting().getTraceReporterType() == TraceReporterType.OTLP) {
62+
configProperties.put(
63+
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT",
64+
agentConfig.getReporting().getEndpoint().getValue());
65+
}
5766
configProperties.put(
5867
OTEL_PROPAGATORS, toOtelPropagators(agentConfig.getPropagationFormatsList()));
5968
// metrics are not reported

0 commit comments

Comments
 (0)