sentry-dotnet
sentry-dotnet copied to clipboard
Improve the `Contexts[".."] = string` pitfall
We have a pitfall on our API today through Contexts
That's because it takes object, which should be valid, but Sentry will error out with:
That's because Sentry expects a complex object. A valid usage would be:
SentrySdk.ConfigureScope(s => s.Contexts["key"] = new { Value = "value" });
As we've documented here.
Some ideas to improve this
Roslyn analyzer
This is ideal IMO, we can warn in the IDE that Sentry expects an object there.
Warn on console, if debug:true
If Debug=true, if the indexer is set with a common simple type like int/string/long, we print to the console that Sentry expects an object
Docs
Note on the docs that Contexts requires an object.
And since I spotted this pitfall when our customer was trying to set User, another idea:
We have docs for setting the user User. Which always has new User in the examples. But, User is already set. So unless you'd like to reset the user value (clean all fields). Better examples would be:
SentrySdk.ConfigureScope(scope => scope.User.Email = "[email protected]");