Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
305baf5
replace hub with scopes
adinauer Mar 27, 2024
95f5e1b
Add Scopes
adinauer Apr 2, 2024
27f2398
Introduce `IScopes` interface.
adinauer Apr 2, 2024
ce3c14f
Replace `IHub` with `IScopes` in core
adinauer Apr 2, 2024
ce615f4
Replace `IHub` with `IScopes` in android core
adinauer Apr 2, 2024
22ddc00
Replace `IHub` with `IScopes` in android integrations
adinauer Apr 2, 2024
305c217
Replace `IHub` with `IScopes` in apollo integrations
adinauer Apr 2, 2024
da927bc
Replace `IHub` with `IScopes` in okhttp integration
adinauer Apr 2, 2024
8279276
Replace `IHub` with `IScopes` in graphql integration
adinauer Apr 2, 2024
9bfc086
Replace `IHub` with `IScopes` in logging integrations
adinauer Apr 2, 2024
b998e50
Replace `IHub` with `IScopes` in more integrations
adinauer Apr 2, 2024
739827a
Replace `IHub` with `IScopes` in OTel integration
adinauer Apr 2, 2024
69f2d63
Replace `IHub` with `IScopes` in Spring 5 / Spring Boot 2 integrations
adinauer Apr 2, 2024
792d482
Replace `IHub` with `IScopes` in Spring 6 / Spring Boot 3 integrations
adinauer Apr 2, 2024
9bcbce6
Replace `IHub` with `IScopes` in samples
adinauer Apr 2, 2024
3f25a4b
Merge branch 'feat/hsm-13-replacements-in-samples' into feat/hubs-sco…
adinauer Apr 2, 2024
d6fb40a
gitscopes -> github
adinauer Apr 2, 2024
7752bcc
Replace ThreadLocal with ScopesStorage
adinauer Apr 4, 2024
1e329c5
Move client and throwable to span map to scope
adinauer Apr 4, 2024
b0d89ae
Add global scope
adinauer Apr 4, 2024
cdd414a
use global scope in Scopes
adinauer Apr 4, 2024
98da9ff
Implement pushScope popScope and withScope for Scopes
adinauer Apr 4, 2024
2d26033
Add pushIsolationScope; add fork methods to ISCope
adinauer Apr 12, 2024
bbb6700
Use separate scopes for current, isolation and global scope; rename m…
adinauer Apr 12, 2024
c714b21
Allow controlling which scope configureScope uses
adinauer Apr 12, 2024
a474402
Combine scopes
adinauer Apr 12, 2024
ae93e33
Use new API for CRONS integrations
adinauer Apr 12, 2024
b01298b
Add lifecycle helper
adinauer Apr 12, 2024
b64e688
Change spring integrations to use new API
adinauer Apr 12, 2024
d06fc50
Use new API in servlet integrations
adinauer Apr 12, 2024
f0af5c3
Use new API for kotlin coroutines and wrapers for Supplier/Callable
adinauer Apr 12, 2024
2f02001
Discussion TODOs
adinauer Apr 12, 2024
bf4a7bf
Fix breadcrumb ordering
adinauer Apr 15, 2024
62cb91a
Mark TODOS with [HSM]
adinauer Apr 15, 2024
b1630ea
Add getGlobalScope and forkedRootScopes to IScopes
adinauer Apr 16, 2024
136b9ce
Fix EventProcessor ordering on scopes
adinauer Apr 16, 2024
94d54ef
Reuse code in Scopes
adinauer Apr 16, 2024
017599d
No longer replace global scope
adinauer Apr 16, 2024
f4c2b3c
Replace hub occurrences in comments, var names etc.
adinauer Apr 16, 2024
61c9d4a
Implement ScopesTest
adinauer Apr 18, 2024
04f3892
Implement CombinedScopeViewTest
adinauer Apr 18, 2024
840c194
Fix combined contexts
adinauer Apr 19, 2024
ab1c3a6
Use combined scopes for cross platform
adinauer Apr 19, 2024
23506c5
Changes according to reviews of previous PRs
adinauer Apr 23, 2024
c9b6f8b
more
adinauer Apr 23, 2024
696a809
even more
adinauer Apr 23, 2024
847200d
isEnabled checks client instead of having a property on Scopes
adinauer Apr 24, 2024
8e86d3b
Use SentryOptions.empty
adinauer Apr 25, 2024
06db228
Remove Hub
adinauer Apr 25, 2024
37ab4d0
Use OpenTelemetry for Performance and Scopes propagation
adinauer Apr 30, 2024
faef2f8
Promote certain span attributes
adinauer May 2, 2024
c57b2d3
Merge branch '8.x.x' into feat/potel-1-context-forking-and-basics
adinauer May 3, 2024
5b15128
Merge branch '8.x.x' into feat/potel-1-context-forking-and-basics
adinauer May 7, 2024
9d48538
Merge branch 'feat/potel-1-context-forking-and-basics' into feat/pote…
adinauer May 7, 2024
9b900c7
Use OTel in Sentry API
adinauer May 13, 2024
b3919bd
Deduplicate SpanInfo extraction
adinauer May 15, 2024
36ed84a
Forward Sentry API to Sentry through OTel
adinauer May 22, 2024
8f56e3f
Use OTel status for Sentry span API
adinauer May 23, 2024
5d07cb0
Merge branch '8.x.x' into feat/potel-6-sync-status
adinauer Jun 18, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public final class io/sentry/opentelemetry/OtelContextScopesStorage : io/sentry/
public fun set (Lio/sentry/IScopes;)Lio/sentry/ISentryLifecycleToken;
}

