Skip to content

Commit c9ed960

Browse files
authored
Default to otlp exporter (hypertrace#297)
* default to otlp exporter * updating agent-config submodule * updating trace reporter type name * updating reporting endpoint in smoke tests * spotless apply * updating smoke-tests as per otlp exporter
1 parent 5e4544d commit c9ed960

File tree

11 files changed

+59
-32
lines changed

11 files changed

+59
-32
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.io.InputStream;
3131
import java.io.InputStreamReader;
3232
import java.io.Reader;
33+
import org.hypertrace.agent.config.Config;
3334
import org.hypertrace.agent.config.Config.AgentConfig;
3435
import org.hypertrace.agent.config.Config.DataCapture;
3536
import org.hypertrace.agent.config.Config.Message;
@@ -55,7 +56,7 @@ private HypertraceConfig() {}
5556
private static volatile AgentConfig agentConfig;
5657

5758
static final String DEFAULT_SERVICE_NAME = "unknown";
58-
static final String DEFAULT_REPORTING_ENDPOINT = "http://localhost:9411/api/v2/spans";
59+
static final String DEFAULT_REPORTING_ENDPOINT = "http://localhost:4317";
5960
static final String DEFAULT_OPA_ENDPOINT = "http://opa.traceableai:8181/";
6061
static final int DEFAULT_OPA_POLL_PERIOD_SECONDS = 30;
6162
// 128 KiB
@@ -187,6 +188,9 @@ private static Reporting.Builder applyReportingDefaults(Reporting.Builder builde
187188
if (!builder.hasEndpoint()) {
188189
builder.setEndpoint(StringValue.newBuilder().setValue(DEFAULT_REPORTING_ENDPOINT).build());
189190
}
191+
if (builder.getTraceReporterType().equals(Config.TraceReporterType.UNSPECIFIED)) {
192+
builder.setTraceReporterType(Config.TraceReporterType.OTLP);
193+
}
190194
Builder opaBuilder = applyOpaDefaults(builder.getOpa().toBuilder());
191195
builder.setOpa(opaBuilder);
192196
return builder;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void defaultValues() throws IOException {
4040
Assertions.assertTrue(agentConfig.getEnabled().getValue());
4141
Assertions.assertEquals("unknown", agentConfig.getServiceName().getValue());
4242
Assertions.assertEquals(
43-
TraceReporterType.ZIPKIN, agentConfig.getReporting().getTraceReporterType());
43+
TraceReporterType.OTLP, agentConfig.getReporting().getTraceReporterType());
4444
Assertions.assertEquals(
4545
HypertraceConfig.DEFAULT_REPORTING_ENDPOINT,
4646
agentConfig.getReporting().getEndpoint().getValue());
@@ -104,7 +104,7 @@ private void assertConfig(AgentConfig agentConfig) {
104104
Assertions.assertEquals(
105105
Arrays.asList(PropagationFormat.B3), agentConfig.getPropagationFormatsList());
106106
Assertions.assertEquals(
107-
TraceReporterType.OTLP, agentConfig.getReporting().getTraceReporterType());
107+
TraceReporterType.ZIPKIN, agentConfig.getReporting().getTraceReporterType());
108108
Assertions.assertEquals(
109109
"http://localhost:9411", agentConfig.getReporting().getEndpoint().getValue());
110110
Assertions.assertEquals(true, agentConfig.getReporting().getSecure().getValue());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ propagationFormats:
66
reporting:
77
endpoint: http://localhost:9411
88
secure: true
9-
trace_reporter_type: OTLP
9+
trace_reporter_type: ZIPKIN
1010
opa:
1111
endpoint: http://opa.localhost:8181/
1212
pollPeriodSeconds: 12

smoke-tests/src/test/groovy/org/hypertrace/agent/smoketest/SmokeTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ abstract class SmokeTest extends Specification {
8484
.withEnv("OTEL_BSP_SCHEDULE_DELAY", "10")
8585
.withEnv("OTEL_EXPORTER_OTLP_ENDPOINT", "http://collector:55680")
8686
.withEnv("HT_SERVICE_NAME", "CIService")
87-
.withEnv("HT_REPORTING_ENDPOINT", "http://collector:9411/api/v2/spans")
87+
.withEnv("HT_REPORTING_ENDPOINT", "http://collector:4317")
8888
.withEnv("OTEL_TRACES_EXPORTER", "otlp")
8989
.withImagePullPolicy(PullPolicy.alwaysPull())
9090
.withEnv(extraEnv)

smoke-tests/src/test/java/org/hypertrace/agent/smoketest/AbstractSmokeTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.protobuf.InvalidProtocolBufferException;
2020
import com.google.protobuf.util.JsonFormat;
2121
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest;
22+
import io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans;
2223
import io.opentelemetry.proto.trace.v1.Span;
2324
import java.io.IOException;
2425
import java.util.Collection;
@@ -55,7 +56,7 @@ public abstract class AbstractSmokeTest {
5556
private static final String NETWORK_ALIAS_OTEL_COLLECTOR = "collector";
5657
private static final String NETWORK_ALIAS_OTEL_MOCK_STORAGE = "backend";
5758
private static final String OTEL_EXPORTER_ENDPOINT =
58-
String.format("http://%s:9411/api/v2/spans", NETWORK_ALIAS_OTEL_COLLECTOR);
59+
String.format("http://%s:4317", NETWORK_ALIAS_OTEL_COLLECTOR);
5960

6061
public static final String OTEL_LIBRARY_VERSION_ATTRIBUTE = "otel.library.version";
6162
public static final String agentPath = getPropertyOrEnv("smoketest.javaagent.path");
@@ -147,10 +148,15 @@ protected static int countSpansByName(
147148
}
148149

149150
protected static Stream<Span> getSpanStream(Collection<ExportTraceServiceRequest> traceRequest) {
151+
return getInstrumentationLibSpanStream(traceRequest)
152+
.flatMap(librarySpans -> librarySpans.getSpansList().stream());
153+
}
154+
155+
protected static Stream<InstrumentationLibrarySpans> getInstrumentationLibSpanStream(
156+
Collection<ExportTraceServiceRequest> traceRequest) {
150157
return traceRequest.stream()
151158
.flatMap(request -> request.getResourceSpansList().stream())
152-
.flatMap(resourceSpans -> resourceSpans.getInstrumentationLibrarySpansList().stream())
153-
.flatMap(librarySpans -> librarySpans.getSpansList().stream());
159+
.flatMap(resourceSpans -> resourceSpans.getInstrumentationLibrarySpansList().stream());
154160
}
155161

156162
protected Collection<ExportTraceServiceRequest> waitForTraces() throws IOException {

smoke-tests/src/test/java/org/hypertrace/agent/smoketest/OpenTelemetryCollector.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class OpenTelemetryCollector extends GenericContainer<OpenTelemetryCollec
2727
public static final int JAEGER_COLLECTOR_THRIFT_PORT = 14268;
2828
public static final int JAEGER_COLLECTOR_GRPC_PORT = 14250;
2929
public static final int ZIPKIN_PORT = 9411;
30+
public static final int OTLP_PORT = 4317;
3031
public static final int HEALTH_CHECK_PORT = 13133;
3132

3233
public OpenTelemetryCollector(String dockerImage) {
@@ -37,7 +38,11 @@ public OpenTelemetryCollector(String dockerImage) {
3738
protected void init() {
3839
waitingFor(new BoundPortHttpWaitStrategy(HEALTH_CHECK_PORT));
3940
withExposedPorts(
40-
HEALTH_CHECK_PORT, JAEGER_COLLECTOR_THRIFT_PORT, JAEGER_COLLECTOR_GRPC_PORT, ZIPKIN_PORT);
41+
HEALTH_CHECK_PORT,
42+
JAEGER_COLLECTOR_THRIFT_PORT,
43+
JAEGER_COLLECTOR_GRPC_PORT,
44+
ZIPKIN_PORT,
45+
OTLP_PORT);
4146
}
4247

4348
public static class BoundPortHttpWaitStrategy extends HttpWaitStrategy {

smoke-tests/src/test/java/org/hypertrace/agent/smoketest/SpringBootDisabledBodyCaptureSmokeTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ public void get() throws IOException {
7979
.get(Attributes.Name.IMPLEMENTATION_VERSION);
8080

8181
Assertions.assertEquals(1, countSpansByName(traces, "/greeting"));
82-
Assertions.assertEquals(1, countSpansByName(traces, "webcontroller.greeting"));
82+
Assertions.assertEquals(1, countSpansByName(traces, "WebController.greeting"));
8383
Assertions.assertTrue(
84-
getSpanStream(traces)
85-
.flatMap(span -> span.getAttributesList().stream())
86-
.filter(attribute -> attribute.getKey().equals(OTEL_LIBRARY_VERSION_ATTRIBUTE))
87-
.map(attribute -> attribute.getValue().getStringValue())
88-
.filter(value -> value.equals(currentAgentVersion))
89-
.count()
90-
> 0);
84+
getInstrumentationLibSpanStream(traces)
85+
.anyMatch(
86+
instLibSpan ->
87+
instLibSpan
88+
.getInstrumentationLibrary()
89+
.getVersion()
90+
.equals(currentAgentVersion)));
9191
Assertions.assertEquals(
9292
0,
9393
getSpanStream(traces)

smoke-tests/src/test/java/org/hypertrace/agent/smoketest/SpringBootSmokeTest.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,32 +80,44 @@ public void get() throws IOException, InterruptedException {
8080
.get(Attributes.Name.IMPLEMENTATION_VERSION);
8181

8282
Assertions.assertEquals(
83-
ResourceAttributes.SERVICE_NAME.getKey(),
83+
ResourceAttributes.CONTAINER_ID.getKey(),
8484
traces.get(0).getResourceSpans(0).getResource().getAttributes(0).getKey());
8585
Assertions.assertEquals(
86-
ResourceAttributes.CONTAINER_ID.getKey(),
87-
traces.get(0).getResourceSpans(0).getResource().getAttributes(1).getKey());
86+
ResourceAttributes.SERVICE_NAME.getKey(),
87+
traces.get(0).getResourceSpans(0).getResource().getAttributes(9).getKey());
88+
Assertions.assertEquals(
89+
ResourceAttributes.TELEMETRY_AUTO_VERSION.getKey(),
90+
traces.get(0).getResourceSpans(0).getResource().getAttributes(10).getKey());
91+
Assertions.assertEquals(
92+
ResourceAttributes.TELEMETRY_SDK_LANGUAGE.getKey(),
93+
traces.get(0).getResourceSpans(0).getResource().getAttributes(11).getKey());
94+
Assertions.assertEquals(
95+
ResourceAttributes.TELEMETRY_SDK_NAME.getKey(),
96+
traces.get(0).getResourceSpans(0).getResource().getAttributes(12).getKey());
97+
Assertions.assertEquals(
98+
ResourceAttributes.TELEMETRY_SDK_VERSION.getKey(),
99+
traces.get(0).getResourceSpans(0).getResource().getAttributes(13).getKey());
88100
// value is specified in resources/ht-config.yaml
89101
Assertions.assertEquals(
90102
"app_under_test",
91103
traces
92104
.get(0)
93105
.getResourceSpans(0)
94106
.getResource()
95-
.getAttributes(0)
107+
.getAttributes(9)
96108
.getValue()
97109
.getStringValue());
98110

99111
Assertions.assertEquals(1, countSpansByName(traces, "/greeting"));
100-
Assertions.assertEquals(1, countSpansByName(traces, "webcontroller.greeting"));
112+
Assertions.assertEquals(1, countSpansByName(traces, "WebController.greeting"));
101113
Assertions.assertTrue(
102-
getSpanStream(traces)
103-
.flatMap(span -> span.getAttributesList().stream())
104-
.filter(attribute -> attribute.getKey().equals(OTEL_LIBRARY_VERSION_ATTRIBUTE))
105-
.map(attribute -> attribute.getValue().getStringValue())
106-
.filter(value -> value.equals(currentAgentVersion))
107-
.count()
108-
> 0);
114+
getInstrumentationLibSpanStream(traces)
115+
.anyMatch(
116+
instLibSpan ->
117+
instLibSpan
118+
.getInstrumentationLibrary()
119+
.getVersion()
120+
.equals(currentAgentVersion)));
109121
Assertions.assertTrue(
110122
getSpanStream(traces)
111123
.flatMap(span -> span.getAttributesList().stream())

smoke-tests/src/test/resources/ht-config-all-disabled.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
service_name: app_under_test
22
reporting:
3-
endpoint: http://localhost:9411
3+
endpoint: http://localhost:4317
44
secure: true
55
data_capture:
66
http_headers:

0 commit comments

Comments
 (0)