Skip to content
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

### ⚠️ Breaking changes

- Rename `messaging.system` to `messaging.system.name` (`aws_sqs` becomes `aws.sqs`) and adopt
the system-specific attribute renames from
[semantic-conventions #4250](https://github.com/open-telemetry/semantic-conventions/pull/4250).
- AWS Lambda invocation spans now replace alias suffixes in `cloud.resource_id` with the resolved
function version when available.
- AWS Lambda spans now use `faas.invocation.id` instead of `faas.invocation_id` for invocation IDs.
Expand Down
4 changes: 2 additions & 2 deletions docs/contributing/style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ across versions). For example:

```java
// copied from MessagingIncubatingAttributes
private static final AttributeKey<String> MESSAGING_SYSTEM =
AttributeKey.stringKey("messaging.system");
private static final AttributeKey<String> MESSAGING_SYSTEM_NAME =
AttributeKey.stringKey("messaging.system.name");
```

**Javaagent instrumentation**: Use the semconv constants from the semconv artifact directly. The
Expand Down
2 changes: 1 addition & 1 deletion docs/declarative-configuration-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ instrumentation/development:
# Enables the creation of Connect and DNS spans.
enabled: false
rocketmq_client:
# Enables capturing experimental span attributes `messaging.rocketmq.message.tag`,
# Enables capturing experimental span attributes `rocketmq.message.tag`,
# `messaging.rocketmq.broker_address`, `messaging.rocketmq.send_result`,
# `messaging.rocketmq.queue_id`, and `messaging.rocketmq.queue_offset`.
experimental_span_attributes/development: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public final class MessagingAttributesExtractor<REQUEST, RESPONSE>
AttributeKey.stringKey("messaging.operation.name");
private static final AttributeKey<String> MESSAGING_OPERATION_TYPE =
AttributeKey.stringKey("messaging.operation.type");
private static final AttributeKey<String> MESSAGING_SYSTEM =
AttributeKey.stringKey("messaging.system");
private static final AttributeKey<String> MESSAGING_SYSTEM_NAME =
AttributeKey.stringKey("messaging.system.name");
Comment on lines +64 to +65

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping the existing schema URL for now, as requested. No published schema includes these renames yet; #21075 tracks aligning it before 3.0 and is assigned to the v3.0.0 milestone. Leaving this finding open because the schema update is deferred, not fixed.


