Skip to content

Conversation

@adinauer
Copy link
Member

@adinauer adinauer commented Apr 12, 2024

#skip-changelog

📜 Description

When creating envelopes/events/transactions/... we now have to use all three scopes (global, isolation and current).

TODO: Breadcrumbs currently do not maintain insertion order across scopes. This will be adressed in a future PR.

💡 Motivation and Context

💚 How did you test it?

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

@github-actions
Copy link
Contributor

github-actions bot commented Apr 12, 2024

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 1a804ca


@Override
public @NotNull Contexts getContexts() {
return new CombinedContextsView(
Copy link
Member Author

Choose a reason for hiding this comment

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

CombinedContextsView isn't totally necessary to have but it avoids constantly creating copies of Contexts.

Copy link
Member Author

@adinauer adinauer Apr 19, 2024

Choose a reason for hiding this comment

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

We should use CombinedContextsView as ScopeType.COMBINED for cross platform SDKs should get all values and calls setDevice and setOperatingSystem so handing back a copy that isn't mutable (or rather loses updates) isn't ideal. See #3375


@Override
public @NotNull IScope clone() {
// TODO just return a new CombinedScopeView with forked scope?
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 quite sure here.

Copy link
Member Author

Choose a reason for hiding this comment

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

We're now returning a new CombinedScopeView with forked isolation and current scope. See #3375

@github-actions
Copy link
Contributor

github-actions bot commented Apr 12, 2024

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 411.22 ms 497.16 ms 85.94 ms
Size 1.70 MiB 2.28 MiB 595.91 KiB

Previous results on branch: feat/hsm-22-combine-scopes

Startup times

Revision Plain With Sentry Diff
be47198 360.88 ms 426.53 ms 65.66 ms

App size

Revision Plain With Sentry Diff
be47198 1.70 MiB 2.28 MiB 595.91 KiB

}

@Override
public @Nullable Device getDevice() {
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm this should only happen if someone calls .setUser on global scope so an actual User instance is returned from CombinedScopeView and then pass that into .setUser that goes to current or isolation scope.

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 CombinedContextsView for user and other fields.

Copy link
Member Author

Choose a reason for hiding this comment

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

Here's an example that should avoid the problem:

@Nullable User user = scope.getUser();
if (user == null) {
user = new User();
scope.setUser(user);
}
if (user.getId() == null) {
try {
user.setId(Installation.id(context));
} catch (RuntimeException e) {
logger.log(SentryLevel.ERROR, "Could not retrieve installation ID", e);
}
}

Copy link
Collaborator

@lbloder lbloder left a comment

Choose a reason for hiding this comment

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

The two comments within Scopes.getGlobalScope() could be removed:

public @NotNull IScope getGlobalScope() {
// TODO should be:
return Sentry.getGlobalScope();
// return scope;
}

LGTM otherwise

Base automatically changed from feat/hsm-21-configure-scope-configurable to 8.x.x April 22, 2024 12:43
@adinauer adinauer merged commit 9546564 into 8.x.x Apr 22, 2024
@adinauer adinauer deleted the feat/hsm-22-combine-scopes branch April 22, 2024 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants