Skip to content

Commit

Permalink
Merge 81fee1d into 07e1216
Browse files Browse the repository at this point in the history
  • Loading branch information
adinauer authored Aug 29, 2024
2 parents 07e1216 + 81fee1d commit bf6dbe7
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 28 deletions.
7 changes: 4 additions & 3 deletions buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,15 @@ object Config {
val apolloKotlin = "com.apollographql.apollo3:apollo-runtime:3.8.2"

object OpenTelemetry {
val otelVersion = "1.39.0"
val otelVersion = "1.41.0"
val otelAlphaVersion = "$otelVersion-alpha"
val otelJavaagentVersion = "2.5.0"
val otelJavaagentVersion = "2.7.0"
val otelJavaagentAlphaVersion = "$otelJavaagentVersion-alpha"
val otelSemanticConvetionsVersion = "1.23.1-alpha"
val otelSemanticConvetionsVersion = "1.25.0-alpha" // check https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/dependencyManagement/build.gradle.kts#L49 for release version above to find a compatible version

val otelSdk = "io.opentelemetry:opentelemetry-sdk:$otelVersion"
val otelSemconv = "io.opentelemetry.semconv:opentelemetry-semconv:$otelSemanticConvetionsVersion"
val otelSemconvIncubating = "io.opentelemetry.semconv:opentelemetry-semconv-incubating:$otelSemanticConvetionsVersion"
val otelJavaAgent = "io.opentelemetry.javaagent:opentelemetry-javaagent:$otelJavaagentVersion"
val otelJavaAgentExtensionApi = "io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api:$otelJavaagentAlphaVersion"
val otelJavaAgentTooling = "io.opentelemetry.javaagent:opentelemetry-javaagent-tooling:$otelJavaagentAlphaVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies {

testImplementation(Config.Libs.OpenTelemetry.otelSdk)
testImplementation(Config.Libs.OpenTelemetry.otelSemconv)
testImplementation(Config.Libs.OpenTelemetry.otelSemconvIncubating)
}

configure<SourceSetContainer> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies {

implementation(Config.Libs.OpenTelemetry.otelSdk)
compileOnly(Config.Libs.OpenTelemetry.otelSemconv)
compileOnly(Config.Libs.OpenTelemetry.otelSemconvIncubating)

compileOnly(Config.CompileOnly.nopen)
errorprone(Config.CompileOnly.nopenChecker)
Expand All @@ -44,6 +45,7 @@ dependencies {

testImplementation(Config.Libs.OpenTelemetry.otelSdk)
testImplementation(Config.Libs.OpenTelemetry.otelSemconv)
testImplementation(Config.Libs.OpenTelemetry.otelSemconvIncubating)
}

configure<SourceSetContainer> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.semconv.UrlAttributes;
import io.sentry.DsnUtil;
import io.sentry.IScopes;
import java.util.Arrays;
Expand All @@ -27,12 +27,13 @@ public static boolean isSentryRequest(
return false;
}

final @Nullable String httpUrl = attributes.get(SemanticAttributes.HTTP_URL);
final @Nullable String httpUrl =
attributes.get(io.opentelemetry.semconv.SemanticAttributes.HTTP_URL);
if (DsnUtil.urlContainsDsnHost(scopes.getOptions(), httpUrl)) {
return true;
}

final @Nullable String fullUrl = attributes.get(SemanticAttributes.URL_FULL);
final @Nullable String fullUrl = attributes.get(UrlAttributes.URL_FULL);
if (DsnUtil.urlContainsDsnHost(scopes.getOptions(), fullUrl)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,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.ResourceAttributes;
import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.semconv.HttpAttributes;
import io.opentelemetry.semconv.incubating.ProcessIncubatingAttributes;
import io.sentry.Baggage;
import io.sentry.DateUtils;
import io.sentry.DefaultSpanFactory;
Expand Down Expand Up @@ -63,7 +63,7 @@ public final class SentrySpanExporter implements SpanExporter {
InternalSemanticAttributes.PROFILE_SAMPLED.getKey(),
InternalSemanticAttributes.PROFILE_SAMPLE_RATE.getKey(),
InternalSemanticAttributes.PARENT_SAMPLED.getKey(),
ResourceAttributes.PROCESS_COMMAND_ARGS.getKey() // can be very long
ProcessIncubatingAttributes.PROCESS_COMMAND_ARGS.getKey() // can be very long
);
private static final @NotNull Long SPAN_TIMEOUT = DateUtils.secondsToNanos(5 * 60);

Expand Down Expand Up @@ -455,7 +455,7 @@ private SpanStatus mapOtelStatus(
}

final @Nullable Long httpStatus =
otelSpanData.getAttributes().get(SemanticAttributes.HTTP_STATUS_CODE);
otelSpanData.getAttributes().get(HttpAttributes.HTTP_RESPONSE_STATUS_CODE);
if (httpStatus != null) {
final @Nullable SpanStatus spanStatus = SpanStatus.fromHttpStatusCode(httpStatus.intValue());
if (spanStatus != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import io.opentelemetry.sdk.trace.SpanProcessor;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.data.StatusData;
import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.semconv.HttpAttributes;
import io.opentelemetry.semconv.UrlAttributes;
import io.sentry.Baggage;
import io.sentry.DsnUtil;
import io.sentry.IScopes;
Expand Down Expand Up @@ -261,7 +262,7 @@ private boolean isSentryRequest(final @NotNull ReadableSpan otelSpan) {
return false;
}

final @Nullable String httpUrl = otelSpan.getAttribute(SemanticAttributes.HTTP_URL);
final @Nullable String httpUrl = otelSpan.getAttribute(UrlAttributes.URL_FULL);
return DsnUtil.urlContainsDsnHost(scopes.getOptions(), httpUrl);
}

Expand Down Expand Up @@ -345,7 +346,8 @@ private SpanStatus mapOtelStatus(final @NotNull ReadableSpan otelSpan) {
return SpanStatus.OK;
}

final @Nullable Long httpStatus = otelSpan.getAttribute(SemanticAttributes.HTTP_STATUS_CODE);
final @Nullable Long httpStatus =
otelSpan.getAttribute(HttpAttributes.HTTP_RESPONSE_STATUS_CODE);
if (httpStatus != null) {
final @Nullable SpanStatus spanStatus = SpanStatus.fromHttpStatusCode(httpStatus.intValue());
if (spanStatus != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.semconv.HttpAttributes;
import io.opentelemetry.semconv.UrlAttributes;
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;
import io.opentelemetry.semconv.incubating.HttpIncubatingAttributes;
import io.sentry.protocol.TransactionNameSource;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
Expand All @@ -17,18 +20,17 @@ public final class SpanDescriptionExtractor {
final @NotNull SpanData otelSpan, final @Nullable OtelSpanWrapper sentrySpan) {
final @NotNull Attributes attributes = otelSpan.getAttributes();

final @Nullable String httpMethod = attributes.get(SemanticAttributes.HTTP_METHOD);
final @Nullable String httpMethod = attributes.get(HttpAttributes.HTTP_REQUEST_METHOD);
if (httpMethod != null) {
return descriptionForHttpMethod(otelSpan, httpMethod);
}

final @Nullable String httpRequestMethod =
attributes.get(SemanticAttributes.HTTP_REQUEST_METHOD);
final @Nullable String httpRequestMethod = attributes.get(HttpAttributes.HTTP_REQUEST_METHOD);
if (httpRequestMethod != null) {
return descriptionForHttpMethod(otelSpan, httpRequestMethod);
}

final @Nullable String dbSystem = attributes.get(SemanticAttributes.DB_SYSTEM);
final @Nullable String dbSystem = attributes.get(DbIncubatingAttributes.DB_SYSTEM);
if (dbSystem != null) {
return descriptionForDbSystem(otelSpan);
}
Expand All @@ -53,15 +55,14 @@ private OtelSpanInfo descriptionForHttpMethod(
} else if (SpanKind.SERVER.equals(kind)) {
opBuilder.append(".server");
}
final @Nullable String httpTarget = attributes.get(SemanticAttributes.HTTP_TARGET);
final @Nullable String httpRoute = attributes.get(SemanticAttributes.HTTP_ROUTE);
final @Nullable String httpTarget = attributes.get(HttpIncubatingAttributes.HTTP_TARGET);
final @Nullable String httpRoute = attributes.get(HttpAttributes.HTTP_ROUTE);
@Nullable String httpPath = httpRoute;
if (httpPath == null) {
httpPath = httpTarget;
}
final @NotNull String op = opBuilder.toString();

final @Nullable String urlFull = attributes.get(SemanticAttributes.URL_FULL);
final @Nullable String urlFull = attributes.get(UrlAttributes.URL_FULL);
if (urlFull != null) {
if (httpPath == null) {
httpPath = urlFull;
Expand All @@ -82,7 +83,7 @@ private OtelSpanInfo descriptionForHttpMethod(
@SuppressWarnings("deprecation")
private OtelSpanInfo descriptionForDbSystem(final @NotNull SpanData otelSpan) {
final @NotNull Attributes attributes = otelSpan.getAttributes();
@Nullable String dbStatement = attributes.get(SemanticAttributes.DB_STATEMENT);
@Nullable String dbStatement = attributes.get(DbIncubatingAttributes.DB_STATEMENT);
@NotNull String description = dbStatement != null ? dbStatement : otelSpan.getName();
return new OtelSpanInfo("db", description, TransactionNameSource.TASK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import io.opentelemetry.sdk.OpenTelemetrySdk
import io.opentelemetry.sdk.trace.ReadWriteSpan
import io.opentelemetry.sdk.trace.ReadableSpan
import io.opentelemetry.sdk.trace.SdkTracerProvider
import io.opentelemetry.semconv.SemanticAttributes
import io.opentelemetry.semconv.HttpAttributes
import io.opentelemetry.semconv.UrlAttributes
import io.sentry.Baggage
import io.sentry.BaggageHeader
import io.sentry.Hint
Expand Down Expand Up @@ -125,7 +126,7 @@ class SentrySpanProcessorTest {
fun `ignores sentry client request`() {
fixture.setup()
givenSpanBuilder(SpanKind.CLIENT)
.setAttribute(SemanticAttributes.HTTP_URL, "https://[email protected]/proj/some-api")
.setAttribute(UrlAttributes.URL_FULL, "https://[email protected]/proj/some-api")
.startSpan()

thenNoTransactionIsStarted()
Expand All @@ -135,7 +136,7 @@ class SentrySpanProcessorTest {
fun `ignores sentry internal request`() {
fixture.setup()
givenSpanBuilder(SpanKind.CLIENT)
.setAttribute(SemanticAttributes.HTTP_URL, "https://[email protected]/proj/some-api")
.setAttribute(UrlAttributes.URL_FULL, "https://[email protected]/proj/some-api")
.startSpan()

thenNoTransactionIsStarted()
Expand Down Expand Up @@ -304,8 +305,8 @@ class SentrySpanProcessorTest {
thenChildSpanIsStarted()

otelChildSpan.setStatus(StatusCode.ERROR)
otelChildSpan.setAttribute(SemanticAttributes.HTTP_URL, "http://github.com/getsentry/sentry-java")
otelChildSpan.setAttribute(SemanticAttributes.HTTP_STATUS_CODE, 404L)
otelChildSpan.setAttribute(UrlAttributes.URL_FULL, "http://github.com/getsentry/sentry-java")
otelChildSpan.setAttribute(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 404L)

otelChildSpan.end()
thenChildSpanIsFinished(SpanStatus.NOT_FOUND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies {

testImplementation(Config.Libs.OpenTelemetry.otelSdk)
testImplementation(Config.Libs.OpenTelemetry.otelSemconv)
testImplementation(Config.Libs.OpenTelemetry.otelSemconvIncubating)
}

configure<SourceSetContainer> {
Expand Down

0 comments on commit bf6dbe7

Please sign in to comment.