Skip to content

Commit

Permalink
Fix panic from empty LeveledMeterProvider (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias authored Sep 29, 2024
1 parent d052ffd commit a1e004c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ import (

"github.com/MrAlias/collex"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/debugexporter"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
"go.opentelemetry.io/otel/sdk/trace"
"go.uber.org/zap"
)
Expand All @@ -32,6 +35,9 @@ func Example() {
TelemetrySettings: component.TelemetrySettings{
Logger: zap.NewExample(), // Log to STDOUT for example.
TracerProvider: otel.GetTracerProvider(),
LeveledMeterProvider: func(configtelemetry.Level) metric.MeterProvider {
return noop.NewMeterProvider()
},
},
}
factory, err := collex.NewFactory(debugexporter.NewFactory(), settings)
Expand All @@ -53,5 +59,5 @@ func Example() {
log.Fatal(err)
}

// Output: {"level":"info","msg":"TracesExporter","#spans":1}
// Output: {"level":"info","msg":"TracesExporter","resource spans":1,"spans":1}
}
6 changes: 6 additions & 0 deletions factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
"go.opentelemetry.io/otel/sdk/trace"
"go.uber.org/zap"
)
Expand All @@ -45,6 +48,9 @@ func NewFactory(f exporter.Factory, set *exporter.Settings) (*Factory, error) {
TelemetrySettings: component.TelemetrySettings{
Logger: logger,
TracerProvider: otel.GetTracerProvider(),
LeveledMeterProvider: func(configtelemetry.Level) metric.MeterProvider {
return noop.NewMeterProvider()
},
},
BuildInfo: component.BuildInfo{
Command: "collex",
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ require (
go.opentelemetry.io/collector/pdata/pprofile v0.110.0 // indirect
go.opentelemetry.io/collector/pipeline v0.110.0 // indirect
go.opentelemetry.io/otel/metric v1.30.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.30.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sys v0.25.0 // indirect
Expand Down

0 comments on commit a1e004c

Please sign in to comment.