Skip to content

Commit 9305829

Browse files
committed
Use contexts instead of map on SentryTracer
1 parent 582b441 commit 9305829

File tree

7 files changed

+32
-15
lines changed

7 files changed

+32
-15
lines changed

sentry-android-core/last_crash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2022-11-11T10:33:27.818Z

sentry-opentelemetry/sentry-opentelemetry-agent/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ tasks {
145145
attributes.put("Premain-Class", "io.opentelemetry.javaagent.OpenTelemetryAgent")
146146
attributes.put("Can-Redefine-Classes", "true")
147147
attributes.put("Can-Retransform-Classes", "true")
148-
attributes.put("Implementation-Vendor", "Demo")
149-
attributes.put("Implementation-Version", "demo-${project.version}-otel-${Config.Libs.otelJavaagentVersion}")
148+
attributes.put("Implementation-Vendor", "Sentry")
149+
attributes.put("Implementation-Version", "sentry-${project.version}-otel-${Config.Libs.otelJavaagentVersion}")
150150
}
151151
}
152152

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

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

3+
import io.opentelemetry.api.common.Attributes;
34
import io.opentelemetry.api.trace.SpanContext;
45
import io.opentelemetry.api.trace.SpanKind;
56
import io.opentelemetry.api.trace.StatusCode;
@@ -183,8 +184,8 @@ private void updateTransactionWithOtelData(
183184
final @NotNull SpanData spanData = otelSpan.toSpanData();
184185
final @NotNull Map<String, Object> context = new HashMap<>();
185186

186-
context.put("attributes", spanData.getAttributes().asMap());
187-
context.put("resource", spanData.getResource().getAttributes().asMap());
187+
context.put("attributes", toMapWithStringKeys(spanData.getAttributes()));
188+
context.put("resource", toMapWithStringKeys(spanData.getResource().getAttributes()));
188189

189190
return context;
190191
}
@@ -233,4 +234,19 @@ private SpanStatus mapOtelStatus(final @NotNull ReadableSpan otelSpan) {
233234
private boolean hasSentryBeenInitialized() {
234235
return Sentry.isEnabled();
235236
}
237+
238+
private @NotNull Map<String, Object> toMapWithStringKeys(@Nullable Attributes attributes) {
239+
@NotNull Map<String, Object> mapWithStringKeys = new HashMap<>();
240+
241+
if (attributes != null) {
242+
attributes.forEach(
243+
(key, value) -> {
244+
if (key != null) {
245+
mapWithStringKeys.put(key.getKey(), value);
246+
}
247+
});
248+
}
249+
250+
return mapWithStringKeys;
251+
}
236252
}

sentry/api/sentry.api

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ public abstract interface class io/sentry/ISpan {
516516
}
517517

518518
public abstract interface class io/sentry/ITransaction : io/sentry/ISpan {
519-
public abstract fun getContexts ()Ljava/util/Map;
519+
public abstract fun getContexts ()Lio/sentry/protocol/Contexts;
520520
public abstract fun getEventId ()Lio/sentry/protocol/SentryId;
521521
public abstract fun getLatestActiveSpan ()Lio/sentry/Span;
522522
public abstract fun getName ()Ljava/lang/String;
@@ -767,7 +767,7 @@ public final class io/sentry/NoOpTransaction : io/sentry/ITransaction {
767767
public fun finish ()V
768768
public fun finish (Lio/sentry/SpanStatus;)V
769769
public fun finish (Lio/sentry/SpanStatus;Ljava/util/Date;)V
770-
public fun getContexts ()Ljava/util/Map;
770+
public fun getContexts ()Lio/sentry/protocol/Contexts;
771771
public fun getData (Ljava/lang/String;)Ljava/lang/Object;
772772
public fun getDescription ()Ljava/lang/String;
773773
public fun getEventId ()Lio/sentry/protocol/SentryId;
@@ -1568,7 +1568,7 @@ public final class io/sentry/SentryTracer : io/sentry/ITransaction {
15681568
public fun finish (Lio/sentry/SpanStatus;)V
15691569
public fun finish (Lio/sentry/SpanStatus;Ljava/util/Date;)V
15701570
public fun getChildren ()Ljava/util/List;
1571-
public fun getContexts ()Ljava/util/Map;
1571+
public fun getContexts ()Lio/sentry/protocol/Contexts;
15721572
public fun getData ()Ljava/util/Map;
15731573
public fun getData (Ljava/lang/String;)Ljava/lang/Object;
15741574
public fun getDescription ()Ljava/lang/String;

sentry/src/main/java/io/sentry/ITransaction.java

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

3+
import io.sentry.protocol.Contexts;
34
import io.sentry.protocol.SentryId;
45
import io.sentry.protocol.TransactionNameSource;
56
import java.util.List;
6-
import java.util.Map;
77
import org.jetbrains.annotations.ApiStatus;
88
import org.jetbrains.annotations.NotNull;
99
import org.jetbrains.annotations.Nullable;
@@ -84,5 +84,5 @@ public interface ITransaction extends ISpan {
8484

8585
@ApiStatus.Internal
8686
@NotNull
87-
Map<String, Object> getContexts();
87+
Contexts getContexts();
8888
}

sentry/src/main/java/io/sentry/NoOpTransaction.java

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

3+
import io.sentry.protocol.Contexts;
34
import io.sentry.protocol.SentryId;
45
import io.sentry.protocol.TransactionNameSource;
56
import java.util.Collections;
67
import java.util.Date;
78
import java.util.List;
8-
import java.util.Map;
9-
import java.util.concurrent.ConcurrentHashMap;
109
import org.jetbrains.annotations.ApiStatus;
1110
import org.jetbrains.annotations.NotNull;
1211
import org.jetbrains.annotations.Nullable;
@@ -186,7 +185,7 @@ public void setContext(@NotNull String key, @NotNull Object context) {}
186185

187186
@ApiStatus.Internal
188187
@Override
189-
public @NotNull Map<String, Object> getContexts() {
190-
return new ConcurrentHashMap<>();
188+
public @NotNull Contexts getContexts() {
189+
return new Contexts();
191190
}
192191
}

sentry/src/main/java/io/sentry/SentryTracer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sentry;
22

3+
import io.sentry.protocol.Contexts;
34
import io.sentry.protocol.MeasurementValue;
45
import io.sentry.protocol.SentryId;
56
import io.sentry.protocol.SentryTransaction;
@@ -78,7 +79,7 @@ public final class SentryTracer implements ITransaction {
7879
private @NotNull TransactionNameSource transactionNameSource;
7980
private final @NotNull Map<String, MeasurementValue> measurements;
8081
private final @NotNull Instrumenter instrumenter;
81-
private final @NotNull Map<String, Object> contexts = new ConcurrentHashMap<>();
82+
private final @NotNull Contexts contexts = new Contexts();
8283

8384
public SentryTracer(final @NotNull TransactionContext context, final @NotNull IHub hub) {
8485
this(context, hub, null);
@@ -670,7 +671,7 @@ public void setContext(@NotNull String key, @NotNull Object context) {
670671

671672
@ApiStatus.Internal
672673
@Override
673-
public @NotNull Map<String, Object> getContexts() {
674+
public @NotNull Contexts getContexts() {
674675
return contexts;
675676
}
676677

0 commit comments

Comments
 (0)