You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Developers can trace their code using Open Telemetry Metrics #44445
changed the title [-]Metrics Support for tracing and Open Telemetry[/-][+]Developers can trace their code using Open Telemetry Metrics[/+]on Jan 5, 2021
In the Metric.Create* methods, consider swapping the order of unit and description, if (name+unit) seems more likely than (name+description).
"Observable" in this context has a meaning opposite of what it means in "ObservableCollection"
We don't have a solid replacement name for it, though, since it seems that every appropriate word already has a conflicting meaning in OpenTelemetry.
Consider renaming Instrument<T> to StreamingInstrument<T>, or some other prefix, to give better separation between ObservableInstrument<T> and "the other kind".
Add a public Measurement(T value) constructor so the params one is not called with the empty array.
For Counter<T>.Add, rename measurement to delta to make it more clear that the caller should provide only the amount to increase since the last call, vs that "Add" means appending to a list.
Rename Histogram<T>.Record's measurement parameter to value (to avoid confusion with Measurement<T> and associated semantics)
Measurement<T> should be declared readonly
MeasurementCallback should constraint T to match the rest of the proposal (T : unmanaged)
Replace all of the T : unmanaged constraints with T : struct
We had to stop before really looking at MetricListener.
Do MeterListener.InstrumentPublished and MeasurementsCompleted need to be get/set? Should they be ctor parameters instead?
It seems there are theoretical scenarios for replacing them later, so get/set is fine
What is the experience when a SetMeasurementCallback wasn't called for the T that is being reported?
Consider something like public Action<Instrument>? UnregisteredMeasurementCallback { get; set; } to get called in that case instead of just data loss.
namespaceSystem.Diagnostics.Metrics{publicclassMeter:IDisposable{/// <summary>/// The constructor allows creating the Meter class with the name and optionally the version./// The name should be validated as described by the OpenTelemetry specs./// </summary>publicMeter(stringname){thrownull;}publicMeter(stringname,string?version){thrownull;}/// <summary>/// Getter properties to retrieve the Meter name and version/// </summary>publicstringName{get;}publicstring?Version{get;}/// <summary>/// Factory methods to create Counter and Histogram instruments./// </summary>publicCounter<T>CreateCounter<T>(stringname,string?unit=null,string?description=null)whereT:struct{thrownull;}publicHistogram<T>CreateHistogram<T>(stringname,string?unit=null,string?description=null)whereT:struct{thrownull;}/// <summary>/// Factory methods to create an ObservableCounter instrument./// </summary>publicObservableCounter<T>CreateObservableCounter<T>(stringname,Func<T>observeValue,string?unit=null,string?description=null)whereT:struct{thrownull;}publicObservableCounter<T>CreateObservableCounter<T>(stringname,Func<Measurement<T>>observeValue,string?unit=null,string?description=null,)whereT:struct{thrownull;}publicObservableCounter<T>CreateObservableCounter<T>(stringname,Func<IEnumerable<Measurement<T>>>observeValues,string?unit=null,string?description=null)whereT:struct{thrownull;}/// <summary>/// Factory methods to create ObservableGauge instrument./// </summary>publicObservableGauge<T>CreateObservableGauge<T>(stringname,Func<T>observeValue,string?unit=null,string?description=null,)whereT:struct{thrownull;}publicObservableGauge<T>CreateObservableGauge<T>(stringname,Func<Measurement<T>>observeValue,string?unit=null,string?description=null)whereT:struct{thrownull;}publicObservableGauge<T>CreateObservableGauge<T>(stringname,Func<IEnumerable<Measurement<T>>>observeValues,string?unit=null,string?description=null)whereT:struct{thrownull;}/// <summary>/// Factory methods to create ObservableUpDownCounter instrument./// </summary>publicObservableUpDownCounter<T>CreateObservableUpDownCounter<T>(stringname,Func<T>observeValue,string?unit=null,string?description=null,)whereT:struct{thrownull;}publicObservableUpDownCounter<T>CreateObservableUpDownCounter<T>(stringname,Func<Measurement<T>>observeValue,string?unit=null,string?description=null,)whereT:struct{thrownull;}publicObservableUpDownCounter<T>CreateObservableUpDownCounter<T>(stringname,Func<IEnumerable<Measurement<T>>>observeValues,string?unit=null,string?description=null)whereT:struct{thrownull;}publicvoidDispose(){thrownull;}}/// <summary>/// Is the base class which contains all common properties between different types of instruments./// It contains the protected constructor and the Publish method allows activating the instrument/// to start recording measurements./// </summary>publicabstractclassInstrument{/// <summary>/// Protected constructor to initialize the common instrument properties./// </summary>protectedInstrument(Metermeter,stringname,string?unit,string?description){thrownull;}/// <summary>/// Publish is to allow activating the instrument to start recording measurements and to allow/// listeners to start listening to such measurements./// </summary>protectedvoidPublish(){thrownull;}/// <summary>/// Getters to retrieve the properties that the instrument is created with./// </summary>publicMeterMeter{get;}publicstringName{get;}publicstring?Unit{get;}publicstring?Description{get;}/// <summary>/// A property tells if a listener is listening to this instrument measurement recording./// </summary>publicboolEnabled=>thrownull;/// <summary>/// A property tells if the instrument is a regular instrument or an observable instrument./// </summary>publicvirtualboolIsObservable=>thrownull;}/// <summary>/// Instrument<T> is the base class from which all instruments that report measurements in the context of the request will inherit from./// Mainly it will support the CLS compliant numerical types./// </summary>publicabstractclassInstrument<T>:InstrumentwhereT:struct{/// <summary>/// Protected constructor to create the instrument with the common properties./// </summary>protectedInstrument(Metermeter,stringname,string?unit,string?description):base(meter,name,unit,description){thrownull;}/// <summary>/// Record measurement overloads allowing passing different numbers of tags./// </summary>protectedvoidRecordMeasurement(Tmeasurement){thrownull;}protectedvoidRecordMeasurement(Tmeasurement,KeyValuePair<string,object?>tag){thrownull;}protectedvoidRecordMeasurement(Tmeasurement,KeyValuePair<string,object?>tag1,KeyValuePair<string,object?>tag2){thrownull;}protectedvoidRecordMeasurement(Tmeasurement,KeyValuePair<string,object?>tag1,KeyValuePair<string,object?>tag2,KeyValuePair<string,object?>tag3){thrownull;}protectedvoidRecordMeasurement(Tmeasurement,ReadOnlySpan<KeyValuePair<string,object?>>tags){thrownull;}}/// <summary>/// ObservableInstrument<T> is the base class from which all observable instruments will inherit from./// It will only support the CLS compliant numerical types./// </summary>publicabstractclassObservableInstrument<T>:InstrumentwhereT:struct{/// <summary>/// Protected constructor to create the instrument with the common properties./// </summary>protectedObservableInstrument(Metermeter,stringname,string?unit,string?description):base(meter,name,unit,description){thrownull;}/// <summary>/// Observe() fetches the current measurements being tracked by this instrument./// </summary>protectedabstractIEnumerable<Measurement<T>>Observe();publicoverrideboolIsObservable=>true;}/// <summary>/// A measurement stores one observed value and its associated tags. This type is used by Observable instruments' Observe() method when reporting current measurements with associated tags./// with the associated tags./// </summary>publicreadonlystructMeasurement<T>whereT:struct{/// <summary>/// Construct the Measurement using the value and the list of tags./// We'll always copy the input list as this is not perf hot path./// </summary>publicMeasurement(Tvalue){thrownull;}publicMeasurement(Tvalue,IEnumerable<KeyValuePair<string,object?>>tags){thrownull;}publicMeasurement(Tvalue,paramsKeyValuePair<string,object?>[]tags){thrownull;}publicMeasurement(Tvalue,ReadOnlySpan<KeyValuePair<string,object?>>tags){thrownull;}publicReadOnlySpan<KeyValuePair<string,object?>>Tags{get{thrownull;}}publicTValue{get;}}/// <summary>/// The counter is an Instrument that supports non-negative increments./// e.g. Number of completed requests./// </summary>publicsealedclassCounter<T>:Instrument<T>whereT:struct{publicvoidAdd(Tdelta){thrownull;}publicvoidAdd(Tdelta,KeyValuePair<string,object?>tag){thrownull;}publicvoidAdd(Tdelta,KeyValuePair<string,object?>tag1,KeyValuePair<string,object?>tag2){thrownull;}publicvoidAdd(Tdelta,KeyValuePair<string,object?>tag1,KeyValuePair<string,object?>tag2,KeyValuePair<string,object?>tag3){thrownull;}publicvoidAdd(Tdelta,ReadOnlySpan<KeyValuePair<string,object?>>tags){thrownull;}publicvoidAdd(Tdelta,paramsKeyValuePair<string,object?>[]tags){thrownull;}}/// <summary>/// The histogram is an Instrument that can be used to report arbitrary values/// that are likely to be statistically meaningful. It is intended for statistics such as the request duration./// e.g. the request duration./// </summary>publicsealedclassHistogram<T>:Instrument<T>whereT:struct{publicvoidRecord(Tvalue){thrownull;}publicvoidRecord(Tvalue,KeyValuePair<string,object?>tag){thrownull;}publicvoidRecord(Tvalue,KeyValuePair<string,object?>tag1,KeyValuePair<string,object?>tag2){thrownull;}publicvoidRecord(Tvalue,KeyValuePair<string,object?>tag1,KeyValuePair<string,object?>tag2,KeyValuePair<string,object?>tag3){thrownull;}publicvoidRecord(Tvalue,ReadOnlySpan<KeyValuePair<string,object?>>tags){thrownull;}publicvoidRecord(Tvalue,paramsKeyValuePair<string,object?>[]tags){thrownull;}}/// <summary>/// ObservableCounter is an observable Instrument that reports monotonically increasing value(s)/// when the instrument is being observed./// e.g. CPU time (for different processes, threads, user mode or kernel mode)./// </summary>publicsealedclassObservableCounter<T>:ObservableInstrument<T>whereT:struct{protectedoverrideIEnumerable<Measurement<T>>Observe(){thrownull;}}/// <summary>/// ObservableUpDownCounter is an observable Instrument that reports additive value(s)/// when the instrument is being observed./// e.g. the process heap size/// </summary>publicsealedclassObservableUpDownCounter<T>:ObservableInstrument<T>whereT:struct{protectedoverrideIEnumerable<Measurement<T>>Observe(){thrownull;}}/// <summary>/// ObservableGauge is an observable Instrument that reports non-additive value(s)/// when the instrument is being observed./// e.g. the current room temperature/// </summary>publicsealedclassObservableGauge<T>:ObservableInstrument<T>whereT:struct{protectedoverrideIEnumerable<Measurement<T>>Observe(){thrownull;}}/// <summary>/// A delegate to represent the callbacks signatures used in the listener./// </summary>publicdelegatevoidMeasurementCallback<T>(Instrumentinstrument,Tmeasurement,ReadOnlySpan<KeyValuePair<string,object?>>tags,object?state)whereT:struct;/// <summary>/// The listener class can be used to listen to kinds of instruments./// recorded measurements./// </summary>publicsealedclassMeterListener:IDisposable{/// <summary>/// Simple constructor/// </summary>publicMeterListener(){thrownull;}/// <summary>/// Callbacks to get notification when an instrument is published/// </summary>publicAction<Instrument,MeterListener>?InstrumentPublished{get;set;}/// <summary>/// Callbacks to get notification when stopping the measurement on some instrument/// this can happen when the Meter or the Listener is disposed of. Or calling Stop()/// on the listener./// </summary>publicAction<Instrument,object?>?MeasurementsCompleted{get;set;}/// <summary>/// Start listening to a specific instrument measurement recording./// </summary>publicvoidEnableMeasurementEvents(Instrumentinstrument,object?state=null){thrownull;}/// <summary>/// Stop listening to a specific instrument measurement recording./// returns the associated state./// </summary>publicobject?DisableMeasurementEvents(Instrumentinstrument){thrownull;}/// <summary>/// Set a callback for a specific numeric type to get the measurement recording notification/// from all instruments which enabled listened to and was created with the same specified/// numeric type. If a measurement of type T is recorded and a callback of type T is registered, that callback is used. If there is no callback for type T but there is a callback for type object, the measured value is boxed and reported via the object typed callback. If there is neither type T callback nor object callback then the measurement will not be reported./// </summary>publicvoidSetMeasurementEventCallback<T>(MeasurementCallback<T>?measurementCallback)whereT:struct{thrownull;}publicvoidStart(){thrownull;}/// <summary>/// Call all Observable instruments to get the recorded measurements reported to the/// callbacks enabled by SetMeasurementEventCallback<T>/// </summary>publicvoidRecordObservableInstruments(){thrownull;}publicvoidDispose(){thrownull;}}}
Activity
Dotnet-GitSync-Bot commentedon Nov 10, 2020
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
tarekgh commentedon Nov 10, 2020
@danmosemsft @ericstj I created this issue to track the metrics work.
iSazonov commentedon Nov 10, 2020
danmoseley commentedon Nov 10, 2020
@glennc should this go under some epic under the cloud native theme?
9 remaining items
[-]Metrics Support for tracing and Open Telemetry[/-][+]Developers can trace their code using Open Telemetry Metrics[/+]bartonjs commentedon May 7, 2021
Video
Instrument<T>toStreamingInstrument<T>, or some other prefix, to give better separation betweenObservableInstrument<T>and "the other kind".public Measurement(T value)constructor so the params one is not called with the empty array.Counter<T>.Add, renamemeasurementtodeltato make it more clear that the caller should provide only the amount to increase since the last call, vs that "Add" means appending to a list.Histogram<T>.Record'smeasurementparameter tovalue(to avoid confusion withMeasurement<T>and associated semantics)Measurement<T>should be declared readonlyWe had to stop before really looking at MetricListener.
bartonjs commentedon May 11, 2021
In addition to the previous feedback:
public Action<Instrument>? UnregisteredMeasurementCallback { get; set; }to get called in that case instead of just data loss.