|
22 | 22 | PeriodicExportingMetricReader,
|
23 | 23 | )
|
24 | 24 |
|
25 |
| -# Use console exporter for the example |
26 |
| -exporter = ConsoleMetricExporter() |
27 |
| - |
28 | 25 | temporality_cumulative = {Counter: AggregationTemporality.CUMULATIVE}
|
29 | 26 | temporality_delta = {Counter: AggregationTemporality.DELTA}
|
30 |
| -# Create a metric reader with cumulative preferred temporality |
31 |
| -# The metrics that are exported using this reader will represent a cumulative value |
| 27 | + |
| 28 | +# Use console exporters for the example |
| 29 | + |
| 30 | +# The metrics that are exported using this exporter will represent a cumulative value |
| 31 | +exporter = ConsoleMetricExporter( |
| 32 | + preferred_temporality=temporality_cumulative, |
| 33 | +) |
| 34 | + |
| 35 | +# The metrics that are exported using this exporter will represent a delta value |
| 36 | +exporter2 = ConsoleMetricExporter( |
| 37 | + preferred_temporality=temporality_delta, |
| 38 | +) |
| 39 | + |
| 40 | +# The PeriodicExportingMetricReader takes the preferred aggregation |
| 41 | +# from the passed in exporter |
32 | 42 | reader = PeriodicExportingMetricReader(
|
33 | 43 | exporter,
|
34 |
| - preferred_temporality=temporality_cumulative, |
35 | 44 | export_interval_millis=5_000,
|
36 | 45 | )
|
37 |
| -# Create a metric reader with delta preferred temporality |
38 |
| -# The metrics that are exported using this reader will represent a delta value |
| 46 | + |
| 47 | +# The PeriodicExportingMetricReader takes the preferred aggregation |
| 48 | +# from the passed in exporter |
39 | 49 | reader2 = PeriodicExportingMetricReader(
|
40 |
| - exporter, |
41 |
| - preferred_temporality=temporality_delta, |
| 50 | + exporter2, |
42 | 51 | export_interval_millis=5_000,
|
43 | 52 | )
|
| 53 | + |
44 | 54 | provider = MeterProvider(metric_readers=[reader, reader2])
|
45 | 55 | set_meter_provider(provider)
|
46 | 56 |
|
|
49 | 59 | counter = meter.create_counter("my-counter")
|
50 | 60 |
|
51 | 61 | # Two metrics are expected to be printed to the console per export interval.
|
52 |
| -# The metric originating from the metric reader with a preferred temporality |
| 62 | +# The metric originating from the metric exporter with a preferred temporality |
53 | 63 | # of cumulative will keep a running sum of all values added.
|
54 |
| -# The metric originating from the metric reader with a preferred temporality |
| 64 | +# The metric originating from the metric exporter with a preferred temporality |
55 | 65 | # of delta will have the sum value reset each export interval.
|
56 |
| -for x in range(10): |
57 |
| - counter.add(x) |
58 |
| - time.sleep(2.0) |
| 66 | +counter.add(5) |
| 67 | +time.sleep(10) |
| 68 | +counter.add(20) |
0 commit comments