Skip to content
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

Client health #1013

Merged
merged 101 commits into from
Jun 11, 2021
Merged

Client health #1013

merged 101 commits into from
Jun 11, 2021

Conversation

Tyrrrz
Copy link
Contributor

@Tyrrrz Tyrrrz commented May 26, 2021

Notes:

  • Increment session error count on all events (with or without exception, so includes CaptureMessage(...) too)
  • Mark sessions as errored if a handled exception event went through.
  • StartSession() should close previous session if it hasn't been closed
  • IHub can be separated from ISentryClient to make it easier to pass Session to CaptureEvent(...)
  • On unhandled exceptions set state -> crashed.
  • On restart, if an open session exists, and it wasn't a crash in the previous run: abnormal state

Dev docs: https://develop.sentry.dev/sdk/sessions/
User docs: https://docs.sentry.io/product/releases/health/

Cocoa reference: https://github.com/getsentry/sentry-cocoa/blob/master/Sources/Sentry/SentrySession.m

src/Sentry/Envelopes/Envelope.cs Show resolved Hide resolved
src/Sentry/Envelopes/Envelope.cs Outdated Show resolved Hide resolved
src/Sentry/Extensibility/DisabledHub.cs Outdated Show resolved Hide resolved
src/Sentry/Extensibility/DisabledHub.cs Outdated Show resolved Hide resolved
src/Sentry/Extensibility/DisabledHub.cs Outdated Show resolved Hide resolved
src/Sentry/Internal/Hub.cs Outdated Show resolved Hide resolved
src/Sentry/Internal/Hub.cs Outdated Show resolved Hide resolved
src/Sentry/Session.cs Outdated Show resolved Hide resolved
@lucas-zimerman
Copy link
Collaborator

It would be great if Capture message with event-level Info and Debug wouldn't count as errors on Sessions.

@bruno-garcia
Copy link
Member

It would be great if Capture message with event-level Info and Debug wouldn't count as errors on Sessions.

We defined in the protocol that any event captured counts as errored

Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

Another pass

src/Sentry.AspNet/SentryAspNetOptionsExtensions.cs Outdated Show resolved Hide resolved
src/Sentry/Envelopes/EnvelopeItem.cs Outdated Show resolved Hide resolved
src/Sentry/GlobalSessionManager.cs Outdated Show resolved Hide resolved
src/Sentry/GlobalSessionManager.cs Outdated Show resolved Hide resolved
src/Sentry/GlobalSessionManager.cs Show resolved Hide resolved
/// <summary>
/// Session auto-generated ID.
/// </summary>
string Id { get; }
Copy link
Member

Choose a reason for hiding this comment

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

Could be Guid instead?

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 want to replace this with SentryId for consistency. Waiting on reply on Sentry discord.

src/Sentry/Internal/Http/HttpTransport.cs Outdated Show resolved Hide resolved
src/Sentry/Internal/Hub.cs Outdated Show resolved Hide resolved
src/Sentry/Internal/Hub.cs Outdated Show resolved Hide resolved
src/Sentry/Internal/Hub.cs Outdated Show resolved Hide resolved
Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

Another bunch

src/Sentry/Internal/ReleaseLocator.cs Outdated Show resolved Hide resolved
src/Sentry/Scope.cs Outdated Show resolved Hide resolved
src/Sentry/Internal/Hub.cs Outdated Show resolved Hide resolved
src/Sentry/Internal/Hub.cs Outdated Show resolved Hide resolved
src/Sentry/Session.cs Show resolved Hide resolved
src/Sentry/Session.cs Show resolved Hide resolved
src/Sentry/SessionEndStatus.cs Outdated Show resolved Hide resolved
src/Sentry/SessionUpdate.cs Show resolved Hide resolved
test/Sentry.Tests/HubTests.cs Outdated Show resolved Hide resolved
test/Sentry.Tests/Internals/Http/HttpTransportTests.cs Outdated Show resolved Hide resolved
test/Sentry.Tests/Internals/Http/HttpTransportTests.cs Outdated Show resolved Hide resolved
test/Sentry.Tests/Protocol/Envelopes/EnvelopeTests.cs Outdated Show resolved Hide resolved
@Tyrrrz
Copy link
Contributor Author

Tyrrrz commented Jun 10, 2021

@bruno-garcia Okay I think I've resolved everything. Please skim over/double check.

Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

Thanks a lot! Left some nitpicks and some other suggestions but we're good to merge this and give it a try!

Huge effort to get here and it's a great addition to the Sentry SDK for .NET. Thanks!

CacheDirectoryPath = tempDirectory.Path,
Release = "test"
});
using var fixture = new Fixture();
Copy link
Member

Choose a reason for hiding this comment

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

xunit will call dispose on test classes that implement IDisposable so if you prefer you can define the fixture as a field (and implement IDisposable).

DiagnosticLogger = Logger
};

SessionManager = new GlobalSessionManager(Options);
Copy link
Member

Choose a reason for hiding this comment

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

nit: You could have a method that returns GlobalSessionManager (usually called GetSut) so that tests get a hold of the newly created reference instead of going through fixture.Xyz and control when to create it, so they can mutate Options before actually creating the instance.

{
if (_currentSession is { } session)
{
session.ReportError();
Copy link
Member

Choose a reason for hiding this comment

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

Technically this could be an 'ended' session since another thread could have raced and closed/also called reported error on it. We either need to be able to flip the errors atomically or we need to sync all methods here to have a consistent view of things.

Considering worst case scenario is that we double report a session with the same state (errored+closed or errored+2) this isn't critical so we can merge as-is.

if (sessionUpdate is not null)
{
CaptureSession(sessionUpdate);
}
Copy link
Member

Choose a reason for hiding this comment

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

When can it return null here? Should we log Debug?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the release is unset for example. It's already logged inside session manager.

@@ -189,8 +234,27 @@ public SentryId CaptureEvent(SentryEvent evt, Scope? scope = null)
evt.Contexts.Trace.ParentSpanId = linkedSpan.ParentSpanId;
}

// Report an error on current session if contains an exception
var sessionUpdate = evt.Exception is not null
Copy link
Member

Choose a reason for hiding this comment

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

The edge case here is that if this was a capture event that came as a result of a manually crafted event or even deserializing an already proceeded event, this instance (evt.Exception) will be null but SentryException wouldn't be null so ideally this could be:

Suggested change
var sessionUpdate = evt.Exception is not null
var sessionUpdate = evt.Exception is not null || evt.SentryException?.Any() == true

? _sessionManager.ReportError()
: null;

// Only set the session if the error count changed from 0 to 1.
Copy link
Member

Choose a reason for hiding this comment

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

Sweet

@bruno-garcia bruno-garcia merged commit 0f4358d into main Jun 11, 2021
@bruno-garcia bruno-garcia deleted the client-health branch June 11, 2021 00:26
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