|
55 | 55 | }); |
56 | 56 |
|
57 | 57 | // Sentry (trace-connected) Metrics via SentrySdk.Experimental.Metrics are enabled by default. |
58 | | - options.Experimental.SetBeforeSendMetric<int>(static metric => |
| 58 | + options.Experimental.SetBeforeSendMetric(static metric => |
59 | 59 | { |
| 60 | + if (metric.TryGetValue(out int integer) && integer < 0) |
| 61 | + { |
| 62 | + // Return null to drop the metric |
| 63 | + return null; |
| 64 | + } |
| 65 | + |
60 | 66 | // A demonstration of how you can modify the metric object before sending it to Sentry |
61 | | - metric.SetAttribute("operating_system.platform", Environment.OSVersion.Platform.ToString()); |
62 | | - metric.SetAttribute("operating_system.version", Environment.OSVersion.Version.ToString()); |
| 67 | + if (metric.Type is SentryMetricType.Counter) |
| 68 | + { |
| 69 | + metric.SetAttribute("operating_system.platform", Environment.OSVersion.Platform.ToString()); |
| 70 | + metric.SetAttribute("operating_system.version", Environment.OSVersion.Version.ToString()); |
| 71 | + } |
63 | 72 |
|
64 | | - // Return null to drop the metric |
65 | 73 | return metric; |
66 | 74 | }); |
67 | 75 | }); |
@@ -95,10 +103,13 @@ async Task FirstFunction() |
95 | 103 | // Info-Log filtered via "BeforeSendLog" callback |
96 | 104 | SentrySdk.Logger.LogInfo("HTTP Request completed."); |
97 | 105 |
|
98 | | - // Metric modified via "BeforeSendMetric" callback for type "int" before sending it to Sentry |
| 106 | + // Counter-Metric prevented from being sent to Sentry via "BeforeSendMetric" callback |
| 107 | + SentrySdk.Experimental.Metrics.EmitCounter("sentry.samples.console.basic.ignore", -1); |
| 108 | + |
| 109 | + // Counter-Metric modified before sending it to Sentry via "BeforeSendMetric" callback |
99 | 110 | SentrySdk.Experimental.Metrics.EmitCounter("sentry.samples.console.basic.http_requests_completed", 1); |
100 | 111 |
|
101 | | - // Metric sent as is because no "BeforeSendMetric" is set for type "double" |
| 112 | + // Distribution-Metric sent as is (see "BeforeSendMetric" callback) |
102 | 113 | SentrySdk.Experimental.Metrics.EmitDistribution("sentry.samples.console.basic.http_request_duration", stopwatch.Elapsed.TotalSeconds, SentryUnits.Duration.Second, |
103 | 114 | [new KeyValuePair<string, object>("http.request.method", HttpMethod.Get.Method), new KeyValuePair<string, object>("http.response.status_code", (int)HttpStatusCode.OK)]); |
104 | 115 | } |
|
0 commit comments