|
18 | 18 | */ |
19 | 19 | package com.example.javaagent.smoketest; |
20 | 20 |
|
| 21 | +import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_INSTANCE_ID; |
| 22 | +import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_NAME; |
| 23 | +import static io.opentelemetry.semconv.incubating.ContainerIncubatingAttributes.CONTAINER_ID; |
| 24 | +import static io.opentelemetry.semconv.incubating.HostIncubatingAttributes.HOST_ARCH; |
| 25 | +import static io.opentelemetry.semconv.incubating.HostIncubatingAttributes.HOST_NAME; |
| 26 | +import static io.opentelemetry.semconv.incubating.OsIncubatingAttributes.OS_TYPE; |
| 27 | +import static io.opentelemetry.semconv.incubating.OsIncubatingAttributes.OS_VERSION; |
| 28 | +import static io.opentelemetry.semconv.incubating.ProcessIncubatingAttributes.PROCESS_COMMAND_ARGS; |
| 29 | +import static io.opentelemetry.semconv.incubating.ProcessIncubatingAttributes.PROCESS_PID; |
| 30 | +import static io.opentelemetry.semconv.incubating.TelemetryIncubatingAttributes.TELEMETRY_DISTRO_NAME; |
| 31 | +import static io.opentelemetry.semconv.incubating.TelemetryIncubatingAttributes.TELEMETRY_DISTRO_VERSION; |
21 | 32 | import static org.assertj.core.api.Assertions.assertThat; |
22 | 33 | import static org.assertj.core.api.Assertions.tuple; |
23 | 34 |
|
@@ -82,20 +93,41 @@ static void start() throws IOException { |
82 | 93 | container |
83 | 94 | .withCopyFileToContainer(MountableFile.forHostPath(configFile), "/config.yaml") |
84 | 95 | .withEnv("OTEL_CONFIG_FILE", "/config.yaml") |
85 | | - .withEnv("OTEL_EXPORTER_OTLP_ENDPOINT", BACKEND_ENDPOINT), |
| 96 | + .withEnv("OTEL_EXPORTER_OTLP_ENDPOINT", BACKEND_ENDPOINT) |
| 97 | + .withEnv("OTEL_SERVICE_NAME", "my-service-name"), |
86 | 98 | false); |
87 | 99 | } |
88 | 100 |
|
89 | 101 | @Test |
90 | | - void healthcheck() { |
| 102 | + void resourceAttributes() { |
91 | 103 | doRequest(getUrl("/health"), okResponseBody("Alive!")); |
92 | 104 |
|
| 105 | + // This does not test that cloud resource providers are included in the config |
| 106 | + // but at least we know that if they are added in the config their names are valid as otherwise |
| 107 | + // the agent does not start with any missing component in config. |
| 108 | + |
93 | 109 | List<ExportTraceServiceRequest> traces = waitForTraces(); |
94 | 110 | List<Span> spans = getSpans(traces).toList(); |
95 | 111 | assertThat(spans) |
96 | 112 | .hasSize(1) |
97 | 113 | .extracting("name", "kind") |
98 | 114 | .containsOnly(tuple("GET /health", Span.SpanKind.SPAN_KIND_SERVER)); |
| 115 | + |
| 116 | + assertThat(getResourceAttributes(traces)) |
| 117 | + .containsKey(HOST_NAME.getKey()) |
| 118 | + .containsKey(HOST_ARCH.getKey()) |
| 119 | + .containsKey(OS_TYPE.getKey()) |
| 120 | + .containsKey(OS_VERSION.getKey()) |
| 121 | + .containsKey(PROCESS_PID.getKey()) |
| 122 | + .containsKey(PROCESS_COMMAND_ARGS.getKey()) |
| 123 | + .containsKey(CONTAINER_ID.getKey()) |
| 124 | + // service name should be provided by the 'service' resource attribute detector which |
| 125 | + // reads environment variables (here it's not env variable injected in declarative config). |
| 126 | + .containsEntry(SERVICE_NAME.getKey(), attributeValue("my-service-name")) |
| 127 | + .containsKey(SERVICE_INSTANCE_ID.getKey()) |
| 128 | + // ensures that we override the default distro resource attributes |
| 129 | + .containsEntry(TELEMETRY_DISTRO_NAME.getKey(), attributeValue("elastic")) |
| 130 | + .containsKey(TELEMETRY_DISTRO_VERSION.getKey()); |
99 | 131 | } |
100 | 132 |
|
101 | 133 | @AfterAll |
|
0 commit comments