sentry-dotnet icon indicating copy to clipboard operation
sentry-dotnet copied to clipboard

Start event not received when using `AutoStartSession`

Open jairbubbles opened this issue 3 years ago • 9 comments

Environment

Sentry.io / NuGet package 3.12.0 / .NET 6.0

Steps to Reproduce

  1. Create a sample project with
using (SentrySdk.Init(o =>
{
    o.Dsn = "<ENTER_YOUR_DSN_HERE>";
    o.AutoSessionTracking = true;
}))
{
    Thread.Sleep(1000); 
    throw new Exception("Test");
}
  1. Go to the dashboard
  2. Observe there is no start event:

image

Workaround

If I explicitly start the session after the init:

using (SentrySdk.Init(o =>
{
    o.Dsn = "<ENTER_YOUR_DSN_HERE>";
}))
{
    SentrySdk.StartSession();
    Thread.Sleep(1000); 
    throw new Exception("Test");
}

I do get the start event:

image

jairbubbles avatar Nov 23 '21 20:11 jairbubbles

Hi jairbubbles, thank you for reporting this bug. The session is being created but the Starting Session breadcrumb is not shown.

The Sentry hub is not yet initialized when sending the "Starting Sentry Session" message thus the message doesn't appear on the breadcrumbs.

lucas-zimerman avatar Nov 25 '21 14:11 lucas-zimerman

Hi @lucas-zimerman, do you mean it's just a visual bug?

Because when looking at the session times it was always 0 which lead me to investigate and found that bug.

jairbubbles avatar Nov 25 '21 14:11 jairbubbles

using (SentrySdk.Init(o =>
{
    o.Dsn = "<ENTER_YOUR_DSN_HERE>";
    o.AutoSessionTracking = true;
    o.Debug = true;
}))
{
    Thread.Sleep(1000); 
    throw new Exception("Test");
}

If you enable the debug flag it should show that the event was ended as shown below

Info: Ended session (SID: ca4fc27b2dde44f58eef2ead04766e22; DID: ac9ea430-fe5d-4ea7-a37e-3d51a73c97c7) with status 'Crashed'.

And also it should show the envelope sent with both error and session together,

If it doesn't show that the session was created or sent, could you share the log created by enabling the Debug flag?

lucas-zimerman avatar Nov 25 '21 16:11 lucas-zimerman

There seems to be a correct session in the envelope.

{"type":"session","length":311}
{"sid":"e15f74b3843b47139ff066304d4b7bb4","did":"4a54d37a-d8b6-4f72-976f-ae2923de90dc","init":false,"started":"2021-11-27T11:30:41.5591781+01:00","timestamp":"2021-11-27T10:30:42.5803918+00:00","seq":1,"duration":1,"errors":0,"status":"crashed","attrs":{"release":"[email protected]","environment":"production"}}

But there is also that mesage:

Debug: Failed to end session because there is none active.

I might have misunderstood the graph but it always showing me 0 ms for session duration:

image

jairbubbles avatar Nov 27 '21 10:11 jairbubbles

I believe Sentry only takes healthy session durations into account. @matejminar might correct me here.

bruno-garcia avatar Nov 28 '21 17:11 bruno-garcia

Thx @bruno-garcia, I sent a few healthy session on my test project and now I can see some numbers: image

I sent two "1 second" sessions, I'm not sure how it's computed 🤔

jairbubbles avatar Nov 28 '21 18:11 jairbubbles

Two 1 second sessions should result in a p50 of 1 second though. Assuming no other session made through for that release

bruno-garcia avatar Dec 19 '21 23:12 bruno-garcia

So, is this a bug? @bruno-garcia

mattjohnsonpint avatar Mar 24 '22 19:03 mattjohnsonpint

Looks like yes, this is a bug.

mattjohnsonpint avatar Mar 30 '22 19:03 mattjohnsonpint

This issue is so old that it's hard to follow up on it and even the product changed in the meantime. The session manager underwent some changes and I remember a fix regarding the Debug: Failed to end session because there is none active. so this might have fixed itself. Please feel free to reopen this if it does still affect you.

bitsandfoxes avatar Feb 01 '24 16:02 bitsandfoxes