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

Automatically create op from span attributes conditionally 5a #3905

Closed
Closed
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 @@ -2,6 +2,7 @@

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.semconv.HttpAttributes;
import io.opentelemetry.semconv.UrlAttributes;
Expand All @@ -18,21 +19,23 @@ public final class SpanDescriptionExtractor {
@SuppressWarnings("deprecation")
public @NotNull OtelSpanInfo extractSpanInfo(
final @NotNull SpanData otelSpan, final @Nullable IOtelSpanWrapper sentrySpan) {
final @NotNull Attributes attributes = otelSpan.getAttributes();
if (isOpenTelemetryAutoInstrumentation(otelSpan)) {
final @NotNull Attributes attributes = otelSpan.getAttributes();

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

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

final @Nullable String dbSystem = attributes.get(DbIncubatingAttributes.DB_SYSTEM);
if (dbSystem != null) {
return descriptionForDbSystem(otelSpan);
final @Nullable String dbSystem = attributes.get(DbIncubatingAttributes.DB_SYSTEM);
if (dbSystem != null) {
return descriptionForDbSystem(otelSpan);
}
}

final @NotNull String name = otelSpan.getName();
Expand All @@ -42,6 +45,13 @@ public final class SpanDescriptionExtractor {
return new OtelSpanInfo(name, description, TransactionNameSource.CUSTOM);
}

private boolean isOpenTelemetryAutoInstrumentation(final @NotNull SpanData otelSpan) {
final @NotNull InstrumentationScopeInfo instrumentationScopeInfo =
otelSpan.getInstrumentationScopeInfo();
final @NotNull String instrumentationName = instrumentationScopeInfo.getName();
return instrumentationName.startsWith("io.opentelemetry");
}

@SuppressWarnings("deprecation")
private OtelSpanInfo descriptionForHttpMethod(
final @NotNull SpanData otelSpan, final @NotNull String httpMethod) {
Expand Down
Loading