Debian Codegraph @

service/telemetry/internal/migration/v0.3.0.go

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package migration // import "go.opentelemetry.io/collector/service/telemetry/internal/migration"
5
6 import (
7 "time"
8
9 config "go.opentelemetry.io/contrib/otelconf/v0.3.0"
10 "go.uber.org/zap/zapcore"
11
12 "go.opentelemetry.io/collector/config/configtelemetry"
13 "go.opentelemetry.io/collector/confmap"
14 )
15
16 type TracesConfigV030 struct {
17 // Level configures whether spans are emitted or not, the possible values are:
18 // - "none" indicates that no tracing data should be collected;
19 // - "basic" is the recommended and covers the basics of the service telemetry.
20 Level configtelemetry.Level `mapstructure:"level"`
21 // Propagators is a list of TextMapPropagators from the supported propagators list. Currently,
22 // tracecontext and b3 are supported. By default, the value is set to empty list and
23 // context propagation is disabled.
24 Propagators []string `mapstructure:"propagators"`
25
26 config.TracerProvider `mapstructure:",squash"`
27 }
28
29 func (c *TracesConfigV030) Unmarshal(conf *confmap.Conf) error {
30 unmarshaled := *c
31 if err := conf.Unmarshal(c); err != nil {
32 v2TracesConfig := tracesConfigV020{
33 Level: unmarshaled.Level,
34 Propagators: unmarshaled.Propagators,
35 }
36 // try unmarshaling using v0.2.0 struct
37 if e := conf.Unmarshal(&v2TracesConfig); e != nil {
38 // error could not be resolved through backwards
39 // compatibility attempts
40 return err
41 }
42 // TODO: add a warning log to tell users to migrate their config
43 return tracesConfigV02ToV03(v2TracesConfig, c)
44 }
45 // ensure endpoint normalization occurs
46 for _, r := range c.Processors {
47 if r.Batch != nil {
48 if r.Batch.Exporter.OTLP != nil {
49 r.Batch.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Batch.Exporter.OTLP.Endpoint, r.Batch.Exporter.OTLP.Insecure)
50 }
51 }
52 if r.Simple != nil {
53 if r.Simple.Exporter.OTLP != nil && r.Simple.Exporter.OTLP.Endpoint != nil {
54 r.Simple.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Simple.Exporter.OTLP.Endpoint, r.Simple.Exporter.OTLP.Insecure)
55 }
56 }
57 }
58 return nil
59 }
60
61 type MetricsConfigV030 struct {
62 // Level is the level of telemetry metrics, the possible values are:
63 // - "none" indicates that no telemetry data should be collected;
64 // - "basic" is the recommended and covers the basics of the service telemetry.
65 // - "normal" adds some other indicators on top of basic.
66 // - "detailed" adds dimensions and views to the previous levels.
67 Level configtelemetry.Level `mapstructure:"level"`
68
69 config.MeterProvider `mapstructure:",squash"`
70 }
71
72 func (c *MetricsConfigV030) Unmarshal(conf *confmap.Conf) error {
73 unmarshaled := *c
74 if err := conf.Unmarshal(c); err != nil {
75 v02 := metricsConfigV020{
76 Level: unmarshaled.Level,
77 }
78 // try unmarshaling using v0.2.0 struct
79 if e := conf.Unmarshal(&v02); e != nil {
80 // error could not be resolved through backwards
81 // compatibility attempts
82 return err
83 }
84 // TODO: add a warning log to tell users to migrate their config
85 return metricsConfigV02ToV03(v02, c)
86 }
87 // ensure endpoint normalization occurs
88 for _, r := range c.Readers {
89 if r.Periodic != nil {
90 if r.Periodic.Exporter.OTLP != nil && r.Periodic.Exporter.OTLP.Endpoint != nil {
91 r.Periodic.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Periodic.Exporter.OTLP.Endpoint, r.Periodic.Exporter.OTLP.Insecure)
92 }
93 }
94 }
95 return nil
96 }
97
98 type LogsConfigV030 struct {
99 // Level is the minimum enabled logging level.
100 // (default = "INFO")
101 Level zapcore.Level `mapstructure:"level"`
102
103 // Development puts the logger in development mode, which changes the
104 // behavior of DPanicLevel and takes stacktraces more liberally.
105 // (default = false)
106 Development bool `mapstructure:"development,omitempty"`
107
108 // Encoding sets the logger's encoding.
109 // Example values are "json", "console".
110 Encoding string `mapstructure:"encoding"`
111
112 // DisableCaller stops annotating logs with the calling function's file
113 // name and line number. By default, all logs are annotated.
114 // (default = false)
115 DisableCaller bool `mapstructure:"disable_caller,omitempty"`
116
117 // DisableStacktrace completely disables automatic stacktrace capturing. By
118 // default, stacktraces are captured for WarnLevel and above logs in
119 // development and ErrorLevel and above in production.
120 // (default = false)
121 DisableStacktrace bool `mapstructure:"disable_stacktrace,omitempty"`
122
123 // Sampling sets a sampling policy.
124 // Default:
125 // sampling:
126 // enabled: true
127 // tick: 10s
128 // initial: 10
129 // thereafter: 100
130 // Sampling can be disabled by setting 'enabled' to false
131 Sampling *LogsSamplingConfig `mapstructure:"sampling"`
132
133 // OutputPaths is a list of URLs or file paths to write logging output to.
134 // The URLs could only be with "file" schema or without schema.
135 // The URLs with "file" schema must be an absolute path.
136 // The URLs without schema are treated as local file paths.
137 // "stdout" and "stderr" are interpreted as os.Stdout and os.Stderr.
138 // see details at Open in zap/writer.go.
139 // (default = ["stderr"])
140 OutputPaths []string `mapstructure:"output_paths"`
141
142 // ErrorOutputPaths is a list of URLs or file paths to write zap internal logger errors to.
143 // The URLs could only be with "file" schema or without schema.
144 // The URLs with "file" schema must use absolute paths.
145 // The URLs without schema are treated as local file paths.
146 // "stdout" and "stderr" are interpreted as os.Stdout and os.Stderr.
147 // see details at Open in zap/writer.go.
148 //
149 // Note that this setting only affects the zap internal logger errors.
150 // (default = ["stderr"])
151 ErrorOutputPaths []string `mapstructure:"error_output_paths"`
152
153 // InitialFields is a collection of fields to add to the root logger.
154 // Example:
155 //
156 // initial_fields:
157 // foo: "bar"
158 //
159 // By default, there is no initial field.
160 InitialFields map[string]any `mapstructure:"initial_fields,omitempty"`
161
162 // Processors allow configuration of log record processors to emit logs to
163 // any number of supported backends.
164 Processors []config.LogRecordProcessor `mapstructure:"processors,omitempty"`
165 }
166
167 // LogsSamplingConfig sets a sampling strategy for the logger. Sampling caps the
168 // global CPU and I/O load that logging puts on your process while attempting
169 // to preserve a representative subset of your logs.
170 type LogsSamplingConfig struct {
171 // Enabled enable sampling logging
172 Enabled bool `mapstructure:"enabled"`
173 // Tick represents the interval in seconds that the logger apply each sampling.
174 Tick time.Duration `mapstructure:"tick"`
175 // Initial represents the first M messages logged each Tick.
176 Initial int `mapstructure:"initial"`
177 // Thereafter represents the sampling rate, every Nth message will be sampled after Initial messages are logged during each Tick.
178 // If Thereafter is zero, the logger will drop all the messages after the Initial each Tick.
179 Thereafter int `mapstructure:"thereafter"`
180 }
181
182 func (c *LogsConfigV030) Unmarshal(conf *confmap.Conf) error {
183 unmarshaled := *c
184 if err := conf.Unmarshal(c); err != nil {
185 v02 := logsConfigV020{
186 Level: unmarshaled.Level,
187 Development: unmarshaled.Development,
188 Encoding: unmarshaled.Encoding,
189 DisableCaller: unmarshaled.DisableCaller,
190 DisableStacktrace: unmarshaled.DisableStacktrace,
191 Sampling: unmarshaled.Sampling,
192 OutputPaths: unmarshaled.OutputPaths,
193 ErrorOutputPaths: unmarshaled.ErrorOutputPaths,
194 InitialFields: unmarshaled.InitialFields,
195 }
196 // try unmarshaling using v0.2.0 struct
197 if e := conf.Unmarshal(&v02); e != nil {
198 // error could not be resolved through backwards
199 // compatibility attempts
200 return err
201 }
202 // TODO: add a warning log to tell users to migrate their config
203 return logsConfigV02ToV03(v02, c)
204 }
205 // ensure endpoint normalization occurs
206 for _, r := range c.Processors {
207 if r.Batch != nil {
208 if r.Batch.Exporter.OTLP != nil {
209 r.Batch.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Batch.Exporter.OTLP.Endpoint, r.Batch.Exporter.OTLP.Insecure)
210 }
211 }
212 if r.Simple != nil {
213 if r.Simple.Exporter.OTLP != nil && r.Simple.Exporter.OTLP.Endpoint != nil {
214 r.Simple.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Simple.Exporter.OTLP.Endpoint, r.Simple.Exporter.OTLP.Insecure)
215 }
216 }
217 }
218 return nil
219 }