Skip to content

Commit b187dbf

Browse files
committed
address review comment
1 parent a8e5e24 commit b187dbf

File tree

3 files changed

+37
-53
lines changed

3 files changed

+37
-53
lines changed

instrumentation/elasticsearch/elasticsearch-transport-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticsearchTransportExperimentalAttributesExtractor.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
package io.opentelemetry.javaagent.instrumentation.elasticsearch.transport;
77

8+
import static io.opentelemetry.api.common.AttributeKey.longKey;
9+
import static io.opentelemetry.api.common.AttributeKey.stringKey;
10+
811
import io.opentelemetry.api.common.AttributeKey;
912
import io.opentelemetry.api.common.AttributesBuilder;
1013
import io.opentelemetry.context.Context;
@@ -24,41 +27,38 @@ public class ElasticsearchTransportExperimentalAttributesExtractor
2427
implements AttributesExtractor<ElasticTransportRequest, ActionResponse> {
2528

2629
private static final AttributeKey<String> ELASTICSEARCH_ACTION =
27-
AttributeKey.stringKey("elasticsearch.action");
30+
stringKey("elasticsearch.action");
2831
private static final AttributeKey<String> ELASTICSEARCH_REQUEST =
29-
AttributeKey.stringKey("elasticsearch.request");
32+
stringKey("elasticsearch.request");
3033
private static final AttributeKey<String> ELASTICSEARCH_REQUEST_INDICES =
31-
AttributeKey.stringKey("elasticsearch.request.indices");
34+
stringKey("elasticsearch.request.indices");
3235
private static final AttributeKey<String> ELASTICSEARCH_REQUEST_SEARCH_TYPES =
33-
AttributeKey.stringKey("elasticsearch.request.search.types");
34-
private static final AttributeKey<String> ELASTICSEARCH_TYPE =
35-
AttributeKey.stringKey("elasticsearch.type");
36-
private static final AttributeKey<String> ELASTICSEARCH_ID =
37-
AttributeKey.stringKey("elasticsearch.id");
38-
private static final AttributeKey<Long> ELASTICSEARCH_VERSION =
39-
AttributeKey.longKey("elasticsearch.version");
36+
stringKey("elasticsearch.request.search.types");
37+
private static final AttributeKey<String> ELASTICSEARCH_TYPE = stringKey("elasticsearch.type");
38+
private static final AttributeKey<String> ELASTICSEARCH_ID = stringKey("elasticsearch.id");
39+
private static final AttributeKey<Long> ELASTICSEARCH_VERSION = longKey("elasticsearch.version");
4040
private static final AttributeKey<Long> ELASTICSEARCH_SHARD_BROADCAST_TOTAL =
41-
AttributeKey.longKey("elasticsearch.shard.broadcast.total");
41+
longKey("elasticsearch.shard.broadcast.total");
4242
private static final AttributeKey<Long> ELASTICSEARCH_SHARD_BROADCAST_SUCCESSFUL =
43-
AttributeKey.longKey("elasticsearch.shard.broadcast.successful");
43+
longKey("elasticsearch.shard.broadcast.successful");
4444
private static final AttributeKey<Long> ELASTICSEARCH_SHARD_BROADCAST_FAILED =
45-
AttributeKey.longKey("elasticsearch.shard.broadcast.failed");
45+
longKey("elasticsearch.shard.broadcast.failed");
4646
private static final AttributeKey<Long> ELASTICSEARCH_SHARD_REPLICATION_TOTAL =
47-
AttributeKey.longKey("elasticsearch.shard.replication.total");
47+
longKey("elasticsearch.shard.replication.total");
4848
private static final AttributeKey<Long> ELASTICSEARCH_SHARD_REPLICATION_SUCCESSFUL =
49-
AttributeKey.longKey("elasticsearch.shard.replication.successful");
49+
longKey("elasticsearch.shard.replication.successful");
5050
private static final AttributeKey<Long> ELASTICSEARCH_SHARD_REPLICATION_FAILED =
51-
AttributeKey.longKey("elasticsearch.shard.replication.failed");
51+
longKey("elasticsearch.shard.replication.failed");
5252
private static final AttributeKey<Long> ELASTICSEARCH_RESPONSE_STATUS =
53-
AttributeKey.longKey("elasticsearch.response.status");
53+
longKey("elasticsearch.response.status");
5454
private static final AttributeKey<Long> ELASTICSEARCH_SHARD_BULK_ID =
55-
AttributeKey.longKey("elasticsearch.shard.bulk.id");
55+
longKey("elasticsearch.shard.bulk.id");
5656
private static final AttributeKey<String> ELASTICSEARCH_SHARD_BULK_INDEX =
57-
AttributeKey.stringKey("elasticsearch.shard.bulk.index");
57+
stringKey("elasticsearch.shard.bulk.index");
5858
private static final AttributeKey<Long> ELASTICSEARCH_NODE_FAILURES =
59-
AttributeKey.longKey("elasticsearch.node.failures");
59+
longKey("elasticsearch.node.failures");
6060
private static final AttributeKey<String> ELASTICSEARCH_NODE_CLUSTER_NAME =
61-
AttributeKey.stringKey("elasticsearch.node.cluster.name");
61+
stringKey("elasticsearch.node.cluster.name");
6262

6363
@Override
6464
public void onStart(

instrumentation/elasticsearch/elasticsearch-transport-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/AbstractElasticsearchNodeClientTest.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
package io.opentelemetry.javaagent.instrumentation.elasticsearch.transport;
77

8+
import static io.opentelemetry.api.common.AttributeKey.longKey;
9+
import static io.opentelemetry.api.common.AttributeKey.stringKey;
810
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
911
import static org.assertj.core.api.Assertions.assertThat;
1012
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1113
import static org.junit.jupiter.api.Named.named;
1214

13-
import io.opentelemetry.api.common.AttributeKey;
1415
import io.opentelemetry.api.trace.SpanKind;
1516
import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier;
1617
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
@@ -228,20 +229,11 @@ void elasticsearchGet() {
228229
equalTo(ELASTICSEARCH_ACTION, "IndexAction"),
229230
equalTo(ELASTICSEARCH_REQUEST, "IndexRequest"),
230231
equalTo(ELASTICSEARCH_REQUEST_INDICES, indexName),
231-
equalTo(
232-
AttributeKey.stringKey("elasticsearch.request.write.type"),
233-
indexType),
234-
equalTo(AttributeKey.longKey("elasticsearch.response.status"), 201),
235-
equalTo(
236-
AttributeKey.longKey("elasticsearch.shard.replication.total"),
237-
2),
238-
equalTo(
239-
AttributeKey.longKey(
240-
"elasticsearch.shard.replication.successful"),
241-
1),
242-
equalTo(
243-
AttributeKey.longKey("elasticsearch.shard.replication.failed"),
244-
0)))),
232+
equalTo(stringKey("elasticsearch.request.write.type"), indexType),
233+
equalTo(longKey("elasticsearch.response.status"), 201),
234+
equalTo(longKey("elasticsearch.shard.replication.total"), 2),
235+
equalTo(longKey("elasticsearch.shard.replication.successful"), 1),
236+
equalTo(longKey("elasticsearch.shard.replication.failed"), 0)))),
245237
trace ->
246238
trace.hasSpansSatisfyingExactly(
247239
span ->
@@ -268,7 +260,7 @@ protected boolean hasWriteVersion() {
268260
private List<AttributeAssertion> addIndexActionAttributes(AttributeAssertion... assertions) {
269261
List<AttributeAssertion> result = new ArrayList<>(Arrays.asList(assertions));
270262
if (hasWriteVersion()) {
271-
result.add(equalTo(AttributeKey.longKey("elasticsearch.request.write.version"), -3));
263+
result.add(equalTo(longKey("elasticsearch.request.write.version"), -3));
272264
}
273265
return result;
274266
}

instrumentation/elasticsearch/elasticsearch-transport-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/AbstractElasticsearchTransportClientTest.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package io.opentelemetry.javaagent.instrumentation.elasticsearch.transport;
77

8+
import static io.opentelemetry.api.common.AttributeKey.longKey;
9+
import static io.opentelemetry.api.common.AttributeKey.stringKey;
810
import static io.opentelemetry.instrumentation.testing.util.TelemetryDataUtil.orderByRootSpanName;
911
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1012
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
@@ -13,7 +15,6 @@
1315
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1416
import static org.junit.jupiter.api.Named.named;
1517

16-
import io.opentelemetry.api.common.AttributeKey;
1718
import io.opentelemetry.api.trace.SpanKind;
1819
import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier;
1920
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
@@ -232,20 +233,11 @@ void elasticsearchGet() {
232233
equalTo(ELASTICSEARCH_ACTION, "IndexAction"),
233234
equalTo(ELASTICSEARCH_REQUEST, "IndexRequest"),
234235
equalTo(ELASTICSEARCH_REQUEST_INDICES, indexName),
235-
equalTo(
236-
AttributeKey.stringKey("elasticsearch.request.write.type"),
237-
indexType),
238-
equalTo(AttributeKey.longKey("elasticsearch.response.status"), 201),
239-
equalTo(
240-
AttributeKey.longKey("elasticsearch.shard.replication.total"),
241-
2),
242-
equalTo(
243-
AttributeKey.longKey(
244-
"elasticsearch.shard.replication.successful"),
245-
1),
246-
equalTo(
247-
AttributeKey.longKey("elasticsearch.shard.replication.failed"),
248-
0)))),
236+
equalTo(stringKey("elasticsearch.request.write.type"), indexType),
237+
equalTo(longKey("elasticsearch.response.status"), 201),
238+
equalTo(longKey("elasticsearch.shard.replication.total"), 2),
239+
equalTo(longKey("elasticsearch.shard.replication.successful"), 1),
240+
equalTo(longKey("elasticsearch.shard.replication.failed"), 0)))),
249241
// moved here by sorting, chronologically happens before PutMappingAction
250242
trace ->
251243
trace.hasSpansSatisfyingExactly(
@@ -314,7 +306,7 @@ protected boolean hasWriteVersion() {
314306
private List<AttributeAssertion> addIndexActionAttributes(AttributeAssertion... assertions) {
315307
List<AttributeAssertion> result = new ArrayList<>(addNetworkTypeAttribute(assertions));
316308
if (hasWriteVersion()) {
317-
result.add(equalTo(AttributeKey.longKey("elasticsearch.request.write.version"), -3));
309+
result.add(equalTo(longKey("elasticsearch.request.write.version"), -3));
318310
}
319311
return result;
320312
}

0 commit comments

Comments
 (0)