Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[component] add LeveledMeterProvider #10931

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .chloggen/codeboten_leveled-meter-split-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type:
codeboten marked this conversation as resolved.
Show resolved Hide resolved

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: component

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Add `TelemetrySettings.LeveledMeterProvider` func to replace MetricsLevel in the near future"

# One or more tracking issues or pull requests related to the change
issues: []
codeboten marked this conversation as resolved.
Show resolved Hide resolved

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
4 changes: 4 additions & 0 deletions component/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ type TelemetrySettings struct {
// MeterProvider that the factory can pass to other instrumented third-party libraries.
MeterProvider metric.MeterProvider

// LeveledMeterProvider returns a MeterProvider for a Level that the factory can
// pass to other instrumented third-party libraries.
LeveledMeterProvider func(level configtelemetry.Level) metric.MeterProvider

// MetricsLevel controls the level of detail for metrics emitted by the collector.
// Experimental: *NOTE* this field is experimental and may be changed or removed.
MetricsLevel configtelemetry.Level
Expand Down
11 changes: 11 additions & 0 deletions processor/processorhelper/obsreport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
Expand Down Expand Up @@ -217,6 +219,9 @@ func TestNoMetrics(t *testing.T) {

set := tt.TelemetrySettings()
set.MetricsLevel = configtelemetry.LevelNone
set.LeveledMeterProvider = func(_ configtelemetry.Level) metric.MeterProvider {
return noop.MeterProvider{}
}

por, err := NewObsReport(ObsReportSettings{
ProcessorID: processorID,
Expand All @@ -239,6 +244,9 @@ func TestNoMetrics(t *testing.T) {

set := tt.TelemetrySettings()
set.MetricsLevel = configtelemetry.LevelNone
set.LeveledMeterProvider = func(_ configtelemetry.Level) metric.MeterProvider {
return noop.MeterProvider{}
}

por, err := NewObsReport(ObsReportSettings{
ProcessorID: processorID,
Expand All @@ -261,6 +269,9 @@ func TestNoMetrics(t *testing.T) {

set := tt.TelemetrySettings()
set.MetricsLevel = configtelemetry.LevelNone
set.LeveledMeterProvider = func(_ configtelemetry.Level) metric.MeterProvider {
return noop.MeterProvider{}
}

por, err := NewObsReport(ObsReportSettings{
ProcessorID: processorID,
Expand Down
5 changes: 5 additions & 0 deletions service/internal/proctelemetry/process_telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
otelprom "go.opentelemetry.io/otel/exporters/prometheus"
"go.opentelemetry.io/otel/metric"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"

Expand Down Expand Up @@ -56,6 +57,10 @@ func setupTelemetry(t *testing.T) testTelemetry {
)
settings.TelemetrySettings.MeterProvider = settings.meterProvider

settings.TelemetrySettings.LeveledMeterProvider = func(_ configtelemetry.Level) metric.MeterProvider {
return settings.meterProvider
}

settings.promHandler = promhttp.HandlerFor(promReg, promhttp.HandlerOpts{})

t.Cleanup(func() { assert.NoError(t, settings.meterProvider.Shutdown(context.Background())) })
Expand Down
7 changes: 7 additions & 0 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"runtime"

"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
sdkresource "go.opentelemetry.io/otel/sdk/resource"
"go.uber.org/multierr"
"go.uber.org/zap"
Expand Down Expand Up @@ -127,6 +128,12 @@ func New(ctx context.Context, set Settings, cfg Config) (*Service, error) {

logsAboutMeterProvider(logger, cfg.Telemetry.Metrics, mp, extendedConfig)
srv.telemetrySettings = component.TelemetrySettings{
LeveledMeterProvider: func(level configtelemetry.Level) metric.MeterProvider {
codeboten marked this conversation as resolved.
Show resolved Hide resolved
if level <= cfg.Telemetry.Metrics.Level {
return mp
}
return noop.MeterProvider{}
},
Logger: logger,
MeterProvider: mp,
TracerProvider: tracerProvider,
Expand Down
Loading