@@ -362,13 +362,15 @@ for the resulting metric. The first step is select to the metrics to whom the Vi
362362is relevant, the second step is to configure the customizations for the the selected
363363metrics.
364364
365- A Metric View is a class that can be instantiated via:
365+ A Metric View can be added to a ` MeterProvider ` like so
366366
367367```` typescript
368- const view = new View ({
369- name: ' metric-view' , // optionally, give the view a unique name
370- // select instruments with a specific name
371- instrumentName: ' http.server.duration' ,
368+ new MeterProvider ({
369+ views: [{
370+ name: ' metric-view' , // optionally, give the view a unique name
371+ // select instruments with a specific name
372+ instrumentName: ' http.server.duration' ,
373+ }]
372374});
373375````
374376
@@ -396,20 +398,22 @@ should be used to define the bucket sizes for the Histogram instrument.
396398Below an example is given how you can define explicit buckets for a histogram.
397399
398400``` typescript
399- // Define view for the histogram metric
400- const histogramView = new View ({
401- aggregation: new ExplicitBucketHistogramAggregation ([0 , 1 , 5 , 10 , 15 , 20 , 25 , 30 ]),
402- instrumentName: ' http.server.duration' ,
403- instrumentType: InstrumentType .HISTOGRAM ,
404- });
405-
406- // Note, the instrumentName is the same as the name that has been passed for
407- // the Meter#createHistogram function
408-
409401// Create an instance of the metric provider
410402const meterProvider = new MeterProvider ({
411403 views: [
412- histogramView
404+ // Define view for the histogram metric
405+ {
406+ aggregation: {
407+ type: AggregationType .EXPLICIT_BUCKET_HISTOGRAM ,
408+ options: {
409+ boundaries: [0 , 1 , 5 , 10 , 15 , 20 , 25 , 30 ],
410+ }
411+ },
412+ // Note, the instrumentName is the same as the name that has been passed for
413+ // the Meter#createHistogram function
414+ instrumentName: ' http.server.duration' ,
415+ instrumentType: InstrumentType .HISTOGRAM ,
416+ }
413417 ]
414418});
415419
@@ -441,20 +445,20 @@ instruments with a specific name:
441445The following view drops all instruments that are associated with a meter named ` pubsub ` :
442446
443447``` typescript
444- const dropView = new View ( {
445- aggregation: new DropAggregation () ,
448+ {
449+ aggregation : { type : AggregationType . DROP } ,
446450 meterName : ' pubsub' ,
447- });
451+ }
448452```
449453
450454Alternatively, you can also drop instruments with a specific instrument name,
451455for example, all instruments of which the name starts with ` http ` :
452456
453457``` typescript
454- const dropView = new View ( {
455- aggregation: new DropAggregation () ,
458+ {
459+ aggregation : { type : AggregationType . DROP } ,
456460 instrumentName : ' http*' ,
457- });
461+ }
458462```
459463
460464### Customizing the metric attributes of instrument
@@ -467,12 +471,12 @@ In the example below will drop all attributes except attribute `environment` for
467471all instruments.
468472
469473``` typescript
470- new View ( {
474+ {
471475 // only export the attribute 'environment'
472476 attributeKeys : [' environment' ],
473477 // apply the view to all instruments
474478 instrumentName : ' *' ,
475- })
479+ }
476480```
477481
478482## Exporting measurements
0 commit comments