Skip to content

Commit ec95dc8

Browse files
committed
start k8s
1 parent 6d6915e commit ec95dc8

File tree

3 files changed

+109
-46
lines changed

3 files changed

+109
-46
lines changed

instrumentation/kubernetes-client-7.0/javaagent/build.gradle.kts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,20 @@ tasks {
3939
}
4040
}
4141

42-
tasks.withType<Test>().configureEach {
43-
// TODO run tests both with and without experimental span attributes
44-
jvmArgs("-Dotel.instrumentation.kubernetes-client.experimental-span-attributes=true")
42+
tasks {
43+
withType<Test>().configureEach {
44+
systemProperty("collectMetadata", findProperty("collectMetadata")?.toString() ?: "false")
45+
}
46+
47+
val testExperimental by registering(Test::class) {
48+
testClassesDirs = sourceSets.test.get().output.classesDirs
49+
classpath = sourceSets.test.get().runtimeClasspath
50+
51+
jvmArgs("-Dotel.instrumentation.kubernetes.experimental-span-attributes=true")
52+
systemProperty("metadataConfig", "otel.instrumentation.kubernetes.experimental-span-attributes=true")
53+
}
54+
55+
check {
56+
dependsOn(testExperimental)
57+
}
4558
}

instrumentation/kubernetes-client-7.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesClientTest.java

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package io.opentelemetry.javaagent.instrumentation.kubernetesclient;
77

8+
import static io.opentelemetry.api.common.AttributeKey.stringKey;
89
import static io.opentelemetry.instrumentation.testing.util.TelemetryDataUtil.orderByRootSpanName;
910
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1011
import static io.opentelemetry.semconv.ErrorAttributes.ERROR_TYPE;
@@ -20,7 +21,6 @@
2021
import io.kubernetes.client.openapi.ApiClient;
2122
import io.kubernetes.client.openapi.ApiException;
2223
import io.kubernetes.client.openapi.apis.CoreV1Api;
23-
import io.opentelemetry.api.common.AttributeKey;
2424
import io.opentelemetry.api.trace.SpanKind;
2525
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
2626
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
@@ -33,6 +33,7 @@
3333
import java.util.Map;
3434
import java.util.concurrent.CountDownLatch;
3535
import java.util.concurrent.atomic.AtomicReference;
36+
import javax.annotation.Nullable;
3637
import org.junit.jupiter.api.AfterEach;
3738
import org.junit.jupiter.api.BeforeEach;
3839
import org.junit.jupiter.api.Test;
@@ -49,6 +50,14 @@ class KubernetesClientTest {
4950

5051
private CoreV1Api coreV1Api;
5152

53+
@Nullable
54+
private static String experimental(String value) {
55+
if (Boolean.getBoolean("otel.instrumentation.kubernetes.experimental-span-attributes")) {
56+
return value;
57+
}
58+
return null;
59+
}
60+
5261
@BeforeEach
5362
void beforeEach() {
5463
mockWebServer.start();
@@ -92,8 +101,9 @@ void synchronousCall() throws ApiException {
92101
equalTo(SERVER_PORT, mockWebServer.httpPort()),
93102
equalTo(PEER_SERVICE, "test-peer-service"),
94103
equalTo(
95-
AttributeKey.stringKey("kubernetes-client.namespace"), "namespace"),
96-
equalTo(AttributeKey.stringKey("kubernetes-client.name"), "name"))));
104+
stringKey("kubernetes-client.namespace"),
105+
experimental("namespace")),
106+
equalTo(stringKey("kubernetes-client.name"), experimental("name")))));
97107
}
98108

99109
@Test
@@ -103,10 +113,7 @@ void handleErrorsInSyncCall() {
103113
ApiException exception = null;
104114
try {
105115
testing.runWithSpan(
106-
"parent",
107-
() -> {
108-
coreV1Api.connectGetNamespacedPodProxy("name", "namespace", "path");
109-
});
116+
"parent", () -> coreV1Api.connectGetNamespacedPodProxy("name", "namespace", "path"));
110117
} catch (ApiException e) {
111118
exception = e;
112119
}
@@ -141,8 +148,9 @@ void handleErrorsInSyncCall() {
141148
equalTo(PEER_SERVICE, "test-peer-service"),
142149
equalTo(ERROR_TYPE, "451"),
143150
equalTo(
144-
AttributeKey.stringKey("kubernetes-client.namespace"), "namespace"),
145-
equalTo(AttributeKey.stringKey("kubernetes-client.name"), "name"))));
151+
stringKey("kubernetes-client.namespace"),
152+
experimental("namespace")),
153+
equalTo(stringKey("kubernetes-client.name"), experimental("name")))));
146154
}
147155

