Skip to content

Commit

Permalink
Semconv 1.25.0 migration (#10983)
Browse files Browse the repository at this point in the history
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
  • Loading branch information
SylvainJuge and renovate[bot] authored Apr 9, 2024
1 parent 0bc2372 commit 955470a
Show file tree
Hide file tree
Showing 417 changed files with 6,396 additions and 5,685 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ tasks.withType<ShadowJar>().configureEach {
// relocate(OpenTelemetry API) since these classes live in the bootstrap class loader
relocate("io.opentelemetry.api", "io.opentelemetry.javaagent.shaded.io.opentelemetry.api")
relocate("io.opentelemetry.semconv", "io.opentelemetry.javaagent.shaded.io.opentelemetry.semconv")
relocate("io.opentelemetry.semconv.incubating", "io.opentelemetry.javaagent.shaded.io.opentelemetry.semconv.incubating")
relocate("io.opentelemetry.context", "io.opentelemetry.javaagent.shaded.io.opentelemetry.context")
relocate("io.opentelemetry.extension.incubator", "io.opentelemetry.javaagent.shaded.io.opentelemetry.extension.incubator")
}
Expand Down
4 changes: 3 additions & 1 deletion dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ val asmVersion = "9.7"
val jmhVersion = "1.37"
val mockitoVersion = "4.11.0"
val slf4jVersion = "2.0.12"
val semConvVersion = "1.25.0-alpha"

val CORE_DEPENDENCIES = listOf(
"io.opentelemetry.semconv:opentelemetry-semconv:1.23.1-alpha",
"io.opentelemetry.semconv:opentelemetry-semconv:${semConvVersion}",
"io.opentelemetry.semconv:opentelemetry-semconv-incubating:${semConvVersion}",
"com.google.auto.service:auto-service:${autoServiceVersion}",
"com.google.auto.service:auto-service-annotations:${autoServiceVersion}",
"com.google.auto.value:auto-value:${autoValueVersion}",
Expand Down
1 change: 1 addition & 0 deletions examples/distro/gradle/shadow.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ext.relocatePackages = { shadowJar ->
// relocate(OpenTelemetry API) since these classes live in the bootstrap class loader
shadowJar.relocate("io.opentelemetry.api", "io.opentelemetry.javaagent.shaded.io.opentelemetry.api")
shadowJar.relocate("io.opentelemetry.semconv", "io.opentelemetry.javaagent.shaded.io.opentelemetry.semconv")
shadowJar.relocate("io.opentelemetry.semconv.incubating", "io.opentelemetry.javaagent.shaded.io.opentelemetry.semconv.incubating")
shadowJar.relocate("io.opentelemetry.context", "io.opentelemetry.javaagent.shaded.io.opentelemetry.context")
shadowJar.relocate("io.opentelemetry.extension.incubator", "io.opentelemetry.javaagent.shaded.io.opentelemetry.extension.incubator")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import static io.opentelemetry.api.common.AttributeKey.booleanKey;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.semconv.SemanticAttributes.CODE_FUNCTION;
import static io.opentelemetry.semconv.SemanticAttributes.CODE_NAMESPACE;
import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_FUNCTION;
import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_NAMESPACE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;

Expand Down
1 change: 1 addition & 0 deletions instrumentation-annotations-support/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {

api("io.opentelemetry:opentelemetry-api")
api("io.opentelemetry.semconv:opentelemetry-semconv")
api("io.opentelemetry.semconv:opentelemetry-semconv-incubating")

compileOnly("com.google.auto.value:auto-value-annotations")
annotationProcessor("com.google.auto.value:auto-value")
Expand Down
1 change: 1 addition & 0 deletions instrumentation-api-incubator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ group = "io.opentelemetry.instrumentation"

dependencies {
api("io.opentelemetry.semconv:opentelemetry-semconv")
api("io.opentelemetry.semconv:opentelemetry-semconv-incubating")
api(project(":instrumentation-api"))
implementation("io.opentelemetry:opentelemetry-extension-incubator")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes;
import javax.annotation.Nullable;

/**
Expand All @@ -37,9 +37,9 @@ private CodeAttributesExtractor(CodeAttributesGetter<REQUEST> getter) {
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
Class<?> cls = getter.getCodeClass(request);
if (cls != null) {
internalSet(attributes, SemanticAttributes.CODE_NAMESPACE, cls.getName());
internalSet(attributes, CodeIncubatingAttributes.CODE_NAMESPACE, cls.getName());
}
internalSet(attributes, SemanticAttributes.CODE_FUNCTION, getter.getMethodName(request));
internalSet(attributes, CodeIncubatingAttributes.CODE_FUNCTION, getter.getMethodName(request));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;

/**
* Extractor of <a
Expand Down Expand Up @@ -38,7 +38,7 @@ public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
super.onStart(attributes, parentContext, request);

internalSet(attributes, SemanticAttributes.DB_STATEMENT, getter.getStatement(request));
internalSet(attributes, SemanticAttributes.DB_OPERATION, getter.getOperation(request));
internalSet(attributes, DbIncubatingAttributes.DB_STATEMENT, getter.getStatement(request));
internalSet(attributes, DbIncubatingAttributes.DB_OPERATION, getter.getOperation(request));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.internal.SpanKey;
import io.opentelemetry.instrumentation.api.internal.SpanKeyProvider;
import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;
import javax.annotation.Nullable;

abstract class DbClientCommonAttributesExtractor<
Expand All @@ -25,13 +25,16 @@ abstract class DbClientCommonAttributesExtractor<
this.getter = getter;
}

@SuppressWarnings("deprecation") // TODO DbIncubatingAttributes.DB_CONNECTION_STRING deprecation
@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
internalSet(attributes, SemanticAttributes.DB_SYSTEM, getter.getSystem(request));
internalSet(attributes, SemanticAttributes.DB_USER, getter.getUser(request));
internalSet(attributes, SemanticAttributes.DB_NAME, getter.getName(request));
internalSet(attributes, DbIncubatingAttributes.DB_SYSTEM, getter.getSystem(request));
internalSet(attributes, DbIncubatingAttributes.DB_USER, getter.getUser(request));
internalSet(attributes, DbIncubatingAttributes.DB_NAME, getter.getName(request));
internalSet(
attributes, SemanticAttributes.DB_CONNECTION_STRING, getter.getConnectionString(request));
attributes,
DbIncubatingAttributes.DB_CONNECTION_STRING,
getter.getConnectionString(request));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;

/**
* Extractor of <a
* href="https://github.com/open-telemetry/semantic-conventions/blob/main/docs/database/database-spans.md">database
* attributes</a>. This class is designed with SQL (or SQL-like) database clients in mind.
*
* <p>It sets the same set of attributes as {@link DbClientAttributesExtractor} plus an additional
* <code>{@linkplain SemanticAttributes#DB_SQL_TABLE db.sql.table}</code> attribute. The raw SQL
* statements returned by the {@link SqlClientAttributesGetter#getRawStatement(Object)} method are
* sanitized before use, all statement parameters are removed.
* <code>{@link DbIncubatingAttributes#DB_SQL_TABLE}</code> attribute. The raw SQL statements
* returned by the {@link SqlClientAttributesGetter#getRawStatement(Object)} method are sanitized
* before use, all statement parameters are removed.
*/
public final class SqlClientAttributesExtractor<REQUEST, RESPONSE>
extends DbClientCommonAttributesExtractor<
Expand Down Expand Up @@ -62,8 +62,9 @@ public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST

SqlStatementInfo sanitizedStatement = sanitizer.sanitize(getter.getRawStatement(request));
String operation = sanitizedStatement.getOperation();
internalSet(attributes, SemanticAttributes.DB_STATEMENT, sanitizedStatement.getFullStatement());
internalSet(attributes, SemanticAttributes.DB_OPERATION, operation);
internalSet(
attributes, DbIncubatingAttributes.DB_STATEMENT, sanitizedStatement.getFullStatement());
internalSet(attributes, DbIncubatingAttributes.DB_OPERATION, operation);
if (!SQL_CALL.equals(operation)) {
internalSet(attributes, dbTableAttribute, sanitizedStatement.getMainIdentifier());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;

/** A builder of {@link SqlClientAttributesExtractor}. */
public final class SqlClientAttributesExtractorBuilder<REQUEST, RESPONSE> {

final SqlClientAttributesGetter<REQUEST> getter;
AttributeKey<String> dbTableAttribute = SemanticAttributes.DB_SQL_TABLE;
AttributeKey<String> dbTableAttribute = DbIncubatingAttributes.DB_SQL_TABLE;
boolean statementSanitizationEnabled = true;

SqlClientAttributesExtractorBuilder(SqlClientAttributesGetter<REQUEST> getter) {
Expand All @@ -26,7 +26,7 @@ public final class SqlClientAttributesExtractorBuilder<REQUEST, RESPONSE> {
/**
* Configures the extractor to set the table value extracted by the {@link
* SqlClientAttributesExtractor} under the {@code dbTableAttribute} key. By default, the <code>
* {@linkplain SemanticAttributes#DB_SQL_TABLE db.sql.table}</code> attribute is used.
* {@link DbIncubatingAttributes#DB_SQL_TABLE}</code> attribute is used.
*
* @param dbTableAttribute The {@link AttributeKey} under which the table extracted by the {@link
* SqlClientAttributesExtractor} will be stored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import io.opentelemetry.instrumentation.api.incubator.semconv.net.internal.UrlParser;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesGetter;
import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.semconv.incubating.PeerIncubatingAttributes;
import java.util.function.Supplier;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -67,7 +67,7 @@ public void onEnd(
Supplier<String> pathSupplier = () -> getUrlPath(attributesGetter, request);
String peerService = mapToPeerService(serverAddress, serverPort, pathSupplier);
if (peerService != null) {
attributes.put(SemanticAttributes.PEER_SERVICE, peerService);
attributes.put(PeerIncubatingAttributes.PEER_SERVICE, peerService);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesGetter;
import io.opentelemetry.instrumentation.api.semconv.http.HttpCommonAttributesGetter;
import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesGetter;
import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.semconv.incubating.HttpIncubatingAttributes;
import java.util.List;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -49,11 +49,11 @@ public void onEnd(
@Nullable Throwable error) {

Long requestBodySize = requestBodySize(request);
internalSet(attributes, SemanticAttributes.HTTP_REQUEST_BODY_SIZE, requestBodySize);
internalSet(attributes, HttpIncubatingAttributes.HTTP_REQUEST_BODY_SIZE, requestBodySize);

if (response != null) {
Long responseBodySize = responseBodySize(request, response);
internalSet(attributes, SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, responseBodySize);
internalSet(attributes, HttpIncubatingAttributes.HTTP_RESPONSE_BODY_SIZE, responseBodySize);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
import io.opentelemetry.api.metrics.LongUpDownCounterBuilder;
import io.opentelemetry.extension.incubator.metrics.ExtendedLongHistogramBuilder;
import io.opentelemetry.extension.incubator.metrics.ExtendedLongUpDownCounterBuilder;
import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.semconv.ErrorAttributes;
import io.opentelemetry.semconv.HttpAttributes;
import io.opentelemetry.semconv.NetworkAttributes;
import io.opentelemetry.semconv.ServerAttributes;
import io.opentelemetry.semconv.UrlAttributes;

final class HttpExperimentalMetricsAdvice {

Expand All @@ -22,13 +26,13 @@ static void applyClientRequestSizeAdvice(LongHistogramBuilder builder) {
((ExtendedLongHistogramBuilder) builder)
.setAttributesAdvice(
asList(
SemanticAttributes.HTTP_REQUEST_METHOD,
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE,
SemanticAttributes.ERROR_TYPE,
SemanticAttributes.NETWORK_PROTOCOL_NAME,
SemanticAttributes.NETWORK_PROTOCOL_VERSION,
SemanticAttributes.SERVER_ADDRESS,
SemanticAttributes.SERVER_PORT));
HttpAttributes.HTTP_REQUEST_METHOD,
HttpAttributes.HTTP_RESPONSE_STATUS_CODE,
ErrorAttributes.ERROR_TYPE,
NetworkAttributes.NETWORK_PROTOCOL_NAME,
NetworkAttributes.NETWORK_PROTOCOL_VERSION,
ServerAttributes.SERVER_ADDRESS,
ServerAttributes.SERVER_PORT));
}

static void applyServerRequestSizeAdvice(LongHistogramBuilder builder) {
Expand All @@ -39,13 +43,13 @@ static void applyServerRequestSizeAdvice(LongHistogramBuilder builder) {
.setAttributesAdvice(
asList(
// stable attributes
SemanticAttributes.HTTP_ROUTE,
SemanticAttributes.HTTP_REQUEST_METHOD,
SemanticAttributes.HTTP_RESPONSE_STATUS_CODE,
SemanticAttributes.ERROR_TYPE,
SemanticAttributes.NETWORK_PROTOCOL_NAME,
SemanticAttributes.NETWORK_PROTOCOL_VERSION,
SemanticAttributes.URL_SCHEME));
HttpAttributes.HTTP_ROUTE,
HttpAttributes.HTTP_REQUEST_METHOD,
HttpAttributes.HTTP_RESPONSE_STATUS_CODE,
ErrorAttributes.ERROR_TYPE,
NetworkAttributes.NETWORK_PROTOCOL_NAME,
NetworkAttributes.NETWORK_PROTOCOL_VERSION,
UrlAttributes.URL_SCHEME));
}

static void applyServerActiveRequestsAdvice(LongUpDownCounterBuilder builder) {
Expand All @@ -56,7 +60,7 @@ static void applyServerActiveRequestsAdvice(LongUpDownCounterBuilder builder) {
.setAttributesAdvice(
asList(
// https://github.com/open-telemetry/semantic-conventions/blob/v1.23.0/docs/http/http-metrics.md#metric-httpserveractive_requests
SemanticAttributes.HTTP_REQUEST_METHOD, SemanticAttributes.URL_SCHEME));
HttpAttributes.HTTP_REQUEST_METHOD, UrlAttributes.URL_SCHEME));
}

private HttpExperimentalMetricsAdvice() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.semconv.incubating.HttpIncubatingAttributes;
import javax.annotation.Nullable;

final class HttpMessageBodySizeUtil {

@Nullable
static Long getHttpRequestBodySize(Attributes... attributesList) {
return getAttribute(SemanticAttributes.HTTP_REQUEST_BODY_SIZE, attributesList);
return getAttribute(HttpIncubatingAttributes.HTTP_REQUEST_BODY_SIZE, attributesList);
}

@Nullable
static Long getHttpResponseBodySize(Attributes... attributesList) {
return getAttribute(SemanticAttributes.HTTP_RESPONSE_BODY_SIZE, attributesList);
return getAttribute(HttpIncubatingAttributes.HTTP_RESPONSE_BODY_SIZE, attributesList);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.internal.SpanKey;
import io.opentelemetry.instrumentation.api.internal.SpanKeyProvider;
import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes;
import java.util.List;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -62,40 +62,46 @@ public static <REQUEST, RESPONSE> MessagingAttributesExtractorBuilder<REQUEST, R

@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
internalSet(attributes, SemanticAttributes.MESSAGING_SYSTEM, getter.getSystem(request));
internalSet(
attributes, MessagingIncubatingAttributes.MESSAGING_SYSTEM, getter.getSystem(request));
boolean isTemporaryDestination = getter.isTemporaryDestination(request);
if (isTemporaryDestination) {
internalSet(attributes, SemanticAttributes.MESSAGING_DESTINATION_TEMPORARY, true);
internalSet(attributes, SemanticAttributes.MESSAGING_DESTINATION_NAME, TEMP_DESTINATION_NAME);
internalSet(attributes, MessagingIncubatingAttributes.MESSAGING_DESTINATION_TEMPORARY, true);
internalSet(
attributes,
MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME,
TEMP_DESTINATION_NAME);
} else {
internalSet(
attributes,
SemanticAttributes.MESSAGING_DESTINATION_NAME,
MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME,
getter.getDestination(request));
internalSet(
attributes,
SemanticAttributes.MESSAGING_DESTINATION_TEMPLATE,
MessagingIncubatingAttributes.MESSAGING_DESTINATION_TEMPLATE,
getter.getDestinationTemplate(request));
}
boolean isAnonymousDestination = getter.isAnonymousDestination(request);
if (isAnonymousDestination) {
internalSet(attributes, SemanticAttributes.MESSAGING_DESTINATION_ANONYMOUS, true);
internalSet(attributes, MessagingIncubatingAttributes.MESSAGING_DESTINATION_ANONYMOUS, true);
}
internalSet(
attributes,
SemanticAttributes.MESSAGING_MESSAGE_CONVERSATION_ID,
MessagingIncubatingAttributes.MESSAGING_MESSAGE_CONVERSATION_ID,
getter.getConversationId(request));
internalSet(
attributes,
SemanticAttributes.MESSAGING_MESSAGE_BODY_SIZE,
MessagingIncubatingAttributes.MESSAGING_MESSAGE_BODY_SIZE,
getter.getMessageBodySize(request));
internalSet(
attributes,
SemanticAttributes.MESSAGING_MESSAGE_ENVELOPE_SIZE,
MessagingIncubatingAttributes.MESSAGING_MESSAGE_ENVELOPE_SIZE,
getter.getMessageEnvelopeSize(request));
internalSet(attributes, SemanticAttributes.MESSAGING_CLIENT_ID, getter.getClientId(request));
internalSet(
attributes, MessagingIncubatingAttributes.MESSAGING_CLIENT_ID, getter.getClientId(request));
if (operation != null) {
internalSet(attributes, SemanticAttributes.MESSAGING_OPERATION, operation.operationName());
internalSet(
attributes, MessagingIncubatingAttributes.MESSAGING_OPERATION, operation.operationName());
}
}

Expand All @@ -108,11 +114,11 @@ public void onEnd(
@Nullable Throwable error) {
internalSet(
attributes,
SemanticAttributes.MESSAGING_MESSAGE_ID,
MessagingIncubatingAttributes.MESSAGING_MESSAGE_ID,
getter.getMessageId(request, response));
internalSet(
attributes,
SemanticAttributes.MESSAGING_BATCH_MESSAGE_COUNT,
MessagingIncubatingAttributes.MESSAGING_BATCH_MESSAGE_COUNT,
getter.getBatchMessageCount(request, response));

for (String name : capturedHeaders) {
Expand Down
Loading

0 comments on commit 955470a

Please sign in to comment.