diff --git a/splunk-otel-android-volley/build.gradle.kts b/splunk-otel-android-volley/build.gradle.kts index 2766039d..8b42b492 100644 --- a/splunk-otel-android-volley/build.gradle.kts +++ b/splunk-otel-android-volley/build.gradle.kts @@ -45,6 +45,7 @@ android { val otelVersion = "1.30.0-SNAPSHOT" val otelAlphaVersion = otelVersion.replaceFirst("(-SNAPSHOT)?$".toRegex(), "-alpha$1") +val otelSemconvVersion = "1.21.0-alpha" dependencies { implementation("androidx.appcompat:appcompat:1.6.1") @@ -57,7 +58,7 @@ dependencies { api("io.opentelemetry:opentelemetry-api") implementation("io.opentelemetry:opentelemetry-sdk") - implementation("io.opentelemetry:opentelemetry-semconv") + implementation("io.opentelemetry.semconv:opentelemetry-semconv:$otelSemconvVersion") implementation(platform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha")) implementation("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api") diff --git a/splunk-otel-android-volley/src/main/java/com/splunk/rum/VolleyHttpClientAttributesGetter.java b/splunk-otel-android-volley/src/main/java/com/splunk/rum/VolleyHttpClientAttributesGetter.java index 205d6e62..5e026f7f 100644 --- a/splunk-otel-android-volley/src/main/java/com/splunk/rum/VolleyHttpClientAttributesGetter.java +++ b/splunk-otel-android-volley/src/main/java/com/splunk/rum/VolleyHttpClientAttributesGetter.java @@ -24,7 +24,7 @@ import com.android.volley.Request; import com.android.volley.toolbox.HttpResponse; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import io.opentelemetry.semconv.SemanticAttributes; import java.util.ArrayList; import java.util.List; import java.util.Map; diff --git a/splunk-otel-android-volley/src/test/java/com/splunk/rum/TracingHurlStackExceptionTest.java b/splunk-otel-android-volley/src/test/java/com/splunk/rum/TracingHurlStackExceptionTest.java index 9fe2a147..cefdf756 100644 --- a/splunk-otel-android-volley/src/test/java/com/splunk/rum/TracingHurlStackExceptionTest.java +++ b/splunk-otel-android-volley/src/test/java/com/splunk/rum/TracingHurlStackExceptionTest.java @@ -25,7 +25,7 @@ import com.android.volley.toolbox.StringRequest; import io.opentelemetry.sdk.testing.junit4.OpenTelemetryRule; import io.opentelemetry.sdk.trace.data.SpanData; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import io.opentelemetry.semconv.SemanticAttributes; import java.util.List; import java.util.concurrent.TimeUnit; import org.junit.After; diff --git a/splunk-otel-android-volley/src/test/java/com/splunk/rum/TracingHurlStackTest.java b/splunk-otel-android-volley/src/test/java/com/splunk/rum/TracingHurlStackTest.java index 3ff70063..a331cae6 100644 --- a/splunk-otel-android-volley/src/test/java/com/splunk/rum/TracingHurlStackTest.java +++ b/splunk-otel-android-volley/src/test/java/com/splunk/rum/TracingHurlStackTest.java @@ -34,7 +34,7 @@ import io.opentelemetry.sdk.testing.junit4.OpenTelemetryRule; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.sdk.trace.data.StatusData; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import io.opentelemetry.semconv.SemanticAttributes; import java.io.IOException; import java.net.ServerSocket; import java.net.URL; diff --git a/splunk-otel-android/build.gradle.kts b/splunk-otel-android/build.gradle.kts index d3b76f38..8bb4ae7a 100644 --- a/splunk-otel-android/build.gradle.kts +++ b/splunk-otel-android/build.gradle.kts @@ -41,6 +41,7 @@ android { val otelVersion = "1.30.0-SNAPSHOT" val otelAlphaVersion = otelVersion.replaceFirst("(-SNAPSHOT)?$".toRegex(), "-alpha$1") +val otelSemconvVersion = "1.21.0-alpha" dependencies { api(platform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:$otelAlphaVersion")) @@ -56,7 +57,7 @@ dependencies { implementation("io.zipkin.reporter2:zipkin-sender-okhttp3") implementation("io.opentelemetry:opentelemetry-exporter-logging") - implementation("io.opentelemetry:opentelemetry-semconv") + implementation("io.opentelemetry.semconv:opentelemetry-semconv:$otelSemconvVersion") implementation("io.opentelemetry.instrumentation:opentelemetry-okhttp-3.0") api("io.opentelemetry:opentelemetry-api") diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/LogToSpanBridge.java b/splunk-otel-android/src/main/java/com/splunk/rum/LogToSpanBridge.java index d4e8085b..4a98b7d4 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/LogToSpanBridge.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/LogToSpanBridge.java @@ -33,7 +33,7 @@ import io.opentelemetry.sdk.logs.ReadWriteLogRecord; import io.opentelemetry.sdk.logs.data.Body; import io.opentelemetry.sdk.logs.data.LogRecordData; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import io.opentelemetry.semconv.SemanticAttributes; import java.util.concurrent.TimeUnit; final class LogToSpanBridge implements LogRecordProcessor { diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/RumInitializer.java b/splunk-otel-android/src/main/java/com/splunk/rum/RumInitializer.java index 56c46bdb..d2206e1a 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/RumInitializer.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/RumInitializer.java @@ -24,7 +24,7 @@ import static com.splunk.rum.SplunkRum.RUM_TRACER_NAME; import static io.opentelemetry.android.RumConstants.APP_START_SPAN_NAME; import static io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor.constant; -import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.DEPLOYMENT_ENVIRONMENT; +import static io.opentelemetry.semconv.ResourceAttributes.DEPLOYMENT_ENVIRONMENT; import static java.util.Objects.requireNonNull; import android.app.Application; diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/SplunkSpanDataModifier.java b/splunk-otel-android/src/main/java/com/splunk/rum/SplunkSpanDataModifier.java index 0aceaa9a..57184ddf 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/SplunkSpanDataModifier.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/SplunkSpanDataModifier.java @@ -19,9 +19,21 @@ import static com.splunk.rum.SplunkRum.ERROR_MESSAGE_KEY; import static com.splunk.rum.SplunkRum.ERROR_TYPE_KEY; import static io.opentelemetry.api.common.AttributeKey.stringKey; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.EXCEPTION_MESSAGE; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.EXCEPTION_STACKTRACE; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.EXCEPTION_TYPE; +import static io.opentelemetry.semconv.SemanticAttributes.EXCEPTION_MESSAGE; +import static io.opentelemetry.semconv.SemanticAttributes.EXCEPTION_STACKTRACE; +import static io.opentelemetry.semconv.SemanticAttributes.EXCEPTION_TYPE; +import static io.opentelemetry.semconv.SemanticAttributes.NETWORK_CARRIER_ICC; +import static io.opentelemetry.semconv.SemanticAttributes.NETWORK_CARRIER_MCC; +import static io.opentelemetry.semconv.SemanticAttributes.NETWORK_CARRIER_MNC; +import static io.opentelemetry.semconv.SemanticAttributes.NETWORK_CARRIER_NAME; +import static io.opentelemetry.semconv.SemanticAttributes.NETWORK_CONNECTION_SUBTYPE; +import static io.opentelemetry.semconv.SemanticAttributes.NETWORK_CONNECTION_TYPE; +import static io.opentelemetry.semconv.SemanticAttributes.NET_HOST_CARRIER_ICC; +import static io.opentelemetry.semconv.SemanticAttributes.NET_HOST_CARRIER_MCC; +import static io.opentelemetry.semconv.SemanticAttributes.NET_HOST_CARRIER_MNC; +import static io.opentelemetry.semconv.SemanticAttributes.NET_HOST_CARRIER_NAME; +import static io.opentelemetry.semconv.SemanticAttributes.NET_HOST_CONNECTION_SUBTYPE; +import static io.opentelemetry.semconv.SemanticAttributes.NET_HOST_CONNECTION_TYPE; import static java.util.Arrays.asList; import static java.util.Collections.unmodifiableSet; @@ -35,8 +47,8 @@ import io.opentelemetry.sdk.trace.data.EventData; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.sdk.trace.export.SpanExporter; -import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import io.opentelemetry.semconv.ResourceAttributes; +import io.opentelemetry.semconv.SemanticAttributes; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -103,6 +115,10 @@ private SpanData modify(SpanData original) { spanContext = original.getSpanContext(); } + // Convert new net semconv to old + modifiedAttributes = + downgradeNetworkAttrNames(original.getAttributes(), modifiedAttributes); + // zipkin eats the event attributes that are recorded by default, so we need to convert // the exception event to span attributes for (EventData event : original.getEvents()) { @@ -129,6 +145,19 @@ private SpanData modify(SpanData original) { return new SplunkSpan(original, spanContext, modifiedEvents, modifiedAttributes.build()); } + // At least until we can leverage the new names... + private AttributesBuilder downgradeNetworkAttrNames( + Attributes originalAttributes, AttributesBuilder attributes) { + return AttributeReplacer.with(originalAttributes, attributes) + .update(NETWORK_CONNECTION_TYPE, NET_HOST_CONNECTION_TYPE) + .update(NETWORK_CONNECTION_SUBTYPE, NET_HOST_CONNECTION_SUBTYPE) + .update(NETWORK_CARRIER_ICC, NET_HOST_CARRIER_ICC) + .update(NETWORK_CARRIER_MCC, NET_HOST_CARRIER_MCC) + .update(NETWORK_CARRIER_MNC, NET_HOST_CARRIER_MNC) + .update(NETWORK_CARRIER_NAME, NET_HOST_CARRIER_NAME) + .finish(); + } + private SpanContext extractReactNativeIdsIfPresent(SpanData original) { Attributes attributes = original.getAttributes(); SpanContext originalSpanContext = original.getSpanContext(); @@ -230,4 +259,31 @@ public int getTotalAttributeCount() { return modifiedAttributes.size(); } } + + private static class AttributeReplacer { + private final Attributes original; + private final AttributesBuilder attributes; + + private static AttributeReplacer with(Attributes original, AttributesBuilder attributes) { + return new AttributeReplacer(original, attributes); + } + + private AttributeReplacer(Attributes original, AttributesBuilder attributes) { + this.original = original; + this.attributes = attributes; + } + + AttributeReplacer update(AttributeKey currentName, AttributeKey replacementName) { + T value = original.get(currentName); + if (value != null) { + attributes.remove(currentName); + attributes.put(replacementName, value); + } + return this; + } + + AttributesBuilder finish() { + return attributes; + } + } } diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/StandardAttributes.java b/splunk-otel-android/src/main/java/com/splunk/rum/StandardAttributes.java index 71296748..6d436097 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/StandardAttributes.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/StandardAttributes.java @@ -21,11 +21,11 @@ import io.opentelemetry.android.export.SpanDataModifier; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import io.opentelemetry.semconv.SemanticAttributes; /** * This class hold {@link AttributeKey}s for standard RUM-related attributes that are not in the - * OpenTelemetry {@link io.opentelemetry.semconv.trace.attributes.SemanticAttributes} definitions. + * OpenTelemetry {@link io.opentelemetry.semconv.SemanticAttributes} definitions. */ public final class StandardAttributes { /** diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/LogToSpanBridgeTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/LogToSpanBridgeTest.java index ebec61de..9ab98f89 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/LogToSpanBridgeTest.java +++ b/splunk-otel-android/src/test/java/com/splunk/rum/LogToSpanBridgeTest.java @@ -28,7 +28,7 @@ import io.opentelemetry.sdk.logs.data.LogRecordData; import io.opentelemetry.sdk.testing.junit5.OpenTelemetryExtension; import io.opentelemetry.sdk.trace.data.SpanData; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import io.opentelemetry.semconv.SemanticAttributes; import java.util.List; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/RumInitializerTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/RumInitializerTest.java index 129f00f8..c2ff8f61 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/RumInitializerTest.java +++ b/splunk-otel-android/src/test/java/com/splunk/rum/RumInitializerTest.java @@ -44,7 +44,7 @@ import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.sdk.trace.data.StatusData; import io.opentelemetry.sdk.trace.export.SpanExporter; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import io.opentelemetry.semconv.SemanticAttributes; import java.util.ArrayList; import java.util.Arrays; import java.util.List; diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/SplunkSpanDataModifierTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/SplunkSpanDataModifierTest.java index 7b0033a5..84161817 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/SplunkSpanDataModifierTest.java +++ b/splunk-otel-android/src/test/java/com/splunk/rum/SplunkSpanDataModifierTest.java @@ -39,8 +39,8 @@ import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.sdk.trace.data.StatusData; import io.opentelemetry.sdk.trace.export.SpanExporter; -import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import io.opentelemetry.semconv.ResourceAttributes; +import io.opentelemetry.semconv.SemanticAttributes; import java.util.Arrays; import java.util.Collection; import org.junit.jupiter.api.Test;