Skip to content

Commit e5e6905

Browse files
authored
Assume http.client for span op if not a root span (#4257)
* Assume http.client for span op if not a root span * changelog
1 parent 9fba6e3 commit e5e6905

File tree

3 files changed

+363
-19
lines changed

3 files changed

+363
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- Pass OpenTelemetry span attributes into TracesSampler callback ([#4253](https://github.com/getsentry/sentry-java/pull/4253))
2020
- `SamplingContext` now has a `getAttribute` method that grants access to OpenTelemetry span attributes via their String key (e.g. `http.request.method`)
2121
- Fix AbstractMethodError when using SentryTraced for Jetpack Compose ([#4255](https://github.com/getsentry/sentry-java/pull/4255))
22+
- Assume `http.client` for span `op` if not a root span ([#4257](https://github.com/getsentry/sentry-java/pull/4257))
2223
- Avoid unnecessary copies when using `CopyOnWriteArrayList` ([#4247](https://github.com/getsentry/sentry-java/pull/4247))
2324
- This affects in particular `SentryTracer.getLatestActiveSpan` which would have previously copied all child span references. This may have caused `OutOfMemoryError` on certain devices due to high frequency of calling the method.
2425

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,16 @@ public final class SpanDescriptionExtractor {
1818
@SuppressWarnings("deprecation")
1919
public @NotNull OtelSpanInfo extractSpanInfo(
2020
final @NotNull SpanData otelSpan, final @Nullable IOtelSpanWrapper sentrySpan) {
21-
if (!isInternalSpanKind(otelSpan)) {
22-
final @NotNull Attributes attributes = otelSpan.getAttributes();
23-
24-
final @Nullable String httpMethod = attributes.get(HttpAttributes.HTTP_REQUEST_METHOD);
25-
if (httpMethod != null) {
26-
return descriptionForHttpMethod(otelSpan, httpMethod);
27-
}
21+
final @NotNull Attributes attributes = otelSpan.getAttributes();
2822

29-
final @Nullable String httpRequestMethod = attributes.get(HttpAttributes.HTTP_REQUEST_METHOD);
30-
if (httpRequestMethod != null) {
31-
return descriptionForHttpMethod(otelSpan, httpRequestMethod);
32-
}
23+
final @Nullable String httpMethod = attributes.get(HttpAttributes.HTTP_REQUEST_METHOD);
24+
if (httpMethod != null) {
25+
return descriptionForHttpMethod(otelSpan, httpMethod);
26+
}
3327

34-
final @Nullable String dbSystem = attributes.get(DbIncubatingAttributes.DB_SYSTEM);
35-
if (dbSystem != null) {
36-
return descriptionForDbSystem(otelSpan);
37-
}
28+
final @Nullable String dbSystem = attributes.get(DbIncubatingAttributes.DB_SYSTEM);
29+
if (dbSystem != null) {
30+
return descriptionForDbSystem(otelSpan);
3831
}
3932

4033
final @NotNull String name = otelSpan.getName();
@@ -44,10 +37,6 @@ public final class SpanDescriptionExtractor {
4437
return new OtelSpanInfo(name, description, TransactionNameSource.CUSTOM);
4538
}
4639

47-
private boolean isInternalSpanKind(final @NotNull SpanData otelSpan) {
48-
return SpanKind.INTERNAL.equals(otelSpan.getKind());
49-
}
50-
5140
@SuppressWarnings("deprecation")
5241
private OtelSpanInfo descriptionForHttpMethod(
5342
final @NotNull SpanData otelSpan, final @NotNull String httpMethod) {
@@ -60,6 +49,12 @@ private OtelSpanInfo descriptionForHttpMethod(
6049
opBuilder.append(".client");
6150
} else if (SpanKind.SERVER.equals(kind)) {
6251
opBuilder.append(".server");
52+
} else {
53+
// we cannot be certain that a root span is a server span as it might simply be a client span
54+
// without parent
55+
if (!isRootSpan(otelSpan)) {
56+
opBuilder.append(".client");
57+
}
6358
}
6459
final @Nullable String httpTarget = attributes.get(HttpIncubatingAttributes.HTTP_TARGET);
6560
final @Nullable String httpRoute = attributes.get(HttpAttributes.HTTP_ROUTE);
@@ -92,6 +87,10 @@ private OtelSpanInfo descriptionForHttpMethod(
9287
return new OtelSpanInfo(op, description, transactionNameSource);
9388
}
9489

90+
private static boolean isRootSpan(SpanData otelSpan) {
91+
return !otelSpan.getParentSpanContext().isValid() || otelSpan.getParentSpanContext().isRemote();
92+
}
93+
9594
@SuppressWarnings("deprecation")
9695
private OtelSpanInfo descriptionForDbSystem(final @NotNull SpanData otelSpan) {
9796
final @NotNull Attributes attributes = otelSpan.getAttributes();

0 commit comments

Comments
 (0)