Skip to content

Commit

Permalink
[component] add LeveledMeterProvider (#10931)
Browse files Browse the repository at this point in the history
This func will MeterProvider and MetricsLevel in the near future. Split
from
#10912

---------

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
  • Loading branch information
codeboten authored Aug 20, 2024
1 parent 0190799 commit 3c1cf33
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
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: enhancement

# 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: [10931]

# (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 {
if level <= cfg.Telemetry.Metrics.Level {
return mp
}
return noop.MeterProvider{}
},
Logger: logger,
MeterProvider: mp,
TracerProvider: tracerProvider,
Expand Down

0 comments on commit 3c1cf33

Please sign in to comment.