Custom tags missing in some contexts #890
-
I'm trying to use the Sentry package in a Topshelf Windows service with Serilog handling logging. The Topshelf package lets you install and start/stop your command line app as a service by simply running the executable with arguments, e.g.
When you run it without arguments, it starts as a command line app. When I start the app as a service (with the What I investigated so far, when starting the app with the I don't know how to explain and fix it. Would you have any suggestions in this context? I would be really grateful, even though I will probably just quit Topshelf in the meantime because I have already wasted too much time without success. Here's my .NET Framework console app code:
|
Beta Was this translation helpful? Give feedback.
Replies: 16 comments
-
My guess is that this is Does it happen also with .NET Framework 4.7.2? Is it possible to initialize the SDK during |
Beta Was this translation helpful? Give feedback.
-
@bruno-garcia, thank you for your response. I use the Sentry package in a .NET Framework 4.7.2 service and a WPF app. I think I tried all possible combinations where to initialize it, but there was always a context where my custom tags were missing. What I eventually did is quit using Topshelf and handle service start/stop manually. I initialize Sentry in the Main method of the service, just as I did in the example in my original post. But I call the But is that approach correct? It seems to work... |
Beta Was this translation helpful? Give feedback.
-
But it's not all. I noticed that the WPF app I mentioned also had similar problems on shutdown. Logs generated in the I haven't investigated that issue further, but I suspect that calling |
Beta Was this translation helpful? Give feedback.
-
@bruno-garcia, could you please help? Let's concentrate on the WPF app now only. I noticed that some Sentry events still miss the custom tags and user ID that I set. Here's my code:
Here's the Serilog config from app.config:
It's a multithreaded environment. The events missing the custom tags come from managed code and a different thread than the one Sentry is initialized in (if it matters). Am I doing something incorrectly or is it a bug? |
Beta Was this translation helpful? Give feedback.
-
@mariusz-schimke-iteo if you could provide us with a reproducible app, it would be great. |
Beta Was this translation helpful? Give feedback.
-
@bruno-garcia, sure, I'll prepare one and will let you know when ready. Thanks! |
Beta Was this translation helpful? Give feedback.
-
@bruno-garcia, sorry it took me so long, but I had no time. Here's a very simple WPF application with Sentry and Serilog integrations: SentrySerilogWpfTest. Just set your valid DSN in the code (App.xaml.cs) and start the app, then close it. You should then get two events in Sentry: the startup event will contain the user.id and a custom tag as expected. The exit event will contain none of them. |
Beta Was this translation helpful? Give feedback.
-
@mariusz-schimke-iteo I was able to reproduce. I found this on SO:
I moved the code from |
Beta Was this translation helpful? Give feedback.
-
@bruno-garcia, sorry again for such a delay. It does not seem to solve the issue. I moved the code to the App class constructor. The OnStartup method then fails to provide user ID and tags, same case for other application contexts (such as logs generated by other threads). |
Beta Was this translation helpful? Give feedback.
-
IIRC I moved all the code to the constructor. Including setting the user to the scope. |
Beta Was this translation helpful? Give feedback.
-
Confirmed, this is what I did too. |
Beta Was this translation helpful? Give feedback.
-
It's what is used to implicitly propagate the scope with async code |
Beta Was this translation helpful? Give feedback.
-
Any progress on this? I'm facing similar issues with Xilium/CefGlue where native code is involved in between. Would be nice to have support for such cases :-) |
Beta Was this translation helpful? Give feedback.
-
I had the same problem on a WPF app. Regardless where the initialization was happening (Startup or constructor) because of the use of |
Beta Was this translation helpful? Give feedback.
-
We need to have a global shared hub/scope stack. Which we'll get to it this year :) Tracking issue is: #628 |
Beta Was this translation helpful? Give feedback.
-
We solved "Global Mode" on version 3.8.1. It makes it so that any call to You can opt-in to this mode through:
To clarify: This options doesn't make sense in any sort of web server where each individual request takes a separate scope (You want each We plan to ship |
Beta Was this translation helpful? Give feedback.
We solved "Global Mode" on version 3.8.1.
It makes it so that any call to
SentrySdk.SetTag
orAddBreadcrumb
or anything else that you do throughSentrySdk.ConfigureScope
mutates a single, staticScope
object that affects all threads of the app. This is useful for Desktop and Mobile apps when you have a single user session and you add context to Sentry anywhere in the app and want that to be included if it crashes in any other thread.You can opt-in to this mode through:
options.IsGlobalModeEnabled = true
To clarify: This options doesn't make sense in any sort of web server where each individual request takes a separate scope (You want each
SetTag("url", ...)
to take a different request UR…