-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support duration and float metrics #223
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. Dang C# has some nice bits but it is verboooooossseeee.
{ | ||
// Have to convert TimeSpan to something .NET meter can work with. For this to even | ||
// happen, a user would have had to set custom options to report as time span. | ||
if (typeof(T) == typeof(TimeSpan)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole non-erased generic type check thing feels deeply illegal to me 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reified generics are so nice in .NET compared to Java's type erasure. This is why you can call AddWorkflow<MyWorkflowClass>()
and similar. But there are some downsides.
@@ -51,18 +51,44 @@ internal class MetricInteger : SafeHandle | |||
/// </summary> | |||
/// <param name="value">Value to record.</param> | |||
/// <param name="attributes">Attributes to set.</param> | |||
public void Record(ulong value, MetricAttributes attributes) | |||
public void RecordInteger(ulong value, MetricAttributes attributes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than allowing all record kinds on one Metric
type it seems like it'd be pretty easy to hand out specialized versions with only one record method each corresponding to the kind passed in when created
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not public user-facing code. We do it in a .NET idiomatic way when it comes to the actual user-facing code. But it is nice for the C FFI if we do combine these into fewer calls and expect the caller be smart.
let meter = &*(self.meter_impl.0); | ||
(meter.metric_record_duration)( | ||
self.metric, | ||
value.as_millis().try_into().unwrap_or(u64::MAX), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't decide in the rare case that this happens if it's better to record this max or simply not record anything at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was stuck a bit here too and just settled on this. Hopefully the issue never arises. But if we think it's enough of an issue, we can look info logging instead.
This gets even worse when we convert back to .NET types because. E.g. for .NET a ulong
(i.e. u64
) is "not CLS-compliant", so it's best to use long
(i.e. i64
) instead, so I limit to max there too (default unchecked cast wraps into negative). This is much more likely of a problem, but I can't currently think of a case where Core side will go over max-i64.
@Sushisource - merged based on approval (waited a day after my most recent comment responses), but we can revisit any of the pieces if you think they are important. |
What was changed
MetricMeter.CreateHistogram
to provide floating point types orTimeSpan
in addition to already-supported integer typesMetricMeter.CreateGauge
to provide floating point types in addition to already-supported integer typesOpenTelemetryOptions.UseSecondsForDuration
option to have OTel metrics use float seconds instead of msPrometheusOptions.UseSecondsForDuration
option to have Prom metrics use float seconds instead of msICustomMetricMeter.CreateHistogram
now supportsdouble
andTimeSpan
(for those creating custom meter impls)ICustomMetricMeter.CreateGauge
now supportsdouble
(for those creating custom meter impls)MetricsOptions.CustomMetricMeterOptions
which accepts an option type whose only field isHistogramDurationFormat
to specify whether meter impls will get duration metrics as integer milliseconds, float seconds, or time spansChecklist