-
-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathSentryMetric.Factory.cs
More file actions
54 lines (44 loc) · 2.23 KB
/
SentryMetric.Factory.cs
File metadata and controls
54 lines (44 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using Sentry.Infrastructure;
namespace Sentry;
public abstract partial class SentryMetric
{
private static SentryMetric<T> CreateCore<T>(IHub hub, SentryOptions options, ISystemClock clock, SentryMetricType type, string name, T value, string? unit, Scope? scope) where T : struct
{
Debug.Assert(IsSupported<T>());
Debug.Assert(!string.IsNullOrEmpty(name));
Debug.Assert(type is not SentryMetricType.Counter || unit is null, $"'{nameof(unit)}' is only used for Metrics of type {nameof(SentryMetricType.Gauge)} and {nameof(SentryMetricType.Distribution)}.");
var timestamp = clock.GetUtcNow();
hub.GetTraceIdAndSpanId(out var traceId, out var spanId);
var metric = new SentryMetric<T>(timestamp, traceId, type, name, value)
{
SpanId = spanId,
Unit = unit,
};
scope ??= hub.GetScope();
metric.Attributes.SetDefaultAttributes(options, scope?.Sdk ?? SdkVersion.Instance);
return metric;
}
internal static SentryMetric<T> Create<T>(IHub hub, SentryOptions options, ISystemClock clock, SentryMetricType type, string name, T value, string? unit, IEnumerable<KeyValuePair<string, object>>? attributes, Scope? scope) where T : struct
{
var metric = CreateCore<T>(hub, options, clock, type, name, value, unit, scope);
metric.Attributes.SetAttributes(attributes);
return metric;
}
internal static SentryMetric<T> Create<T>(IHub hub, SentryOptions options, ISystemClock clock, SentryMetricType type, string name, T value, string? unit, ReadOnlySpan<KeyValuePair<string, object>> attributes, Scope? scope) where T : struct
{
var metric = CreateCore<T>(hub, options, clock, type, name, value, unit, scope);
metric.Attributes.SetAttributes(attributes);
return metric;
}
private static bool IsSupported<T>() where T : struct
{
var valueType = typeof(T);
return IsSupported(valueType);
}
internal static bool IsSupported(Type valueType)
{
return valueType == typeof(long) || valueType == typeof(double)
|| valueType == typeof(int) || valueType == typeof(float)
|| valueType == typeof(short) || valueType == typeof(byte);
}
}