@@ -19,6 +19,10 @@ import { Metric } from '../metrics/export/types';
1919import { TagMap } from '../tags/tag-map' ;
2020import { TagKey , TagValue } from '../tags/types' ;
2121
22+ /** Default type for functions */
23+ // tslint:disable:no-any
24+ export type Func < T > = ( ...args : any [ ] ) => T ;
25+
2226/** Main interface for stats. */
2327export interface Stats {
2428 /**
@@ -29,7 +33,7 @@ export interface Stats {
2933 * @param tagKeys The view columns (tag keys)
3034 * @param description The view description
3135 * @param bucketBoundaries The view bucket boundaries for a distribution
32- * aggregation type
36+ * aggregation type
3337 */
3438 createView (
3539 name : string ,
@@ -75,10 +79,17 @@ export interface Stats {
7579 * Updates all views with the new measurements.
7680 * @param measurements A list of measurements to record
7781 * @param tags optional The tags to which the value is applied.
78- * tags could either be explicitly passed to the method, or implicitly
79- * read from current execution context.
82+ * tags could either be explicitly passed to the method, or implicitly
83+ * read from current execution context.
84+ * @param attachments optional The contextual information associated with an
85+ * example value. The contextual information is represented as key - value
86+ * string pairs.
8087 */
81- record ( measurements : Measurement [ ] , tags ?: TagMap ) : void ;
88+ record (
89+ measurements : Measurement [ ] ,
90+ tags ?: TagMap ,
91+ attachments ?: { [ key : string ] : string }
92+ ) : void ;
8293
8394 /**
8495 * Remove all registered Views and exporters from the stats.
@@ -103,6 +114,18 @@ export interface Stats {
103114 * @param exporter An stats exporter
104115 */
105116 unregisterExporter ( exporter : StatsEventListener ) : void ;
117+
118+ /**
119+ * Enters the scope of code where the given `TagMap` is in the current context
120+ * (replacing the previous `TagMap`).
121+ * @param tags The TagMap to be set to the current context.
122+ * @param fn Callback function.
123+ * @returns The callback return.
124+ */
125+ withTagContext < T > ( tags : TagMap , fn : Func < T > ) : T ;
126+
127+ /** Gets the current tag context. */
128+ getCurrentTagContext ( ) : TagMap ;
106129}
107130
108131/**
@@ -181,7 +204,7 @@ export interface View {
181204 /**
182205 * The end time for this view - represents the last time a value was recorded
183206 */
184- endTime : number ;
207+ endTime ? : number ;
185208 /** true if the view was registered */
186209 registered : boolean ;
187210 /**
@@ -191,13 +214,20 @@ export interface View {
191214 * Measurements with measurement type INT64 will have its value truncated.
192215 * @param measurement The measurement to record
193216 * @param tags The tags to which the value is applied
217+ * @param attachments optional The contextual information associated with an
218+ * example value. THe contextual information is represented as key - value
219+ * string pairs.
194220 */
195- recordMeasurement ( measurement : Measurement , tags : TagMap ) : void ;
221+ recordMeasurement (
222+ measurement : Measurement ,
223+ tags : TagMap ,
224+ attachments ?: { [ key : string ] : string }
225+ ) : void ;
196226 /**
197227 * Returns a snapshot of an AggregationData for that tags/labels values.
198228 * @param tagValues The desired data's tag values.
199229 */
200- getSnapshot ( tagValues : TagValue [ ] ) : AggregationData ;
230+ getSnapshot ( tagValues : Array < TagValue | null > ) : AggregationData ;
201231 /** Gets the view's tag keys */
202232 getColumns ( ) : TagKey [ ] ;
203233 /** Gets view`s metric */
@@ -220,7 +250,7 @@ export interface AggregationMetadata {
220250 /** The aggregation type of the aggregation data */
221251 readonly type : AggregationType ;
222252 /** The tagValues that this AggregationData collects and aggregates */
223- readonly tagValues : TagValue [ ] ;
253+ readonly tagValues : Array < TagValue | null > ;
224254 /** The latest timestamp a new data point was recorded */
225255 timestamp : number ;
226256}
@@ -279,6 +309,25 @@ export interface DistributionData extends AggregationMetadata {
279309 buckets : Bucket [ ] ;
280310 /** Buckets count */
281311 bucketCounts ?: number [ ] ;
312+ /** If the distribution does not have a histogram, then omit this field. */
313+ exemplars ?: StatsExemplar [ ] ;
314+ }
315+
316+ /**
317+ * Exemplars are example points that may be used to annotate aggregated
318+ * Distribution values. They are metadata that gives information about a
319+ * particular value added to a Distribution bucket.
320+ */
321+ export interface StatsExemplar {
322+ /**
323+ * Value of the exemplar point. It determines which bucket the exemplar
324+ * belongs to.
325+ */
326+ readonly value : number ;
327+ /** The observation (sampling) time of the above value. */
328+ readonly timestamp : number ;
329+ /** Contextual information about the example value. */
330+ readonly attachments : { [ key : string ] : string } ;
282331}
283332
284333export type Bucket = number ;
0 commit comments