Skip to content

Commit 63abdaf

Browse files
committed
improve
1 parent 19928c6 commit 63abdaf

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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, final @NotNull ISpan sentrySpan, final @NotNull AttributeKey<T> key) {
13+
final @NotNull Attributes attributes = otelSpan.getAttributes();
14+
final @Nullable T value = attributes.get(key);
15+
if (value != null) {
16+
sentrySpan.setData(key.getKey(), value);
17+
}
18+
}
19+
}

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

Lines changed: 4 additions & 14 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;
@@ -340,7 +341,9 @@ private void transferSpanDetails(
340341
setOtelInstrumentationInfo(span, sentryTransaction);
341342
setOtelSpanKind(span, sentryTransaction);
342343
transferSpanDetails(sentrySpanMaybe, sentryTransaction);
343-
maybeTransferOtelThreadAttributes(span, sentryTransaction);
344+
345+
maybeTransferOtelAttribute(span, sentryTransaction, ThreadIncubatingAttributes.THREAD_ID);
346+
maybeTransferOtelAttribute(span, sentryTransaction, ThreadIncubatingAttributes.THREAD_NAME);
344347

345348
scopesToUse.configureScope(
346349
ScopeType.CURRENT,
@@ -349,19 +352,6 @@ private void transferSpanDetails(
349352
return sentryTransaction;
350353
}
351354

352-
private void maybeTransferOtelThreadAttributes(
353-
final @NotNull SpanData span, final @NotNull ITransaction sentryTransaction) {
354-
final @NotNull Attributes attributes = span.getAttributes();
355-
final @Nullable Long threadId = attributes.get(ThreadIncubatingAttributes.THREAD_ID);
356-
if (threadId != null) {
357-
sentryTransaction.setData(ThreadIncubatingAttributes.THREAD_ID.getKey(), threadId);
358-
}
359-
final @Nullable String threadName = attributes.get(ThreadIncubatingAttributes.THREAD_NAME);
360-
if (threadName != null) {
361-
sentryTransaction.setData(ThreadIncubatingAttributes.THREAD_NAME.getKey(), threadName);
362-
}
363-
}
364-
365355
private List<SpanNode> findCompletedRootNodes(final @NotNull List<SpanNode> grouped) {
366356
final @NotNull Predicate<SpanNode> isRootPredicate =
367357
(node) -> {

sentry/src/main/java/io/sentry/opentelemetry/OpenTelemetryUtil.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package io.sentry.opentelemetry;
22

3-
import io.sentry.NoOpLogger;
4-
import io.sentry.SentryLevel;
5-
import io.sentry.SentryOpenTelemetryMode;
6-
import io.sentry.SentryOptions;
3+
import io.sentry.*;
74
import io.sentry.util.LoadClass;
85
import io.sentry.util.Platform;
96
import io.sentry.util.SpanUtils;
107
import java.util.Collections;
118
import java.util.List;
129
import org.jetbrains.annotations.ApiStatus;
1310
import org.jetbrains.annotations.NotNull;
11+
import org.jetbrains.annotations.Nullable;
1412

1513
@ApiStatus.Internal
1614
public final class OpenTelemetryUtil {

0 commit comments

Comments
 (0)