Skip to content

feat: Trace Generation Integration#2123

Merged
bitsandfoxes merged 17 commits intomainfrom
feat/trace-id-integration
Apr 24, 2025
Merged

feat: Trace Generation Integration#2123
bitsandfoxes merged 17 commits intomainfrom
feat/trace-id-integration

Conversation

@bitsandfoxes
Copy link
Copy Markdown
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).

@github-actions
Copy link
Copy Markdown
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

return;
}

options.DiagnosticLogger?.LogDebug("Registering Session integration.");
Copy link
Copy Markdown
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.


namespace Sentry.Unity;

internal interface ISentryMonoBehaviour
Copy link
Copy Markdown
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 thread src/Sentry.Unity/SentryUnitySDK.cs Outdated
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
Copy Markdown
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.

Comment thread src/sentry-dotnet
Copy link
Copy Markdown
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
Comment thread CHANGELOG.md Outdated
Comment thread src/Sentry.Unity/Integrations/TraceGenerationIntegration.cs Outdated
Comment thread test/Sentry.Unity.Tests/TraceGenerationIntegrationTests.cs
Comment thread src/Sentry.Unity/Integrations/TraceGenerationIntegration.cs Outdated
@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
Copy Markdown
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