diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/AttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/AttributesExtractor.java index c1bf6fe78cf0..f98f672c8d0b 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/AttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/AttributesExtractor.java @@ -7,6 +7,9 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.instrumentation.api.instrumenter.db.DbAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; /** * Extractor of {@link io.opentelemetry.api.common.Attributes} for a given request and response. @@ -16,6 +19,7 @@ * lifecycle. It is best to populate as much as possible in {@link #onStart(AttributesBuilder, * Object)} to have it available during sampling. * + * @see DbAttributesExtractor * @see HttpAttributesExtractor * @see NetAttributesExtractor */ diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/HttpSpanNameExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/HttpSpanNameExtractor.java deleted file mode 100644 index 896b79c55ec8..000000000000 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/HttpSpanNameExtractor.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter; - -final class HttpSpanNameExtractor implements SpanNameExtractor { - - private final HttpAttributesExtractor attributesExtractor; - - HttpSpanNameExtractor(HttpAttributesExtractor attributesExtractor) { - this.attributesExtractor = attributesExtractor; - } - - @Override - public String extract(REQUEST request) { - String route = attributesExtractor.route(request); - if (route != null) { - return route; - } - String method = attributesExtractor.method(request); - if (method != null) { - return "HTTP " + method; - } - return "HTTP request"; - } -} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/HttpSpanStatusExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/HttpSpanStatusExtractor.java deleted file mode 100644 index fec689ccb038..000000000000 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/HttpSpanStatusExtractor.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.instrumenter; - -import io.opentelemetry.api.trace.StatusCode; -import io.opentelemetry.instrumentation.api.tracer.HttpStatusConverter; - -final class HttpSpanStatusExtractor - implements SpanStatusExtractor { - - private final HttpAttributesExtractor attributesExtractor; - - protected HttpSpanStatusExtractor( - HttpAttributesExtractor attributesExtractor) { - this.attributesExtractor = attributesExtractor; - } - - @Override - public StatusCode extract(REQUEST request, RESPONSE response, Throwable error) { - Long statusCode = attributesExtractor.statusCode(request, response); - if (statusCode != null) { - return HttpStatusConverter.statusFromHttpStatus((int) (long) statusCode); - } - return SpanStatusExtractor.getDefault().extract(request, response, error); - } -} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SpanNameExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SpanNameExtractor.java index 3d1b58f06ccd..801d9003934f 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SpanNameExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SpanNameExtractor.java @@ -14,15 +14,6 @@ @FunctionalInterface public interface SpanNameExtractor { - /** - * Returns a {@link SpanNameExtractor} which should be used for HTTP requests. HTTP attributes - * will be examined to determine the name of the span. - */ - static SpanNameExtractor http( - HttpAttributesExtractor attributesExtractor) { - return new HttpSpanNameExtractor<>(attributesExtractor); - } - /** Returns the span name. */ String extract(REQUEST request); } diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SpanStatusExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SpanStatusExtractor.java index 89040925ef58..685e2844aba4 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SpanStatusExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SpanStatusExtractor.java @@ -24,16 +24,6 @@ static SpanStatusExtractor getDefault() { return (SpanStatusExtractor) DefaultSpanStatusExtractor.INSTANCE; } - /** - * Returns the {@link SpanStatusExtractor} for HTTP requests, which will use the HTTP status code - * to determine the {@link StatusCode} if available or fallback to {@linkplain #getDefault() the - * default status} otherwise. - */ - static SpanStatusExtractor http( - HttpAttributesExtractor attributesExtractor) { - return new HttpSpanStatusExtractor<>(attributesExtractor); - } - /** Returns the {@link StatusCode}. */ StatusCode extract(REQUEST request, RESPONSE response, @Nullable Throwable error); } diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbAttributesExtractor.java index 2631f88fab31..a331482eb70f 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbAttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbAttributesExtractor.java @@ -22,32 +22,32 @@ public abstract class DbAttributesExtractor extends AttributesExtractor { @Override protected void onStart(AttributesBuilder attributes, REQUEST request) { - set(attributes, SemanticAttributes.DB_SYSTEM, dbSystem(request)); - set(attributes, SemanticAttributes.DB_USER, dbUser(request)); - set(attributes, SemanticAttributes.DB_NAME, dbName(request)); - set(attributes, SemanticAttributes.DB_CONNECTION_STRING, dbConnectionString(request)); - set(attributes, SemanticAttributes.DB_STATEMENT, dbStatement(request)); - set(attributes, SemanticAttributes.DB_OPERATION, dbOperation(request)); + set(attributes, SemanticAttributes.DB_SYSTEM, system(request)); + set(attributes, SemanticAttributes.DB_USER, user(request)); + set(attributes, SemanticAttributes.DB_NAME, name(request)); + set(attributes, SemanticAttributes.DB_CONNECTION_STRING, connectionString(request)); + set(attributes, SemanticAttributes.DB_STATEMENT, statement(request)); + set(attributes, SemanticAttributes.DB_OPERATION, operation(request)); } @Override protected final void onEnd(AttributesBuilder attributes, REQUEST request, Void unused) {} @Nullable - protected abstract String dbSystem(REQUEST request); + protected abstract String system(REQUEST request); @Nullable - protected abstract String dbUser(REQUEST request); + protected abstract String user(REQUEST request); @Nullable - protected abstract String dbName(REQUEST request); + protected abstract String name(REQUEST request); @Nullable - protected abstract String dbConnectionString(REQUEST request); + protected abstract String connectionString(REQUEST request); @Nullable - protected abstract String dbStatement(REQUEST request); + protected abstract String statement(REQUEST request); @Nullable - protected abstract String dbOperation(REQUEST request); + protected abstract String operation(REQUEST request); } diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbSpanNameExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbSpanNameExtractor.java index fa349c850b81..5626b7122a6d 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbSpanNameExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbSpanNameExtractor.java @@ -11,11 +11,11 @@ public final class DbSpanNameExtractor implements SpanNameExtractor { /** * Returns a {@link SpanNameExtractor} that constructs the span name according to DB semantic - * conventions: {@code }. + * conventions: {@code .
}. * - * @see DbAttributesExtractor#dbOperation(Object) used to extract {@code }. - * @see DbAttributesExtractor#dbName(Object) used to extract {@code }. - * @see SqlAttributesExtractor#dbTable(Object) used to extract {@code }. + * @see DbAttributesExtractor#operation(Object) used to extract {@code }. + * @see DbAttributesExtractor#name(Object) used to extract {@code }. + * @see SqlAttributesExtractor#table(Object) used to extract {@code }. */ public static SpanNameExtractor create( DbAttributesExtractor attributesExtractor) { @@ -32,8 +32,8 @@ private DbSpanNameExtractor(DbAttributesExtractor attributesExtractor) @Override public String extract(REQUEST request) { - String operation = attributesExtractor.dbOperation(request); - String dbName = attributesExtractor.dbName(request); + String operation = attributesExtractor.operation(request); + String dbName = attributesExtractor.name(request); if (operation == null) { return dbName == null ? DEFAULT_SPAN_NAME : dbName; } @@ -58,7 +58,7 @@ public String extract(REQUEST request) { @Nullable private String getTableName(REQUEST request) { if (attributesExtractor instanceof SqlAttributesExtractor) { - return ((SqlAttributesExtractor) attributesExtractor).dbTable(request); + return ((SqlAttributesExtractor) attributesExtractor).table(request); } return null; } diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/SqlAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/SqlAttributesExtractor.java index 71dc39d74cd7..fe3b4536614a 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/SqlAttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/SqlAttributesExtractor.java @@ -29,35 +29,35 @@ protected final void onStart(AttributesBuilder attributes, REQUEST request) { super.onStart(attributes, request); AttributeKey dbTable = dbTableAttribute(); if (dbTable != null) { - set(attributes, dbTable, dbTable(request)); + set(attributes, dbTable, table(request)); } } @Nullable @Override - protected final String dbStatement(REQUEST request) { + protected final String statement(REQUEST request) { return sanitize(request).getFullStatement(); } @Nullable @Override - protected final String dbOperation(REQUEST request) { + protected final String operation(REQUEST request) { return sanitize(request).getOperation(); } @Nullable - protected final String dbTable(REQUEST request) { + protected final String table(REQUEST request) { return sanitize(request).getTable(); } private SqlStatementInfo sanitize(REQUEST request) { // sanitized statement is cached - return SqlStatementSanitizer.sanitize(rawDbStatement(request)); + return SqlStatementSanitizer.sanitize(rawStatement(request)); } @Nullable protected abstract AttributeKey dbTableAttribute(); @Nullable - protected abstract String rawDbStatement(REQUEST request); + protected abstract String rawStatement(REQUEST request); } diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/HttpAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpAttributesExtractor.java similarity index 96% rename from instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/HttpAttributesExtractor.java rename to instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpAttributesExtractor.java index c83eb567b3be..a8731a52133b 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/HttpAttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpAttributesExtractor.java @@ -3,9 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.api.instrumenter; +package io.opentelemetry.instrumentation.api.instrumenter.http; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.checkerframework.checker.nullness.qual.Nullable; diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanNameExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanNameExtractor.java new file mode 100644 index 000000000000..949dfb976bce --- /dev/null +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanNameExtractor.java @@ -0,0 +1,45 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.http; + +import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; + +/** + * Extractor of the HTTP + * span name. Instrumentation of HTTP server or client frameworks should use this class to + * comply with OpenTelemetry HTTP semantic conventions. + */ +public final class HttpSpanNameExtractor implements SpanNameExtractor { + + /** + * Returns a {@link SpanNameExtractor} which should be used for HTTP requests. HTTP attributes + * will be examined to determine the name of the span. + */ + public static SpanNameExtractor create( + HttpAttributesExtractor attributesExtractor) { + return new HttpSpanNameExtractor<>(attributesExtractor); + } + + private final HttpAttributesExtractor attributesExtractor; + + private HttpSpanNameExtractor(HttpAttributesExtractor attributesExtractor) { + this.attributesExtractor = attributesExtractor; + } + + @Override + public String extract(REQUEST request) { + String route = attributesExtractor.route(request); + if (route != null) { + return route; + } + String method = attributesExtractor.method(request); + if (method != null) { + return "HTTP " + method; + } + return "HTTP request"; + } +} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanStatusExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanStatusExtractor.java new file mode 100644 index 000000000000..2e6d664f535d --- /dev/null +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanStatusExtractor.java @@ -0,0 +1,45 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.http; + +import io.opentelemetry.api.trace.StatusCode; +import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor; +import io.opentelemetry.instrumentation.api.tracer.HttpStatusConverter; + +/** + * Extractor of the HTTP + * span status. Instrumentation of HTTP server or client frameworks should use this class to + * comply with OpenTelemetry HTTP semantic conventions. + */ +public final class HttpSpanStatusExtractor + implements SpanStatusExtractor { + + /** + * Returns the {@link SpanStatusExtractor} for HTTP requests, which will use the HTTP status code + * to determine the {@link StatusCode} if available or fallback to {@linkplain #getDefault() the + * default status} otherwise. + */ + public static SpanStatusExtractor create( + HttpAttributesExtractor attributesExtractor) { + return new HttpSpanStatusExtractor<>(attributesExtractor); + } + + private final HttpAttributesExtractor attributesExtractor; + + private HttpSpanStatusExtractor(HttpAttributesExtractor attributesExtractor) { + this.attributesExtractor = attributesExtractor; + } + + @Override + public StatusCode extract(REQUEST request, RESPONSE response, Throwable error) { + Long statusCode = attributesExtractor.statusCode(request, response); + if (statusCode != null) { + return HttpStatusConverter.statusFromHttpStatus(statusCode.intValue()); + } + return SpanStatusExtractor.getDefault().extract(request, response, error); + } +} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/InetSocketAddressNetAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetAttributesExtractor.java similarity index 74% rename from instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/InetSocketAddressNetAttributesExtractor.java rename to instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetAttributesExtractor.java index c44e6910dac0..60074bb8bdcd 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/InetSocketAddressNetAttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetAttributesExtractor.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.api.instrumenter; +package io.opentelemetry.instrumentation.api.instrumenter.net; import java.net.InetAddress; import java.net.InetSocketAddress; @@ -19,12 +19,17 @@ public abstract class InetSocketAddressNetAttributesExtractor extends NetAttributesExtractor { + /** + * This method will be called twice: both when the request starts ({@code response} is always null + * then) and when the response ends. This way it is possible to capture net attributes in both + * phases of processing. + */ @Nullable - protected abstract InetSocketAddress getAddress(REQUEST request, RESPONSE response); + protected abstract InetSocketAddress getAddress(REQUEST request, @Nullable RESPONSE response); @Override @Nullable - protected final String peerName(REQUEST request, RESPONSE response) { + protected final String peerName(REQUEST request, @Nullable RESPONSE response) { InetSocketAddress address = getAddress(request, response); if (address == null) { return null; @@ -37,7 +42,7 @@ protected final String peerName(REQUEST request, RESPONSE response) { @Override @Nullable - protected final Long peerPort(REQUEST request, RESPONSE response) { + protected final Long peerPort(REQUEST request, @Nullable RESPONSE response) { InetSocketAddress address = getAddress(request, response); if (address == null) { return null; @@ -47,7 +52,7 @@ protected final Long peerPort(REQUEST request, RESPONSE response) { @Override @Nullable - protected final String peerIp(REQUEST request, RESPONSE response) { + protected final String peerIp(REQUEST request, @Nullable RESPONSE response) { InetSocketAddress address = getAddress(request, response); if (address == null) { return null; diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/NetAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetAttributesExtractor.java similarity index 51% rename from instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/NetAttributesExtractor.java rename to instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetAttributesExtractor.java index afc08ed310fa..4ea348ecc428 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/NetAttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetAttributesExtractor.java @@ -3,9 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.api.instrumenter; +package io.opentelemetry.instrumentation.api.instrumenter.net; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.checkerframework.checker.nullness.qual.Nullable; @@ -21,15 +22,14 @@ public abstract class NetAttributesExtractor @Override protected final void onStart(AttributesBuilder attributes, REQUEST request) { set(attributes, SemanticAttributes.NET_TRANSPORT, transport(request)); + set(attributes, SemanticAttributes.NET_PEER_IP, peerIp(request, null)); + set(attributes, SemanticAttributes.NET_PEER_NAME, peerName(request, null)); + set(attributes, SemanticAttributes.NET_PEER_PORT, peerPort(request, null)); } @Override protected final void onEnd(AttributesBuilder attributes, REQUEST request, RESPONSE response) { set(attributes, SemanticAttributes.NET_PEER_IP, peerIp(request, response)); - - // TODO(anuraaga): Clients don't have peer information available during the request usually. - // By only resolving them after the response, we can simplify the code a lot but sacrifice - // having them available during sampling on the server side. Revisit if that seems important. set(attributes, SemanticAttributes.NET_PEER_NAME, peerName(request, response)); set(attributes, SemanticAttributes.NET_PEER_PORT, peerPort(request, response)); } @@ -37,12 +37,27 @@ protected final void onEnd(AttributesBuilder attributes, REQUEST request, RESPON @Nullable protected abstract String transport(REQUEST request); + /** + * This method will be called twice: both when the request starts ({@code response} is always null + * then) and when the response ends. This way it is possible to capture net attributes in both + * phases of processing. + */ @Nullable - protected abstract String peerName(REQUEST request, RESPONSE response); + protected abstract String peerName(REQUEST request, @Nullable RESPONSE response); + /** + * This method will be called twice: both when the request starts ({@code response} is always null + * then) and when the response ends. This way it is possible to capture net attributes in both + * phases of processing. + */ @Nullable - protected abstract Long peerPort(REQUEST request, RESPONSE response); + protected abstract Long peerPort(REQUEST request, @Nullable RESPONSE response); + /** + * This method will be called twice: both when the request starts ({@code response} is always null + * then) and when the response ends. This way it is possible to capture net attributes in both + * phases of processing. + */ @Nullable - protected abstract String peerIp(REQUEST request, RESPONSE response); + protected abstract String peerIp(REQUEST request, @Nullable RESPONSE response); } diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbAttributesExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbAttributesExtractorTest.java index 9652bb85a0bb..3ddd244a74bb 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbAttributesExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbAttributesExtractorTest.java @@ -20,32 +20,32 @@ class DbAttributesExtractorTest { DbAttributesExtractor> underTest = new DbAttributesExtractor>() { @Override - protected String dbSystem(Map map) { + protected String system(Map map) { return map.get("db.system"); } @Override - protected String dbUser(Map map) { + protected String user(Map map) { return map.get("db.user"); } @Override - protected String dbName(Map map) { + protected String name(Map map) { return map.get("db.name"); } @Override - protected String dbConnectionString(Map map) { + protected String connectionString(Map map) { return map.get("db.connection_string"); } @Override - protected String dbStatement(Map map) { + protected String statement(Map map) { return map.get("db.statement"); } @Override - protected String dbOperation(Map map) { + protected String operation(Map map) { return map.get("db.operation"); } }; diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbSpanNameExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbSpanNameExtractorTest.java index 0ab2f079a1a7..253a3daae865 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbSpanNameExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbSpanNameExtractorTest.java @@ -25,8 +25,8 @@ void shouldExtractFullSpanName() { DbRequest dbRequest = new DbRequest(); // cannot stub dbOperation() and dbTable() because they're final - given(sqlAttributesExtractor.rawDbStatement(dbRequest)).willReturn("SELECT * FROM table"); - given(sqlAttributesExtractor.dbName(dbRequest)).willReturn("database"); + given(sqlAttributesExtractor.rawStatement(dbRequest)).willReturn("SELECT * FROM table"); + given(sqlAttributesExtractor.name(dbRequest)).willReturn("database"); SpanNameExtractor underTest = DbSpanNameExtractor.create(sqlAttributesExtractor); @@ -43,7 +43,7 @@ void shouldExtractOperationAndTable() { DbRequest dbRequest = new DbRequest(); // cannot stub dbOperation() and dbTable() because they're final - given(sqlAttributesExtractor.rawDbStatement(dbRequest)).willReturn("SELECT * FROM table"); + given(sqlAttributesExtractor.rawStatement(dbRequest)).willReturn("SELECT * FROM table"); SpanNameExtractor underTest = DbSpanNameExtractor.create(sqlAttributesExtractor); @@ -59,8 +59,8 @@ void shouldExtractOperationAndName() { // given DbRequest dbRequest = new DbRequest(); - given(dbAttributesExtractor.dbOperation(dbRequest)).willReturn("SELECT"); - given(dbAttributesExtractor.dbName(dbRequest)).willReturn("database"); + given(dbAttributesExtractor.operation(dbRequest)).willReturn("SELECT"); + given(dbAttributesExtractor.name(dbRequest)).willReturn("database"); SpanNameExtractor underTest = DbSpanNameExtractor.create(dbAttributesExtractor); @@ -76,7 +76,7 @@ void shouldExtractOperation() { // given DbRequest dbRequest = new DbRequest(); - given(dbAttributesExtractor.dbOperation(dbRequest)).willReturn("SELECT"); + given(dbAttributesExtractor.operation(dbRequest)).willReturn("SELECT"); SpanNameExtractor underTest = DbSpanNameExtractor.create(dbAttributesExtractor); @@ -92,7 +92,7 @@ void shouldExtractDbName() { // given DbRequest dbRequest = new DbRequest(); - given(dbAttributesExtractor.dbName(dbRequest)).willReturn("database"); + given(dbAttributesExtractor.name(dbRequest)).willReturn("database"); SpanNameExtractor underTest = DbSpanNameExtractor.create(dbAttributesExtractor); diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/SqlAttributesExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/SqlAttributesExtractorTest.java index 80f209cd5b9d..2b8dbcd82403 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/SqlAttributesExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/SqlAttributesExtractorTest.java @@ -28,27 +28,27 @@ protected AttributeKey dbTableAttribute() { } @Override - protected String rawDbStatement(Map map) { + protected String rawStatement(Map map) { return map.get("db.statement"); } @Override - protected String dbSystem(Map map) { + protected String system(Map map) { return map.get("db.system"); } @Override - protected String dbUser(Map map) { + protected String user(Map map) { return map.get("db.user"); } @Override - protected String dbName(Map map) { + protected String name(Map map) { return map.get("db.name"); } @Override - protected String dbConnectionString(Map map) { + protected String connectionString(Map map) { return map.get("db.connection_string"); } }; diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/HttpAttributesExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpAttributesExtractorTest.java similarity index 98% rename from instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/HttpAttributesExtractorTest.java rename to instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpAttributesExtractorTest.java index 00ae984331c4..72c695d81c2b 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/HttpAttributesExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpAttributesExtractorTest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.api.instrumenter; +package io.opentelemetry.instrumentation.api.instrumenter.http; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static org.assertj.core.api.Assertions.entry; diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/HttpSpanNameExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanNameExtractorTest.java similarity index 77% rename from instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/HttpSpanNameExtractorTest.java rename to instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanNameExtractorTest.java index b4ca5b62fe7e..7abe98c69d50 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/HttpSpanNameExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanNameExtractorTest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.api.instrumenter; +package io.opentelemetry.instrumentation.api.instrumenter.http; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.anyMap; @@ -28,20 +28,20 @@ class HttpSpanNameExtractorTest { void routeAndMethod() { when(extractor.route(anyMap())).thenReturn("/cats/{id}"); when(extractor.method(anyMap())).thenReturn("GET"); - assertThat(SpanNameExtractor.http(extractor).extract(Collections.emptyMap())) + assertThat(HttpSpanNameExtractor.create(extractor).extract(Collections.emptyMap())) .isEqualTo("/cats/{id}"); } @Test void method() { when(extractor.method(anyMap())).thenReturn("GET"); - assertThat(SpanNameExtractor.http(extractor).extract(Collections.emptyMap())) + assertThat(HttpSpanNameExtractor.create(extractor).extract(Collections.emptyMap())) .isEqualTo("HTTP GET"); } @Test void nothing() { - assertThat(SpanNameExtractor.http(extractor).extract(Collections.emptyMap())) + assertThat(HttpSpanNameExtractor.create(extractor).extract(Collections.emptyMap())) .isEqualTo("HTTP request"); } } diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/HttpSpanStatusExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanStatusExtractorTest.java similarity index 89% rename from instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/HttpSpanStatusExtractorTest.java rename to instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanStatusExtractorTest.java index 3d9b4f37c56d..4b5b4bdd91fb 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/HttpSpanStatusExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanStatusExtractorTest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.api.instrumenter; +package io.opentelemetry.instrumentation.api.instrumenter.http; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.anyMap; @@ -30,7 +30,7 @@ void hasStatus(long statusCode) { when(extractor.statusCode(anyMap(), anyMap())).thenReturn(statusCode); assertThat( - SpanStatusExtractor.http(extractor) + HttpSpanStatusExtractor.create(extractor) .extract(Collections.emptyMap(), Collections.emptyMap(), null)) .isEqualTo(HttpStatusConverter.statusFromHttpStatus((int) statusCode)); } @@ -42,7 +42,7 @@ void hasStatus_ignoresException(long statusCode) { // Presence of exception has no effect. assertThat( - SpanStatusExtractor.http(extractor) + HttpSpanStatusExtractor.create(extractor) .extract( Collections.emptyMap(), Collections.emptyMap(), new IllegalStateException())) .isEqualTo(HttpStatusConverter.statusFromHttpStatus((int) statusCode)); @@ -53,7 +53,7 @@ void fallsBackToDefault_unset() { when(extractor.statusCode(anyMap(), anyMap())).thenReturn(null); assertThat( - SpanStatusExtractor.http(extractor) + HttpSpanStatusExtractor.create(extractor) .extract(Collections.emptyMap(), Collections.emptyMap(), null)) .isEqualTo(StatusCode.UNSET); } @@ -63,7 +63,7 @@ void fallsBackToDefault_error() { when(extractor.statusCode(anyMap(), anyMap())).thenReturn(null); assertThat( - SpanStatusExtractor.http(extractor) + HttpSpanStatusExtractor.create(extractor) .extract( Collections.emptyMap(), Collections.emptyMap(), new IllegalStateException())) .isEqualTo(StatusCode.ERROR); diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InetSocketAddressNetAttributesExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetAttributesExtractorTest.java similarity index 56% rename from instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InetSocketAddressNetAttributesExtractorTest.java rename to instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetAttributesExtractorTest.java index 561e1477172a..d670c7597f3e 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InetSocketAddressNetAttributesExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetAttributesExtractorTest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.api.instrumenter; +package io.opentelemetry.instrumentation.api.instrumenter.net; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static org.assertj.core.api.Assertions.entry; @@ -19,18 +19,20 @@ @ExtendWith(MockitoExtension.class) class InetSocketAddressNetAttributesExtractorTest { - private final InetSocketAddressNetAttributesExtractor extractor = - new InetSocketAddressNetAttributesExtractor() { - @Override - protected InetSocketAddress getAddress(InetSocketAddress inetSocketAddress, Void unused) { - return inetSocketAddress; - } + private final InetSocketAddressNetAttributesExtractor + extractor = + new InetSocketAddressNetAttributesExtractor() { + @Override + protected InetSocketAddress getAddress( + InetSocketAddress request, InetSocketAddress response) { + return response != null ? response : request; + } - @Override - protected String transport(InetSocketAddress inetSocketAddress) { - return SemanticAttributes.NetTransportValues.IP_TCP.getValue(); - } - }; + @Override + protected String transport(InetSocketAddress inetSocketAddress) { + return SemanticAttributes.NetTransportValues.IP_TCP.getValue(); + } + }; @Test void noInetSocketAddress() { @@ -46,19 +48,19 @@ void noInetSocketAddress() { @Test void fullAddress() { + // given InetSocketAddress address = new InetSocketAddress("github.com", 123); assertThat(address.getAddress().getHostAddress()).isNotNull(); - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, address); - assertThat(attributes.build()) - .containsOnly( - entry( - SemanticAttributes.NET_TRANSPORT, - SemanticAttributes.NetTransportValues.IP_TCP.getValue())); + // when + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, address); - extractor.onEnd(attributes, address, null); - assertThat(attributes.build()) + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, null, address); + + // then + assertThat(startAttributes.build()) .containsOnly( entry( SemanticAttributes.NET_TRANSPORT, @@ -66,28 +68,39 @@ void fullAddress() { entry(SemanticAttributes.NET_PEER_IP, address.getAddress().getHostAddress()), entry(SemanticAttributes.NET_PEER_NAME, "github.com"), entry(SemanticAttributes.NET_PEER_PORT, 123L)); + + assertThat(endAttributes.build()) + .containsOnly( + entry(SemanticAttributes.NET_PEER_IP, address.getAddress().getHostAddress()), + entry(SemanticAttributes.NET_PEER_NAME, "github.com"), + entry(SemanticAttributes.NET_PEER_PORT, 123L)); } @Test void unresolved() { + // given InetSocketAddress address = InetSocketAddress.createUnresolved("github.com", 123); assertThat(address.getAddress()).isNull(); - AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, address); - assertThat(attributes.build()) - .containsOnly( - entry( - SemanticAttributes.NET_TRANSPORT, - SemanticAttributes.NetTransportValues.IP_TCP.getValue())); + // when + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, address); - extractor.onEnd(attributes, address, null); - assertThat(attributes.build()) + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, null, address); + + // then + assertThat(startAttributes.build()) .containsOnly( entry( SemanticAttributes.NET_TRANSPORT, SemanticAttributes.NetTransportValues.IP_TCP.getValue()), entry(SemanticAttributes.NET_PEER_NAME, "github.com"), entry(SemanticAttributes.NET_PEER_PORT, 123L)); + + assertThat(endAttributes.build()) + .containsOnly( + entry(SemanticAttributes.NET_PEER_NAME, "github.com"), + entry(SemanticAttributes.NET_PEER_PORT, 123L)); } } diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/NetAttributesExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetAttributesExtractorTest.java similarity index 61% rename from instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/NetAttributesExtractorTest.java rename to instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetAttributesExtractorTest.java index 3b37886c3251..673077cf1e36 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/NetAttributesExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetAttributesExtractorTest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.api.instrumenter; +package io.opentelemetry.instrumentation.api.instrumenter.net; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static org.assertj.core.api.Assertions.entry; @@ -11,7 +11,6 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import org.junit.jupiter.api.Test; @@ -28,37 +27,64 @@ protected String transport(Map request) { @Override protected String peerName(Map request, Map response) { + if (response != null) { + return response.get("peerName"); + } return request.get("peerName"); } @Override protected Long peerPort(Map request, Map response) { - return Long.parseLong(request.get("peerPort")); + if (response != null) { + return Long.valueOf(response.get("peerPort")); + } + return Long.valueOf(request.get("peerPort")); } @Override protected String peerIp(Map request, Map response) { + if (response != null) { + return response.get("peerIp"); + } return request.get("peerIp"); } } @Test void normal() { + // given Map request = new HashMap<>(); request.put("transport", "TCP"); request.put("peerName", "github.com"); request.put("peerPort", "123"); request.put("peerIp", "1.2.3.4"); - AttributesBuilder attributes = Attributes.builder(); + + Map response = new HashMap<>(); + response.put("peerName", "opentelemetry.io"); + response.put("peerPort", "42"); + response.put("peerIp", "4.3.2.1"); + TestNetAttributesExtractor extractor = new TestNetAttributesExtractor(); - extractor.onStart(attributes, request); - assertThat(attributes.build()).containsOnly(entry(SemanticAttributes.NET_TRANSPORT, "TCP")); - extractor.onEnd(attributes, request, Collections.emptyMap()); - assertThat(attributes.build()) + + // when + AttributesBuilder startAttributes = Attributes.builder(); + extractor.onStart(startAttributes, request); + + AttributesBuilder endAttributes = Attributes.builder(); + extractor.onEnd(endAttributes, request, response); + + // then + assertThat(startAttributes.build()) .containsOnly( entry(SemanticAttributes.NET_TRANSPORT, "TCP"), entry(SemanticAttributes.NET_PEER_NAME, "github.com"), entry(SemanticAttributes.NET_PEER_PORT, 123L), entry(SemanticAttributes.NET_PEER_IP, "1.2.3.4")); + + assertThat(endAttributes.build()) + .containsOnly( + entry(SemanticAttributes.NET_PEER_NAME, "opentelemetry.io"), + entry(SemanticAttributes.NET_PEER_PORT, 42L), + entry(SemanticAttributes.NET_PEER_IP, "4.3.2.1")); } } diff --git a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpAttributesExtractor.java b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpAttributesExtractor.java index 35069200ed2d..8e31fd3c29aa 100644 --- a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpAttributesExtractor.java +++ b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpAttributesExtractor.java @@ -12,7 +12,7 @@ import com.linecorp.armeria.common.SessionProtocol; import com.linecorp.armeria.common.logging.RequestLog; import com.linecorp.armeria.server.ServiceRequestContext; -import io.opentelemetry.instrumentation.api.instrumenter.HttpAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.checkerframework.checker.nullness.qual.Nullable; diff --git a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaNetAttributesExtractor.java b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaNetAttributesExtractor.java index 58ad825f9943..d3a38ef4589f 100644 --- a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaNetAttributesExtractor.java +++ b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaNetAttributesExtractor.java @@ -7,7 +7,7 @@ import com.linecorp.armeria.common.RequestContext; import com.linecorp.armeria.common.logging.RequestLog; -import io.opentelemetry.instrumentation.api.instrumenter.InetSocketAddressNetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetAttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; import java.net.SocketAddress; @@ -23,7 +23,8 @@ protected String transport(RequestContext requestContext) { @Override @Nullable - protected InetSocketAddress getAddress(RequestContext requestContext, RequestLog requestLog) { + protected InetSocketAddress getAddress( + RequestContext requestContext, @Nullable RequestLog requestLog) { SocketAddress address = requestContext.remoteAddress(); if (address instanceof InetSocketAddress) { return (InetSocketAddress) address; diff --git a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTracingBuilder.java b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTracingBuilder.java index fb4f2270b580..636d7f8f10a6 100644 --- a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTracingBuilder.java +++ b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTracingBuilder.java @@ -15,6 +15,8 @@ import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; import java.util.ArrayList; import java.util.List; import java.util.function.Function; @@ -62,9 +64,9 @@ public ArmeriaTracing build() { ArmeriaNetAttributesExtractor netAttributesExtractor = new ArmeriaNetAttributesExtractor(); SpanNameExtractor spanNameExtractor = - SpanNameExtractor.http(httpAttributesExtractor); + HttpSpanNameExtractor.create(httpAttributesExtractor); SpanStatusExtractor spanStatusExtractor = - statusExtractorTransformer.apply(SpanStatusExtractor.http(httpAttributesExtractor)); + statusExtractorTransformer.apply(HttpSpanStatusExtractor.create(httpAttributesExtractor)); InstrumenterBuilder clientInstrumenterBuilder = Instrumenter.newBuilder(openTelemetry, INSTRUMENTATION_NAME, spanNameExtractor); diff --git a/instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/JdbcAttributesExtractor.java b/instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/JdbcAttributesExtractor.java index 4aab1381a444..100008c97e74 100644 --- a/instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/JdbcAttributesExtractor.java +++ b/instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/JdbcAttributesExtractor.java @@ -13,26 +13,26 @@ final class JdbcAttributesExtractor extends SqlAttributesExtractor { @Nullable @Override - protected String dbSystem(DbRequest dbRequest) { + protected String system(DbRequest dbRequest) { return dbRequest.getDbInfo().getSystem(); } @Nullable @Override - protected String dbUser(DbRequest dbRequest) { + protected String user(DbRequest dbRequest) { return dbRequest.getDbInfo().getUser(); } @Nullable @Override - protected String dbName(DbRequest dbRequest) { + protected String name(DbRequest dbRequest) { DbInfo dbInfo = dbRequest.getDbInfo(); return dbInfo.getName() == null ? dbInfo.getDb() : dbInfo.getName(); } @Nullable @Override - protected String dbConnectionString(DbRequest dbRequest) { + protected String connectionString(DbRequest dbRequest) { return dbRequest.getDbInfo().getShortUrl(); } @@ -43,7 +43,7 @@ protected AttributeKey dbTableAttribute() { @Nullable @Override - protected String rawDbStatement(DbRequest dbRequest) { + protected String rawStatement(DbRequest dbRequest) { return dbRequest.getStatement(); } } diff --git a/instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/JdbcNetAttributesExtractor.java b/instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/JdbcNetAttributesExtractor.java index 733dcd4fe274..38e8d5e999a4 100644 --- a/instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/JdbcNetAttributesExtractor.java +++ b/instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/JdbcNetAttributesExtractor.java @@ -5,7 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.jdbc; -import io.opentelemetry.instrumentation.api.instrumenter.NetAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor; import org.checkerframework.checker.nullness.qual.Nullable; final class JdbcNetAttributesExtractor extends NetAttributesExtractor { @@ -18,20 +18,20 @@ protected String transport(DbRequest dbRequest) { @Nullable @Override - protected String peerName(DbRequest request, Void unused) { + protected String peerName(DbRequest request, @Nullable Void response) { return request.getDbInfo().getHost(); } @Nullable @Override - protected Long peerPort(DbRequest request, Void unused) { + protected Long peerPort(DbRequest request, @Nullable Void response) { Integer port = request.getDbInfo().getPort(); return port == null ? null : port.longValue(); } @Nullable @Override - protected String peerIp(DbRequest request, Void unused) { + protected String peerIp(DbRequest request, @Nullable Void response) { return null; } }