@@ -11,7 +11,6 @@ import (
11
11
"go.opentelemetry.io/otel/attribute"
12
12
"go.opentelemetry.io/otel/metric"
13
13
"go.opentelemetry.io/otel/metric/instrument"
14
- "go.opentelemetry.io/otel/metric/instrument/syncfloat64"
15
14
)
16
15
17
16
// InstrumentMetrics starts reporting OpenTelemetry Metrics.
@@ -88,39 +87,39 @@ func reportPoolStats(rdb *redis.Client, conf *config) error {
88
87
idleAttrs := append (labels , attribute .String ("state" , "idle" ))
89
88
usedAttrs := append (labels , attribute .String ("state" , "used" ))
90
89
91
- idleMax , err := conf .meter .AsyncInt64 (). UpDownCounter (
90
+ idleMax , err := conf .meter .Int64ObservableUpDownCounter (
92
91
"db.client.connections.idle.max" ,
93
92
instrument .WithDescription ("The maximum number of idle open connections allowed" ),
94
93
)
95
94
if err != nil {
96
95
return err
97
96
}
98
97
99
- idleMin , err := conf .meter .AsyncInt64 (). UpDownCounter (
98
+ idleMin , err := conf .meter .Int64ObservableUpDownCounter (
100
99
"db.client.connections.idle.min" ,
101
100
instrument .WithDescription ("The minimum number of idle open connections allowed" ),
102
101
)
103
102
if err != nil {
104
103
return err
105
104
}
106
105
107
- connsMax , err := conf .meter .AsyncInt64 (). UpDownCounter (
106
+ connsMax , err := conf .meter .Int64ObservableUpDownCounter (
108
107
"db.client.connections.max" ,
109
108
instrument .WithDescription ("The maximum number of open connections allowed" ),
110
109
)
111
110
if err != nil {
112
111
return err
113
112
}
114
113
115
- usage , err := conf .meter .AsyncInt64 (). UpDownCounter (
114
+ usage , err := conf .meter .Int64ObservableUpDownCounter (
116
115
"db.client.connections.usage" ,
117
116
instrument .WithDescription ("The number of connections that are currently in state described by the state attribute" ),
118
117
)
119
118
if err != nil {
120
119
return err
121
120
}
122
121
123
- timeouts , err := conf .meter .AsyncInt64 (). UpDownCounter (
122
+ timeouts , err := conf .meter .Int64ObservableUpDownCounter (
124
123
"db.client.connections.timeouts" ,
125
124
instrument .WithDescription ("The number of connection timeouts that have occurred trying to obtain a connection from the pool" ),
126
125
)
@@ -129,31 +128,32 @@ func reportPoolStats(rdb *redis.Client, conf *config) error {
129
128
}
130
129
131
130
redisConf := rdb .Options ()
132
- return conf .meter .RegisterCallback (
133
- []instrument.Asynchronous {
134
- idleMax ,
135
- idleMin ,
136
- connsMax ,
137
- usage ,
138
- timeouts ,
139
- },
140
- func (ctx context.Context ) {
131
+ _ , err = conf .meter .RegisterCallback (
132
+ func (ctx context.Context , o metric.Observer ) error {
141
133
stats := rdb .PoolStats ()
142
134
143
- idleMax . Observe ( ctx , int64 (redisConf .MaxIdleConns ), labels ... )
144
- idleMin . Observe ( ctx , int64 (redisConf .MinIdleConns ), labels ... )
145
- connsMax . Observe ( ctx , int64 (redisConf .PoolSize ), labels ... )
135
+ o . ObserveInt64 ( idleMax , int64 (redisConf .MaxIdleConns ), labels ... )
136
+ o . ObserveInt64 ( idleMin , int64 (redisConf .MinIdleConns ), labels ... )
137
+ o . ObserveInt64 ( connsMax , int64 (redisConf .PoolSize ), labels ... )
146
138
147
- usage . Observe ( ctx , int64 (stats .IdleConns ), idleAttrs ... )
148
- usage . Observe ( ctx , int64 (stats .TotalConns - stats .IdleConns ), usedAttrs ... )
139
+ o . ObserveInt64 ( usage , int64 (stats .IdleConns ), idleAttrs ... )
140
+ o . ObserveInt64 ( usage , int64 (stats .TotalConns - stats .IdleConns ), usedAttrs ... )
149
141
150
- timeouts .Observe (ctx , int64 (stats .Timeouts ), labels ... )
142
+ o .ObserveInt64 (timeouts , int64 (stats .Timeouts ), labels ... )
143
+ return nil
151
144
},
145
+ idleMax ,
146
+ idleMin ,
147
+ connsMax ,
148
+ usage ,
149
+ timeouts ,
152
150
)
151
+
152
+ return err
153
153
}
154
154
155
155
func addMetricsHook (rdb * redis.Client , conf * config ) error {
156
- createTime , err := conf .meter .SyncFloat64 (). Histogram (
156
+ createTime , err := conf .meter .Float64Histogram (
157
157
"db.client.connections.create_time" ,
158
158
instrument .WithDescription ("The time it took to create a new connection." ),
159
159
instrument .WithUnit ("ms" ),
@@ -162,7 +162,7 @@ func addMetricsHook(rdb *redis.Client, conf *config) error {
162
162
return err
163
163
}
164
164
165
- useTime , err := conf .meter .SyncFloat64 (). Histogram (
165
+ useTime , err := conf .meter .Float64Histogram (
166
166
"db.client.connections.use_time" ,
167
167
instrument .WithDescription ("The time between borrowing a connection and returning it to the pool." ),
168
168
instrument .WithUnit ("ms" ),
@@ -180,8 +180,8 @@ func addMetricsHook(rdb *redis.Client, conf *config) error {
180
180
}
181
181
182
182
type metricsHook struct {
183
- createTime syncfloat64. Histogram
184
- useTime syncfloat64. Histogram
183
+ createTime instrument. Float64Histogram
184
+ useTime instrument. Float64Histogram
185
185
attrs []attribute.KeyValue
186
186
}
187
187
0 commit comments