diff --git a/internal/cmd/pdatagen/internal/pdata/one_of_field.go b/internal/cmd/pdatagen/internal/pdata/one_of_field.go index f97bcf5bc22..b37dd4381cd 100644 --- a/internal/cmd/pdatagen/internal/pdata/one_of_field.go +++ b/internal/cmd/pdatagen/internal/pdata/one_of_field.go @@ -11,7 +11,7 @@ import ( ) const oneOfAccessorTemplate = `// {{ .typeFuncName }} returns the type of the {{ .lowerOriginFieldName }} for this {{ .structName }}. -// Calling this function on zero-initialized {{ .structName }} will cause a panic. +// Calling this function on zero-initialized {{ .structName }} is invalid and will cause a panic. func (ms {{ .structName }}) {{ .typeFuncName }}() {{ .typeName }} { switch ms.{{ .origAccessor }}.{{ .originFieldName }}.(type) { {{- range .values }} diff --git a/internal/cmd/pdatagen/internal/pdata/one_of_message_value.go b/internal/cmd/pdatagen/internal/pdata/one_of_message_value.go index d015703c05b..c0efded19f9 100644 --- a/internal/cmd/pdatagen/internal/pdata/one_of_message_value.go +++ b/internal/cmd/pdatagen/internal/pdata/one_of_message_value.go @@ -15,7 +15,7 @@ const oneOfMessageAccessorsTemplate = `// {{ .fieldName }} returns the {{ .lower // Calling this function when {{ .originOneOfTypeFuncName }}() != {{ .typeName }} returns an invalid // zero-initialized instance of {{ .returnType }}. Note that using such {{ .returnType }} instance can cause panic. // -// Calling this function on zero-initialized {{ .structName }} will cause a panic. +// Calling this function on zero-initialized {{ .structName }} is invalid and will cause a panic. func (ms {{ .structName }}) {{ .fieldName }}() {{ .returnType }} { v, ok := ms.orig.Get{{ .originOneOfFieldName }}().(*internal.{{ .originStructType }}) if !ok { @@ -28,7 +28,7 @@ func (ms {{ .structName }}) {{ .fieldName }}() {{ .returnType }} { // // After this, {{ .originOneOfTypeFuncName }}() function will return {{ .typeName }}". // -// Calling this function on zero-initialized {{ .structName }} will cause a panic. +// Calling this function on zero-initialized {{ .structName }} is invalid and will cause a panic. func (ms {{ .structName }}) SetEmpty{{ .fieldName }}() {{ .returnType }} { ms.state.AssertMutable() var ov *internal.{{ .originStructType }} diff --git a/pdata/pcommon/value.go b/pdata/pcommon/value.go index 3c39e704ed9..729b2b898c3 100644 --- a/pdata/pcommon/value.go +++ b/pdata/pcommon/value.go @@ -148,7 +148,7 @@ func (v Value) getState() *internal.State { } // FromRaw sets the value from the given raw value. -// Calling this function on zero-initialized Value will cause a panic. +// Calling this function on zero-initialized Value is invalid and will cause a panic. func (v Value) FromRaw(iv any) error { switch tv := iv.(type) { case nil: @@ -194,7 +194,7 @@ func (v Value) FromRaw(iv any) error { } // Type returns the type of the value for this Value. -// Calling this function on zero-initialized Value will cause a panic. +// Calling this function on zero-initialized Value is invalid and will cause a panic. func (v Value) Type() ValueType { switch v.getOrig().Value.(type) { case *internal.AnyValue_StringValue: @@ -277,7 +277,7 @@ func (v Value) Bytes() ByteSlice { // it also changes the type to be ValueTypeStr. // The shorter name is used instead of SetString to avoid implementing // fmt.Stringer interface by the corresponding getter method. -// Calling this function on zero-initialized Value will cause a panic. +// Calling this function on zero-initialized Value is invalid and will cause a panic. func (v Value) SetStr(sv string) { v.getState().AssertMutable() // Delete everything but the AnyValue object itself. @@ -289,7 +289,7 @@ func (v Value) SetStr(sv string) { // SetInt replaces the int64 value associated with this Value, // it also changes the type to be ValueTypeInt. -// Calling this function on zero-initialized Value will cause a panic. +// Calling this function on zero-initialized Value is invalid and will cause a panic. func (v Value) SetInt(iv int64) { v.getState().AssertMutable() // Delete everything but the AnyValue object itself. @@ -301,7 +301,7 @@ func (v Value) SetInt(iv int64) { // SetDouble replaces the float64 value associated with this Value, // it also changes the type to be ValueTypeDouble. -// Calling this function on zero-initialized Value will cause a panic. +// Calling this function on zero-initialized Value is invalid and will cause a panic. func (v Value) SetDouble(dv float64) { v.getState().AssertMutable() // Delete everything but the AnyValue object itself. @@ -313,7 +313,7 @@ func (v Value) SetDouble(dv float64) { // SetBool replaces the bool value associated with this Value, // it also changes the type to be ValueTypeBool. -// Calling this function on zero-initialized Value will cause a panic. +// Calling this function on zero-initialized Value is invalid and will cause a panic. func (v Value) SetBool(bv bool) { v.getState().AssertMutable() // Delete everything but the AnyValue object itself. @@ -324,7 +324,7 @@ func (v Value) SetBool(bv bool) { } // SetEmptyBytes sets value to an empty byte slice and returns it. -// Calling this function on zero-initialized Value will cause a panic. +// Calling this function on zero-initialized Value is invalid and will cause a panic. func (v Value) SetEmptyBytes() ByteSlice { v.getState().AssertMutable() // Delete everything but the AnyValue object itself. @@ -335,7 +335,7 @@ func (v Value) SetEmptyBytes() ByteSlice { } // SetEmptyMap sets value to an empty map and returns it. -// Calling this function on zero-initialized Value will cause a panic. +// Calling this function on zero-initialized Value is invalid and will cause a panic. func (v Value) SetEmptyMap() Map { v.getState().AssertMutable() // Delete everything but the AnyValue object itself. @@ -347,7 +347,7 @@ func (v Value) SetEmptyMap() Map { } // SetEmptySlice sets value to an empty slice and returns it. -// Calling this function on zero-initialized Value will cause a panic. +// Calling this function on zero-initialized Value is invalid and will cause a panic. func (v Value) SetEmptySlice() Slice { v.getState().AssertMutable() // Delete everything but the AnyValue object itself. @@ -360,7 +360,7 @@ func (v Value) SetEmptySlice() Slice { // MoveTo moves the Value from current overriding the destination and // resetting the current instance to empty value. -// Calling this function on zero-initialized Value will cause a panic. +// Calling this function on zero-initialized Value is invalid and will cause a panic. func (v Value) MoveTo(dest Value) { v.getState().AssertMutable() dest.getState().AssertMutable() @@ -373,7 +373,7 @@ func (v Value) MoveTo(dest Value) { } // CopyTo copies the Value instance overriding the destination. -// Calling this function on zero-initialized Value will cause a panic. +// Calling this function on zero-initialized Value is invalid and will cause a panic. func (v Value) CopyTo(dest Value) { dest.getState().AssertMutable() internal.CopyAnyValue(dest.getOrig(), v.getOrig()) @@ -382,7 +382,7 @@ func (v Value) CopyTo(dest Value) { // AsString converts an OTLP Value object of any type to its equivalent string // representation. This differs from Str which only returns a non-empty value // if the ValueType is ValueTypeStr. -// Calling this function on zero-initialized Value will cause a panic. +// Calling this function on zero-initialized Value is invalid and will cause a panic. func (v Value) AsString() string { switch v.Type() { case ValueTypeEmpty: diff --git a/pdata/pmetric/generated_exemplar.go b/pdata/pmetric/generated_exemplar.go index 12c9984abc6..ec4b4b3aa68 100644 --- a/pdata/pmetric/generated_exemplar.go +++ b/pdata/pmetric/generated_exemplar.go @@ -68,7 +68,7 @@ func (ms Exemplar) SetTimestamp(v pcommon.Timestamp) { } // ValueType returns the type of the value for this Exemplar. -// Calling this function on zero-initialized Exemplar will cause a panic. +// Calling this function on zero-initialized Exemplar is invalid and will cause a panic. func (ms Exemplar) ValueType() ExemplarValueType { switch ms.orig.Value.(type) { case *internal.Exemplar_AsDouble: diff --git a/pdata/pmetric/generated_metric.go b/pdata/pmetric/generated_metric.go index 792d38da8fd..120330a13e4 100644 --- a/pdata/pmetric/generated_metric.go +++ b/pdata/pmetric/generated_metric.go @@ -83,7 +83,7 @@ func (ms Metric) SetUnit(v string) { } // Type returns the type of the data for this Metric. -// Calling this function on zero-initialized Metric will cause a panic. +// Calling this function on zero-initialized Metric is invalid and will cause a panic. func (ms Metric) Type() MetricType { switch ms.orig.Data.(type) { case *internal.Metric_Gauge: @@ -105,7 +105,7 @@ func (ms Metric) Type() MetricType { // Calling this function when Type() != MetricTypeGauge returns an invalid // zero-initialized instance of Gauge. Note that using such Gauge instance can cause panic. // -// Calling this function on zero-initialized Metric will cause a panic. +// Calling this function on zero-initialized Metric is invalid and will cause a panic. func (ms Metric) Gauge() Gauge { v, ok := ms.orig.GetData().(*internal.Metric_Gauge) if !ok { @@ -118,7 +118,7 @@ func (ms Metric) Gauge() Gauge { // // After this, Type() function will return MetricTypeGauge". // -// Calling this function on zero-initialized Metric will cause a panic. +// Calling this function on zero-initialized Metric is invalid and will cause a panic. func (ms Metric) SetEmptyGauge() Gauge { ms.state.AssertMutable() var ov *internal.Metric_Gauge @@ -134,7 +134,7 @@ func (ms Metric) SetEmptyGauge() Gauge { // Calling this function when Type() != MetricTypeSum returns an invalid // zero-initialized instance of Sum. Note that using such Sum instance can cause panic. // -// Calling this function on zero-initialized Metric will cause a panic. +// Calling this function on zero-initialized Metric is invalid and will cause a panic. func (ms Metric) Sum() Sum { v, ok := ms.orig.GetData().(*internal.Metric_Sum) if !ok { @@ -147,7 +147,7 @@ func (ms Metric) Sum() Sum { // // After this, Type() function will return MetricTypeSum". // -// Calling this function on zero-initialized Metric will cause a panic. +// Calling this function on zero-initialized Metric is invalid and will cause a panic. func (ms Metric) SetEmptySum() Sum { ms.state.AssertMutable() var ov *internal.Metric_Sum @@ -163,7 +163,7 @@ func (ms Metric) SetEmptySum() Sum { // Calling this function when Type() != MetricTypeHistogram returns an invalid // zero-initialized instance of Histogram. Note that using such Histogram instance can cause panic. // -// Calling this function on zero-initialized Metric will cause a panic. +// Calling this function on zero-initialized Metric is invalid and will cause a panic. func (ms Metric) Histogram() Histogram { v, ok := ms.orig.GetData().(*internal.Metric_Histogram) if !ok { @@ -176,7 +176,7 @@ func (ms Metric) Histogram() Histogram { // // After this, Type() function will return MetricTypeHistogram". // -// Calling this function on zero-initialized Metric will cause a panic. +// Calling this function on zero-initialized Metric is invalid and will cause a panic. func (ms Metric) SetEmptyHistogram() Histogram { ms.state.AssertMutable() var ov *internal.Metric_Histogram @@ -192,7 +192,7 @@ func (ms Metric) SetEmptyHistogram() Histogram { // Calling this function when Type() != MetricTypeExponentialHistogram returns an invalid // zero-initialized instance of ExponentialHistogram. Note that using such ExponentialHistogram instance can cause panic. // -// Calling this function on zero-initialized Metric will cause a panic. +// Calling this function on zero-initialized Metric is invalid and will cause a panic. func (ms Metric) ExponentialHistogram() ExponentialHistogram { v, ok := ms.orig.GetData().(*internal.Metric_ExponentialHistogram) if !ok { @@ -205,7 +205,7 @@ func (ms Metric) ExponentialHistogram() ExponentialHistogram { // // After this, Type() function will return MetricTypeExponentialHistogram". // -// Calling this function on zero-initialized Metric will cause a panic. +// Calling this function on zero-initialized Metric is invalid and will cause a panic. func (ms Metric) SetEmptyExponentialHistogram() ExponentialHistogram { ms.state.AssertMutable() var ov *internal.Metric_ExponentialHistogram @@ -221,7 +221,7 @@ func (ms Metric) SetEmptyExponentialHistogram() ExponentialHistogram { // Calling this function when Type() != MetricTypeSummary returns an invalid // zero-initialized instance of Summary. Note that using such Summary instance can cause panic. // -// Calling this function on zero-initialized Metric will cause a panic. +// Calling this function on zero-initialized Metric is invalid and will cause a panic. func (ms Metric) Summary() Summary { v, ok := ms.orig.GetData().(*internal.Metric_Summary) if !ok { @@ -234,7 +234,7 @@ func (ms Metric) Summary() Summary { // // After this, Type() function will return MetricTypeSummary". // -// Calling this function on zero-initialized Metric will cause a panic. +// Calling this function on zero-initialized Metric is invalid and will cause a panic. func (ms Metric) SetEmptySummary() Summary { ms.state.AssertMutable() var ov *internal.Metric_Summary diff --git a/pdata/pmetric/generated_numberdatapoint.go b/pdata/pmetric/generated_numberdatapoint.go index 8dc926bbef4..7a2287be8db 100644 --- a/pdata/pmetric/generated_numberdatapoint.go +++ b/pdata/pmetric/generated_numberdatapoint.go @@ -76,7 +76,7 @@ func (ms NumberDataPoint) SetTimestamp(v pcommon.Timestamp) { } // ValueType returns the type of the value for this NumberDataPoint. -// Calling this function on zero-initialized NumberDataPoint will cause a panic. +// Calling this function on zero-initialized NumberDataPoint is invalid and will cause a panic. func (ms NumberDataPoint) ValueType() NumberDataPointValueType { switch ms.orig.Value.(type) { case *internal.NumberDataPoint_AsDouble: diff --git a/service/service.go b/service/service.go index dd0ec2b9804..70dd807437a 100644 --- a/service/service.go +++ b/service/service.go @@ -34,6 +34,7 @@ import ( "go.opentelemetry.io/collector/service/internal/proctelemetry" "go.opentelemetry.io/collector/service/internal/status" "go.opentelemetry.io/collector/service/telemetry" + "go.opentelemetry.io/collector/service/telemetry/otelconftelemetry" ) // This feature gate is deprecated and will be removed in 1.40.0. Views can now be configured. @@ -234,8 +235,11 @@ func New(ctx context.Context, set Settings, cfg Config) (_ *Service, resultErr e return nil, err } - if err := proctelemetry.RegisterProcessMetrics(srv.telemetrySettings); err != nil { - return nil, fmt.Errorf("failed to register process metrics: %w", err) + // Only register process metrics if metrics telemetry is enabled + if telemetryCfg, ok := cfg.Telemetry.(*otelconftelemetry.Config); !ok || telemetryCfg.Metrics.Level != configtelemetry.LevelNone { + if err := proctelemetry.RegisterProcessMetrics(srv.telemetrySettings); err != nil { + return nil, fmt.Errorf("failed to register process metrics: %w", err) + } } return srv, nil }