Set to false in order to disable the SentrySdk.Experimental.Metrics APIs.
To filter metrics, or update them before they are sent to Sentry, you can use the SetBeforeSendMetric(Func<SentryMetric, SentryMetric?>) option. If the callback returns null, the metric is not emitted. Attributes can also be updated in the callback delegate.
SentrySdk.Init(options =>
{
options.Dsn = "___PUBLIC_DSN___";
options.Experimental.SetBeforeSendMetric(static metric =>
{
if (metric.Name == "removed-metric")
{
return null;
}
metric.SetAttribute("extra", "foo");
return metric;
});
});The beforeSendMetric delegate receives a metric object, and should return the metric object if you want it to be sent to Sentry, or null if you want to discard it.
The metric object of type SentryMetric has the following members:
| Member | Type | Description |
|---|---|---|
Timestamp |
DateTimeOffset |
Timestamp indicating when the metric was emitted. |
TraceId |
SentryId |
The trace ID of the trace this metric belongs to. |
Type |
SentryMetricType |
The type of metric. One of Counter, Gauge, Distribution. |
Name |
string |
The name of the metric. |
SpanId |
SpanId? |
The span ID of the span that was active when the metric was emitted. |
Unit |
string? |
The unit of measurement for the metric value. Applies to Gauge and Distribution only. |
TryGetValue<TValue>(out TValue value) |
Method | Gets the numeric value of the metric. Returns true if the metric value is of type TValue, otherwise false. Supported numeric value types are byte, short, int, long, float, and double. |
TryGetAttribute<TAttribute>(string key, out TAttribute value) |
Method | Gets the attribute value associated with the specified key. Returns true if the metric contains an attribute with the specified key and its value is of type TAttribute, otherwise false. |
SetAttribute<TAttribute>(string key, TAttribute value) |
Method | Sets a key-value pair of data attached to the metric. Supported types are string, bool, integers up to a size of 64-bit signed, and floating-point numbers up to a size of 64-bit. |
The numeric value of SentryMetric has the same numeric type that the metric was emitted with.
The supported numeric types are byte, short, int, long, float, and double.