Skip to content

Commit 8094503

Browse files
lcianadinauergetsentry-bot
authored
Set thread information on transaction from OpenTelemetry attributes (#4478)
Co-authored-by: Alexander Dinauer <adinauer@users.noreply.github.com> Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io>
1 parent 0f37c1d commit 8094503

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Optimize scope when maxBreadcrumb is 0 ([#4504](https://github.com/getsentry/sentry-java/pull/4504))
88
- Fix javadoc on TransportResult ([#4528](https://github.com/getsentry/sentry-java/pull/4528))
9+
- Set thread information on transaction from OpenTelemetry attributes ([#4478](https://github.com/getsentry/sentry-java/pull/4478))
910

1011
### Internal
1112

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public final class io/sentry/opentelemetry/OtelSpanInfo {
5050
public fun getTransactionNameSource ()Lio/sentry/protocol/TransactionNameSource;
5151
}
5252

53+
public final class io/sentry/opentelemetry/OtelSpanUtils {
54+
public fun <init> ()V
55+
public static fun maybeTransferOtelAttribute (Lio/opentelemetry/sdk/trace/data/SpanData;Lio/sentry/ISpan;Lio/opentelemetry/api/common/AttributeKey;)V
56+
}
57+
5358
public final class io/sentry/opentelemetry/OtelSpanWrapper : io/sentry/opentelemetry/IOtelSpanWrapper {
5459
public fun <init> (Lio/opentelemetry/sdk/trace/ReadWriteSpan;Lio/sentry/IScopes;Lio/sentry/SentryDate;Lio/sentry/TracesSamplingDecision;Lio/sentry/opentelemetry/IOtelSpanWrapper;Lio/sentry/SpanId;Lio/sentry/Baggage;)V
5560
public fun finish ()V
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.sentry.opentelemetry;
2+
3+
import io.opentelemetry.api.common.AttributeKey;
4+
import io.opentelemetry.api.common.Attributes;
5+
import io.opentelemetry.sdk.trace.data.SpanData;
6+
import io.sentry.ISpan;
7+
import org.jetbrains.annotations.NotNull;
8+
import org.jetbrains.annotations.Nullable;
9+
10+
public final class OtelSpanUtils {
11+
public static <T> void maybeTransferOtelAttribute(
12+
final @NotNull SpanData otelSpan,
13+
final @NotNull ISpan sentrySpan,
14+
final @NotNull AttributeKey<T> key) {
15+
final @NotNull Attributes attributes = otelSpan.getAttributes();
16+
final @Nullable T value = attributes.get(key);
17+
if (value != null) {
18+
sentrySpan.setData(key.getKey(), value);
19+
}
20+
}
21+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static io.sentry.TransactionContext.DEFAULT_TRANSACTION_NAME;
44
import static io.sentry.opentelemetry.InternalSemanticAttributes.IS_REMOTE_PARENT;
55
import static io.sentry.opentelemetry.OtelInternalSpanDetectionUtil.isSentryRequest;
6+
import static io.sentry.opentelemetry.OtelSpanUtils.maybeTransferOtelAttribute;
67

78
import io.opentelemetry.api.common.Attributes;
89
import io.opentelemetry.api.trace.StatusCode;
@@ -12,6 +13,7 @@
1213
import io.opentelemetry.sdk.trace.export.SpanExporter;
1314
import io.opentelemetry.semconv.HttpAttributes;
1415
import io.opentelemetry.semconv.incubating.ProcessIncubatingAttributes;
16+
import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes;
1517
import io.sentry.Baggage;
1618
import io.sentry.DateUtils;
1719
import io.sentry.DefaultSpanFactory;
@@ -340,6 +342,9 @@ private void transferSpanDetails(
340342
setOtelSpanKind(span, sentryTransaction);
341343
transferSpanDetails(sentrySpanMaybe, sentryTransaction);
342344

345+
maybeTransferOtelAttribute(span, sentryTransaction, ThreadIncubatingAttributes.THREAD_ID);
346+
maybeTransferOtelAttribute(span, sentryTransaction, ThreadIncubatingAttributes.THREAD_NAME);
347+
343348
scopesToUse.configureScope(
344349
ScopeType.CURRENT,
345350
scope -> attributesExtractor.extract(span, scope, scopesToUse.getOptions()));

0 commit comments

Comments
 (0)