Skip to content

feat: Trace Generation Integration #2123

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

Merged
merged 17 commits into from
Apr 24, 2025
Merged

Conversation

bitsandfoxes
Copy link
Contributor

@bitsandfoxes bitsandfoxes commented Apr 17, 2025

This PR adds an integration that is responsible for generating a new trace based
on already existing mechanisms using in the SceneManagerIntegration and the SessionIntegration

  • Active scene changes
  • When the app gains focus

In practical terms this translates into the following flow:

  1. App starts up
  2. SDK auto-initializes
  3. TraceGenerationIntegration gets registered and starts a new trace
  4. The rest of the startup procedure (i.e. subsystem registration, splash-screen e.t.c.)
  5. First scene load
  6. Active Scene changes - TraceGenerationIntegration kicks in and creates a new trace

Logically, this separates the startup from the actual game. During gameplay the trace gets re-generated every time the game gains focus. This can/might/should/could get updated in the future by different lifecycle events. I.e. touches on mobile (like Android does it).

Copy link
Contributor

github-actions bot commented Apr 17, 2025

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

Generated by 🚫 dangerJS against acbcda8

@@ -19,8 +19,6 @@ public void Register(IHub hub, SentryOptions options)
return;
}

options.DiagnosticLogger?.LogDebug("Registering Session integration.");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The hub already logs which integration get registered. This is redundant.

@@ -4,11 +4,16 @@

namespace Sentry.Unity;

internal interface ISentryMonoBehaviour
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm creating an internal interface to be able to mock this in the tests.

Comment on lines 54 to 58
// For now, we're creating a new trace after initializing to be able to tie errors and crashes together on all
// layers. To be able to regenerate new traces based on some mechanism, this will move into some sort of
// integration i.e. scene manager.
SentrySdk.SetTrace(SentryId.Create(), SpanId.Create());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the part that is getting replaced by the integration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The changes here contain: InternalsVisibleTo for the tests and removing the internal SentrySdk.SetTrace that got replaced by accessing the scope directly.

@bitsandfoxes bitsandfoxes marked this pull request as ready for review April 22, 2025 12:35
@bitsandfoxes bitsandfoxes requested a review from Flash0ver April 23, 2025 15:16
public void Register(IHub hub, SentryOptions options)
{
hub.ConfigureScope(scope =>
scope.SetPropagationContext(new SentryPropagationContext(SentryId.Create(), SpanId.Create())));
Copy link
Member

Choose a reason for hiding this comment

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

This constructor feels like a lot of boiler plate. In fact even having to pass a new propagation context feels redundant as it seems it's the main use case we have, just setting a new propagation context.

Could also be solved with an extension method like ResetPropagationContext() that calls SetPropagationContext(new SentryPropagationContext(SentryId.Create(), SpanId.Create())))

@bitsandfoxes bitsandfoxes merged commit b63aa7b into main Apr 24, 2025
78 checks passed
@bitsandfoxes bitsandfoxes deleted the feat/trace-id-integration branch April 24, 2025 10:24
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