/**
* Creates the messaging attributes extractor for the given operation type.
Expand Down Expand Up @@ -138,7 +138,7 @@ public static <REQUEST, RESPONSE> MessagingAttributesExtractorBuilder<REQUEST, R

@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
attributes.put(MESSAGING_SYSTEM, getter.getSystem(request));
attributes.put(MESSAGING_SYSTEM_NAME, getter.getSystem(request));
boolean isTemporaryDestination = getter.isTemporaryDestination(request);
if (isTemporaryDestination) {
attributes.put(MESSAGING_DESTINATION_TEMPORARY, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ final class MessagingMetricsAdvice {
asList(0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1.0, 2.5, 5.0, 7.5, 10.0));

// copied from MessagingIncubatingAttributes
private static final AttributeKey<String> MESSAGING_SYSTEM =
AttributeKey.stringKey("messaging.system");
private static final AttributeKey<String> MESSAGING_SYSTEM_NAME =
AttributeKey.stringKey("messaging.system.name");
private static final AttributeKey<String> MESSAGING_DESTINATION_NAME =
AttributeKey.stringKey("messaging.destination.name");
private static final AttributeKey<Boolean> MESSAGING_DESTINATION_ANONYMOUS =
Expand Down Expand Up @@ -62,7 +62,7 @@ private static List<AttributeKey<?>> buildAttributes(
boolean includeConsumerAttributes, boolean includeOperationType, boolean includeErrorType) {
List<AttributeKey<?>> attributes = new ArrayList<>();
attributes.add(MESSAGING_OPERATION_NAME);
attributes.add(MESSAGING_SYSTEM);
attributes.add(MESSAGING_SYSTEM_NAME);
if (includeErrorType) {
attributes.add(ERROR_TYPE);
}
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.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.semconv.ErrorAttributes.ERROR_TYPE;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_BATCH_MESSAGE_COUNT;
Expand All @@ -17,7 +18,6 @@
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_MESSAGE_ID;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION_NAME;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION_TYPE;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_SYSTEM;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand Down Expand Up @@ -93,7 +93,7 @@ void shouldExtractAllAvailableAttributes(

// then
List<MapEntry<AttributeKey<?>, Object>> expectedEntries = new ArrayList<>();
expectedEntries.add(entry(MESSAGING_SYSTEM, "myQueue"));
expectedEntries.add(entry(stringKey("messaging.system.name"), "myQueue"));
if (temporary) {
expectedEntries.add(entry(MESSAGING_DESTINATION_TEMPORARY, true));
expectedEntries.add(entry(MESSAGING_DESTINATION_NAME, destination));
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.incubator.semconv.messaging.MessagingOperationType.RECEIVE;
import static io.opentelemetry.instrumentation.api.incubator.semconv.messaging.internal.MessagingTelemetrySignal.CLIENT_OPERATION_DURATION;
import static io.opentelemetry.instrumentation.api.incubator.semconv.messaging.internal.MessagingTelemetrySignal.CONSUMED_MESSAGES;
Expand All @@ -20,7 +21,6 @@
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_DESTINATION_TEMPLATE;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION_NAME;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION_TYPE;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_SYSTEM;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.junit.jupiter.params.provider.Arguments.argumentSet;

Expand Down Expand Up @@ -56,7 +56,7 @@ void collectsMetricsAndCountsBatchOnce() {

Attributes requestAttributes =
Attributes.builder()
.put(MESSAGING_SYSTEM, "pulsar")
.put(stringKey("messaging.system.name"), "pulsar")
.put(MESSAGING_DESTINATION_NAME, "topic")
.put(MESSAGING_DESTINATION_TEMPLATE, "topic-{id}")
.put(MESSAGING_OPERATION_NAME, "receive")
Expand Down Expand Up @@ -94,7 +94,7 @@ void collectsMetricsAndCountsBatchOnce() {
.hasBucketBoundaries(DURATION_BUCKETS)
.hasAttributesSatisfyingExactly(
equalTo(MESSAGING_OPERATION_NAME, "receive"),
equalTo(MESSAGING_SYSTEM, "pulsar"),
equalTo(stringKey("messaging.system.name"), "pulsar"),
equalTo(MESSAGING_CONSUMER_GROUP_NAME, "group"),
equalTo(MESSAGING_DESTINATION_TEMPLATE, "topic-{id}"),
equalTo(
Expand All @@ -117,7 +117,7 @@ void collectsMetricsAndCountsBatchOnce() {
.hasValue(3)
.hasAttributesSatisfyingExactly(
equalTo(MESSAGING_OPERATION_NAME, "receive"),
equalTo(MESSAGING_SYSTEM, "pulsar"),
equalTo(stringKey("messaging.system.name"), "pulsar"),
equalTo(
ERROR_TYPE, IllegalStateException.class.getName()),
equalTo(MESSAGING_CONSUMER_GROUP_NAME, "group"),
Expand All @@ -137,7 +137,7 @@ void outerReceivePreventsDuplicateNestedMetrics() {
OperationListener inner = MessagingConsumerMetrics.get().create(meterProvider.get("inner"));
Attributes attributes =
Attributes.builder()
.put(MESSAGING_SYSTEM, "kafka")
.put(stringKey("messaging.system.name"), "kafka")
.put(MESSAGING_OPERATION_NAME, "receive")
.put(MESSAGING_OPERATION_TYPE, "receive")
.put(MESSAGING_BATCH_MESSAGE_COUNT, 3)
Expand Down Expand Up @@ -259,7 +259,7 @@ void failedReceiveWithoutBatchCountCountsNoConsumedMessages() {

Attributes requestAttributes =
Attributes.builder()
.put(MESSAGING_SYSTEM, "pulsar")
.put(stringKey("messaging.system.name"), "pulsar")
.put(MESSAGING_OPERATION_NAME, "receive")
.put(MESSAGING_OPERATION_TYPE, "receive")
.build();
Expand All @@ -286,7 +286,7 @@ void consumedMessagesOnlyCountsFailedDelivery() {

Attributes attributes =
Attributes.builder()
.put(MESSAGING_SYSTEM, "pulsar")
.put(stringKey("messaging.system.name"), "pulsar")
.put(MESSAGING_DESTINATION_NAME, "topic")
.put(MESSAGING_OPERATION_NAME, "process")
.put(MESSAGING_OPERATION_TYPE, "process")
Expand All @@ -309,7 +309,7 @@ void consumedMessagesOnlyCountsFailedDelivery() {
.hasValue(1)
.hasAttributesSatisfyingExactly(
equalTo(MESSAGING_OPERATION_NAME, "process"),
equalTo(MESSAGING_SYSTEM, "pulsar"),
equalTo(stringKey("messaging.system.name"), "pulsar"),
equalTo(MESSAGING_DESTINATION_NAME, "topic"),
equalTo(
ERROR_TYPE,
Expand All @@ -327,7 +327,7 @@ void clientOperationDurationOnlyDoesNotCountConsumedMessages() {

Attributes attributes =
Attributes.builder()
.put(MESSAGING_SYSTEM, "kafka")
.put(stringKey("messaging.system.name"), "kafka")
.put(MESSAGING_OPERATION_NAME, "poll")
.put(MESSAGING_OPERATION_TYPE, "receive")
.put(MESSAGING_BATCH_MESSAGE_COUNT, 3)
Expand Down Expand Up @@ -436,7 +436,7 @@ void successfulReceiveWithoutBatchCountCountsOneConsumedMessage() {

Attributes attributes =
Attributes.builder()
.put(MESSAGING_SYSTEM, "pulsar")
.put(stringKey("messaging.system.name"), "pulsar")
.put(MESSAGING_OPERATION_NAME, "receive")
.put(MESSAGING_OPERATION_TYPE, "receive")
.build();
Expand Down
Comment thread
trask marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,55 @@

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

import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_DESTINATION_ANONYMOUS;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_DESTINATION_TEMPLATE;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_DESTINATION_TEMPORARY;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.incubator.metrics.ExtendedDoubleHistogramBuilder;
import io.opentelemetry.api.incubator.metrics.ExtendedLongCounterBuilder;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class MessagingMetricsAdviceTest {

@Captor ArgumentCaptor<List<AttributeKey<?>>> attributesCaptor;

@Test
void advisesSystemNameForAllMetrics() {
ExtendedDoubleHistogramBuilder clientDuration = mock(ExtendedDoubleHistogramBuilder.class);
ExtendedDoubleHistogramBuilder processDuration = mock(ExtendedDoubleHistogramBuilder.class);
ExtendedLongCounterBuilder sentMessages = mock(ExtendedLongCounterBuilder.class);
ExtendedLongCounterBuilder consumedMessages = mock(ExtendedLongCounterBuilder.class);

MessagingMetricsAdvice.applyClientOperationDurationAdvice(clientDuration);
MessagingMetricsAdvice.applyProcessDurationAdvice(processDuration);
MessagingMetricsAdvice.applySentMessagesAdvice(sentMessages);
MessagingMetricsAdvice.applyConsumedMessagesAdvice(consumedMessages);

verify(clientDuration).setAttributesAdvice(attributesCaptor.capture());
verify(processDuration).setAttributesAdvice(attributesCaptor.capture());
verify(sentMessages).setAttributesAdvice(attributesCaptor.capture());
verify(consumedMessages).setAttributesAdvice(attributesCaptor.capture());
assertThat(attributesCaptor.getAllValues())
.allSatisfy(
attributes ->
assertThat(attributes)
.contains(stringKey("messaging.system.name"))
.doesNotContain(stringKey("messaging.system")));
}

@Test
@SuppressWarnings("deprecation") // using deprecated semconv
void filtersHighCardinalityDestinationNames() {
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.incubator.semconv.messaging.MessagingOperationType.PROCESS;
import static io.opentelemetry.instrumentation.api.incubator.semconv.messaging.internal.MessagingTelemetrySignal.PROCESS_DURATION;
import static io.opentelemetry.instrumentation.api.incubator.semconv.messaging.internal.MessagingTelemetryState.contains;
Expand All @@ -16,7 +17,6 @@
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_DESTINATION_TEMPLATE;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION_NAME;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION_TYPE;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_SYSTEM;
import static java.util.concurrent.TimeUnit.MILLISECONDS;

import io.opentelemetry.api.common.Attributes;
Expand Down Expand Up @@ -47,7 +47,7 @@ void emitsProcessDurationAccordingToConfiguration() {

Attributes attributes =
Attributes.builder()
.put(MESSAGING_SYSTEM, "pulsar")
.put(stringKey("messaging.system.name"), "pulsar")
.put(MESSAGING_DESTINATION_NAME, "topic")
.put(MESSAGING_DESTINATION_TEMPLATE, "topic-{id}")
.put(MESSAGING_OPERATION_NAME, "process")
Expand Down Expand Up @@ -77,7 +77,7 @@ void emitsProcessDurationAccordingToConfiguration() {
.hasBucketBoundaries(DURATION_BUCKETS)
.hasAttributesSatisfyingExactly(
equalTo(MESSAGING_OPERATION_NAME, "process"),
equalTo(MESSAGING_SYSTEM, "pulsar"),
equalTo(stringKey("messaging.system.name"), "pulsar"),
equalTo(MESSAGING_DESTINATION_TEMPLATE, "topic-{id}"),
equalTo(
ERROR_TYPE,
Expand All @@ -94,7 +94,7 @@ void outerOperationPreventsDuplicateNestedProcessDuration() {
OperationListener inner = MessagingProcessMetrics.get().create(meterProvider.get("inner"));
Attributes attributes =
Attributes.builder()
.put(MESSAGING_SYSTEM, "kafka")
.put(stringKey("messaging.system.name"), "kafka")
.put(MESSAGING_OPERATION_NAME, "process")
.put(MESSAGING_OPERATION_TYPE, "process")
.build();
Expand Down
Loading
Loading