Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,29 @@

final class CapturedMessageHeadersUtil {

private static final ConcurrentMap<String, AttributeKey<List<String>>> attributeKeysCache =
new ConcurrentHashMap<>();
private static final ConcurrentMap<String, AttributeKey<List<String>>>
oldSemconvAttributeKeysCache = new ConcurrentHashMap<>();
private static final ConcurrentMap<String, AttributeKey<List<String>>>
stableSemconvAttributeKeysCache = new ConcurrentHashMap<>();

static AttributeKey<List<String>> attributeKey(String headerName) {
return attributeKeysCache.computeIfAbsent(headerName, n -> createKey(n));
static AttributeKey<List<String>> oldSemconvAttributeKey(String headerName) {
return oldSemconvAttributeKeysCache.computeIfAbsent(headerName, n -> createOldSemconvKey(n));
}

private static AttributeKey<List<String>> createKey(String headerName) {
static AttributeKey<List<String>> stableSemconvAttributeKey(String headerName) {
return stableSemconvAttributeKeysCache.computeIfAbsent(
headerName, n -> createStableSemconvKey(n));
}

private static AttributeKey<List<String>> createOldSemconvKey(String headerName) {
String key = "messaging.header." + headerName.replace('-', '_');
return AttributeKey.stringArrayKey(key);
}

private static AttributeKey<List<String>> createStableSemconvKey(String headerName) {
String key = "messaging.header." + headerName;
return AttributeKey.stringArrayKey(key);
}

private CapturedMessageHeadersUtil() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.instrumentation.api.internal.SpanKey;
import io.opentelemetry.instrumentation.api.internal.SpanKeyProvider;
import java.util.ArrayList;
Expand Down Expand Up @@ -131,7 +132,13 @@ public void onEnd(
for (String name : capturedHeaders) {
List<String> values = getter.getMessageHeader(request, name);
if (!values.isEmpty()) {
internalSet(attributes, CapturedMessageHeadersUtil.attributeKey(name), values);
if (SemconvStability.isEmitOldMessageSemconv()) {
internalSet(attributes, CapturedMessageHeadersUtil.oldSemconvAttributeKey(name), values);
}
if (SemconvStability.isEmitStableMessageSemconv()) {
internalSet(
attributes, CapturedMessageHeadersUtil.stableSemconvAttributeKey(name), values);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ public final class SemconvStability {
private static final boolean emitOldCodeSemconv;
private static final boolean emitStableCodeSemconv;

private static final boolean emitOldMessageSemconv;
private static final boolean emitStableMessageSemconv;

static {
boolean oldDatabase = true;
boolean stableDatabase = false;

boolean oldCode = true;
boolean stableCode = false;

boolean oldMessage = true;
boolean stableMessage = false;

String value = ConfigPropertiesUtil.getString("otel.semconv-stability.opt-in");
if (value != null) {
Set<String> values = new HashSet<>(asList(value.split(",")));
Expand All @@ -55,13 +61,25 @@ public final class SemconvStability {
oldCode = true;
stableCode = true;
}

if (values.contains("message")) {
oldMessage = false;
stableMessage = true;
}
if (values.contains("message/dup")) {
oldMessage = true;
stableMessage = true;
}
}

emitOldDatabaseSemconv = oldDatabase;
emitStableDatabaseSemconv = stableDatabase;

emitOldCodeSemconv = oldCode;
emitStableCodeSemconv = stableCode;

emitOldMessageSemconv = oldMessage;
emitStableMessageSemconv = stableMessage;
}

public static boolean emitOldDatabaseSemconv() {
Expand Down Expand Up @@ -105,5 +123,13 @@ public static boolean isEmitStableCodeSemconv() {
return emitStableCodeSemconv;
}

public static boolean isEmitOldMessageSemconv() {
return emitOldMessageSemconv;
}

public static boolean isEmitStableMessageSemconv() {
return emitStableMessageSemconv;
}

private SemconvStability() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package io.opentelemetry.instrumentation.awssdk.v1_11;

import static io.opentelemetry.api.common.AttributeKey.stringArrayKey;
import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
Expand Down Expand Up @@ -42,6 +41,7 @@
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.test.utils.PortUtils;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.message.SemconvMessageStabilityUtil;
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
import io.opentelemetry.sdk.testing.assertj.SpanDataAssert;
import io.opentelemetry.sdk.trace.data.SpanData;
Expand Down Expand Up @@ -182,7 +182,8 @@ void testSimpleSqsProducerConsumerServicesCaptureHeaders(boolean testCaptureHead
if (testCaptureHeaders) {
attributes.add(
satisfies(
stringArrayKey("messaging.header.Test_Message_Header"),
SemconvMessageStabilityUtil.headerAttributeKey(
"Test-Message-Header"),
val -> val.isEqualTo(singletonList("test"))));
}

Expand Down Expand Up @@ -222,7 +223,8 @@ void testSimpleSqsProducerConsumerServicesCaptureHeaders(boolean testCaptureHead
if (testCaptureHeaders) {
attributes.add(
satisfies(
stringArrayKey("messaging.header.Test_Message_Header"),
SemconvMessageStabilityUtil.headerAttributeKey(
"Test-Message-Header"),
val -> val.isEqualTo(singletonList("test"))));
}

Expand Down Expand Up @@ -261,7 +263,8 @@ void testSimpleSqsProducerConsumerServicesCaptureHeaders(boolean testCaptureHead
if (testCaptureHeaders) {
attributes.add(
satisfies(
stringArrayKey("messaging.header.Test_Message_Header"),
SemconvMessageStabilityUtil.headerAttributeKey(
"Test-Message-Header"),
val -> val.isEqualTo(singletonList("test"))));
}
span.hasName("testSdkSqs process")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package io.opentelemetry.instrumentation.awssdk.v2_2;

import static io.opentelemetry.api.common.AttributeKey.stringArrayKey;
import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
Expand All @@ -29,6 +28,7 @@

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.testing.junit.message.SemconvMessageStabilityUtil;
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
import io.opentelemetry.sdk.testing.assertj.SpanDataAssert;
import io.opentelemetry.sdk.trace.data.SpanData;
Expand Down Expand Up @@ -93,7 +93,8 @@ protected void assertSqsTraces(boolean withParent, boolean captureHeaders) {
if (captureHeaders) {
attributes.add(
satisfies(
stringArrayKey("messaging.header.Test_Message_Header"),
SemconvMessageStabilityUtil.headerAttributeKey(
"Test-Message-Header"),
v -> v.isEqualTo(ImmutableList.of("test"))));
}
span.hasName("testSdkSqs publish")
Expand Down Expand Up @@ -163,7 +164,8 @@ protected void assertSqsTraces(boolean withParent, boolean captureHeaders) {
if (captureHeaders) {
attributes.add(
satisfies(
stringArrayKey("messaging.header.Test_Message_Header"),
SemconvMessageStabilityUtil.headerAttributeKey(
"Test-Message-Header"),
v -> v.isEqualTo(ImmutableList.of("test"))));
}

Expand Down Expand Up @@ -201,7 +203,8 @@ protected void assertSqsTraces(boolean withParent, boolean captureHeaders) {
if (captureHeaders) {
attributes.add(
satisfies(
stringArrayKey("messaging.header.Test_Message_Header"),
SemconvMessageStabilityUtil.headerAttributeKey(
"Test-Message-Header"),
v -> v.isEqualTo(singletonList("test"))));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_SYSTEM;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.testing.junit.message.SemconvMessageStabilityUtil;
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
Expand Down Expand Up @@ -188,7 +189,7 @@ protected static List<AttributeAssertion> sendAttributes(
if (testHeaders) {
assertions.add(
equalTo(
AttributeKey.stringArrayKey("messaging.header.Test_Message_Header"),
SemconvMessageStabilityUtil.headerAttributeKey("Test-Message-Header"),
Collections.singletonList("test")));
}
return assertions;
Expand All @@ -211,7 +212,7 @@ protected static List<AttributeAssertion> receiveAttributes(boolean testHeaders)
if (testHeaders) {
assertions.add(
equalTo(
AttributeKey.stringArrayKey("messaging.header.Test_Message_Header"),
SemconvMessageStabilityUtil.headerAttributeKey("Test-Message-Header"),
Collections.singletonList("test")));
}
return assertions;
Expand Down Expand Up @@ -249,7 +250,7 @@ protected static List<AttributeAssertion> processAttributes(
if (testHeaders) {
assertions.add(
equalTo(
AttributeKey.stringArrayKey("messaging.header.Test_Message_Header"),
SemconvMessageStabilityUtil.headerAttributeKey("Test-Message-Header"),
Collections.singletonList("test")));
}

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

package io.opentelemetry.instrumentation.kafkaclients.v2_6;

import static io.opentelemetry.api.common.AttributeKey.stringArrayKey;
import static io.opentelemetry.instrumentation.testing.util.TelemetryDataUtil.orderByRootSpanName;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
Expand All @@ -22,6 +21,7 @@

import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.testing.junit.message.SemconvMessageStabilityUtil;
import io.opentelemetry.sdk.trace.data.LinkData;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicReference;
Expand All @@ -45,7 +45,7 @@ void assertTraces() {
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
equalTo(
stringArrayKey("messaging.header.Test_Message_Header"),
SemconvMessageStabilityUtil.headerAttributeKey("Test-Message-Header"),
singletonList("test")),
equalTo(MESSAGING_SYSTEM, "kafka"),
equalTo(MESSAGING_DESTINATION_NAME, SHARED_TOPIC),
Expand All @@ -70,7 +70,8 @@ void assertTraces() {
.hasLinksSatisfying(links -> assertThat(links).isEmpty())
.hasAttributesSatisfyingExactly(
equalTo(
stringArrayKey("messaging.header.Test_Message_Header"),
SemconvMessageStabilityUtil.headerAttributeKey(
"Test-Message-Header"),
singletonList("test")),
equalTo(MESSAGING_SYSTEM, "kafka"),
equalTo(MESSAGING_DESTINATION_NAME, SHARED_TOPIC),
Expand All @@ -87,7 +88,8 @@ void assertTraces() {
.hasLinks(LinkData.create(producerSpanContext.get()))
.hasAttributesSatisfyingExactly(
equalTo(
stringArrayKey("messaging.header.Test_Message_Header"),
SemconvMessageStabilityUtil.headerAttributeKey(
"Test-Message-Header"),
singletonList("test")),
equalTo(MESSAGING_SYSTEM, "kafka"),
equalTo(MESSAGING_DESTINATION_NAME, SHARED_TOPIC),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.testing.junit.message.SemconvMessageStabilityUtil;
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
Expand Down Expand Up @@ -73,7 +74,7 @@ protected static List<AttributeAssertion> sendAttributes(boolean testHeaders) {
if (testHeaders) {
assertions.add(
equalTo(
AttributeKey.stringArrayKey("messaging.header.Test_Message_Header"),
SemconvMessageStabilityUtil.headerAttributeKey("Test-Message-Header"),
Collections.singletonList("test")));
}
return assertions;
Expand All @@ -100,7 +101,7 @@ private static List<AttributeAssertion> processAttributes(String greeting, boole
if (testHeaders) {
assertions.add(
equalTo(
AttributeKey.stringArrayKey("messaging.header.Test_Message_Header"),
SemconvMessageStabilityUtil.headerAttributeKey("Test-Message-Header"),
Collections.singletonList("test")));
}
return assertions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.testing.junit.message.SemconvMessageStabilityUtil;
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
import io.opentelemetry.sdk.trace.data.LinkData;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -96,7 +97,7 @@ protected static List<AttributeAssertion> sendAttributes(boolean testHeaders) {
if (testHeaders) {
assertions.add(
equalTo(
AttributeKey.stringArrayKey("messaging.header.Test_Message_Header"),
SemconvMessageStabilityUtil.headerAttributeKey("Test-Message-Header"),
Collections.singletonList("test")));
}
return assertions;
Expand All @@ -123,7 +124,7 @@ private static List<AttributeAssertion> processAttributes(String greeting, boole
if (testHeaders) {
assertions.add(
equalTo(
AttributeKey.stringArrayKey("messaging.header.Test_Message_Header"),
SemconvMessageStabilityUtil.headerAttributeKey("Test-Message-Header"),
Collections.singletonList("test")));
}
return assertions;
Expand All @@ -143,7 +144,7 @@ protected static List<AttributeAssertion> receiveAttributes(boolean testHeaders)
if (testHeaders) {
assertions.add(
equalTo(
AttributeKey.stringArrayKey("messaging.header.Test_Message_Header"),
SemconvMessageStabilityUtil.headerAttributeKey("Test-Message-Header"),
Collections.singletonList("test")));
}
return assertions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.message.SemconvMessageStabilityUtil;
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
import io.opentelemetry.sdk.trace.data.LinkData;
import io.opentelemetry.sdk.trace.data.SpanData;
Expand Down Expand Up @@ -363,7 +364,7 @@ static List<AttributeAssertion> sendAttributes(
if (testHeaders) {
assertions.add(
equalTo(
AttributeKey.stringArrayKey("messaging.header.Test_Message_Header"),
SemconvMessageStabilityUtil.headerAttributeKey("Test-Message-Header"),
Collections.singletonList("test")));
}
int partitionIndex = TopicName.getPartitionIndex(destination);
Expand Down Expand Up @@ -399,7 +400,7 @@ static List<AttributeAssertion> receiveAttributes(
if (testHeaders) {
assertions.add(
equalTo(
AttributeKey.stringArrayKey("messaging.header.Test_Message_Header"),
SemconvMessageStabilityUtil.headerAttributeKey("Test-Message-Header"),
Collections.singletonList("test")));
}
if (isBatch) {
Expand All @@ -426,7 +427,7 @@ static List<AttributeAssertion> processAttributes(
if (testHeaders) {
assertions.add(
equalTo(
AttributeKey.stringArrayKey("messaging.header.Test_Message_Header"),
SemconvMessageStabilityUtil.headerAttributeKey("Test-Message-Header"),
Collections.singletonList("test")));
}
int partitionIndex = TopicName.getPartitionIndex(destination);
Expand Down
Loading