Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
27 changes: 27 additions & 0 deletions .chloggen/service-deprecate-featuregate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

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

# 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: The `telemetry.disableHighCardinalityMetrics` feature gate is deprecated

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

# (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 feature gate is now deprecated since metric views can be configured.
The gate will be removed in v1.40.0.
Copy link
Contributor

@jade-guiton-dd jade-guiton-dd Jul 31, 2025

Choose a reason for hiding this comment

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

So I'm having second thoughts about whether it's a good idea to deprecate this now. Yes, users can now configure metric views that do the same thing as the gate (and at the very least, we'll want to document how).

But because metric views are incompatible with level != detailed, users that were previously using the gate will also have to reproduce all the default level-based views set up in service.go. There was a proposal at one point for a Collector subcommand that lists the metric views for a given level to make this easier, but it hasn't been implemented. So that's a bit of a painful migration path, especially since I suspect users of the feature gate can't easily do without it (it would increase the cardinality of their metrics by a lot).

# 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]
56 changes: 8 additions & 48 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"go.opentelemetry.io/otel/metric"
noopmetric "go.opentelemetry.io/otel/metric/noop"
sdkresource "go.opentelemetry.io/otel/sdk/resource"
semconv118 "go.opentelemetry.io/otel/semconv/v1.18.0"
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
nooptrace "go.opentelemetry.io/otel/trace/noop"
"go.uber.org/multierr"
Expand Down Expand Up @@ -45,13 +44,14 @@ import (
"go.opentelemetry.io/collector/service/telemetry"
)

// disableHighCardinalityMetricsFeatureGate is the feature gate that controls whether the collector should enable
// potentially high cardinality metrics. The gate will be removed when the collector allows for view configuration.
var disableHighCardinalityMetricsFeatureGate = featuregate.GlobalRegistry().MustRegister(
// This feature gate is deprecated and will be removed in 1.40.0. Views can now be configured.
var _ = featuregate.GlobalRegistry().MustRegister(
"telemetry.disableHighCardinalityMetrics",
featuregate.StageAlpha,
featuregate.WithRegisterDescription("controls whether the collector should enable potentially high"+
"cardinality metrics. The gate will be removed when the collector allows for view configuration."))
featuregate.StageDeprecated,
featuregate.WithRegisterToVersion("1.39.0"),
featuregate.WithRegisterDescription(
"Controls whether the collector should enable potentially high "+
"cardinality metrics. Deprecated, configure service::telemetry::metrics::views instead."))

// ModuleInfo describes the Go module for a particular component.
type ModuleInfo = moduleinfo.ModuleInfo
Expand Down Expand Up @@ -134,12 +134,7 @@ func New(ctx context.Context, set Settings, cfg Config) (*Service, error) {
sch := semconv.SchemaURL

mpConfig := &cfg.Telemetry.Metrics.MeterProvider

if mpConfig.Views != nil {
if disableHighCardinalityMetricsFeatureGate.IsEnabled() {
return nil, errors.New("telemetry.disableHighCardinalityMetrics gate is incompatible with service::telemetry::metrics::views")
}
} else {
if mpConfig.Views == nil {
mpConfig.Views = configureViews(cfg.Telemetry.Metrics.Level)
}

Expand Down Expand Up @@ -433,41 +428,6 @@ func configureViews(level configtelemetry.Level) []config.View {
)
}

// Make sure to add the AttributeKeys view after the AggregationDrop view:
// Only the first view outputting a given metric identity is actually used, so placing the
// AttributeKeys view first would never drop the metrics regadless of level.
if disableHighCardinalityMetricsFeatureGate.IsEnabled() {
views = append(views, []config.View{
{
Selector: &config.ViewSelector{
MeterName: ptr("go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"),
},
Stream: &config.ViewStream{
AttributeKeys: &config.IncludeExclude{
Excluded: []string{
string(semconv118.NetSockPeerAddrKey),
string(semconv118.NetSockPeerPortKey),
string(semconv118.NetSockPeerNameKey),
},
},
},
},
{
Selector: &config.ViewSelector{
MeterName: ptr("go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"),
},
Stream: &config.ViewStream{
AttributeKeys: &config.IncludeExclude{
Excluded: []string{
string(semconv118.NetHostNameKey),
string(semconv118.NetHostPortKey),
},
},
},
},
}...)
}

// otel-arrow library metrics
// See https://github.com/open-telemetry/otel-arrow/blob/c39257/pkg/otel/arrow_record/consumer.go#L174-L176
if level < configtelemetry.LevelNormal {
Expand Down
16 changes: 5 additions & 11 deletions service/telemetry/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
config "go.opentelemetry.io/contrib/otelconf/v0.3.0"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
semconv "go.opentelemetry.io/otel/semconv/v1.18.0"
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"

"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/service/internal/promtest"
Expand Down Expand Up @@ -57,9 +57,7 @@ func TestTelemetryInit(t *testing.T) {
metricPrefix + grpcPrefix + counterName: {
value: 11,
labels: map[string]string{
"net_sock_peer_addr": "",
"net_sock_peer_name": "",
"net_sock_peer_port": "",
"rpc_system": "grpc",
"service_name": "otelcol",
"service_version": "latest",
"service_instance_id": testInstanceID,
Expand All @@ -68,8 +66,7 @@ func TestTelemetryInit(t *testing.T) {
metricPrefix + httpPrefix + counterName: {
value: 10,
labels: map[string]string{
"net_host_name": "",
"net_host_port": "",
"http_request_method": "GET",
"service_name": "otelcol",
"service_version": "latest",
"service_instance_id": testInstanceID,
Expand Down Expand Up @@ -167,16 +164,13 @@ func createTestMetrics(t *testing.T, mp metric.MeterProvider) {
grpcExampleCounter, err := mp.Meter("go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc").Int64Counter(metricPrefix + grpcPrefix + counterName)
require.NoError(t, err)
grpcExampleCounter.Add(context.Background(), 11, metric.WithAttributeSet(attribute.NewSet(
attribute.String(string(semconv.NetSockPeerAddrKey), ""),
attribute.String(string(semconv.NetSockPeerPortKey), ""),
attribute.String(string(semconv.NetSockPeerNameKey), ""),
attribute.String(string(semconv.RPCSystemKey), "grpc"),
)))

httpExampleCounter, err := mp.Meter("go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp").Int64Counter(metricPrefix + httpPrefix + counterName)
require.NoError(t, err)
httpExampleCounter.Add(context.Background(), 10, metric.WithAttributeSet(attribute.NewSet(
attribute.String(string(semconv.NetHostNameKey), ""),
attribute.String(string(semconv.NetHostPortKey), ""),
attribute.String(string(semconv.HTTPRequestMethodKey), "GET"),
)))
}

Expand Down
Loading