Skip to content

Commit

Permalink
Distributed internal metrics across different levels
Browse files Browse the repository at this point in the history
The internal metrics levels are updated along with reported metrics:
    - The default level is changed from `basic` to `normal`, which can be overridden with `service::telmetry::metrics::level` configuration.
    - Batch processor metrics are updated to be reported starting from `normal` level:
      - `processor_batch_batch_send_size`
      - `processor_batch_metadata_cardinality`
      - `processor_batch_timeout_trigger_send`
      - `processor_batch_size_trigger_send`
    - GRPC/HTTP server and client metrics are updated to be reported starting from `detailed` level:
      - http.client.* metrics
      - http.server.* metrics
      - rpc.server.* metrics
      - rpc.client.* metrics
  • Loading branch information
dmitryax committed Apr 16, 2024
1 parent e8cabb7 commit ee3f4bc
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 19 deletions.
37 changes: 37 additions & 0 deletions .chloggen/update-internal-metric-levels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Distributed internal metrics across different levels.

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

# (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: |
The internal metrics levels are updated along with reported metrics:
- The default level is changed from `basic` to `normal`, which can be overridden with `service::telmetry::metrics::level` configuration.
- Batch processor metrics are updated to be reported starting from `normal` level:
- `processor_batch_batch_send_size`
- `processor_batch_metadata_cardinality`
- `processor_batch_timeout_trigger_send`
- `processor_batch_size_trigger_send`
- GRPC/HTTP server and client metrics are updated to be reported starting from `detailed` level:
- http.client.* metrics
- http.server.* metrics
- rpc.server.* metrics
- rpc.client.* metrics
# 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: [user]
9 changes: 7 additions & 2 deletions config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"go.opentelemetry.io/collector/config/configcompression"
"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/config/internal"
"go.opentelemetry.io/collector/extension/auth"
Expand Down Expand Up @@ -253,9 +254,11 @@ func (gcs *ClientConfig) toDialOptions(host component.Host, settings component.T

otelOpts := []otelgrpc.Option{
otelgrpc.WithTracerProvider(settings.TracerProvider),
otelgrpc.WithMeterProvider(settings.MeterProvider),
otelgrpc.WithPropagators(otel.GetTextMapPropagator()),
}
if settings.MetricsLevel >= configtelemetry.LevelDetailed {
otelOpts = append(otelOpts, otelgrpc.WithMeterProvider(settings.MeterProvider))

Check warning on line 260 in config/configgrpc/configgrpc.go

View check run for this annotation

Codecov / codecov/patch

config/configgrpc/configgrpc.go#L260

Added line #L260 was not covered by tests
}

// Enable OpenTelemetry observability plugin.
opts = append(opts, grpc.WithStatsHandler(otelgrpc.NewClientHandler(otelOpts...)))
Expand Down Expand Up @@ -356,9 +359,11 @@ func (gss *ServerConfig) toServerOption(host component.Host, settings component.

otelOpts := []otelgrpc.Option{
otelgrpc.WithTracerProvider(settings.TracerProvider),
otelgrpc.WithMeterProvider(settings.MeterProvider),
otelgrpc.WithPropagators(otel.GetTextMapPropagator()),
}
if settings.MetricsLevel >= configtelemetry.LevelDetailed {
otelOpts = append(otelOpts, otelgrpc.WithMeterProvider(settings.MeterProvider))

Check warning on line 365 in config/configgrpc/configgrpc.go

View check run for this annotation

Codecov / codecov/patch

config/configgrpc/configgrpc.go#L365

Added line #L365 was not covered by tests
}

// Enable OpenTelemetry observability plugin.

Expand Down
2 changes: 1 addition & 1 deletion config/configgrpc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
go.opentelemetry.io/collector/config/configcompression v1.5.0
go.opentelemetry.io/collector/config/confignet v0.98.0
go.opentelemetry.io/collector/config/configopaque v1.5.0
go.opentelemetry.io/collector/config/configtelemetry v0.98.0
go.opentelemetry.io/collector/config/configtls v0.98.0
go.opentelemetry.io/collector/config/internal v0.98.0
go.opentelemetry.io/collector/extension/auth v0.98.0
Expand Down Expand Up @@ -48,7 +49,6 @@ require (
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.52.3 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.98.0 // indirect
go.opentelemetry.io/collector/confmap v0.98.0 // indirect
go.opentelemetry.io/collector/extension v0.98.0 // indirect
go.opentelemetry.io/collector/featuregate v1.5.0 // indirect
Expand Down
32 changes: 19 additions & 13 deletions config/confighttp/confighttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"go.opentelemetry.io/collector/config/configauth"
"go.opentelemetry.io/collector/config/configcompression"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/config/internal"
"go.opentelemetry.io/collector/extension/auth"
Expand Down Expand Up @@ -206,14 +207,17 @@ func (hcs *ClientConfig) ToClient(ctx context.Context, host component.Host, sett
}
}

otelOpts := []otelhttp.Option{
otelhttp.WithTracerProvider(settings.TracerProvider),
otelhttp.WithPropagators(otel.GetTextMapPropagator()),
}
if settings.MetricsLevel >= configtelemetry.LevelDetailed {
otelOpts = append(otelOpts, otelhttp.WithMeterProvider(settings.MeterProvider))

Check warning on line 215 in config/confighttp/confighttp.go

View check run for this annotation

Codecov / codecov/patch

config/confighttp/confighttp.go#L215

Added line #L215 was not covered by tests
}

// wrapping http transport with otelhttp transport to enable otel instrumentation
if settings.TracerProvider != nil && settings.MeterProvider != nil {
clientTransport = otelhttp.NewTransport(
clientTransport,
otelhttp.WithTracerProvider(settings.TracerProvider),
otelhttp.WithMeterProvider(settings.MeterProvider),
otelhttp.WithPropagators(otel.GetTextMapPropagator()),
)
clientTransport = otelhttp.NewTransport(clientTransport, otelOpts...)
}

if hcs.CustomRoundTripper != nil {
Expand Down Expand Up @@ -383,18 +387,20 @@ func (hss *ServerConfig) ToServer(_ context.Context, host component.Host, settin
handler = responseHeadersHandler(handler, hss.ResponseHeaders)
}

// Enable OpenTelemetry observability plugin.
// TODO: Consider to use component ID string as prefix for all the operations.
handler = otelhttp.NewHandler(
handler,
"",
otelOpts := []otelhttp.Option{
otelhttp.WithTracerProvider(settings.TracerProvider),
otelhttp.WithMeterProvider(settings.MeterProvider),
otelhttp.WithPropagators(otel.GetTextMapPropagator()),
otelhttp.WithSpanNameFormatter(func(_ string, r *http.Request) string {
return r.URL.Path
}),
)
}
if settings.MetricsLevel >= configtelemetry.LevelDetailed {
otelOpts = append(otelOpts, otelhttp.WithMeterProvider(settings.MeterProvider))

Check warning on line 398 in config/confighttp/confighttp.go

View check run for this annotation

Codecov / codecov/patch

config/confighttp/confighttp.go#L398

Added line #L398 was not covered by tests
}

// Enable OpenTelemetry observability plugin.
// TODO: Consider to use component ID string as prefix for all the operations.
handler = otelhttp.NewHandler(handler, "", otelOpts...)

// wrap the current handler in an interceptor that will add client.Info to the request's context
handler = &clientInfoHandler{
Expand Down
2 changes: 1 addition & 1 deletion otelcol/unmarshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func unmarshal(v *confmap.Conf, factories Factories) (*configSettings, error) {
InitialFields: map[string]any(nil),
},
Metrics: telemetry.MetricsConfig{
Level: configtelemetry.LevelBasic,
Level: configtelemetry.LevelNormal,
Address: ":8888",
},
},
Expand Down
14 changes: 12 additions & 2 deletions processor/batchprocessor/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
noopmetric "go.opentelemetry.io/otel/metric/noop"
"go.uber.org/multierr"

"go.opentelemetry.io/collector/component"
Expand Down Expand Up @@ -56,8 +57,17 @@ func newBatchProcessorTelemetry(set processor.CreateSettings, currentMetadataCar
}

func (bpt *batchProcessorTelemetry) createOtelMetrics(set component.TelemetrySettings, currentMetadataCardinality func() int) error {
var errors, err error
meter := metadata.Meter(set)
var (
errors, err error
meter metric.Meter
)

// BatchProcessor are emitted starting from Normal level only.
if bpt.level >= configtelemetry.LevelNormal {
meter = metadata.Meter(set)
} else {
meter = noopmetric.Meter{}
}

bpt.batchSizeTriggerSend, err = meter.Int64Counter(
processorhelper.BuildCustomMetricName(typeStr, "batch_size_trigger_send"),
Expand Down

0 comments on commit ee3f4bc

Please sign in to comment.