public final class io/sentry/opentelemetry/OtelSpanContext : io/sentry/SpanContext {
public fun <init> (Lio/opentelemetry/sdk/trace/ReadWriteSpan;Lio/opentelemetry/api/trace/Span;)V
public fun getStatus ()Lio/sentry/SpanStatus;
public fun setStatus (Lio/sentry/SpanStatus;)V
}

public final class io/sentry/opentelemetry/OtelSpanFactory : io/sentry/ISpanFactory {
public fun <init> ()V
public fun createSpan (Ljava/lang/String;Ljava/lang/String;Lio/sentry/IScopes;Lio/sentry/SpanOptions;Lio/sentry/ISpan;)Lio/sentry/ISpan;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package io.sentry.opentelemetry;

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.sdk.trace.ReadWriteSpan;
import io.opentelemetry.sdk.trace.data.StatusData;
import io.sentry.SpanContext;
import io.sentry.SpanId;
import io.sentry.SpanStatus;
import io.sentry.protocol.SentryId;
import java.lang.ref.WeakReference;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public final class OtelSpanContext extends SpanContext {

/**
* OpenTelemetry span which this wrapper wraps. Needs to be referenced weakly as otherwise we'd
* create a circular reference from {@link io.opentelemetry.sdk.trace.data.SpanData} to {@link
* OtelSpanWrapper} and indirectly back to {@link io.opentelemetry.sdk.trace.data.SpanData} via
* {@link Span}. Also see {@link SentryWeakSpanStorage}.
*/
private final @NotNull WeakReference<ReadWriteSpan> span;

public OtelSpanContext(final @NotNull ReadWriteSpan span, final @Nullable Span parentSpan) {
// TODO [POTEL] tracesSamplingDecision
super(
new SentryId(span.getSpanContext().getTraceId()),
new SpanId(span.getSpanContext().getSpanId()),
parentSpan == null ? null : new SpanId(parentSpan.getSpanContext().getSpanId()),
span.getName(),
null,
null,
null,
null);
this.span = new WeakReference<>(span);
}

@Override
public @Nullable SpanStatus getStatus() {
final @Nullable ReadWriteSpan otelSpan = span.get();

if (otelSpan != null) {
final @NotNull StatusData otelStatus = otelSpan.toSpanData().getStatus();
final @NotNull String otelStatusDescription = otelStatus.getDescription();
if (otelStatusDescription.isEmpty()) {
return otelStatusCodeFallback(otelStatus);
}
final @Nullable SpanStatus spanStatus = SpanStatus.fromApiNameSafely(otelStatusDescription);
if (spanStatus == null) {
return otelStatusCodeFallback(otelStatus);
}
return spanStatus;
}

return null;
}

@Override
public void setStatus(@Nullable SpanStatus status) {
if (status != null) {
final @Nullable ReadWriteSpan otelSpan = span.get();
if (otelSpan != null) {
final @NotNull StatusCode statusCode = translateStatusCode(status);
otelSpan.setStatus(statusCode, status.apiName());
}
}
}

private @Nullable SpanStatus otelStatusCodeFallback(final @NotNull StatusData otelStatus) {
if (otelStatus.getStatusCode() == StatusCode.ERROR) {
return SpanStatus.UNKNOWN_ERROR;
} else if (otelStatus.getStatusCode() == StatusCode.OK) {
return SpanStatus.OK;
}
return null;
}

private @NotNull StatusCode translateStatusCode(final @Nullable SpanStatus status) {
if (status == null) {
return StatusCode.UNSET;
} else if (status == SpanStatus.OK) {
return StatusCode.OK;
} else {
return StatusCode.ERROR;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,7 @@ public OtelSpanWrapper(
this.scopes = Objects.requireNonNull(scopes, "scopes are required");
this.span = new WeakReference<>(span);
this.startTimestamp = startTimestamp;
final @NotNull SentryId traceId = new SentryId(span.getSpanContext().getTraceId());
final @NotNull SpanId spanId = new SpanId(span.getSpanContext().getSpanId());
final @Nullable SpanId parentSpanId =
parentSpan == null ? null : new SpanId(parentSpan.getSpanContext().getSpanId());
@NotNull String operation = span.getName();

// TODO [POTEL] tracesSamplingDecision
this.context = new SpanContext(traceId, spanId, operation, parentSpanId, null);
this.context = new OtelSpanContext(span, parentSpan);
}

@Override
Expand Down Expand Up @@ -228,15 +221,12 @@ public void setDescription(@Nullable String description) {
}

@Override
public void setStatus(@Nullable SpanStatus status) {
// TODO [POTEL] need to find a way to transfer data from this wrapper to SpanExporter
// ^ could go in span attributes
this.context.setStatus(status);
public void setStatus(final @Nullable SpanStatus status) {
context.setStatus(status);
}

@Override
public @Nullable SpanStatus getStatus() {
// TODO [POTEL] need to find a way to transfer data from this wrapper to SpanExporter
return context.getStatus();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ private List<SpanData> maybeSend(final @NotNull List<SpanData> spans) {

// spanStorage.getScope()
// transaction.finishWithScope
transaction.finish(mapOtelStatus(span), new SentryLongDate(span.getEndEpochNanos()));
transaction.finish(
mapOtelStatus(span, transaction), new SentryLongDate(span.getEndEpochNanos()));
}

return remaining.stream()
Expand Down Expand Up @@ -244,6 +245,9 @@ private void createAndFinishSpanForOtelSpan(
parentSentrySpan.startChild(
spanInfo.getOp(), spanInfo.getDescription(), startDate, Instrumenter.OTEL);

// TODO [POTEL] Check if we want to use `instrumentationScopeInfo.name` and append it to
// `auto.otel`
// TODO [POTEL] For spans manually created via Sentry API we should set manual, not auto.otel
sentryChildSpan.getSpanContext().setOrigin(TRACE_ORIGN);
for (Map.Entry<String, Object> dataField : spanInfo.getDataFields().entrySet()) {
sentryChildSpan.setData(dataField.getKey(), dataField.getValue());
Expand All @@ -256,7 +260,7 @@ private void createAndFinishSpanForOtelSpan(
}

sentryChildSpan.finish(
mapOtelStatus(spanData), new SentryLongDate(spanData.getEndEpochNanos()));
mapOtelStatus(spanData, sentryChildSpan), new SentryLongDate(spanData.getEndEpochNanos()));
}

private void transferSpanDetails(
Expand Down Expand Up @@ -285,6 +289,8 @@ private void transferSpanDetails(
for (Map.Entry<String, String> entry : tags.entrySet()) {
targetSpan.setTag(entry.getKey(), entry.getValue());
}

targetSpan.setStatus(sourceSpan.getStatus());
}
}

Expand Down Expand Up @@ -463,7 +469,14 @@ private void createOrUpdateSpanNodeAndRefs(
}

@SuppressWarnings("deprecation")
private SpanStatus mapOtelStatus(final @NotNull SpanData otelSpanData) {
private SpanStatus mapOtelStatus(
final @NotNull SpanData otelSpanData, final @NotNull ISpan sentrySpan) {
final @Nullable SpanStatus existingStatus = sentrySpan.getStatus();
// TODO [POTEL] do we want the unknown error check here?
if (existingStatus != null && existingStatus != SpanStatus.UNKNOWN_ERROR) {
return existingStatus;
}

final @NotNull StatusData otelStatus = otelSpanData.getStatus();
final @NotNull StatusCode otelStatusCode = otelStatus.getStatusCode();

Expand Down
2 changes: 2 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -3272,6 +3272,8 @@ public final class io/sentry/SpanStatus : java/lang/Enum, io/sentry/JsonSerializ
public static final field UNIMPLEMENTED Lio/sentry/SpanStatus;
public static final field UNKNOWN Lio/sentry/SpanStatus;
public static final field UNKNOWN_ERROR Lio/sentry/SpanStatus;
public fun apiName ()Ljava/lang/String;
public static fun fromApiNameSafely (Ljava/lang/String;)Lio/sentry/SpanStatus;
public static fun fromHttpStatusCode (I)Lio/sentry/SpanStatus;
public static fun fromHttpStatusCode (Ljava/lang/Integer;Lio/sentry/SpanStatus;)Lio/sentry/SpanStatus;
public fun serialize (Lio/sentry/ObjectWriter;Lio/sentry/ILogger;)V
Expand Down
9 changes: 5 additions & 4 deletions sentry/src/main/java/io/sentry/SpanContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public SpanId getParentSpanId() {
}

public @NotNull String getOperation() {
// TODO [POTEL] use span name here
return op;
}

Expand Down Expand Up @@ -223,12 +224,12 @@ public boolean equals(Object o) {
&& Objects.equals(parentSpanId, that.parentSpanId)
&& op.equals(that.op)
&& Objects.equals(description, that.description)
&& status == that.status;
&& getStatus() == that.getStatus();
}

@Override
public int hashCode() {
return Objects.hash(traceId, spanId, parentSpanId, op, description, status);
return Objects.hash(traceId, spanId, parentSpanId, op, description, getStatus());
}

// region JsonSerializable
Expand Down Expand Up @@ -260,8 +261,8 @@ public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger
if (description != null) {
writer.name(JsonKeys.DESCRIPTION).value(description);
}
if (status != null) {
writer.name(JsonKeys.STATUS).value(logger, status);
if (getStatus() != null) {
writer.name(JsonKeys.STATUS).value(logger, getStatus());
}
if (origin != null) {
writer.name(JsonKeys.ORIGIN).value(logger, origin);
Expand Down
17 changes: 16 additions & 1 deletion sentry/src/main/java/io/sentry/SpanStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,27 @@ private boolean matches(int httpStatusCode) {
return httpStatusCode >= minHttpStatusCode && httpStatusCode <= maxHttpStatusCode;
}

public @NotNull String apiName() {
return name().toLowerCase(Locale.ROOT);
}

public static @Nullable SpanStatus fromApiNameSafely(final @Nullable String apiName) {
if (apiName == null) {
return null;
}
try {
return SpanStatus.valueOf(apiName.toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException ex) {
return null;
}
}

// JsonSerializable

@Override
public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger logger)
throws IOException {
writer.value(name().toLowerCase(Locale.ROOT));
writer.value(apiName());
}

public static final class Deserializer implements JsonDeserializer<SpanStatus> {
Expand Down