Skip to content

Commit

Permalink
feat(metrics): introduce Tracker interface
Browse files Browse the repository at this point in the history
Signed-off-by: lvlcn-t <75443136+lvlcn-t@users.noreply.github.com>
  • Loading branch information
lvlcn-t committed Nov 24, 2024
1 parent cb2e662 commit 09f4b08
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 7 additions & 1 deletion metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ type Collector interface {
GetRegistry() *prometheus.Registry
}

// Tracker is the interface that wraps the basic methods of the OpenTelemetry tracer and Prometheus collector.
type Tracker interface {
Tracer
Collector
}

// manager implements the Tracer and Collector interfaces
// It is used to initialize the OpenTelemetry manager and Prometheus collectors
type manager struct {
Expand All @@ -45,7 +51,7 @@ type manager struct {

// New creates a new metrics instance with the given configuration.
// This instance can be used to initialize the OpenTelemetry metrics and Prometheus collectors.
func New(config Config) *manager {
func New(config Config) Tracker {
registry := prometheus.NewRegistry()

registry.MustRegister(
Expand Down
6 changes: 2 additions & 4 deletions metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ func TestNew(t *testing.T) {
)

t.Run("Register a collector", func(t *testing.T) {
testMetrics.registry.MustRegister(
testGauge,
)
testMetrics.GetRegistry().MustRegister(testGauge)
})
}

Expand Down Expand Up @@ -123,7 +121,7 @@ func TestTracer_Initialize_Shutdown(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := New(tt.config)
m := New(tt.config).(*manager)
if _, ok := tt.wantErr.(*ErrAlreadyInitialized); ok {
m.tracer = sdktrace.NewTracerProvider()
}
Expand Down

0 comments on commit 09f4b08

Please sign in to comment.