Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Nov 10, 2024
1 parent c151604 commit d4b8454
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@ExtendWith(MockitoExtension.class)
class DbClientSpanNameExtractorTest {
@Mock DbClientAttributesGetter<DbRequest, Void> dbAttributesGetter;
@Mock SqlClientAttributesGetter<DbRequest> sqlAttributesGetter;
@Mock SqlClientAttributesGetter<DbRequest, Void> sqlAttributesGetter;

@Test
void shouldExtractFullSpanName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class SqlClientAttributesExtractorTest {

static final class TestAttributesGetter
implements SqlClientAttributesGetter<Map<String, String>> {
implements SqlClientAttributesGetter<Map<String, String>, Void> {

@Override
public String getRawQueryText(Map<String, String> map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.apache.http.HttpEntity;
import org.elasticsearch.client.Response;

/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
final class ElasticsearchDbAttributesGetter
implements DbClientAttributesGetter<ElasticsearchRestRequest, Void> {
implements DbClientAttributesGetter<ElasticsearchRestRequest, Response> {

private static final Logger logger =
Logger.getLogger(ElasticsearchDbAttributesGetter.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesGetter;
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;
import javax.annotation.Nullable;
import org.elasticsearch.action.ActionResponse;

final class ElasticsearchTransportAttributesGetter
implements DbClientAttributesGetter<ElasticTransportRequest, Void> {
implements DbClientAttributesGetter<ElasticTransportRequest, ActionResponse> {

@Override
public String getDbSystem(ElasticTransportRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
import io.opentelemetry.instrumentation.api.incubator.semconv.net.PeerServiceAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor;
import io.opentelemetry.instrumentation.api.semconv.network.ServerAttributesExtractor;
import io.opentelemetry.instrumentation.jdbc.internal.DbRequest;
import io.opentelemetry.instrumentation.jdbc.internal.JdbcAttributesGetter;
import io.opentelemetry.instrumentation.jdbc.internal.JdbcNetworkAttributesGetter;
import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig;
import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig;
import io.opentelemetry.javaagent.bootstrap.jdbc.DbInfo;
Expand All @@ -31,7 +29,6 @@ public final class JdbcSingletons {

static {
JdbcAttributesGetter dbAttributesGetter = new JdbcAttributesGetter();
JdbcNetworkAttributesGetter netAttributesGetter = new JdbcNetworkAttributesGetter();

STATEMENT_INSTRUMENTER =
Instrumenter.<DbRequest, Void>builder(
Expand All @@ -46,10 +43,9 @@ public final class JdbcSingletons {
"otel.instrumentation.jdbc.statement-sanitizer.enabled",
AgentCommonConfig.get().isStatementSanitizationEnabled()))
.build())
.addAttributesExtractor(ServerAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractor(
PeerServiceAttributesExtractor.create(
netAttributesGetter, AgentCommonConfig.get().getPeerServiceResolver()))
dbAttributesGetter, AgentCommonConfig.get().getPeerServiceResolver()))
.buildInstrumenter(SpanKindExtractor.alwaysClient());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public final class JdbcAttributesGetter implements SqlClientAttributesGetter<DbRequest> {
public final class JdbcAttributesGetter implements SqlClientAttributesGetter<DbRequest, Void> {

@Nullable
@Override
Expand Down Expand Up @@ -47,4 +47,16 @@ public String getConnectionString(DbRequest request) {
public String getRawQueryText(DbRequest request) {
return request.getQueryText();
}

@Nullable
@Override
public String getServerAddress(DbRequest request) {
return request.getDbInfo().getHost();
}

@Nullable
@Override
public Integer getServerPort(DbRequest request) {
return request.getDbInfo().getPort();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor;
import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil;
import io.opentelemetry.instrumentation.api.semconv.network.ServerAttributesExtractor;
import io.opentelemetry.instrumentation.jdbc.internal.dbinfo.DbInfo;
import javax.sql.DataSource;

Expand All @@ -25,8 +24,6 @@
public final class JdbcInstrumenterFactory {
public static final String INSTRUMENTATION_NAME = "io.opentelemetry.jdbc";
private static final JdbcAttributesGetter dbAttributesGetter = new JdbcAttributesGetter();
private static final JdbcNetworkAttributesGetter netAttributesGetter =
new JdbcNetworkAttributesGetter();

public static Instrumenter<DbRequest, Void> createStatementInstrumenter() {
return createStatementInstrumenter(GlobalOpenTelemetry.get());
Expand All @@ -51,7 +48,6 @@ public static Instrumenter<DbRequest, Void> createStatementInstrumenter(
SqlClientAttributesExtractor.builder(dbAttributesGetter)
.setStatementSanitizationEnabled(statementSanitizationEnabled)
.build())
.addAttributesExtractor(ServerAttributesExtractor.create(netAttributesGetter))
.setEnabled(enabled)
.buildInstrumenter(SpanKindExtractor.alwaysClient());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,9 @@
package io.opentelemetry.instrumentation.jdbc.internal;

import io.opentelemetry.instrumentation.api.semconv.network.ServerAttributesGetter;
import javax.annotation.Nullable;

/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public final class JdbcNetworkAttributesGetter implements ServerAttributesGetter<DbRequest> {

@Nullable
@Override
public String getServerAddress(DbRequest request) {
return request.getDbInfo().getHost();
}

@Nullable
@Override
public Integer getServerPort(DbRequest request) {
return request.getDbInfo().getPort();
}
}
public final class JdbcNetworkAttributesGetter implements ServerAttributesGetter<DbRequest> {}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesGetter;
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;
import javax.annotation.Nullable;
import org.opensearch.client.Response;

final class OpenSearchRestAttributesGetter
implements DbClientAttributesGetter<OpenSearchRestRequest, Void> {
implements DbClientAttributesGetter<OpenSearchRestRequest, Response> {

@Override
public String getDbSystem(OpenSearchRestRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.api.incubator.semconv.net.PeerServiceAttributesExtractor;
import io.opentelemetry.instrumentation.r2dbc.v1_0.internal.shaded.R2dbcTelemetry;
import io.opentelemetry.instrumentation.r2dbc.v1_0.internal.shaded.internal.R2dbcNetAttributesGetter;
import io.opentelemetry.instrumentation.r2dbc.v1_0.internal.shaded.internal.R2dbcSqlAttributesGetter;
import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig;
import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig;

Expand All @@ -23,7 +23,7 @@ public final class R2dbcSingletons {
AgentCommonConfig.get().isStatementSanitizationEnabled()))
.addAttributeExtractor(
PeerServiceAttributesExtractor.create(
R2dbcNetAttributesGetter.INSTANCE,
R2dbcSqlAttributesGetter.INSTANCE,
AgentCommonConfig.get().getPeerServiceResolver()))
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import javax.annotation.Nullable;

public class SpymemcachedAttributesGetter
implements DbClientAttributesGetter<SpymemcachedRequest, Void> {
implements DbClientAttributesGetter<SpymemcachedRequest, Object> {

@Override
public String getDbSystem(SpymemcachedRequest spymemcachedRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import javax.annotation.Nullable;

public enum VertxSqlClientAttributesGetter
implements SqlClientAttributesGetter<VertxSqlClientRequest> {
implements SqlClientAttributesGetter<VertxSqlClientRequest, Void> {
INSTANCE;

@Override
Expand Down

0 comments on commit d4b8454

Please sign in to comment.