Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.
Closed
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
16 changes: 14 additions & 2 deletions sentry-core/src/main/java/io/sentry/core/Scope.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.sentry.core;

import io.sentry.core.protocol.Contexts;
import io.sentry.core.protocol.User;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand All @@ -21,6 +21,8 @@ public final class Scope implements Cloneable {
private @NotNull Map<String, String> tags = new ConcurrentHashMap<>();
private @NotNull Map<String, Object> extra = new ConcurrentHashMap<>();
private @NotNull List<EventProcessor> eventProcessors = new CopyOnWriteArrayList<>();
private Contexts contexts = new Contexts();

private final @NotNull SentryOptions options;

public Scope(final @NotNull SentryOptions options) {
Expand Down Expand Up @@ -146,6 +148,14 @@ public void removeExtra(@NotNull String key) {
this.extra.remove(key);
}

public @NotNull Contexts getContexts() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we want to expose the whole Contexts, but rather just add items to it

return contexts;
}

public void setContexts(@NotNull Contexts contexts) {
this.contexts = contexts;
}

private @NotNull Queue<Breadcrumb> createBreadcrumbsList(final int maxBreadcrumb) {
return SynchronizedQueue.synchronizedQueue(new CircularFifoQueue<>(maxBreadcrumb));
}
Expand Down Expand Up @@ -188,7 +198,7 @@ public Scope clone() throws CloneNotSupportedException {

final Map<String, Object> extraRef = extra;

Map<String, Object> extraClone = new HashMap<>();
Map<String, Object> extraClone = new ConcurrentHashMap<>();

for (Map.Entry<String, Object> item : extraRef.entrySet()) {
if (item != null) {
Expand All @@ -198,6 +208,8 @@ public Scope clone() throws CloneNotSupportedException {

clone.extra = extraClone;

clone.contexts = new Contexts(contexts);

return clone;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package io.sentry.core.protocol;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public final class Contexts extends ConcurrentHashMap<String, Object> {
private static final long serialVersionUID = 252445813254943011L;

public Contexts(Map<String, Object> initialValues) {
super(initialValues);
}

private <T> T toContextType(String key, Class<T> clazz) {
Object item = get(key);
return clazz.isInstance(item) ? clazz.cast(item) : null;
Expand Down
6 changes: 6 additions & 0 deletions sentry-core/src/test/java/io/sentry/core/ScopeTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.sentry.core

import io.sentry.core.protocol.App
import io.sentry.core.protocol.User
import kotlin.test.Test
import kotlin.test.assertEquals
Expand All @@ -23,6 +24,7 @@ class ScopeTest {

scope.user = user
scope.transaction = "transaction"
scope.contexts.app = App()

val fingerprints = mutableListOf("abc", "def")
scope.fingerprint = fingerprints
Expand All @@ -47,6 +49,8 @@ class ScopeTest {
assertNotNull(clone)
assertNotSame(scope, clone)
assertNotSame(scope.user, clone.user)
assertNotSame(scope.contexts, clone.contexts)
assertNotSame(scope.contexts.app, clone.contexts.app)
assertNotSame(scope.fingerprint, clone.fingerprint)
assertNotSame(scope.breadcrumbs, clone.breadcrumbs)
assertNotSame(scope.tags, clone.tags)
Expand All @@ -66,6 +70,8 @@ class ScopeTest {
scope.user = user
scope.transaction = "transaction"

scope.contexts.app = App()

val fingerprints = mutableListOf("abc")
scope.fingerprint = fingerprints

Expand Down