Add Context
Custom contexts allow you to attach arbitrary data to an event. Often, this context is shared among any issue captured in its lifecycle. You cannot search these, but they are viewable on the issue page:
If you need to be able to search on custom data, use tags instead.
Structured Context
The best practice to attach custom data is via structured contexts. A context must always be a dictionary or map, and its values can be arbitrary.
Then, use Contexts
and give the context a unique name:
using Sentry;
SentrySdk.ConfigureScope(scope =>
{
scope.Contexts["character"] = new
{
Name = "Mighty Fighter",
Age = 19,
AttackType = "melee"
};
});
There are no restrictions on context name. In the context object, all keys are allowed except for type
, which is used internally.
Learn more about conventions for common contexts in the contexts interface developer documentation.
Size Limitations
When sending context, consider payload size limits. Sentry does not recommend sending the entire application state and large data blobs in contexts. If you exceed the maximum payload size, Sentry will respond with HTTP error 413 Payload Too Large
and reject the event.
The Sentry SDK will try its best to accommodate the data you send and trim large context payloads. Some SDKS can truncate parts of the event; for more details, see the developer documentation on SDK data handling.
Additional Data
In addition to structured contexts, Sentry supports adding unstructured "Additional Data" via SetExtra
. Additional Data is deprecated in favor of structured contexts and should be avoided when possible.
- Package:
- nuget:Sentry
- Version:
- 4.9.0
- Repository:
- https://github.com/getsentry/sentry-dotnet