|
2 | 2 |
|
3 | 3 | import io.opentelemetry.api.common.Attributes; |
4 | 4 | import io.opentelemetry.api.trace.SpanKind; |
5 | | -import io.opentelemetry.sdk.trace.ReadableSpan; |
6 | 5 | import io.opentelemetry.sdk.trace.data.SpanData; |
7 | 6 | import io.opentelemetry.semconv.SemanticAttributes; |
8 | 7 | import io.sentry.protocol.TransactionNameSource; |
|
15 | 14 | @ApiStatus.Internal |
16 | 15 | public final class SpanDescriptionExtractor { |
17 | 16 |
|
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 | | - |
71 | 17 | @SuppressWarnings("deprecation") |
72 | 18 | public @NotNull OtelSpanInfo extractSpanInfo(final @NotNull SpanData otelSpan) { |
73 | 19 | OtelSpanInfo spanInfo = extractSpanDescription(otelSpan); |
|
0 commit comments