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

[service] add level for trace configuration #10892

Merged
merged 2 commits into from
Aug 26, 2024
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_trace-level.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: service

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Adds `level` configuration option to `service::telemetry::trace` to allow users to disable the default TracerProvider"

# One or more tracking issues or pull requests related to the change
issues: [10892]

# (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: "This replaces the feature gate `service.noopTracerProvider` introduced in v0.107.0"
codeboten marked this conversation as resolved.
Show resolved Hide resolved
songy23 marked this conversation as resolved.
Show resolved Hide resolved

# 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: []
1 change: 1 addition & 0 deletions internal/globalgates/globalgates.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ var DisableOpenCensusBridge = featuregate.GlobalRegistry().MustRegister("service
var NoopTracerProvider = featuregate.GlobalRegistry().MustRegister("service.noopTracerProvider",
featuregate.StageAlpha,
featuregate.WithRegisterFromVersion("v0.107.0"),
featuregate.WithRegisterToVersion("v0.109.0"),
featuregate.WithRegisterDescription("Sets a Noop OpenTelemetry TracerProvider to reduce memory allocations. This featuregate is incompatible with the zPages extension."))
4 changes: 4 additions & 0 deletions service/telemetry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ type MetricsConfig struct {
// TracesConfig exposes the common Telemetry configuration for collector's internal spans.
// Experimental: *NOTE* this structure is subject to change or removal in the future.
type TracesConfig struct {
// Level configures whether spans are emitted or not, the possible values are:
// - "none" indicates that no tracing data should be collected;
// - "basic" is the recommended and covers the basics of the service telemetry.
Level configtelemetry.Level `mapstructure:"level"`
// Propagators is a list of TextMapPropagators from the supported propagators list. Currently,
// tracecontext and b3 are supported. By default, the value is set to empty list and
// context propagation is disabled.
Expand Down
4 changes: 3 additions & 1 deletion service/telemetry/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/noop"

"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/internal/globalgates"
)

Expand Down Expand Up @@ -48,9 +49,10 @@ func attributes(set Settings, cfg Config) map[string]interface{} {

// New creates a new Telemetry from Config.
func newTracerProvider(ctx context.Context, set Settings, cfg Config) (trace.TracerProvider, error) {
if globalgates.NoopTracerProvider.IsEnabled() {
if globalgates.NoopTracerProvider.IsEnabled() || cfg.Traces.Level == configtelemetry.LevelNone {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be documented somewhere that level:none breaks zpage?

Copy link
Contributor Author

@codeboten codeboten Aug 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add a note in the zpages documentation, note that the zpages extension already logs a warning if this happens

return noop.NewTracerProvider(), nil
}

sch := semconv.SchemaURL
res := config.Resource{
SchemaUrl: &sch,
Expand Down
27 changes: 19 additions & 8 deletions service/telemetry/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"go.opentelemetry.io/otel/trace/noop"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/internal/globalgates"
"go.opentelemetry.io/collector/service/telemetry/internal"
Expand Down Expand Up @@ -65,11 +66,22 @@ func TestNewTracerProvider(t *testing.T) {
tests := []struct {
name string
wantTracerProvider any
noopTracer bool
noopTracerGate bool
cfg Config
}{
{
name: "noop tracer provider",
noopTracer: true,
name: "trace level none",
cfg: Config{
Traces: TracesConfig{
Level: configtelemetry.LevelNone,
},
},
wantTracerProvider: noop.TracerProvider{},
},
{
name: "noop tracer feature gate",
cfg: Config{},
noopTracerGate: true,
wantTracerProvider: noop.TracerProvider{},
},
{
Expand All @@ -80,13 +92,12 @@ func TestNewTracerProvider(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
previousValue := globalgates.NoopTracerProvider.IsEnabled()
err := featuregate.GlobalRegistry().Set(globalgates.NoopTracerProvider.ID(), tt.noopTracer)
require.NoError(t, err)
// expect error due to deprecated flag
require.NoError(t, featuregate.GlobalRegistry().Set(globalgates.NoopTracerProvider.ID(), tt.noopTracerGate))
defer func() {
err = featuregate.GlobalRegistry().Set(globalgates.NoopTracerProvider.ID(), previousValue)
require.NoError(t, err)
require.NoError(t, featuregate.GlobalRegistry().Set(globalgates.NoopTracerProvider.ID(), previousValue))
}()
provider, err := newTracerProvider(context.TODO(), internal.Settings{}, Config{})
provider, err := newTracerProvider(context.TODO(), internal.Settings{}, tt.cfg)
require.NoError(t, err)
require.IsType(t, tt.wantTracerProvider, provider)
})
Expand Down
Loading