Skip to content

Commit 6c49b12

Browse files
Add instrumentation API and native OpenTelemetry implementation (#588)
Signed-off-by: Alexander Wert <alexander.wert@elastic.co> Co-authored-by: Sylvain Wallez <sylvain@elastic.co>
1 parent caba4f6 commit 6c49b12

File tree

448 files changed

+7351
-46
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

448 files changed

+7351
-46
lines changed

example-transports/src/main/java/co/elastic/clients/transport/netty/NettyTransportHttpClient.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@
5656
import javax.annotation.Nullable;
5757
import javax.net.ssl.SSLException;
5858
import java.io.IOException;
59-
import java.io.UnsupportedEncodingException;
6059
import java.net.URLEncoder;
6160
import java.nio.ByteBuffer;
61+
import java.nio.charset.StandardCharsets;
6262
import java.util.ArrayList;
6363
import java.util.Collections;
6464
import java.util.HashMap;
@@ -231,12 +231,8 @@ private String queryString(Request request, TransportOptions options) {
231231
.entrySet()
232232
.stream()
233233
.map(e -> {
234-
try {
235-
return URLEncoder.encode(e.getKey(), "UTF-8") + "=" +
236-
URLEncoder.encode(e.getValue(), "UTF-8");
237-
} catch(UnsupportedEncodingException ex) {
238-
throw new RuntimeException(ex);
239-
}
234+
return URLEncoder.encode(e.getKey(), StandardCharsets.UTF_8) + "=" +
235+
URLEncoder.encode(e.getValue(), StandardCharsets.UTF_8);
240236
})
241237
.collect(Collectors.joining("&"));
242238
}

java-client/build.gradle.kts

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
*/
1919

2020
import com.github.jk1.license.ProjectData
21-
import com.github.jk1.license.render.ReportRenderer
2221
import com.github.jk1.license.render.LicenseDataCollector
22+
import com.github.jk1.license.render.ReportRenderer
2323
import java.io.FileWriter
2424

2525
plugins {
@@ -53,8 +53,8 @@ tasks.getByName<ProcessResources>("processResources") {
5353
if (name != "apis.json") {
5454
// Only process main source-set resources (test files are large)
5555
expand(
56-
"version" to version,
57-
"git_revision" to (if (rootProject.extra.has("gitHashFull")) rootProject.extra["gitHashFull"] else "unknown")
56+
"version" to version,
57+
"git_revision" to (if (rootProject.extra.has("gitHashFull")) rootProject.extra["gitHashFull"] else "unknown")
5858
)
5959
}
6060
}
@@ -69,7 +69,7 @@ tasks.withType<Jar> {
6969
if (rootProject.extra.has("gitHashFull")) {
7070
val jar = this as Jar
7171
jar.manifest.attributes["X-Git-Revision"] = rootProject.extra["gitHashFull"]
72-
jar.manifest.attributes["X-Git-Commit-Time"] = rootProject .extra["gitCommitTime"]
72+
jar.manifest.attributes["X-Git-Commit-Time"] = rootProject.extra["gitCommitTime"]
7373
} else {
7474
throw GradleException("No git information available")
7575
}
@@ -154,7 +154,7 @@ publishing {
154154
// are the same as the one used in the dependency section below.
155155
val xPathFactory = javax.xml.xpath.XPathFactory.newInstance()
156156
val depSelector = xPathFactory.newXPath()
157-
.compile("/project/dependencies/dependency[groupId/text() = 'org.elasticsearch.client']")
157+
.compile("/project/dependencies/dependency[groupId/text() = 'org.elasticsearch.client']")
158158
val versionSelector = xPathFactory.newXPath().compile("version")
159159

160160
var foundVersion = false;
@@ -183,6 +183,7 @@ dependencies {
183183
// the Java API client coexists with a 7.x HLRC work fine
184184
val elasticsearchVersion = "7.17.7"
185185
val jacksonVersion = "2.13.3"
186+
val openTelemetryVersion = "1.29.0"
186187

187188
// Apache 2.0
188189
// https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-low.html
@@ -201,6 +202,13 @@ dependencies {
201202
// https://github.com/eclipse-ee4j/parsson
202203
api("org.eclipse.parsson:parsson:1.0.0")
203204

205+
// OpenTelemetry API for native instrumentation of the client.
206+
// Apache 2.0
207+
// https://github.com/open-telemetry/opentelemetry-java
208+
implementation("io.opentelemetry", "opentelemetry-api", openTelemetryVersion)
209+
// Use it once it's stable (see Instrumentation.java). Limited to tests for now.
210+
testImplementation("io.opentelemetry", "opentelemetry-semconv", "$openTelemetryVersion-alpha")
211+
204212
// EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
205213
// https://github.com/eclipse-ee4j/jsonb-api
206214
compileOnly("jakarta.json.bind", "jakarta.json.bind-api", "2.0.0")
@@ -236,6 +244,9 @@ dependencies {
236244
// https://www.testcontainers.org/
237245
testImplementation("org.testcontainers", "testcontainers", "1.17.3")
238246
testImplementation("org.testcontainers", "elasticsearch", "1.17.3")
247+
248+
249+
testImplementation("io.opentelemetry", "opentelemetry-sdk", openTelemetryVersion)
239250
}
240251

241252

@@ -247,17 +258,18 @@ licenseReport {
247258
class SpdxReporter(val dest: File) : ReportRenderer {
248259
// License names to their SPDX identifier
249260
val spdxIds = mapOf(
250-
"Apache License, Version 2.0" to "Apache-2.0",
251-
"The Apache Software License, Version 2.0" to "Apache-2.0",
252-
"BSD Zero Clause License" to "0BSD",
253-
"Eclipse Public License 2.0" to "EPL-2.0",
254-
"Eclipse Public License v. 2.0" to "EPL-2.0",
255-
"Eclipse Public License - v 2.0" to "EPL-2.0",
256-
"GNU General Public License, version 2 with the GNU Classpath Exception" to "GPL-2.0 WITH Classpath-exception-2.0",
257-
"COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0" to "CDDL-1.0"
261+
"The Apache License, Version 2.0" to "Apache-2.0",
262+
"Apache License, Version 2.0" to "Apache-2.0",
263+
"The Apache Software License, Version 2.0" to "Apache-2.0",
264+
"BSD Zero Clause License" to "0BSD",
265+
"Eclipse Public License 2.0" to "EPL-2.0",
266+
"Eclipse Public License v. 2.0" to "EPL-2.0",
267+
"Eclipse Public License - v 2.0" to "EPL-2.0",
268+
"GNU General Public License, version 2 with the GNU Classpath Exception" to "GPL-2.0 WITH Classpath-exception-2.0",
269+
"COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0" to "CDDL-1.0"
258270
)
259271

260-
private fun quote(str: String) : String {
272+
private fun quote(str: String): String {
261273
return if (str.contains(',') || str.contains("\"")) {
262274
"\"" + str.replace("\"", "\"\"") + "\""
263275
} else {

java-client/src/main/java/co/elastic/clients/elasticsearch/async_search/AsyncSearchStatusRequest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import jakarta.json.stream.JsonGenerator;
3737
import java.lang.String;
3838
import java.util.Collections;
39+
import java.util.HashMap;
40+
import java.util.Map;
3941
import java.util.Objects;
4042
import java.util.function.Function;
4143
import javax.annotation.Nullable;
@@ -149,6 +151,21 @@ public AsyncSearchStatusRequest build() {
149151

150152
},
151153

154+
// Path parameters
155+
request -> {
156+
Map<String, String> params = new HashMap<>();
157+
final int _id = 1 << 0;
158+
159+
int propsSet = 0;
160+
161+
propsSet |= _id;
162+
163+
if (propsSet == (_id)) {
164+
params.put("id", request.id);
165+
}
166+
return params;
167+
},
168+
152169
// Request parameters
153170
request -> {
154171
return Collections.emptyMap();

java-client/src/main/java/co/elastic/clients/elasticsearch/async_search/DeleteAsyncSearchRequest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import jakarta.json.stream.JsonGenerator;
3737
import java.lang.String;
3838
import java.util.Collections;
39+
import java.util.HashMap;
40+
import java.util.Map;
3941
import java.util.Objects;
4042
import java.util.function.Function;
4143
import javax.annotation.Nullable;
@@ -150,6 +152,21 @@ public DeleteAsyncSearchRequest build() {
150152

151153
},
152154

155+
// Path parameters
156+
request -> {
157+
Map<String, String> params = new HashMap<>();
158+
final int _id = 1 << 0;
159+
160+
int propsSet = 0;
161+
162+
propsSet |= _id;
163+
164+
if (propsSet == (_id)) {
165+
params.put("id", request.id);
166+
}
167+
return params;
168+
},
169+
153170
// Request parameters
154171
request -> {
155172
return Collections.emptyMap();

java-client/src/main/java/co/elastic/clients/elasticsearch/async_search/GetAsyncSearchRequest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,21 @@ public GetAsyncSearchRequest build() {
248248

249249
},
250250

251+
// Path parameters
252+
request -> {
253+
Map<String, String> params = new HashMap<>();
254+
final int _id = 1 << 0;
255+
256+
int propsSet = 0;
257+
258+
propsSet |= _id;
259+
260+
if (propsSet == (_id)) {
261+
params.put("id", request.id);
262+
}
263+
return params;
264+
},
265+
251266
// Request parameters
252267
request -> {
253268
Map<String, String> params = new HashMap<>();

java-client/src/main/java/co/elastic/clients/elasticsearch/async_search/SubmitRequest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,6 +2436,24 @@ protected static void setupSubmitRequestDeserializer(ObjectDeserializer<SubmitRe
24362436

24372437
},
24382438

2439+
// Path parameters
2440+
request -> {
2441+
Map<String, String> params = new HashMap<>();
2442+
final int _index = 1 << 0;
2443+
2444+
int propsSet = 0;
2445+
2446+
if (ApiTypeHelper.isDefined(request.index()))
2447+
propsSet |= _index;
2448+
2449+
if (propsSet == 0) {
2450+
}
2451+
if (propsSet == (_index)) {
2452+
params.put("index", request.index.stream().map(v -> v).collect(Collectors.joining(",")));
2453+
}
2454+
return params;
2455+
},
2456+
24392457
// Request parameters
24402458
request -> {
24412459
Map<String, String> params = new HashMap<>();

java-client/src/main/java/co/elastic/clients/elasticsearch/autoscaling/DeleteAutoscalingPolicyRequest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import jakarta.json.stream.JsonGenerator;
3737
import java.lang.String;
3838
import java.util.Collections;
39+
import java.util.HashMap;
40+
import java.util.Map;
3941
import java.util.Objects;
4042
import java.util.function.Function;
4143
import javax.annotation.Nullable;
@@ -149,6 +151,21 @@ public DeleteAutoscalingPolicyRequest build() {
149151

150152
},
151153

154+
// Path parameters
155+
request -> {
156+
Map<String, String> params = new HashMap<>();
157+
final int _name = 1 << 0;
158+
159+
int propsSet = 0;
160+
161+
propsSet |= _name;
162+
163+
if (propsSet == (_name)) {
164+
params.put("name", request.name);
165+
}
166+
return params;
167+
},
168+
152169
// Request parameters
153170
request -> {
154171
return Collections.emptyMap();

java-client/src/main/java/co/elastic/clients/elasticsearch/autoscaling/GetAutoscalingCapacityRequest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public GetAutoscalingCapacityRequest() {
7777

7878
},
7979

80+
// Path parameters
81+
request -> {
82+
return Collections.emptyMap();
83+
},
84+
8085
// Request parameters
8186
request -> {
8287
return Collections.emptyMap();

java-client/src/main/java/co/elastic/clients/elasticsearch/autoscaling/GetAutoscalingPolicyRequest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import jakarta.json.stream.JsonGenerator;
3737
import java.lang.String;
3838
import java.util.Collections;
39+
import java.util.HashMap;
40+
import java.util.Map;
3941
import java.util.Objects;
4042
import java.util.function.Function;
4143
import javax.annotation.Nullable;
@@ -148,6 +150,21 @@ public GetAutoscalingPolicyRequest build() {
148150

149151
},
150152

153+
// Path parameters
154+
request -> {
155+
Map<String, String> params = new HashMap<>();
156+
final int _name = 1 << 0;
157+
158+
int propsSet = 0;
159+
160+
propsSet |= _name;
161+
162+
if (propsSet == (_name)) {
163+
params.put("name", request.name);
164+
}
165+
return params;
166+
},
167+
151168
// Request parameters
152169
request -> {
153170
return Collections.emptyMap();

java-client/src/main/java/co/elastic/clients/elasticsearch/autoscaling/PutAutoscalingPolicyRequest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import jakarta.json.stream.JsonParser;
4040
import java.lang.String;
4141
import java.util.Collections;
42+
import java.util.HashMap;
43+
import java.util.Map;
4244
import java.util.Objects;
4345
import java.util.function.Function;
4446
import javax.annotation.Nullable;
@@ -203,6 +205,21 @@ protected static JsonpDeserializer<PutAutoscalingPolicyRequest> createPutAutosca
203205

204206
},
205207

208+
// Path parameters
209+
request -> {
210+
Map<String, String> params = new HashMap<>();
211+
final int _name = 1 << 0;
212+
213+
int propsSet = 0;
214+
215+
propsSet |= _name;
216+
217+
if (propsSet == (_name)) {
218+
params.put("name", request.name);
219+
}
220+
return params;
221+
},
222+
206223
// Request parameters
207224
request -> {
208225
return Collections.emptyMap();

java-client/src/main/java/co/elastic/clients/elasticsearch/cat/AliasesRequest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,24 @@ public AliasesRequest build() {
223223

224224
},
225225

226+
// Path parameters
227+
request -> {
228+
Map<String, String> params = new HashMap<>();
229+
final int _name = 1 << 0;
230+
231+
int propsSet = 0;
232+
233+
if (ApiTypeHelper.isDefined(request.name()))
234+
propsSet |= _name;
235+
236+
if (propsSet == 0) {
237+
}
238+
if (propsSet == (_name)) {
239+
params.put("name", request.name.stream().map(v -> v).collect(Collectors.joining(",")));
240+
}
241+
return params;
242+
},
243+
226244
// Request parameters
227245
request -> {
228246
Map<String, String> params = new HashMap<>();

java-client/src/main/java/co/elastic/clients/elasticsearch/cat/AllocationRequest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,24 @@ public AllocationRequest build() {
205205

206206
},
207207

208+
// Path parameters
209+
request -> {
210+
Map<String, String> params = new HashMap<>();
211+
final int _nodeId = 1 << 0;
212+
213+
int propsSet = 0;
214+
215+
if (ApiTypeHelper.isDefined(request.nodeId()))
216+
propsSet |= _nodeId;
217+
218+
if (propsSet == 0) {
219+
}
220+
if (propsSet == (_nodeId)) {
221+
params.put("nodeId", request.nodeId.stream().map(v -> v).collect(Collectors.joining(",")));
222+
}
223+
return params;
224+
},
225+
208226
// Request parameters
209227
request -> {
210228
Map<String, String> params = new HashMap<>();

0 commit comments

Comments
 (0)