-
-
Notifications
You must be signed in to change notification settings - Fork 461
Hubs/Scopes Merge 22 - Combine global, isolation and current scope #3346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
305baf5
95f5e1b
27f2398
ce3c14f
ce615f4
22ddc00
305c217
da927bc
8279276
9bfc086
b998e50
739827a
69f2d63
792d482
9bcbce6
3f25a4b
d6fb40a
7752bcc
1e329c5
b0d89ae
cdd414a
98da9ff
2d26033
bbb6700
c714b21
a474402
1a804ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,214 @@ | ||||||||||||||||||||||||||
| package io.sentry; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| import io.sentry.protocol.App; | ||||||||||||||||||||||||||
| import io.sentry.protocol.Browser; | ||||||||||||||||||||||||||
| import io.sentry.protocol.Contexts; | ||||||||||||||||||||||||||
| import io.sentry.protocol.Device; | ||||||||||||||||||||||||||
| import io.sentry.protocol.Gpu; | ||||||||||||||||||||||||||
| import io.sentry.protocol.OperatingSystem; | ||||||||||||||||||||||||||
| import io.sentry.protocol.Response; | ||||||||||||||||||||||||||
| import io.sentry.protocol.SentryRuntime; | ||||||||||||||||||||||||||
| import io.sentry.util.HintUtils; | ||||||||||||||||||||||||||
| import java.io.IOException; | ||||||||||||||||||||||||||
| import org.jetbrains.annotations.NotNull; | ||||||||||||||||||||||||||
| import org.jetbrains.annotations.Nullable; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| public final class CombinedContextsView extends Contexts { | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| private static final long serialVersionUID = 3585992094653318439L; | ||||||||||||||||||||||||||
| private final @NotNull Contexts globalContexts; | ||||||||||||||||||||||||||
| private final @NotNull Contexts isolationContexts; | ||||||||||||||||||||||||||
| private final @NotNull Contexts currentContexts; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| private final @NotNull ScopeType defaultScopeType; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| public CombinedContextsView( | ||||||||||||||||||||||||||
| final @NotNull Contexts globalContexts, | ||||||||||||||||||||||||||
| final @NotNull Contexts isolationContexts, | ||||||||||||||||||||||||||
| final @NotNull Contexts currentContexts, | ||||||||||||||||||||||||||
| final @NotNull ScopeType defaultScopeType) { | ||||||||||||||||||||||||||
| this.globalContexts = globalContexts; | ||||||||||||||||||||||||||
| this.isolationContexts = isolationContexts; | ||||||||||||||||||||||||||
| this.currentContexts = currentContexts; | ||||||||||||||||||||||||||
| this.defaultScopeType = defaultScopeType; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||
| public @Nullable SpanContext getTrace() { | ||||||||||||||||||||||||||
| final @Nullable SpanContext current = currentContexts.getTrace(); | ||||||||||||||||||||||||||
| if (current != null) { | ||||||||||||||||||||||||||
| return current; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| final @Nullable SpanContext isolation = isolationContexts.getTrace(); | ||||||||||||||||||||||||||
| if (isolation != null) { | ||||||||||||||||||||||||||
| return isolation; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| return globalContexts.getTrace(); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||
| public void setTrace(@Nullable SpanContext traceContext) { | ||||||||||||||||||||||||||
| getDefaultContexts().setTrace(traceContext); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| private Contexts getDefaultContexts() { | ||||||||||||||||||||||||||
| switch (defaultScopeType) { | ||||||||||||||||||||||||||
| case CURRENT: | ||||||||||||||||||||||||||
| return currentContexts; | ||||||||||||||||||||||||||
| case ISOLATION: | ||||||||||||||||||||||||||
| return isolationContexts; | ||||||||||||||||||||||||||
| case GLOBAL: | ||||||||||||||||||||||||||
| return globalContexts; | ||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||
| return currentContexts; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||
| public @Nullable App getApp() { | ||||||||||||||||||||||||||
| final @Nullable App current = currentContexts.getApp(); | ||||||||||||||||||||||||||
| if (current != null) { | ||||||||||||||||||||||||||
| return current; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| final @Nullable App isolation = isolationContexts.getApp(); | ||||||||||||||||||||||||||
| if (isolation != null) { | ||||||||||||||||||||||||||
| return isolation; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| return globalContexts.getApp(); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||
| public void setApp(@NotNull App app) { | ||||||||||||||||||||||||||
| getDefaultContexts().setApp(app); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||
| public @Nullable Browser getBrowser() { | ||||||||||||||||||||||||||
| final @Nullable Browser current = currentContexts.getBrowser(); | ||||||||||||||||||||||||||
| if (current != null) { | ||||||||||||||||||||||||||
| return current; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| final @Nullable Browser isolation = isolationContexts.getBrowser(); | ||||||||||||||||||||||||||
| if (isolation != null) { | ||||||||||||||||||||||||||
| return isolation; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| return globalContexts.getBrowser(); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||
| public void setBrowser(@NotNull Browser browser) { | ||||||||||||||||||||||||||
| getDefaultContexts().setBrowser(browser); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||
| public @Nullable Device getDevice() { | ||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need some propagation or copy-on-write mechanism for all Scope related fields. E.g. val user = Sentry.getUser() // returns global scope user, as it's unset
Sentry.setUser(user) // now default scope is set to the user
user.email = "[email protected]" // both global and default scope is written to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm this should only happen if someone calls Can we ignore this edge case for now and address it, when it actually happens for a customer? One solution would be to have something like
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's an example that should avoid the problem: sentry-java/sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java Lines 87 to 98 in ab1c3a6
|
||||||||||||||||||||||||||
| final @Nullable Device current = currentContexts.getDevice(); | ||||||||||||||||||||||||||
| if (current != null) { | ||||||||||||||||||||||||||
| return current; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| final @Nullable Device isolation = isolationContexts.getDevice(); | ||||||||||||||||||||||||||
| if (isolation != null) { | ||||||||||||||||||||||||||
| return isolation; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| return globalContexts.getDevice(); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||
| public void setDevice(@NotNull Device device) { | ||||||||||||||||||||||||||
| getDefaultContexts().setDevice(device); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||
| public @Nullable OperatingSystem getOperatingSystem() { | ||||||||||||||||||||||||||
| final @Nullable OperatingSystem current = currentContexts.getOperatingSystem(); | ||||||||||||||||||||||||||
| if (current != null) { | ||||||||||||||||||||||||||
| return current; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| final @Nullable OperatingSystem isolation = isolationContexts.getOperatingSystem(); | ||||||||||||||||||||||||||
| if (isolation != null) { | ||||||||||||||||||||||||||
| return isolation; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| return globalContexts.getOperatingSystem(); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||
| public void setOperatingSystem(@NotNull OperatingSystem operatingSystem) { | ||||||||||||||||||||||||||
| getDefaultContexts().setOperatingSystem(operatingSystem); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||
| public @Nullable SentryRuntime getRuntime() { | ||||||||||||||||||||||||||
| final @Nullable SentryRuntime current = currentContexts.getRuntime(); | ||||||||||||||||||||||||||
| if (current != null) { | ||||||||||||||||||||||||||
| return current; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| final @Nullable SentryRuntime isolation = isolationContexts.getRuntime(); | ||||||||||||||||||||||||||
| if (isolation != null) { | ||||||||||||||||||||||||||
| return isolation; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| return globalContexts.getRuntime(); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||
| public void setRuntime(@NotNull SentryRuntime runtime) { | ||||||||||||||||||||||||||
| getDefaultContexts().setRuntime(runtime); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||
| public @Nullable Gpu getGpu() { | ||||||||||||||||||||||||||
| final @Nullable Gpu current = currentContexts.getGpu(); | ||||||||||||||||||||||||||
| if (current != null) { | ||||||||||||||||||||||||||
| return current; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| final @Nullable Gpu isolation = isolationContexts.getGpu(); | ||||||||||||||||||||||||||
| if (isolation != null) { | ||||||||||||||||||||||||||
| return isolation; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| return globalContexts.getGpu(); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||
| public void setGpu(@NotNull Gpu gpu) { | ||||||||||||||||||||||||||
| getDefaultContexts().setGpu(gpu); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||
| public @Nullable Response getResponse() { | ||||||||||||||||||||||||||
| final @Nullable Response current = currentContexts.getResponse(); | ||||||||||||||||||||||||||
| if (current != null) { | ||||||||||||||||||||||||||
| return current; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| final @Nullable Response isolation = isolationContexts.getResponse(); | ||||||||||||||||||||||||||
| if (isolation != null) { | ||||||||||||||||||||||||||
| return isolation; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| return globalContexts.getResponse(); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||
| public void withResponse(HintUtils.SentryConsumer<Response> callback) { | ||||||||||||||||||||||||||
| if (currentContexts.getResponse() != null) { | ||||||||||||||||||||||||||
| currentContexts.withResponse(callback); | ||||||||||||||||||||||||||
| } else if (isolationContexts.getResponse() != null) { | ||||||||||||||||||||||||||
| isolationContexts.withResponse(callback); | ||||||||||||||||||||||||||
| } else if (globalContexts.getResponse() != null) { | ||||||||||||||||||||||||||
| globalContexts.withResponse(callback); | ||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||
| getDefaultContexts().withResponse(callback); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||
| public void setResponse(@NotNull Response response) { | ||||||||||||||||||||||||||
| getDefaultContexts().setResponse(response); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||
| public void serialize(@NotNull ObjectWriter writer, @NotNull ILogger logger) throws IOException { | ||||||||||||||||||||||||||
| final @NotNull Contexts allContexts = new Contexts(); | ||||||||||||||||||||||||||
| allContexts.putAll(globalContexts); | ||||||||||||||||||||||||||
| allContexts.putAll(isolationContexts); | ||||||||||||||||||||||||||
| allContexts.putAll(currentContexts); | ||||||||||||||||||||||||||
| allContexts.serialize(writer, logger); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.