-
-
Notifications
You must be signed in to change notification settings - Fork 240
Expand file tree
/
Copy pathSentryMetric.Factory.cs
More file actions
64 lines (53 loc) · 2.89 KB
/
Copy pathSentryMetric.Factory.cs
File metadata and controls
64 lines (53 loc) · 2.89 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
55
56
57
58
59
60
61
62
63
64
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;
}
#if NET6_0_OR_GREATER
[SuppressMessage("Roslynator", "RCS1242:Do not pass non-read-only struct by read-only reference", Justification = $"Ensure that only readonly instance members of {nameof(TagList)} are invoked, to avoid a defensive copy created by the compiler.")]
internal static SentryMetric<T> Create<T>(IHub hub, SentryOptions options, ISystemClock clock, SentryMetricType type, string name, T value, string? unit, in TagList attributes, Scope? scope) where T : struct
{
var metric = CreateCore<T>(hub, options, clock, type, name, value, unit, scope);
metric.Attributes.SetAttributes(in attributes);
return metric;
}
#endif
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);
}
}