Skip to content

Commit b3919bd

Browse files
committed
Deduplicate SpanInfo extraction
1 parent 9b900c7 commit b3919bd

File tree

3 files changed

+2
-57
lines changed

3 files changed

+2
-57
lines changed

sentry-opentelemetry/sentry-opentelemetry-core/api/sentry-opentelemetry-core.api

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public final class io/sentry/opentelemetry/SentrySpanProcessor : io/opentelemetr
5454

5555
public final class io/sentry/opentelemetry/SpanDescriptionExtractor {
5656
public fun <init> ()V
57-
public fun extractSpanDescription (Lio/opentelemetry/sdk/trace/ReadableSpan;)Lio/sentry/opentelemetry/OtelSpanInfo;
5857
public fun extractSpanInfo (Lio/opentelemetry/sdk/trace/data/SpanData;)Lio/sentry/opentelemetry/OtelSpanInfo;
5958
}
6059

sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/SentrySpanProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ private boolean isSentryRequest(final @NotNull ReadableSpan otelSpan) {
282282
private void updateTransactionWithOtelData(
283283
final @NotNull ITransaction sentryTransaction, final @NotNull ReadableSpan otelSpan) {
284284
final @NotNull OtelSpanInfo otelSpanInfo =
285-
spanDescriptionExtractor.extractSpanDescription(otelSpan);
285+
spanDescriptionExtractor.extractSpanInfo(otelSpan.toSpanData());
286286
sentryTransaction.setOperation(otelSpanInfo.getOp());
287287
sentryTransaction.setName(
288288
otelSpanInfo.getDescription(), otelSpanInfo.getTransactionNameSource());
@@ -317,7 +317,7 @@ private void updateSpanWithOtelData(
317317
});
318318

319319
final @NotNull OtelSpanInfo otelSpanInfo =
320-
spanDescriptionExtractor.extractSpanDescription(otelSpan);
320+
spanDescriptionExtractor.extractSpanInfo(otelSpan.toSpanData());
321321
sentrySpan.setOperation(otelSpanInfo.getOp());
322322
sentrySpan.setDescription(otelSpanInfo.getDescription());
323323
}

sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/SpanDescriptionExtractor.java

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import io.opentelemetry.api.common.Attributes;
44
import io.opentelemetry.api.trace.SpanKind;
5-
import io.opentelemetry.sdk.trace.ReadableSpan;
65
import io.opentelemetry.sdk.trace.data.SpanData;
76
import io.opentelemetry.semconv.SemanticAttributes;
87
import io.sentry.protocol.TransactionNameSource;
@@ -15,59 +14,6 @@
1514
@ApiStatus.Internal
1615
public final class SpanDescriptionExtractor {
1716

18-
// TODO [POTEL] remove these method overloads and pass in SpanData instead (span.toSpanData())
19-
@SuppressWarnings("deprecation")
20-
public @NotNull OtelSpanInfo extractSpanDescription(final @NotNull ReadableSpan otelSpan) {
21-
final @NotNull String name = otelSpan.getName();
22-
23-
final @Nullable String httpMethod = otelSpan.getAttribute(SemanticAttributes.HTTP_METHOD);
24-
if (httpMethod != null) {
25-
return descriptionForHttpMethod(otelSpan, httpMethod);
26-
}
27-
28-
final @Nullable String dbSystem = otelSpan.getAttribute(SemanticAttributes.DB_SYSTEM);
29-
if (dbSystem != null) {
30-
return descriptionForDbSystem(otelSpan);
31-
}
32-
33-
return new OtelSpanInfo(name, name, TransactionNameSource.CUSTOM);
34-
}
35-
36-
@SuppressWarnings("deprecation")
37-
private OtelSpanInfo descriptionForHttpMethod(
38-
final @NotNull ReadableSpan otelSpan, final @NotNull String httpMethod) {
39-
final @NotNull String name = otelSpan.getName();
40-
final @NotNull SpanKind kind = otelSpan.getKind();
41-
final @NotNull StringBuilder opBuilder = new StringBuilder("http");
42-
43-
if (SpanKind.CLIENT.equals(kind)) {
44-
opBuilder.append(".client");
45-
} else if (SpanKind.SERVER.equals(kind)) {
46-
opBuilder.append(".server");
47-
}
48-
final @Nullable String httpTarget = otelSpan.getAttribute(SemanticAttributes.HTTP_TARGET);
49-
final @Nullable String httpRoute = otelSpan.getAttribute(SemanticAttributes.HTTP_ROUTE);
50-
final @Nullable String httpPath = httpRoute != null ? httpRoute : httpTarget;
51-
final @NotNull String op = opBuilder.toString();
52-
53-
if (httpPath == null) {
54-
return new OtelSpanInfo(op, name, TransactionNameSource.CUSTOM);
55-
}
56-
57-
final @NotNull String description = httpMethod + " " + httpPath;
58-
final @NotNull TransactionNameSource transactionNameSource =
59-
httpRoute != null ? TransactionNameSource.ROUTE : TransactionNameSource.URL;
60-
61-
return new OtelSpanInfo(op, description, transactionNameSource);
62-
}
63-
64-
@SuppressWarnings("deprecation")
65-
private OtelSpanInfo descriptionForDbSystem(final @NotNull ReadableSpan otelSpan) {
66-
@Nullable String dbStatement = otelSpan.getAttribute(SemanticAttributes.DB_STATEMENT);
67-
@NotNull String description = dbStatement != null ? dbStatement : otelSpan.getName();
68-
return new OtelSpanInfo("db", description, TransactionNameSource.TASK);
69-
}
70-
7117
@SuppressWarnings("deprecation")
7218
public @NotNull OtelSpanInfo extractSpanInfo(final @NotNull SpanData otelSpan) {
7319
OtelSpanInfo spanInfo = extractSpanDescription(otelSpan);

0 commit comments

Comments
 (0)