| 1 | // Copyright The OpenTelemetry Authors |
| 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| 4 | package otelconftelemetry // import "go.opentelemetry.io/collector/service/telemetry/otelconftelemetry" |
| 5 | |
| 6 | import ( |
| 7 | "errors" |
| 8 | |
| 9 | "go.opentelemetry.io/collector/config/configtelemetry" |
| 10 | "go.opentelemetry.io/collector/service/telemetry/internal/migration" |
| 11 | ) |
| 12 | |
| 13 | // Config defines the configurable settings for service telemetry. |
| 14 | type Config struct { |
| 15 | Logs LogsConfig `mapstructure:"logs"` |
| 16 | Metrics MetricsConfig `mapstructure:"metrics"` |
| 17 | Traces TracesConfig `mapstructure:"traces,omitempty"` |
| 18 | |
| 19 | // Resource specifies user-defined attributes to include with all emitted telemetry. |
| 20 | // Note that some attributes are added automatically (e.g. service.version) even |
| 21 | // if they are not specified here. In order to suppress such attributes the |
| 22 | // attribute must be specified in this map with null YAML value (nil string pointer). |
| 23 | Resource map[string]*string `mapstructure:"resource,omitempty"` |
| 24 | } |
| 25 | |
| 26 | // LogsConfig defines the configurable settings for service telemetry logs. |
| 27 | // This MUST be compatible with zap.Config. Cannot use directly zap.Config because |
| 28 | // the collector uses mapstructure and not yaml tags. |
| 29 | type LogsConfig = migration.LogsConfigV030 |
| 30 | |
| 31 | // LogsSamplingConfig sets a sampling strategy for the logger. Sampling caps the |
| 32 | // global CPU and I/O load that logging puts on your process while attempting |
| 33 | // to preserve a representative subset of your logs. |
| 34 | type LogsSamplingConfig = migration.LogsSamplingConfig |
| 35 | |
| 36 | // MetricsConfig exposes the common Telemetry configuration for one component. |
| 37 | // Experimental: *NOTE* this structure is subject to change or removal in the future. |
| 38 | type MetricsConfig = migration.MetricsConfigV030 |
| 39 | |
| 40 | // TracesConfig exposes the common Telemetry configuration for collector's internal spans. |
| 41 | // Experimental: *NOTE* this structure is subject to change or removal in the future. |
| 42 | type TracesConfig = migration.TracesConfigV030 |
| 43 | |
| 44 | // Validate checks whether the current configuration is valid |
| 45 | func (c *Config) Validate() error { |
| 46 | // Check when service telemetry metric level is not none, the metrics readers should not be empty |
| 47 | if c.Metrics.Level != configtelemetry.LevelNone && len(c.Metrics.Readers) == 0 { |
| 48 | return errors.New("collector telemetry metrics reader should exist when metric level is not none") |
| 49 | } |
| 50 | |
| 51 | if c.Metrics.Views != nil && c.Metrics.Level != configtelemetry.LevelDetailed { |
| 52 | return errors.New("service::telemetry::metrics::views can only be set when service::telemetry::metrics::level is detailed") |
| 53 | } |
| 54 | |
| 55 | return nil |
| 56 | } |