29
29
from opentelemetry .sdk .metrics .export .controller import PushController
30
30
31
31
batcher_mode = "stateful"
32
+ stateful_bacher = False
32
33
33
34
34
35
def usage (argv ):
@@ -50,7 +51,8 @@ def usage(argv):
50
51
# lifetime.
51
52
# False indicates the batcher computes checkpoints which describe the updates
52
53
# of a single collection period (deltas)
53
- batcher = UngroupedBatcher (batcher_mode == "stateful" )
54
+ stateful_bacher = batcher_mode == "stateful"
55
+ batcher = UngroupedBatcher (stateful = stateful_bacher )
54
56
55
57
# If a batcher is not provided, a default batcher is used
56
58
# Meter is responsible for creating and recording metrics
@@ -66,15 +68,30 @@ def usage(argv):
66
68
67
69
# Metric instruments allow to capture measurements
68
70
requests_counter = meter .create_metric (
69
- "requests" , "number of requests" , 1 , int , Counter , ("environment" ,)
71
+ name = "requests" ,
72
+ description = "number of requests" ,
73
+ unit = "1" ,
74
+ value_type = int ,
75
+ metric_type = Counter ,
76
+ label_keys = ("environment" ,),
70
77
)
71
78
72
79
clicks_counter = meter .create_metric (
73
- "clicks" , "number of clicks" , 1 , int , Counter , ("environment" ,)
80
+ name = "clicks" ,
81
+ description = "number of clicks" ,
82
+ unit = "1" ,
83
+ value_type = int ,
84
+ metric_type = Counter ,
85
+ label_keys = ("environment" ,),
74
86
)
75
87
76
88
requests_size = meter .create_metric (
77
- "requests_size" , "size of requests" , 1 , int , Measure , ("environment" ,)
89
+ name = "requests_size" ,
90
+ description = "size of requests" ,
91
+ unit = "1" ,
92
+ value_type = int ,
93
+ metric_type = Measure ,
94
+ label_keys = ("environment" ,),
78
95
)
79
96
80
97
# Labelsets are used to identify key-values that are associated with a specific
@@ -86,21 +103,15 @@ def usage(argv):
86
103
# Update the metric instruments using the direct calling convention
87
104
requests_size .record (100 , staging_label_set )
88
105
requests_counter .add (25 , staging_label_set )
89
- # Sleep for 5 seconds, exported value should be 25
90
106
time .sleep (5 )
91
107
92
108
requests_size .record (5000 , staging_label_set )
93
109
requests_counter .add (50 , staging_label_set )
94
- # Exported value should be 75
95
110
time .sleep (5 )
96
111
97
112
requests_size .record (2 , testing_label_set )
98
113
requests_counter .add (35 , testing_label_set )
99
- # There should be two exported values 75 and 35, one for each labelset
100
114
time .sleep (5 )
101
115
102
116
clicks_counter .add (5 , staging_label_set )
103
- # There should be three exported values, labelsets can be reused for different
104
- # metrics but will be recorded seperately, 75, 35 and 5
105
-
106
117
time .sleep (5 )
0 commit comments