generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recorder.go
64 lines (54 loc) 路 2.06 KB
/
recorder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package telemetry
import (
"log/slog"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/trace"
)
// Recorder records traces, metrics and logs for a particular subsystem.
type Recorder struct {
name string
attrs []Attr
tracer trace.Tracer
meter metric.Meter
logger *slog.Logger
errors metric.Int64Counter
}
// Int64Counter returns a new Int64Counter instrument.
func (r *Recorder) Int64Counter(name string, options ...metric.Int64CounterOption) metric.Int64Counter {
return instrument(r, r.meter.Int64Counter, name, options)
}
// Int64UpDownCounter returns a new Int64UpDownCounter instrument.
func (r *Recorder) Int64UpDownCounter(name string, options ...metric.Int64UpDownCounterOption) metric.Int64UpDownCounter {
return instrument(r, r.meter.Int64UpDownCounter, name, options)
}
// Int64Histogram returns a new Int64Histogram instrument.
func (r *Recorder) Int64Histogram(name string, options ...metric.Int64HistogramOption) metric.Int64Histogram {
return instrument(r, r.meter.Int64Histogram, name, options)
}
// Float64Counter returns a new Float64Counter instrument.
func (r *Recorder) Float64Counter(name string, options ...metric.Float64CounterOption) metric.Float64Counter {
return instrument(r, r.meter.Float64Counter, name, options)
}
// Float64UpDownCounter returns a new Float64UpDownCounter instrument.
func (r *Recorder) Float64UpDownCounter(name string, options ...metric.Float64UpDownCounterOption) metric.Float64UpDownCounter {
return instrument(r, r.meter.Float64UpDownCounter, name, options)
}
// Float64Histogram returns a new Float64Histogram instrument.
func (r *Recorder) Float64Histogram(name string, options ...metric.Float64HistogramOption) metric.Float64Histogram {
return instrument(r, r.meter.Float64Histogram, name, options)
}
// instrument constructs a new instrument using fn. Its name is prefixed with
// r's name.
func instrument[T, O any](
r *Recorder,
fn func(string, ...O) (T, error),
name string,
options []O,
) T {
name = r.name + "." + name
inst, err := fn(name, options...)
if err != nil {
panic(err)
}
return inst
}