You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add overload to the public API to take Action<Scope> #675
On the IHub methods like CaptureEvent, CaptureMessage and CaptureException should have an overload that takes: Action<Scope>.
The implementation should do what WithScope does, it pushes a scope, and passes the instance to the callback to be mutated. The result is then applied (normal code path of CaptureEvent(event, scope).
This serves as a replacement to the api:
SentrySdk.WithScope(s =>
{
s...;
// Odd call to static method in callback. Data passed magically through the callback
SentrySdk.CaptureX
});
Start with a draft PR touching only the main static API: SentrySdk.
Add the overloads to all methods
Add Obsolete to WithScope
Amend tests
The goal is to verify the effort to adding the thing and the impact in the API.
Even though this was discussed internally and added to some SDKs, seems like we don't have it on our develop docs:
We just updated to Sentry 3.14.1 and changed from WithScope to CaptureMessege etc. where applicable. However, we had some lines with
SentrySdk.WithScope(scope =>{scope.SetTag("ATag","This is a tag");scope.SetExtra("extra","This is extra");_logger.LogWarning("Printing a warning in the console and logging to Sentry");});
ILogger _logger prints to output AND logs to Sentry including the tag and extra data.
SentrySdk.CaptureMessage(
"Printing a warning in the console and logging to Sentry",
scope =>
{
scope.SetTag("ATag", "This is a tag");
scope.SetExtra("extra", "This is extra");
},
SentryLevel.Warning);
Please let us know if you have problems so we can reopen
The logger.LogWarning works fine, it logs to Sentry with all "default" tags AND logs to console. In my previous example, using SentrySdk.WithScope it would also include extra tags.
The SentrySdk.CaptureMessage do log to Sentry with "default" and extra tags, but it doesn't log to console.
I might have missed something, but I don't know what.
Activity
bruno-garcia commentedon Dec 7, 2021
Suggestion to tackle this:
SentrySdk.WithScopeThe goal is to verify the effort to adding the thing and the impact in the API.
Even though this was discussed internally and added to some SDKs, seems like we don't have it on our develop docs:
Please also add to the docs: https://github.com/getsentry/develop
tengl commentedon Feb 21, 2022
Hi @bruno-garcia
We just updated to Sentry 3.14.1 and changed from
WithScopetoCaptureMessegeetc. where applicable. However, we had some lines withILogger _loggerprints to output AND logs to Sentry including the tag and extra data.How do we do that with the new API?
bruno-garcia commentedon May 10, 2022
You can use:
sentry-dotnet/src/Sentry/SentrySdk.cs
Lines 337 to 338 in c6a660b
Please let us know if you have problems so we can reopen
tengl commentedon May 11, 2022
@bruno-garcia
Thanks for the reply! I still can't make it work.
Here is the background, we have a generic host that initializes Sentry with the code below (as shown in the generic host sample).
I run this code
The
logger.LogWarningworks fine, it logs to Sentry with all "default" tags AND logs to console. In my previous example, usingSentrySdk.WithScopeit would also include extra tags.The
SentrySdk.CaptureMessagedo log to Sentry with "default" and extra tags, but it doesn't log to console.I might have missed something, but I don't know what.