148156
@Test
@@ -154,21 +162,20 @@ void asynchronousCall() throws ApiException, InterruptedException {
154162

155163
testing.runWithSpan(
156164
"parent",
157-
() -> {
158-
coreV1Api.connectGetNamespacedPodProxyAsync(
159-
"name",
160-
"namespace",
161-
"path",
162-
new ApiCallbackTemplate() {
163-
@Override
164-
public void onSuccess(
165-
String result, int statusCode, Map<String, List<String>> responseHeaders) {
166-
responseBodyReference.set(result);
167-
countDownLatch.countDown();
168-
testing.runWithSpan("callback", () -> {});
169-
}
170-
});
171-
});
165+
() ->
166+
coreV1Api.connectGetNamespacedPodProxyAsync(
167+
"name",
168+
"namespace",
169+
"path",
170+
new ApiCallbackTemplate() {
171+
@Override
172+
public void onSuccess(
173+
String result, int statusCode, Map<String, List<String>> responseHeaders) {
174+
responseBodyReference.set(result);
175+
countDownLatch.countDown();
176+
testing.runWithSpan("callback", () -> {});
177+
}
178+
}));
172179

173180
countDownLatch.await();
174181

@@ -195,8 +202,9 @@ public void onSuccess(
195202
equalTo(SERVER_PORT, mockWebServer.httpPort()),
196203
equalTo(PEER_SERVICE, "test-peer-service"),
197204
equalTo(
198-
AttributeKey.stringKey("kubernetes-client.namespace"), "namespace"),
199-
equalTo(AttributeKey.stringKey("kubernetes-client.name"), "name")),
205+
stringKey("kubernetes-client.namespace"),
206+
experimental("namespace")),
207+
equalTo(stringKey("kubernetes-client.name"), experimental("name"))),
200208
span ->
201209
span.hasName("callback")
202210
.hasKind(SpanKind.INTERNAL)
@@ -214,21 +222,20 @@ void handleErrorsInAsynchronousCall() throws ApiException, InterruptedException
214222

215223
testing.runWithSpan(
216224
"parent",
217-
() -> {
218-
coreV1Api.connectGetNamespacedPodProxyAsync(
219-
"name",
220-
"namespace",
221-
"path",
222-
new ApiCallbackTemplate() {
223-
@Override
224-
public void onFailure(
225-
ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {
226-
exceptionReference.set(e);
227-
countDownLatch.countDown();
228-
testing.runWithSpan("callback", () -> {});
229-
}
230-
});
231-
});
225+
() ->
226+
coreV1Api.connectGetNamespacedPodProxyAsync(
227+
"name",
228+
"namespace",
229+
"path",
230+
new ApiCallbackTemplate() {
231+
@Override
232+
public void onFailure(
233+
ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {
234+
exceptionReference.set(e);
235+
countDownLatch.countDown();
236+
testing.runWithSpan("callback", () -> {});
237+
}
238+
}));
232239

233240
countDownLatch.await();
234241

@@ -258,8 +265,9 @@ public void onFailure(
258265
equalTo(PEER_SERVICE, "test-peer-service"),
259266
equalTo(ERROR_TYPE, "451"),
260267
equalTo(
261-
AttributeKey.stringKey("kubernetes-client.namespace"), "namespace"),
262-
equalTo(AttributeKey.stringKey("kubernetes-client.name"), "name")),
268+
stringKey("kubernetes-client.namespace"),
269+
experimental("namespace")),
270+
equalTo(stringKey("kubernetes-client.name"), experimental("name"))),
263271
span ->
264272
span.hasName("callback")
265273
.hasKind(SpanKind.INTERNAL)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
description: This instrumentation enables HTTP client spans and HTTP client metrics for the Kubernetes Client for Java.
2+
display_name: Kubernetes Client
3+
semantic_conventions:
4+
- HTTP_CLIENT_SPANS
5+
- HTTP_CLIENT_METRICS
6+
library_link: https://github.com/kubernetes-client/java
7+
configurations:
8+
- name: otel.instrumentation.kubernetes-client.experimental-span-attributes
9+
description: >
10+
Enables experimental span attributes `kubernetes-client.namespace` and
11+
`kubernetes-client.name` for Kubernetes API requests.
12+
type: boolean
13+
default: false
14+
- name: otel.instrumentation.http.known-methods
15+
description: >
16+
Configures the instrumentation to recognize an alternative set of HTTP request methods. All
17+
other methods will be treated as `_OTHER`.
18+
type: list
19+
default: "CONNECT,DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT,TRACE"
20+
- name: otel.instrumentation.http.client.capture-request-headers
21+
description: List of HTTP request headers to capture in HTTP client telemetry.
22+
type: list
23+
default: ""
24+
- name: otel.instrumentation.http.client.capture-response-headers
25+
description: List of HTTP response headers to capture in HTTP client telemetry.
26+
type: list
27+
default: ""
28+
- name: otel.instrumentation.common.peer-service-mapping
29+
description: Used to specify a mapping from host names or IP addresses to peer services.
30+
type: map
31+
default: ""
32+
- name: otel.instrumentation.http.client.emit-experimental-telemetry
33+
description: >
34+
Enable the capture of experimental HTTP client telemetry. Adds the `http.request.body.size`
35+
and `http.response.body.size` attributes to spans, and records `http.client.request.size` and
36+
`http.client.response.size` metrics.
37+
type: boolean
38+
default: false
39+
- name: otel.instrumentation.http.client.experimental.redact-query-parameters
40+
description: Redact sensitive URL parameters. See https://opentelemetry.io/docs/specs/semconv/http/http-spans.
41+
type: boolean
42+
default: true

0 commit comments

Comments
 (0)