From 3c2d109771e8fde68fd25e977dbfc3cc38bdee96 Mon Sep 17 00:00:00 2001 From: Murphy Chen Date: Thu, 18 Sep 2025 15:24:54 +0800 Subject: [PATCH 1/9] Change default duration metrics unit from `ms` to `s` --- .chloggen/fix-42462.yaml | 30 +++++++++++++++++++ connector/spanmetricsconnector/README.md | 2 +- connector/spanmetricsconnector/config_test.go | 2 +- connector/spanmetricsconnector/connector.go | 2 +- .../spanmetricsconnector/connector_test.go | 14 ++++----- connector/spanmetricsconnector/factory.go | 8 ++--- .../spanmetricsconnector/factory_test.go | 4 +++ 7 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 .chloggen/fix-42462.yaml diff --git a/.chloggen/fix-42462.yaml b/.chloggen/fix-42462.yaml new file mode 100644 index 0000000000000..4cbc96a5ba30a --- /dev/null +++ b/.chloggen/fix-42462.yaml @@ -0,0 +1,30 @@ +# 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. filelogreceiver) +component: spanmetricsconnector + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Change default duration metrics unit from `ms` to `s` + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [42462] + +# (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 change will result in a breaking change: + - There is no breaking change if the user has manually set the `unit` configuration. + - A breaking change will occur if the user relies on the default `unit` setting; in this case, please manually revert it to the desired `unit`. + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# 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] diff --git a/connector/spanmetricsconnector/README.md b/connector/spanmetricsconnector/README.md index 32cb665db33dd..9fa20809ba393 100644 --- a/connector/spanmetricsconnector/README.md +++ b/connector/spanmetricsconnector/README.md @@ -96,7 +96,7 @@ The following settings can be optionally configured: - `histogram` (default: `explicit`): Use to configure the type of histogram to record calculated from spans duration measurements. Must be either `explicit` or `exponential`. - `disable` (default: `false`): Disable all histogram metrics. - - `unit` (default: `ms`): The time unit for recording duration measurements. + - `unit` (default: `s`): The time unit for recording duration measurements. calculated from spans duration measurements. One of either: `ms` or `s`. - `dimensions`: additional attributes to add as dimensions to the `traces.span.metrics.duration` metric, which will be included _on top of_ the common and configured `dimensions` for span attributes and resource attributes. diff --git a/connector/spanmetricsconnector/config_test.go b/connector/spanmetricsconnector/config_test.go index e1e5ae164cbb6..557ca8ee4b0b1 100644 --- a/connector/spanmetricsconnector/config_test.go +++ b/connector/spanmetricsconnector/config_test.go @@ -87,7 +87,7 @@ func TestLoadConfig(t *testing.T) { MaxPerDataPoint: defaultMaxPerDatapoint, }, Histogram: HistogramConfig{ - Unit: metrics.Milliseconds, + Unit: metrics.Seconds, Exponential: configoptional.Some(ExponentialHistogramConfig{ MaxSize: 10, }), diff --git a/connector/spanmetricsconnector/connector.go b/connector/spanmetricsconnector/connector.go index 26ecc414e2b68..0f6fa6ef564ab 100644 --- a/connector/spanmetricsconnector/connector.go +++ b/connector/spanmetricsconnector/connector.go @@ -43,7 +43,7 @@ const ( metricNameCalls = "calls" metricNameEvents = "events" - defaultUnit = metrics.Milliseconds + defaultUnit = metrics.Seconds // https://github.com/open-telemetry/opentelemetry-go/blob/3ae002c3caf3e44387f0554dfcbbde2c5aab7909/sdk/metric/internal/aggregate/limit.go#L11C36-L11C50 overflowKey = "otel.metric.overflow" diff --git a/connector/spanmetricsconnector/connector_test.go b/connector/spanmetricsconnector/connector_test.go index 325b50090fe94..9aff73a5bf698 100644 --- a/connector/spanmetricsconnector/connector_test.go +++ b/connector/spanmetricsconnector/connector_test.go @@ -50,7 +50,7 @@ const ( resourceMetricsCacheSize = 5 sampleRegion = "us-east-1" - sampleDuration = float64(11) + sampleDuration = 11 * time.Millisecond instanceID = "0044953a-2946-449f-a5c8-2971f2a63928" ) @@ -231,7 +231,7 @@ func verifyExplicitHistogramDataPoints(tb testing.TB, dps pmetric.HistogramDataP dp := dps.At(dpi) assert.Equal( tb, - sampleDuration*float64(numCumulativeConsumptions), + sampleDuration.Seconds()*float64(numCumulativeConsumptions), dp.Sum(), "Should be a 11ms duration measurement, multiplied by the number of stateful accumulations.") assert.NotZero(tb, dp.Timestamp(), "Timestamp should be set") @@ -245,7 +245,7 @@ func verifyExplicitHistogramDataPoints(tb testing.TB, dps pmetric.HistogramDataP // Find the bucket index where the 11ms duration should belong in. var foundDurationIndex int for foundDurationIndex = 0; foundDurationIndex < dp.ExplicitBounds().Len(); foundDurationIndex++ { - if dp.ExplicitBounds().At(foundDurationIndex) > sampleDuration { + if dp.ExplicitBounds().At(foundDurationIndex) > sampleDuration.Seconds() { break } } @@ -270,7 +270,7 @@ func verifyExponentialHistogramDataPoints(tb testing.TB, dps pmetric.Exponential dp := dps.At(dpi) assert.Equal( tb, - sampleDuration*float64(numCumulativeConsumptions), + sampleDuration.Seconds()*float64(numCumulativeConsumptions), dp.Sum(), "Should be a 11ms duration measurement, multiplied by the number of stateful accumulations.") assert.Equal(tb, uint64(numCumulativeConsumptions), dp.Count()) @@ -325,7 +325,7 @@ func buildBadSampleTrace() ptrace.Traces { // Flipping timestamp for a bad duration span.SetEndTimestamp(pcommon.NewTimestampFromTime(now)) span.SetStartTimestamp( - pcommon.NewTimestampFromTime(now.Add(time.Duration(sampleDuration) * time.Millisecond))) + pcommon.NewTimestampFromTime(now.Add(sampleDuration))) return badTrace } @@ -394,7 +394,7 @@ func initSpan(span span, s ptrace.Span) { now := time.Now() s.SetStartTimestamp(pcommon.NewTimestampFromTime(now)) s.SetEndTimestamp( - pcommon.NewTimestampFromTime(now.Add(time.Duration(sampleDuration) * time.Millisecond))) + pcommon.NewTimestampFromTime(now.Add(sampleDuration))) s.Attributes().PutStr(stringAttrName, "stringAttrValue") s.Attributes().PutInt(intAttrName, 99) @@ -1371,7 +1371,7 @@ func TestConnector_durationsToUnits(t *testing.T) { 3 * time.Second, }, unit: defaultUnit, - want: []float64{0.000003, 0.003, 3, 3000}, + want: []float64{3e-09, 3e-06, 0.003, 3}, }, { input: []time.Duration{ diff --git a/connector/spanmetricsconnector/factory.go b/connector/spanmetricsconnector/factory.go index 6dea8ab1ef626..456e34586db9a 100644 --- a/connector/spanmetricsconnector/factory.go +++ b/connector/spanmetricsconnector/factory.go @@ -21,9 +21,9 @@ import ( ) const ( - DefaultNamespace = "traces.span.metrics" - legacyMetricNamesFeatureGateID = "connector.spanmetrics.legacyMetricNames" - includeCollectorInstanceIDGateID = "connector.spanmetrics.includeCollectorInstanceID" + DefaultNamespace = "traces.span.metrics" + legacyMetricNamesFeatureGateID = "connector.spanmetrics.legacyMetricNames" + includeCollectorInstanceIDFeatureGateID = "connector.spanmetrics.includeCollectorInstanceID" ) var ( @@ -40,7 +40,7 @@ func init() { featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33227"), ) includeCollectorInstanceID = featuregate.GlobalRegistry().MustRegister( - includeCollectorInstanceIDGateID, + includeCollectorInstanceIDFeatureGateID, featuregate.StageAlpha, featuregate.WithRegisterDescription("When enabled, connector add collector.instance.id to default dimensions."), featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/40400"), diff --git a/connector/spanmetricsconnector/factory_test.go b/connector/spanmetricsconnector/factory_test.go index 845e847a9347d..594921ffbf2ff 100644 --- a/connector/spanmetricsconnector/factory_test.go +++ b/connector/spanmetricsconnector/factory_test.go @@ -68,3 +68,7 @@ func TestNewConnector(t *testing.T) { }) } } + +func TestCreateDefaultConfig(t *testing.T) { + +} From 2b5bf68cd0f278f4d061dd3e467f8add98227037 Mon Sep 17 00:00:00 2001 From: Murphy Chen Date: Fri, 19 Sep 2025 14:17:31 +0800 Subject: [PATCH 2/9] update --- .chloggen/fix-42462.yaml | 11 ++++++--- connector/spanmetricsconnector/README.md | 2 +- connector/spanmetricsconnector/config_test.go | 4 ++++ connector/spanmetricsconnector/factory.go | 23 +++++++++++++++---- .../spanmetricsconnector/factory_test.go | 4 ---- 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/.chloggen/fix-42462.yaml b/.chloggen/fix-42462.yaml index 4cbc96a5ba30a..6c6397daf5a24 100644 --- a/.chloggen/fix-42462.yaml +++ b/.chloggen/fix-42462.yaml @@ -16,9 +16,14 @@ issues: [42462] # These lines will be padded with 2 spaces and then inserted directly into the document. # Use pipe (|) for multiline entries. subtext: | - This change will result in a breaking change: - - There is no breaking change if the user has manually set the `unit` configuration. - - A breaking change will occur if the user relies on the default `unit` setting; in this case, please manually revert it to the desired `unit`. + This change introduces a breaking change, which is now guarded by the feature gate `connector.spanmetrics.legacyDefaultMetricsUnit`. + Currently, the feature gate is enabled by default, so the unit will remain `ms`. After one or two release cycles, the unit will switch to `s` and the feature gate will also be disabled by default. + To revert this change manually, users can either enable the feature gate or modify the configuration as follows: + ``` + spanmetrics: + histogram: + unit: "ms" + ``` # If your change doesn't affect end users or the exported elements of any package, # you should instead start your pull request title with [chore] or use the "Skip Changelog" label. diff --git a/connector/spanmetricsconnector/README.md b/connector/spanmetricsconnector/README.md index 9fa20809ba393..016a648b0c5c7 100644 --- a/connector/spanmetricsconnector/README.md +++ b/connector/spanmetricsconnector/README.md @@ -96,7 +96,7 @@ The following settings can be optionally configured: - `histogram` (default: `explicit`): Use to configure the type of histogram to record calculated from spans duration measurements. Must be either `explicit` or `exponential`. - `disable` (default: `false`): Disable all histogram metrics. - - `unit` (default: `s`): The time unit for recording duration measurements. + - `unit` (default: `ms`, it will change to `s` in the featurn release, you can enable feature-gate `connector.spanmetrics.legacyDefaultMetricsUnit` to keep use `ms` unit): The time unit for recording duration measurements. calculated from spans duration measurements. One of either: `ms` or `s`. - `dimensions`: additional attributes to add as dimensions to the `traces.span.metrics.duration` metric, which will be included _on top of_ the common and configured `dimensions` for span attributes and resource attributes. diff --git a/connector/spanmetricsconnector/config_test.go b/connector/spanmetricsconnector/config_test.go index 557ca8ee4b0b1..6f20966ee0fc5 100644 --- a/connector/spanmetricsconnector/config_test.go +++ b/connector/spanmetricsconnector/config_test.go @@ -16,6 +16,7 @@ import ( "go.opentelemetry.io/collector/config/configoptional" "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/confmap/xconfmap" + "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/pdata/pmetric" "github.com/open-telemetry/opentelemetry-collector-contrib/connector/spanmetricsconnector/internal/metadata" @@ -25,6 +26,9 @@ import ( func TestLoadConfig(t *testing.T) { t.Parallel() + // disable legacyDefaultMetricsUnit featuregate + require.NoError(t, featuregate.GlobalRegistry().Set(legacyDefaultMetricsUnit.ID(), false)) + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) require.NoError(t, err) diff --git a/connector/spanmetricsconnector/factory.go b/connector/spanmetricsconnector/factory.go index 456e34586db9a..c68941bbd39db 100644 --- a/connector/spanmetricsconnector/factory.go +++ b/connector/spanmetricsconnector/factory.go @@ -18,17 +18,20 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/connector/spanmetricsconnector/internal/metadata" + "github.com/open-telemetry/opentelemetry-collector-contrib/connector/spanmetricsconnector/internal/metrics" ) const ( DefaultNamespace = "traces.span.metrics" legacyMetricNamesFeatureGateID = "connector.spanmetrics.legacyMetricNames" includeCollectorInstanceIDFeatureGateID = "connector.spanmetrics.includeCollectorInstanceID" + legacyDefaultMetricsUnitFeatureGateID = "connector.spanmetrics.legacyDefaultMetricsUnit" ) var ( legacyMetricNamesFeatureGate *featuregate.Gate includeCollectorInstanceID *featuregate.Gate + legacyDefaultMetricsUnit *featuregate.Gate ) func init() { @@ -45,6 +48,12 @@ func init() { featuregate.WithRegisterDescription("When enabled, connector add collector.instance.id to default dimensions."), featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/40400"), ) + legacyDefaultMetricsUnit = featuregate.GlobalRegistry().MustRegister( + legacyDefaultMetricsUnitFeatureGateID, + featuregate.StageBeta, // current enabled by default and disable it in the feature release + featuregate.WithRegisterDescription("enabled by default, connector use ms unit for duration metrics."), + featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/42103"), + ) } // NewFactory creates a factory for the spanmetrics connector. @@ -58,10 +67,16 @@ func NewFactory() connector.Factory { func createDefaultConfig() component.Config { return &Config{ - AggregationTemporality: "AGGREGATION_TEMPORALITY_CUMULATIVE", - ResourceMetricsCacheSize: defaultResourceMetricsCacheSize, - MetricsFlushInterval: 60 * time.Second, - Histogram: HistogramConfig{Disable: false, Unit: defaultUnit}, + AggregationTemporality: "AGGREGATION_TEMPORALITY_CUMULATIVE", + ResourceMetricsCacheSize: defaultResourceMetricsCacheSize, + MetricsFlushInterval: 60 * time.Second, + Histogram: HistogramConfig{Disable: false, Unit: func() metrics.Unit { + if legacyDefaultMetricsUnit.IsEnabled() { + return metrics.Milliseconds + } + + return metrics.Seconds + }()}, Namespace: DefaultNamespace, AggregationCardinalityLimit: 0, Exemplars: ExemplarsConfig{ diff --git a/connector/spanmetricsconnector/factory_test.go b/connector/spanmetricsconnector/factory_test.go index 594921ffbf2ff..845e847a9347d 100644 --- a/connector/spanmetricsconnector/factory_test.go +++ b/connector/spanmetricsconnector/factory_test.go @@ -68,7 +68,3 @@ func TestNewConnector(t *testing.T) { }) } } - -func TestCreateDefaultConfig(t *testing.T) { - -} From ae24de14931983144501d5b97e817a65e91b3157 Mon Sep 17 00:00:00 2001 From: Murphy Chen Date: Mon, 22 Sep 2025 15:25:41 +0800 Subject: [PATCH 3/9] Update connector/spanmetricsconnector/README.md Co-authored-by: Antoine Toulme --- connector/spanmetricsconnector/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/spanmetricsconnector/README.md b/connector/spanmetricsconnector/README.md index 016a648b0c5c7..9a71da501d702 100644 --- a/connector/spanmetricsconnector/README.md +++ b/connector/spanmetricsconnector/README.md @@ -96,7 +96,7 @@ The following settings can be optionally configured: - `histogram` (default: `explicit`): Use to configure the type of histogram to record calculated from spans duration measurements. Must be either `explicit` or `exponential`. - `disable` (default: `false`): Disable all histogram metrics. - - `unit` (default: `ms`, it will change to `s` in the featurn release, you can enable feature-gate `connector.spanmetrics.legacyDefaultMetricsUnit` to keep use `ms` unit): The time unit for recording duration measurements. + - `unit` (default: `ms`, it will change to `s` in the next release, you can enable feature-gate `connector.spanmetrics.legacyDefaultMetricsUnit` to keep use `ms` unit): The time unit for recording duration measurements. calculated from spans duration measurements. One of either: `ms` or `s`. - `dimensions`: additional attributes to add as dimensions to the `traces.span.metrics.duration` metric, which will be included _on top of_ the common and configured `dimensions` for span attributes and resource attributes. From eb7c81af97d54254710b2d5474c2a33af99bab24 Mon Sep 17 00:00:00 2001 From: Murphy Chen Date: Mon, 22 Sep 2025 15:47:41 +0800 Subject: [PATCH 4/9] apply review's suggestion --- .chloggen/fix-42462.yaml | 7 ++++--- connector/spanmetricsconnector/factory.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.chloggen/fix-42462.yaml b/.chloggen/fix-42462.yaml index 6c6397daf5a24..4efeacc712ac0 100644 --- a/.chloggen/fix-42462.yaml +++ b/.chloggen/fix-42462.yaml @@ -20,9 +20,10 @@ subtext: | Currently, the feature gate is enabled by default, so the unit will remain `ms`. After one or two release cycles, the unit will switch to `s` and the feature gate will also be disabled by default. To revert this change manually, users can either enable the feature gate or modify the configuration as follows: ``` - spanmetrics: - histogram: - unit: "ms" + connectors + spanmetrics: + histogram: + unit: "ms" ``` # If your change doesn't affect end users or the exported elements of any package, diff --git a/connector/spanmetricsconnector/factory.go b/connector/spanmetricsconnector/factory.go index c68941bbd39db..ae6ded7827611 100644 --- a/connector/spanmetricsconnector/factory.go +++ b/connector/spanmetricsconnector/factory.go @@ -50,7 +50,7 @@ func init() { ) legacyDefaultMetricsUnit = featuregate.GlobalRegistry().MustRegister( legacyDefaultMetricsUnitFeatureGateID, - featuregate.StageBeta, // current enabled by default and disable it in the feature release + featuregate.StageBeta, // current enabled by default and disable it in the next release featuregate.WithRegisterDescription("enabled by default, connector use ms unit for duration metrics."), featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/42103"), ) From 2b03261dcb23f1be43396bda2cfd59f8f25c0430 Mon Sep 17 00:00:00 2001 From: Murphy Chen Date: Fri, 26 Sep 2025 11:17:33 +0800 Subject: [PATCH 5/9] use alpha stage feature-gate --- .chloggen/fix-42462.yaml | 4 ++-- connector/spanmetricsconnector/README.md | 14 +++++++++++++- connector/spanmetricsconnector/config_test.go | 4 +--- connector/spanmetricsconnector/factory.go | 18 +++++++++--------- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/.chloggen/fix-42462.yaml b/.chloggen/fix-42462.yaml index 4efeacc712ac0..f09671fb670e5 100644 --- a/.chloggen/fix-42462.yaml +++ b/.chloggen/fix-42462.yaml @@ -16,8 +16,8 @@ issues: [42462] # These lines will be padded with 2 spaces and then inserted directly into the document. # Use pipe (|) for multiline entries. subtext: | - This change introduces a breaking change, which is now guarded by the feature gate `connector.spanmetrics.legacyDefaultMetricsUnit`. - Currently, the feature gate is enabled by default, so the unit will remain `ms`. After one or two release cycles, the unit will switch to `s` and the feature gate will also be disabled by default. + This change introduces a breaking change, which is now guarded by the feature gate `connector.spanmetrics.useSCDefaultMetricsUnit`. + Currently, the feature gate is disabled by default, so the unit will remain `ms`. After one release cycle, the unit will switch to `s` and the feature gate will also be enabled by default. To revert this change manually, users can either enable the feature gate or modify the configuration as follows: ``` connectors diff --git a/connector/spanmetricsconnector/README.md b/connector/spanmetricsconnector/README.md index 9a71da501d702..a216d1c26162f 100644 --- a/connector/spanmetricsconnector/README.md +++ b/connector/spanmetricsconnector/README.md @@ -23,6 +23,18 @@ [Stability Level]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#stability-levels +⚠️ Breaking Change Warning: +The default duration metrics unit will change from `ms` to `s` to adhere to the OpenTelemetry semantic conventions and a feature gate `connector.spanmetrics.useSCDefaultMetricsUnit` is also added. + +Currently, the feature gate is disabled by default, so the unit will remain `ms`. After one release cycle, the unit will switch to `s` and the feature gate will also be enabled by default. +To revert this change manually, users can either disabled the feature gate or modify the configuration as follows: + ``` + connectors + spanmetrics: + histogram: + unit: "ms" + ``` + ## Overview Aggregates Request, Error and Duration (R.E.D) OpenTelemetry metrics from span data. @@ -96,7 +108,7 @@ The following settings can be optionally configured: - `histogram` (default: `explicit`): Use to configure the type of histogram to record calculated from spans duration measurements. Must be either `explicit` or `exponential`. - `disable` (default: `false`): Disable all histogram metrics. - - `unit` (default: `ms`, it will change to `s` in the next release, you can enable feature-gate `connector.spanmetrics.legacyDefaultMetricsUnit` to keep use `ms` unit): The time unit for recording duration measurements. + - `unit` (default: `ms`): The time unit for recording duration measurements. calculated from spans duration measurements. One of either: `ms` or `s`. - `dimensions`: additional attributes to add as dimensions to the `traces.span.metrics.duration` metric, which will be included _on top of_ the common and configured `dimensions` for span attributes and resource attributes. diff --git a/connector/spanmetricsconnector/config_test.go b/connector/spanmetricsconnector/config_test.go index 6f20966ee0fc5..c971bf6b91f23 100644 --- a/connector/spanmetricsconnector/config_test.go +++ b/connector/spanmetricsconnector/config_test.go @@ -26,9 +26,7 @@ import ( func TestLoadConfig(t *testing.T) { t.Parallel() - // disable legacyDefaultMetricsUnit featuregate - require.NoError(t, featuregate.GlobalRegistry().Set(legacyDefaultMetricsUnit.ID(), false)) - + require.NoError(t, featuregate.GlobalRegistry().Set(useSCDefaultMetricsUnit.ID(), true)) cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) require.NoError(t, err) diff --git a/connector/spanmetricsconnector/factory.go b/connector/spanmetricsconnector/factory.go index ae6ded7827611..896f852fcf064 100644 --- a/connector/spanmetricsconnector/factory.go +++ b/connector/spanmetricsconnector/factory.go @@ -25,13 +25,13 @@ const ( DefaultNamespace = "traces.span.metrics" legacyMetricNamesFeatureGateID = "connector.spanmetrics.legacyMetricNames" includeCollectorInstanceIDFeatureGateID = "connector.spanmetrics.includeCollectorInstanceID" - legacyDefaultMetricsUnitFeatureGateID = "connector.spanmetrics.legacyDefaultMetricsUnit" + useSCDefaultMetricsUnitFeatureGateID = "connector.spanmetrics.useSCDefaultMetricsUnit" ) var ( legacyMetricNamesFeatureGate *featuregate.Gate includeCollectorInstanceID *featuregate.Gate - legacyDefaultMetricsUnit *featuregate.Gate + useSCDefaultMetricsUnit *featuregate.Gate ) func init() { @@ -48,10 +48,10 @@ func init() { featuregate.WithRegisterDescription("When enabled, connector add collector.instance.id to default dimensions."), featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/40400"), ) - legacyDefaultMetricsUnit = featuregate.GlobalRegistry().MustRegister( - legacyDefaultMetricsUnitFeatureGateID, - featuregate.StageBeta, // current enabled by default and disable it in the next release - featuregate.WithRegisterDescription("enabled by default, connector use ms unit for duration metrics."), + useSCDefaultMetricsUnit = featuregate.GlobalRegistry().MustRegister( + useSCDefaultMetricsUnitFeatureGateID, + featuregate.StageAlpha, + featuregate.WithRegisterDescription("When enabled, connector use second as default unit for duration metrics."), featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/42103"), ) } @@ -71,11 +71,11 @@ func createDefaultConfig() component.Config { ResourceMetricsCacheSize: defaultResourceMetricsCacheSize, MetricsFlushInterval: 60 * time.Second, Histogram: HistogramConfig{Disable: false, Unit: func() metrics.Unit { - if legacyDefaultMetricsUnit.IsEnabled() { - return metrics.Milliseconds + if useSCDefaultMetricsUnit.IsEnabled() { + return metrics.Seconds } - return metrics.Seconds + return metrics.Milliseconds }()}, Namespace: DefaultNamespace, AggregationCardinalityLimit: 0, From ab8d47067c2c8b4c566867b1224018ad20b23804 Mon Sep 17 00:00:00 2001 From: Murphy Chen Date: Fri, 26 Sep 2025 22:08:59 +0800 Subject: [PATCH 6/9] Update .chloggen/fix-42462.yaml Co-authored-by: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> --- .chloggen/fix-42462.yaml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.chloggen/fix-42462.yaml b/.chloggen/fix-42462.yaml index f09671fb670e5..bd90c458ab9b4 100644 --- a/.chloggen/fix-42462.yaml +++ b/.chloggen/fix-42462.yaml @@ -18,13 +18,6 @@ issues: [42462] subtext: | This change introduces a breaking change, which is now guarded by the feature gate `connector.spanmetrics.useSCDefaultMetricsUnit`. Currently, the feature gate is disabled by default, so the unit will remain `ms`. After one release cycle, the unit will switch to `s` and the feature gate will also be enabled by default. - To revert this change manually, users can either enable the feature gate or modify the configuration as follows: - ``` - connectors - spanmetrics: - histogram: - unit: "ms" - ``` # If your change doesn't affect end users or the exported elements of any package, # you should instead start your pull request title with [chore] or use the "Skip Changelog" label. From 98b5a3beeb68a979aaa81a032e73f3a90a460389 Mon Sep 17 00:00:00 2001 From: Murphy Chen Date: Fri, 26 Sep 2025 22:09:54 +0800 Subject: [PATCH 7/9] Update connector/spanmetricsconnector/README.md Co-authored-by: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> --- connector/spanmetricsconnector/README.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/connector/spanmetricsconnector/README.md b/connector/spanmetricsconnector/README.md index a216d1c26162f..7f2a24685ba46 100644 --- a/connector/spanmetricsconnector/README.md +++ b/connector/spanmetricsconnector/README.md @@ -27,13 +27,6 @@ The default duration metrics unit will change from `ms` to `s` to adhere to the OpenTelemetry semantic conventions and a feature gate `connector.spanmetrics.useSCDefaultMetricsUnit` is also added. Currently, the feature gate is disabled by default, so the unit will remain `ms`. After one release cycle, the unit will switch to `s` and the feature gate will also be enabled by default. -To revert this change manually, users can either disabled the feature gate or modify the configuration as follows: - ``` - connectors - spanmetrics: - histogram: - unit: "ms" - ``` ## Overview From 1577202b881fe14c1397c86c227ada793ad97bb6 Mon Sep 17 00:00:00 2001 From: Murphy Chen Date: Fri, 26 Sep 2025 22:13:51 +0800 Subject: [PATCH 8/9] update --- connector/spanmetricsconnector/config_test.go | 2 +- connector/spanmetricsconnector/factory.go | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/connector/spanmetricsconnector/config_test.go b/connector/spanmetricsconnector/config_test.go index c971bf6b91f23..75bc73f323ed6 100644 --- a/connector/spanmetricsconnector/config_test.go +++ b/connector/spanmetricsconnector/config_test.go @@ -26,7 +26,7 @@ import ( func TestLoadConfig(t *testing.T) { t.Parallel() - require.NoError(t, featuregate.GlobalRegistry().Set(useSCDefaultMetricsUnit.ID(), true)) + require.NoError(t, featuregate.GlobalRegistry().Set(useSecondAsDefaultMetricsUnit.ID(), true)) cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) require.NoError(t, err) diff --git a/connector/spanmetricsconnector/factory.go b/connector/spanmetricsconnector/factory.go index 896f852fcf064..f46d68d88e6de 100644 --- a/connector/spanmetricsconnector/factory.go +++ b/connector/spanmetricsconnector/factory.go @@ -22,16 +22,16 @@ import ( ) const ( - DefaultNamespace = "traces.span.metrics" - legacyMetricNamesFeatureGateID = "connector.spanmetrics.legacyMetricNames" - includeCollectorInstanceIDFeatureGateID = "connector.spanmetrics.includeCollectorInstanceID" - useSCDefaultMetricsUnitFeatureGateID = "connector.spanmetrics.useSCDefaultMetricsUnit" + DefaultNamespace = "traces.span.metrics" + legacyMetricNamesFeatureGateID = "connector.spanmetrics.legacyMetricNames" + includeCollectorInstanceIDFeatureGateID = "connector.spanmetrics.includeCollectorInstanceID" + useSecondAsDefaultMetricsUnitFeatureGateID = "connector.spanmetrics.useSecondAsDefaultMetricsUnit" ) var ( - legacyMetricNamesFeatureGate *featuregate.Gate - includeCollectorInstanceID *featuregate.Gate - useSCDefaultMetricsUnit *featuregate.Gate + legacyMetricNamesFeatureGate *featuregate.Gate + includeCollectorInstanceID *featuregate.Gate + useSecondAsDefaultMetricsUnit *featuregate.Gate ) func init() { @@ -48,8 +48,8 @@ func init() { featuregate.WithRegisterDescription("When enabled, connector add collector.instance.id to default dimensions."), featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/40400"), ) - useSCDefaultMetricsUnit = featuregate.GlobalRegistry().MustRegister( - useSCDefaultMetricsUnitFeatureGateID, + useSecondAsDefaultMetricsUnit = featuregate.GlobalRegistry().MustRegister( + useSecondAsDefaultMetricsUnitFeatureGateID, featuregate.StageAlpha, featuregate.WithRegisterDescription("When enabled, connector use second as default unit for duration metrics."), featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/42103"), @@ -71,7 +71,7 @@ func createDefaultConfig() component.Config { ResourceMetricsCacheSize: defaultResourceMetricsCacheSize, MetricsFlushInterval: 60 * time.Second, Histogram: HistogramConfig{Disable: false, Unit: func() metrics.Unit { - if useSCDefaultMetricsUnit.IsEnabled() { + if useSecondAsDefaultMetricsUnit.IsEnabled() { return metrics.Seconds } From cf1f2d18c0aa65a20beb92342ef39b6dc74414fe Mon Sep 17 00:00:00 2001 From: Murphy Chen Date: Sat, 27 Sep 2025 06:36:46 +0800 Subject: [PATCH 9/9] update --- .chloggen/fix-42462.yaml | 2 +- connector/spanmetricsconnector/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.chloggen/fix-42462.yaml b/.chloggen/fix-42462.yaml index bd90c458ab9b4..395a9cd6d8bda 100644 --- a/.chloggen/fix-42462.yaml +++ b/.chloggen/fix-42462.yaml @@ -16,7 +16,7 @@ issues: [42462] # These lines will be padded with 2 spaces and then inserted directly into the document. # Use pipe (|) for multiline entries. subtext: | - This change introduces a breaking change, which is now guarded by the feature gate `connector.spanmetrics.useSCDefaultMetricsUnit`. + This change introduces a breaking change, which is now guarded by the feature gate `connector.spanmetrics.useSecondAsDefaultMetricsUnit`. Currently, the feature gate is disabled by default, so the unit will remain `ms`. After one release cycle, the unit will switch to `s` and the feature gate will also be enabled by default. # If your change doesn't affect end users or the exported elements of any package, diff --git a/connector/spanmetricsconnector/README.md b/connector/spanmetricsconnector/README.md index 7f2a24685ba46..2da51fcbf12e8 100644 --- a/connector/spanmetricsconnector/README.md +++ b/connector/spanmetricsconnector/README.md @@ -24,7 +24,7 @@ ⚠️ Breaking Change Warning: -The default duration metrics unit will change from `ms` to `s` to adhere to the OpenTelemetry semantic conventions and a feature gate `connector.spanmetrics.useSCDefaultMetricsUnit` is also added. +The default duration metrics unit will change from `ms` to `s` to adhere to the OpenTelemetry semantic conventions and a feature gate `connector.spanmetrics.useSecondAsDefaultMetricsUnit` is also added. Currently, the feature gate is disabled by default, so the unit will remain `ms`. After one release cycle, the unit will switch to `s` and the feature gate will also be enabled by default.