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
6 changes: 6 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ public final class io/sentry/HubScopesWrapper : io/sentry/IHub {
public fun getParentScopes ()Lio/sentry/IScopes;
public fun getRateLimiter ()Lio/sentry/transport/RateLimiter;
public fun getScope ()Lio/sentry/IScope;
public fun getScopes ()Lio/sentry/IScopes;
public fun getSpan ()Lio/sentry/ISpan;
public fun getTraceparent ()Lio/sentry/SentryTraceHeader;
public fun getTransaction ()Lio/sentry/ITransaction;
Expand Down Expand Up @@ -6921,6 +6922,11 @@ public final class io/sentry/util/SampleRateUtils {
public static fun isValidTracesSampleRate (Ljava/lang/Double;Z)Z
}

public final class io/sentry/util/ScopesUtil {
public fun <init> ()V
public static fun printScopesChain (Lio/sentry/IScopes;)V
}

public final class io/sentry/util/SentryRandom {
public fun <init> ()V
public static fun current ()Lio/sentry/util/Random;
Expand Down
4 changes: 4 additions & 0 deletions sentry/src/main/java/io/sentry/HubScopesWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public HubScopesWrapper(final @NotNull IScopes scopes) {
this.scopes = scopes;
}

public @NotNull IScopes getScopes() {
return scopes;
}

@Override
public boolean isEnabled() {
return scopes.isEnabled();
Expand Down
58 changes: 58 additions & 0 deletions sentry/src/main/java/io/sentry/util/ScopesUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package io.sentry.util;

import io.sentry.IScopes;
import io.sentry.Scopes;
import io.sentry.ScopesAdapter;
import io.sentry.Sentry;
import org.jetbrains.annotations.Nullable;

/**
* A util for printing the scopes chain from passed in scopes all the way up to its initial
* ancestor.
*
* <p>It walks up the parents of each scopes instance until it reaches a parent of null. The scopes
* without a parent are the ones created in Sentry.init.
*/
public final class ScopesUtil {

public static void printScopesChain(final @Nullable IScopes scopes) {
System.out.println("==========================================");
System.out.println("=============== v Scopes v ===============");
System.out.println("==========================================");

printScopesChainInternal(scopes);

System.out.println("==========================================");
System.out.println("=============== ^ Scopes ^ ===============");
System.out.println("==========================================");
}

@SuppressWarnings({"ObjectToString", "deprecation"})
private static void printScopesChainInternal(final @Nullable IScopes someScopes) {
if (someScopes != null) {
if (someScopes instanceof Scopes) {
Scopes scopes = (Scopes) someScopes;
String info =
String.format(
"%-25s {g=%-25s, i=%-25s, c=%-25s} [%s]",
scopes,
scopes.getGlobalScope(),
scopes.getIsolationScope(),
scopes.getScope(),
scopes.getCreator());
System.out.println(info);
printScopesChainInternal(someScopes.getParentScopes());
} else if (someScopes instanceof ScopesAdapter
|| someScopes instanceof io.sentry.HubAdapter) {
printScopesChainInternal(Sentry.getCurrentScopes());
} else if (someScopes instanceof io.sentry.HubScopesWrapper) {
io.sentry.HubScopesWrapper wrapper = (io.sentry.HubScopesWrapper) someScopes;
printScopesChainInternal(wrapper.getScopes());
} else {
System.out.println("Hit unhandled Scopes class" + someScopes.getClass());
}
} else {
System.out.println("-");
}
}
}
Loading