Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

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

### Internal

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public final class io/sentry/opentelemetry/OtelSpanInfo {
public fun getTransactionNameSource ()Lio/sentry/protocol/TransactionNameSource;
}

public final class io/sentry/opentelemetry/OtelSpanUtils {
public fun <init> ()V
public static fun maybeTransferOtelAttribute (Lio/opentelemetry/sdk/trace/data/SpanData;Lio/sentry/ISpan;Lio/opentelemetry/api/common/AttributeKey;)V
}

public final class io/sentry/opentelemetry/OtelSpanWrapper : io/sentry/opentelemetry/IOtelSpanWrapper {
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
public fun finish ()V
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.sentry.opentelemetry;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.sentry.ISpan;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public final class OtelSpanUtils {
public static <T> void maybeTransferOtelAttribute(
final @NotNull SpanData otelSpan,
final @NotNull ISpan sentrySpan,
final @NotNull AttributeKey<T> key) {
final @NotNull Attributes attributes = otelSpan.getAttributes();
final @Nullable T value = attributes.get(key);
if (value != null) {
sentrySpan.setData(key.getKey(), value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static io.sentry.TransactionContext.DEFAULT_TRANSACTION_NAME;
import static io.sentry.opentelemetry.InternalSemanticAttributes.IS_REMOTE_PARENT;
import static io.sentry.opentelemetry.OtelInternalSpanDetectionUtil.isSentryRequest;
import static io.sentry.opentelemetry.OtelSpanUtils.maybeTransferOtelAttribute;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.StatusCode;
Expand All @@ -12,6 +13,7 @@
import io.opentelemetry.sdk.trace.export.SpanExporter;
import io.opentelemetry.semconv.HttpAttributes;
import io.opentelemetry.semconv.incubating.ProcessIncubatingAttributes;
import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes;
import io.sentry.Baggage;
import io.sentry.DateUtils;
import io.sentry.DefaultSpanFactory;
Expand Down Expand Up @@ -340,6 +342,9 @@ private void transferSpanDetails(
setOtelSpanKind(span, sentryTransaction);
transferSpanDetails(sentrySpanMaybe, sentryTransaction);

maybeTransferOtelAttribute(span, sentryTransaction, ThreadIncubatingAttributes.THREAD_ID);
maybeTransferOtelAttribute(span, sentryTransaction, ThreadIncubatingAttributes.THREAD_NAME);

scopesToUse.configureScope(
ScopeType.CURRENT,
scope -> attributesExtractor.extract(span, scope, scopesToUse.getOptions()));
Expand Down
Loading