Sentry
Sentry takes OTLP traces and logs, but nothing it receives over OTLP becomes an Issue. The Sentry exporter posts each error as a Sentry event to the project's envelope endpoint, so one pipeline carries traces, logs and metrics over OTLP and errors as Sentry Issues - grouped by their stack traces, symbolicated, and linked to their traces - without a Sentry SDK in the app.
DSN
The exporter needs the project's DSN (Settings - Client Keys). Outside the browser, with
options.UseEnvironmentVariables on, the DSN of an exporter added without one is read from
SENTRY_DSN - but that variable never adds the exporter by itself: an app sets it for a Sentry SDK of
its own, which would report every error a second time. An invalid DSN is skipped with a startup warning. For
traces and logs in Sentry as well, add an OTLP exporter to the project's OTLP endpoint next to it.
builder.Services.AddBitBelemetryServices(options =>
{
options.ServiceName = "shop";
options.Environment = builder.Environment.EnvironmentName;
// Errors as Sentry Issues.
options.AddSentryExporter(builder.Configuration["Sentry:Dsn"]!);
// Traces and logs in Sentry too, over OTLP: the endpoints and the header from the project's Client Keys page.
options.AddOtlpExporter(o =>
{
o.TracesEndpoint = new Uri(builder.Configuration["Sentry:OtlpTracesEndpoint"]!);
o.LogsEndpoint = new Uri(builder.Configuration["Sentry:OtlpLogsEndpoint"]!);
o.Signals = BelemetrySignals.Traces | BelemetrySignals.Logs;
o.Headers["x-sentry-auth"] = "sentry sentry_key=<public key>"; // .NET's exports
o.BrowserHeaders["x-sentry-auth"] = "sentry sentry_key=<public key>"; // the page's: public, like the DSN's key
});
});
The DSN's public key is public by design - Sentry's browser SDK puts it in every page - so the browser script
sends its JS errors to Sentry too (IncludeInBrowser, on by default), with the key in the URL. A
legacy secret key in the DSN is never used, nor handed to the page. With the Relay
transport the browser's errors reach Sentry through .NET, as the same events.
What becomes an event
-
A record carrying an exception - an
ILoggerentry with one,TrackException, an unhandled .NET exception, a JS error, an exception recorded on a span - becomes an error event with its exception chain and its stack trace. -
A plain log record becomes a message event. Both only at or above
MinimumEventLevel(Errorby default, as with Sentry's own logging integration). Page views, custom events and web vitals never do. - An exception logged under a span and recorded on that span too is one event, and the error limits apply as to every other exporter.
-
Each event carries its record's trace and span ids, so the Issue links to the trace Sentry received over
OTLP, and the user (
user.id, elseenduser.pseudo.id), the session, the release, the environment and the record's other attributes - all as the privacy rules and processors left them.
Symbolication
Neither Relay nor Sentry parses a stack string, so Belemetry sends the frames. A .NET frame carries the
method's metadata token and its IL offset, and the event lists the assembly's pe_dotnet debug
image: upload the PDBs, and Sentry's symbolicator adds the file and the line. That needs the assembly as a
file - servers, desktop apps, MAUI on Windows. In WebAssembly, on Android and iOS, and in single-file or
NativeAOT apps, the frames carry what the stack trace's text tells. JavaScript stacks are parsed for V8,
SpiderMonkey and JavaScriptCore; upload the source maps for the release.
Crashes on Android, iOS and Mac Catalyst
Native crashes on mobile are out of Belemetry's reach. Keep a Sentry SDK there as the crash reporter only - the
core Sentry package rather than Sentry.Maui, with tracing off - and turn
IncludeUnhandledExceptions off, as that SDK reports the .NET crashes too. Belemetry sends the rest.
Release, IP address and delivery
Release defaults to {service.name}@{service.version}. With MaskIp (on by
default) Sentry is told not to infer the user's IP address. A rate limit (429, with Retry-After)
and an unavailable Relay (502, 503, 504) are retried, and kept by the offline
persistence while the network is down; an event keeps its id across retries, so Sentry drops a duplicate.
API
BelemetrySentryExporterOptions
Class
Settings of the Sentry exporter, which posts error events to the project's envelope endpoint (/api/{project}/envelope/), so exceptions become Sentry Issues - grouped by their stack traces, symbolicated from the PDBs uploaded to Sentry, and linked to their traces - without a Sentry SDK in the app. Spans, logs and metrics are left to the other exporters (Sentry also takes OTLP traces and logs, through an OTLP exporter).
| Name | Type and default | Description |
|---|---|---|
Dsn |
string |
The project's DSN (https://{public key}@{host}/{project id}). The public key is public by design - Sentry's browser SDK puts it in every page - so the browser script gets it too; a legacy secret key in the DSN is never used or handed to the page. Defaults to SENTRY_DSN when set (outside the browser, with BelemetryOptions.UseEnvironmentVariables) - which never adds an exporter by itself. An invalid DSN skips the exporter, with a startup warning. |
Release |
string |
The Sentry release of every event. Defaults to {service.name}@{service.version} of the records' resource (the shape Sentry's own SDKs use), and to none without a service version. |
MinimumEventLevel |
LogLevel= LogLevel.Error |
The least severe record that becomes a Sentry event: a record carrying an exception (a log record with exception.type or exception.message, IBelemetry.TrackException, a JS error, an exception recorded on a span) becomes an error event with its stack trace, and a plain log record (no exception, not an event such as a page view) a message event. The default, LogLevel.Error, is what Sentry's own logging integration sends as events. An exception recorded on a span counts as an error. |
IncludeUnhandledExceptions |
bool= true |
Whether the .NET exceptions nothing caught (BelemetryErrorOptions.CaptureUnhandledExceptions: AppDomain.UnhandledException, unobserved task exceptions, and what Belemetry.TrackBitBelemetryUnhandledException forwards) are sent to Sentry. Set it to false where a Sentry SDK runs as the crash reporter (Android, iOS and Mac Catalyst, for the native crashes Belemetry cannot see), which reports these as well. Defaults to true. |
MaskIp |
bool= true |
Whether Sentry is told not to infer the user's IP address from the request (sdk.settings.infer_ip = never), so it neither stores it nor derives a location from it. Defaults to true. |
Compression |
BelemetryCompression= BelemetryCompression.None |
The request-body compression. Defaults to none. |
Timeout |
TimeSpan= 00:00:30 |
The maximum time one export request may take. Defaults to 30 seconds. |
IncludeInBrowser |
bool= true |
Whether the browser script sends its errors to Sentry too (with BelemetryBrowserTransport.Direct). Defaults to true. |