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

Update java semantic conventions #658

Merged
merged 4 commits into from
Oct 16, 2023
Merged
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
3 changes: 2 additions & 1 deletion splunk-otel-android-volley/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion splunk-otel-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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()) {
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}

<T> AttributeReplacer update(AttributeKey<T> currentName, AttributeKey<T> replacementName) {
T value = original.get(currentName);
if (value != null) {
attributes.remove(currentName);
attributes.put(replacementName, value);
}
return this;
}

AttributesBuilder finish() {
return attributes;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down