Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Semconv to 1.26 #11792

Closed
Closed
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ val asmVersion = "9.7"
val jmhVersion = "1.37"
val mockitoVersion = "4.11.0"
val slf4jVersion = "2.0.13"
val semConvVersion = "1.25.0-alpha"
val semConvVersion = "1.26.0-alpha"

val CORE_DEPENDENCIES = listOf(
"io.opentelemetry.semconv:opentelemetry-semconv:${semConvVersion}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public final class DbClientAttributesExtractor<REQUEST, RESPONSE>
REQUEST, RESPONSE, DbClientAttributesGetter<REQUEST>> {

// copied from DbIncubatingAttributes
private static final AttributeKey<String> DB_STATEMENT = AttributeKey.stringKey("db.statement");
private static final AttributeKey<String> DB_OPERATION = AttributeKey.stringKey("db.operation");
private static final AttributeKey<String> DB_QUERY_TEXT = AttributeKey.stringKey("db.query.text");
private static final AttributeKey<String> DB_OPERATION_NAME_NAME =
crossoverJie marked this conversation as resolved.
Show resolved Hide resolved
AttributeKey.stringKey("db.operation.name");

/** Creates the database client attributes extractor with default configuration. */
public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
Expand All @@ -42,7 +43,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, DB_STATEMENT, getter.getStatement(request));
internalSet(attributes, DB_OPERATION, getter.getOperation(request));
internalSet(attributes, DB_QUERY_TEXT, getter.getStatement(request));
internalSet(attributes, DB_OPERATION_NAME_NAME, getter.getOperation(request));
crossoverJie marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ abstract class DbClientCommonAttributesExtractor<
implements AttributesExtractor<REQUEST, RESPONSE>, SpanKeyProvider {

// copied from DbIncubatingAttributes
private static final AttributeKey<String> DB_NAME = AttributeKey.stringKey("db.name");
private static final AttributeKey<String> DB_NAMESPACE = AttributeKey.stringKey("db.namespace");
private static final AttributeKey<String> DB_SYSTEM = AttributeKey.stringKey("db.system");
private static final AttributeKey<String> DB_USER = AttributeKey.stringKey("db.user");
private static final AttributeKey<String> DB_CONNECTION_STRING =
AttributeKey.stringKey("db.connection_string");

Expand All @@ -35,8 +34,7 @@ abstract class DbClientCommonAttributesExtractor<
@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
internalSet(attributes, DB_SYSTEM, getter.getSystem(request));
internalSet(attributes, DB_USER, getter.getUser(request));
internalSet(attributes, DB_NAME, getter.getName(request));
internalSet(attributes, DB_NAMESPACE, getter.getName(request));
internalSet(attributes, DB_CONNECTION_STRING, getter.getConnectionString(request));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public final class SqlClientAttributesExtractor<REQUEST, RESPONSE>
REQUEST, RESPONSE, SqlClientAttributesGetter<REQUEST>> {

// copied from DbIncubatingAttributes
private static final AttributeKey<String> DB_OPERATION = AttributeKey.stringKey("db.operation");
private static final AttributeKey<String> DB_STATEMENT = AttributeKey.stringKey("db.statement");
private static final AttributeKey<String> DB_QUERY_TEXT = AttributeKey.stringKey("db.query.text");
private static final AttributeKey<String> DB_OPERATION_NAME_NAME =
crossoverJie marked this conversation as resolved.
Show resolved Hide resolved
AttributeKey.stringKey("db.operation.name");

/** Creates the SQL client attributes extractor with default configuration. */
public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
Expand Down Expand Up @@ -70,9 +71,9 @@ public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST
String operation = sanitizedStatement.getOperation();
internalSet(
attributes,
DB_STATEMENT,
DB_QUERY_TEXT,
statementSanitizationEnabled ? sanitizedStatement.getFullStatement() : rawStatement);
internalSet(attributes, DB_OPERATION, operation);
internalSet(attributes, DB_OPERATION_NAME_NAME, operation);
crossoverJie marked this conversation as resolved.
Show resolved Hide resolved
if (!SQL_CALL.equals(operation)) {
internalSet(attributes, dbTableAttribute, sanitizedStatement.getMainIdentifier());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
public final class SqlClientAttributesExtractorBuilder<REQUEST, RESPONSE> {

// copied from DbIncubatingAttributes
private static final AttributeKey<String> DB_SQL_TABLE = AttributeKey.stringKey("db.sql.table");
private static final AttributeKey<String> DB_COLLECTION_NAME =
AttributeKey.stringKey("db.collection.name");

final SqlClientAttributesGetter<REQUEST> getter;
AttributeKey<String> dbTableAttribute = DB_SQL_TABLE;
AttributeKey<String> dbTableAttribute = DB_COLLECTION_NAME;
boolean statementSanitizationEnabled = true;

SqlClientAttributesExtractorBuilder(SqlClientAttributesGetter<REQUEST> getter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.instrumentation.api.incubator.semconv.messaging;

import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;

import io.opentelemetry.api.common.AttributeKey;
Expand All @@ -31,7 +32,7 @@ public final class MessagingAttributesExtractor<REQUEST, RESPONSE>
private static final AttributeKey<Long> MESSAGING_BATCH_MESSAGE_COUNT =
AttributeKey.longKey("messaging.batch.message_count");
private static final AttributeKey<String> MESSAGING_CLIENT_ID =
AttributeKey.stringKey("messaging.client_id");
AttributeKey.stringKey("messaging.client.id");
private static final AttributeKey<Boolean> MESSAGING_DESTINATION_ANONYMOUS =
AttributeKey.booleanKey("messaging.destination.anonymous");
private static final AttributeKey<String> MESSAGING_DESTINATION_NAME =
Expand All @@ -48,8 +49,8 @@ public final class MessagingAttributesExtractor<REQUEST, RESPONSE>
AttributeKey.longKey("messaging.message.envelope.size");
private static final AttributeKey<String> MESSAGING_MESSAGE_ID =
AttributeKey.stringKey("messaging.message.id");
private static final AttributeKey<String> MESSAGING_OPERATION =
AttributeKey.stringKey("messaging.operation");
private static final AttributeKey<String> MESSAGING_OPERATION_TYPE =
stringKey("messaging.operation.type");
private static final AttributeKey<String> MESSAGING_SYSTEM =
AttributeKey.stringKey("messaging.system");

Expand Down Expand Up @@ -108,7 +109,7 @@ public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST
attributes, MESSAGING_MESSAGE_ENVELOPE_SIZE, getter.getMessageEnvelopeSize(request));
internalSet(attributes, MESSAGING_CLIENT_ID, getter.getClientId(request));
if (operation != null) {
internalSet(attributes, MESSAGING_OPERATION, operation.operationName());
internalSet(attributes, MESSAGING_OPERATION_TYPE, operation.operationName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ final class MessagingMetricsAdvice {
AttributeKey.stringKey("messaging.system");
private static final AttributeKey<String> MESSAGING_DESTINATION_NAME =
AttributeKey.stringKey("messaging.destination.name");
private static final AttributeKey<String> MESSAGING_OPERATION =
AttributeKey.stringKey("messaging.operation");
private static final AttributeKey<String> MESSAGING_OPERATION_TYPE =
AttributeKey.stringKey("messaging.operation.type");
private static final AttributeKey<Long> MESSAGING_BATCH_MESSAGE_COUNT =
AttributeKey.longKey("messaging.batch.message_count");

Expand All @@ -39,7 +39,7 @@ static void applyPublishDurationAdvice(DoubleHistogramBuilder builder) {
asList(
MESSAGING_SYSTEM,
MESSAGING_DESTINATION_NAME,
MESSAGING_OPERATION,
MESSAGING_OPERATION_TYPE,
MESSAGING_BATCH_MESSAGE_COUNT,
ErrorAttributes.ERROR_TYPE,
ServerAttributes.SERVER_PORT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ void shouldExtractAllAvailableAttributes() {
assertThat(startAttributes.build())
.containsOnly(
entry(DbIncubatingAttributes.DB_SYSTEM, "myDb"),
entry(DbIncubatingAttributes.DB_USER, "username"),
entry(DbIncubatingAttributes.DB_NAME, "potatoes"),
entry(DbIncubatingAttributes.DB_NAMESPACE, "potatoes"),
entry(DbIncubatingAttributes.DB_CONNECTION_STRING, "mydb:///potatoes"),
entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT * FROM potato"),
entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"));
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT * FROM potato"),
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT"));

assertThat(endAttributes.build().isEmpty()).isTrue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,11 @@ void shouldExtractAllAttributes() {
assertThat(startAttributes.build())
.containsOnly(
entry(DbIncubatingAttributes.DB_SYSTEM, "myDb"),
entry(DbIncubatingAttributes.DB_USER, "username"),
entry(DbIncubatingAttributes.DB_NAME, "potatoes"),
entry(DbIncubatingAttributes.DB_NAMESPACE, "potatoes"),
entry(DbIncubatingAttributes.DB_CONNECTION_STRING, "mydb:///potatoes"),
entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT * FROM potato WHERE id=?"),
entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"),
entry(DbIncubatingAttributes.DB_SQL_TABLE, "potato"));
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT * FROM potato WHERE id=?"),
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT"),
entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "potato"));

assertThat(endAttributes.build().isEmpty()).isTrue();
}
Expand All @@ -104,8 +103,8 @@ void shouldNotExtractTableIfAttributeIsNotSet() {
// then
assertThat(attributes.build())
.containsOnly(
entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT *"),
entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"));
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT *"),
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT"));
}

@Test
Expand All @@ -118,7 +117,7 @@ void shouldExtractTableToSpecifiedKey() {

AttributesExtractor<Map<String, String>, Void> underTest =
SqlClientAttributesExtractor.<Map<String, String>, Void>builder(new TestAttributesGetter())
.setTableAttribute(DbIncubatingAttributes.DB_CASSANDRA_TABLE)
.setTableAttribute(DbIncubatingAttributes.DB_COLLECTION_NAME)
.build();

// when
Expand All @@ -128,9 +127,9 @@ void shouldExtractTableToSpecifiedKey() {
// then
assertThat(attributes.build())
.containsOnly(
entry(DbIncubatingAttributes.DB_STATEMENT, "SELECT * FROM table"),
entry(DbIncubatingAttributes.DB_OPERATION, "SELECT"),
entry(DbIncubatingAttributes.DB_CASSANDRA_TABLE, "table"));
entry(DbIncubatingAttributes.DB_QUERY_TEXT, "SELECT * FROM table"),
entry(DbIncubatingAttributes.DB_OPERATION_NAME, "SELECT"),
entry(DbIncubatingAttributes.DB_COLLECTION_NAME, "table"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void shouldExtractAllAvailableAttributes(
expectedEntries.add(entry(MessagingIncubatingAttributes.MESSAGING_MESSAGE_ENVELOPE_SIZE, 120L));
expectedEntries.add(entry(MessagingIncubatingAttributes.MESSAGING_CLIENT_ID, "43"));
expectedEntries.add(
entry(MessagingIncubatingAttributes.MESSAGING_OPERATION, operation.operationName()));
entry(MessagingIncubatingAttributes.MESSAGING_OPERATION_TYPE, operation.operationName()));

@SuppressWarnings({"unchecked", "rawtypes"})
MapEntry<? extends AttributeKey<?>, ?>[] expectedEntriesArr =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void collectsMetrics() {
.put(
MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME,
"persistent://public/default/topic")
.put(MessagingIncubatingAttributes.MESSAGING_OPERATION, "publish")
.put(MessagingIncubatingAttributes.MESSAGING_OPERATION_TYPE, "publish")
.put(ServerAttributes.SERVER_PORT, 6650)
.put(ServerAttributes.SERVER_ADDRESS, "localhost")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.semconv.ServerAttributes;
import io.opentelemetry.semconv.incubating.MessageIncubatingAttributes;
import io.opentelemetry.semconv.incubating.RpcIncubatingAttributes;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -87,15 +86,15 @@ void grpcInstrumentation() {
event
.hasName("message")
.hasAttributesSatisfyingExactly(
equalTo(MessageIncubatingAttributes.MESSAGE_TYPE, "SENT"),
equalTo(MessageIncubatingAttributes.MESSAGE_ID, 1L)),
equalTo(RpcIncubatingAttributes.RPC_MESSAGE_TYPE, "SENT"),
equalTo(RpcIncubatingAttributes.RPC_MESSAGE_ID, 1L)),
event ->
event
.hasName("message")
.hasAttributesSatisfyingExactly(
equalTo(
MessageIncubatingAttributes.MESSAGE_TYPE, "RECEIVED"),
equalTo(MessageIncubatingAttributes.MESSAGE_ID, 2L))),
RpcIncubatingAttributes.RPC_MESSAGE_TYPE, "RECEIVED"),
equalTo(RpcIncubatingAttributes.RPC_MESSAGE_ID, 2L))),
span ->
span.hasName("example.Greeter/SayHello")
.hasKind(SpanKind.SERVER)
Expand All @@ -115,13 +114,13 @@ void grpcInstrumentation() {
.hasName("message")
.hasAttributesSatisfyingExactly(
equalTo(
MessageIncubatingAttributes.MESSAGE_TYPE, "RECEIVED"),
equalTo(MessageIncubatingAttributes.MESSAGE_ID, 1L)),
RpcIncubatingAttributes.RPC_MESSAGE_TYPE, "RECEIVED"),
equalTo(RpcIncubatingAttributes.RPC_MESSAGE_ID, 1L)),
event ->
event
.hasName("message")
.hasAttributesSatisfyingExactly(
equalTo(MessageIncubatingAttributes.MESSAGE_TYPE, "SENT"),
equalTo(MessageIncubatingAttributes.MESSAGE_ID, 2L)))));
equalTo(RpcIncubatingAttributes.RPC_MESSAGE_TYPE, "SENT"),
equalTo(RpcIncubatingAttributes.RPC_MESSAGE_ID, 2L)))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.instrumentation.awslambdaevents.v2_2.internal;

import static io.opentelemetry.api.common.AttributeKey.stringKey;

import com.amazonaws.services.lambda.runtime.events.SQSEvent;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.AttributesBuilder;
Expand All @@ -15,8 +17,8 @@
class SqsEventAttributesExtractor implements AttributesExtractor<SQSEvent, Void> {

// copied from MessagingIncubatingAttributes
private static final AttributeKey<String> MESSAGING_OPERATION =
AttributeKey.stringKey("messaging.operation");
private static final AttributeKey<String> MESSAGING_OPERATION_TYPE =
stringKey("messaging.operation.type");
private static final AttributeKey<String> MESSAGING_SYSTEM =
AttributeKey.stringKey("messaging.system");
// copied from MessagingIncubatingAttributes.MessagingSystemValues
Expand All @@ -25,7 +27,7 @@ class SqsEventAttributesExtractor implements AttributesExtractor<SQSEvent, Void>
@Override
public void onStart(AttributesBuilder attributes, Context parentContext, SQSEvent event) {
attributes.put(MESSAGING_SYSTEM, AWS_SQS);
attributes.put(MESSAGING_OPERATION, "process");
attributes.put(MESSAGING_OPERATION_TYPE, "process");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.instrumentation.awslambdaevents.v2_2.internal;

import static io.opentelemetry.api.common.AttributeKey.stringKey;

import com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.AttributesBuilder;
Expand All @@ -19,8 +21,8 @@ class SqsMessageAttributesExtractor implements AttributesExtractor<SQSMessage, V
AttributeKey.stringKey("messaging.destination.name");
private static final AttributeKey<String> MESSAGING_MESSAGE_ID =
AttributeKey.stringKey("messaging.message.id");
private static final AttributeKey<String> MESSAGING_OPERATION =
AttributeKey.stringKey("messaging.operation");
private static final AttributeKey<String> MESSAGING_OPERATION_TYPE =
stringKey("messaging.operation.type");
private static final AttributeKey<String> MESSAGING_SYSTEM =
AttributeKey.stringKey("messaging.system");
// copied from MessagingIncubatingAttributes.MessagingSystemValues
Expand All @@ -29,7 +31,7 @@ class SqsMessageAttributesExtractor implements AttributesExtractor<SQSMessage, V
@Override
public void onStart(AttributesBuilder attributes, Context parentContext, SQSMessage message) {
attributes.put(MESSAGING_SYSTEM, AWS_SQS);
attributes.put(MESSAGING_OPERATION, "process");
attributes.put(MESSAGING_OPERATION_TYPE, "process");
attributes.put(MESSAGING_MESSAGE_ID, message.getMessageId());
attributes.put(MESSAGING_DESTINATION_NAME, message.getEventSource());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ void eventTraced() {
MessagingIncubatingAttributes.MESSAGING_SYSTEM,
MessagingIncubatingAttributes.MessagingSystemValues.AWS_SQS),
equalTo(
MessagingIncubatingAttributes.MESSAGING_OPERATION, "process"))));
MessagingIncubatingAttributes.MESSAGING_OPERATION_TYPE,
"process"))));
}

public static final class TestRequestHandler implements RequestHandler<SQSEvent, Void> {
Expand Down
Loading
Loading