Debian Codegraph @

docs/coding-guidelines.md

raw
1 # Coding guidelines
2
3 We consider the OpenTelemetry Collector to be close to production quality and the quality bar
4 for contributions is set accordingly. Contributions must have readable code written
5 with maintainability in mind (if in doubt check [Effective Go](https://golang.org/doc/effective_go.html)
6 for coding advice). The code must adhere to the following robustness principles that
7 are important for software that runs autonomously and continuously without direct
8 interaction with a human (such as this Collector).
9
10 ## Naming convention
11
12 To keep naming patterns consistent across the project, naming patterns are enforced to make intent clear by:
13
14 - Methods that return a variable that uses the zero value or values provided via the method MUST have the prefix `New`. For example:
15 - `func NewKinesisExporter(kpl aws.KinesisProducerLibrary)` allocates a variable that uses
16 the variables passed on creation.
17 - `func NewKeyValueBuilder()` SHOULD allocate internal variables to a safe zero value.
18 - Methods that return a variable that uses non-zero value(s) that impacts business logic MUST use the prefix `NewDefault`. For example:
19 - `func NewDefaultKinesisConfig()` would return a configuration that is the suggested default
20 and can be updated without concern of causing a race condition.
21 - Methods that act upon an input variable MUST have a signature that reflects concisely the logic being done. For example:
22 - `func FilterAttributes(attrs []Attribute, match func(attr Attribute) bool) []Attribute` MUST only filter attributes out of the passed input
23 slice and return a new slice with values that `match` returns true. It may not do more work than what the method name implies, ie, it
24 must not key a global history of all the slices that have been filtered.
25 - Methods that get the value of a field i.e. a getterMethod MUST use an uppercase first letter and NOT a `get` prefix. For example:
26 - `func (p *Person) Name() string {return p.name} ` Name (with an uppercase N, exported) method is used here to get the value of the name field and not `getName`.The use of upper-case names for export provides the hook to discriminate the field from the method.
27 - Methods that set the value of a field i.e. a setterMethod MUST use a `set` prefix. For example:
28 - `func (p *Person) SetName(newName string) {p.name = newName}` SetName method here sets the value of the name field.
29 - Variable assigned in a package's global scope that is preconfigured with a default set of values MUST use `Default` as the prefix. For example:
30 - `var DefaultMarshallers = map[string]pdata.Marshallers{...}` is defined with an exporter package that allows for converting an encoding name,
31 `zipkin`, and return the preconfigured marshaller to be used in the export process.
32 - Types that are specific to a signal MUST be worded with the signal used as an adjective, i.e. `SignalType`. For example:
33 - `type TracesSink interface {...}`
34 - Types that deal with multiple signal types should use the relationship between the signals to describe the type, e.g. `SignalToSignalType` or `SignalAndSignalType`. For example:
35 - `type TracesToTracesFunc func(...) ...`
36 - Functions dealing with specific signals or signal-specific types MUST be worded with the signal or type as a direct object, i.e. `VerbSignal`, or `VerbType` where `Type` is the full name of the type including the signal name. For example:
37 - `func ConsumeTraces(...) {...}`
38 - `func CreateTracesExport(...) {...}`
39 - `func CreateTracesToTracesFunc(...) {...}`
40
41 ### Configuration structs
42
43 When naming configuration structs, use the following guidelines:
44
45 - Separate the configuration set by end users in their YAML configuration from the configuration set by developers in the code into different structs.
46 - Use the `Config` suffix for configuration structs that have end user configuration (i.e. that set in their YAML configuration). For example, `configgrpc.ClientConfig` ends in `Config` since it contains end user configuration.
47 - Use the `Settings` suffix for configuration structs that are set by developers in the code. For example, `component.TelemetrySettings` ends in `Settings` since it is set by developers in the code.
48 - Avoid redundant prefixes that are already implied by the package name. For example, use`configgrpc.ClientConfig` instead of `configgrpc.GRPCClientConfig`.
49
50 ## Module organization
51
52 As usual in Go projects, organize your code into packages grouping related functionality. To ensure
53 that we can evolve different parts of the API independently, you should also group related packages
54 into modules.
55
56 We use the following rules for some common situations where we split into separate modules:
57 1. Each top-level directory should be a separate module.
58 1. Each component referenceable by the OpenTelemetry Collector Builder should be in a separate
59 module. For example, the OTLP receiver is in its own module, different from that of other
60 receivers.
61 1. Consider splitting into separate modules if the API may evolve independently in separate groups
62 of packages. For example, the configuration related to HTTP and gRPC evolve independently, so
63 `config/configgrpc` and `config/confighttp` are separate modules.
64 1. For component names, add the component kind as a suffix for the module name. For example, the
65 OTLP receiver is in the `receiver/otlpreceiver` module.
66 1. Modules that add specific functionality related to a parent folder should have a prefix in the
67 name that relates to the parent module. For example, `configauth` has the `config` prefix since
68 it is part of the `config` folder, and `extensionauth` has `extension` as a prefix since it is
69 part of the `extension` module.
70 1. Testing helpers should be in a separate submodule with the suffix `test`. For example, if you
71 have a module `component`, the helpers should be in `component/componenttest`. Testing helpers
72 that are used across multiple modules should be in the [`internal/testutil`](https://github.com/open-telemetry/opentelemetry-collector/tree/main/internal/testutil)
73 module.
74 1. Experimental packages that will later be added to another module should be in their own module,
75 named as they will be after integration. For example, if adding a `pprofile` package to `pdata`,
76 you should add a separate module `pdata/pprofile` for the experimental code.
77 1. Experimental code that will be added to an existing package in a stable module can be a submodule
78 with the same name, but prefixed with an `x`. For example, `config/confighttp` module can have an
79 experimental module named `config/confighttp/xconfighttp` that contains experimental APIs.
80
81 When adding a new module remember to update the following:
82 1. Add a changelog note for the new module.
83 1. Add the module in `versions.yaml`.
84 1. Use `make crosslink` to make sure the module replaces are added correctly throughout the
85 codebase. You may also have to manually add some of the replaces.
86 1. Update the [otelcorecol
87 manifest](https://github.com/open-telemetry/opentelemetry-collector/blob/main/cmd/otelcorecol/builder-config.yaml)
88 and [builder
89 tests](https://github.com/open-telemetry/opentelemetry-collector/blob/main/cmd/builder/internal/builder/main_test.go).
90 1. Open a follow up PR to update pseudo-versions in all go.mod files. See [this example
91 PR](https://github.com/open-telemetry/opentelemetry-collector/pull/11668).
92
93 ## Enumerations
94
95 To keep naming patterns consistent across the project, enumeration patterns are enforced to make intent clear:
96
97 - Enumerations should be defined using a type definition, such as `type Level int32`.
98 - Enumerations should use either `int` or `string` as the underlying type
99 - The enumeration name should succinctly describe its purpose
100 - If the package name represents the entity described by the enumeration then the package name should be factored into the name of the enumeration. For example, `component.Type` instead of `component.ComponentType`.
101 - The name should convey a sense of limited categorization. For example, `pcommon.ValueType` is better than `pcommon.Value` and `component.Kind` is better than `component.KindType`, since `Kind` already conveys categorization.
102 - Constant values of an enumeration should be prefixed with the enumeration type name in the name:
103 - `pcommon.ValueTypeStr` for `pcommon.ValueType`
104 - `pmetric.MetricTypeGauge` for `pmetric.MetricType`
105
106
107 ## Recommended Libraries / Defaults
108
109 In order to simplify development within the project, we have made certain library recommendations that should be followed.
110
111 | Scenario | Recommended | Rationale |
112 |------------|------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
113 | Hashing | ["hashing/fnv"](https://pkg.go.dev/hash/fnv) | The project adopted this as the default hashing method due to the efficiency and is reasonable for non-cryptographic use |
114 | Testing | Use `t.Parallel()` where possible | Enabling more tests to be run in parallel will speed up the feedback process when working on the project. |
115
116
117 Within the project, there are some packages that have yet to follow the recommendations and are being addressed. However, any new code should adhere to the recommendations.
118
119 ## Default Configuration
120
121 To guarantee backward-compatible behavior, all configuration packages should supply a `NewDefault[config name]` functions that create a default version of the config. The package does not need to guarantee that `NewDefault[config name]` returns a usable configuration—only that default values will be set. For example, if the configuration requires that a field, such as `Endpoint` be set, but there is no valid default value, then `NewDefault[config name]` may set that value to `""` with the expectation that the user will set a valid value.
122
123 Users should always initialize the config struct with this function and overwrite anything as needed.
124
125 ## Startup Error Handling
126
127 Verify configuration during startup and fail fast if the configuration is invalid.
128 This will bring the attention of a human to the problem as it is more typical for humans
129 to notice problems when the process is starting as opposed to problems that may arise
130 sometime (potentially long time) after process startup. Monitoring systems are likely
131 to automatically flag processes that exit with failure during startup, making it
132 easier to notice the problem. The Collector should print a reasonable log message to
133 explain the problem and exit with a non-zero code. It is acceptable to crash the process
134 during startup if there is no good way to exit cleanly but do your best to log and
135 exit cleanly with a process exit code.
136
137 ## Propagate Errors to the Caller
138
139 Do not crash or exit outside the `main()` function, e.g. via `log.Fatal` or `os.Exit`,
140 even during startup. Instead, return detailed errors to be handled appropriately
141 by the caller. The code in packages other than `main` may be imported and used by
142 third-party applications, and they should have full control over error handling
143 and process termination.
144
145 ## Do not Crash after Startup
146
147 Do not crash or exit the Collector process after the startup sequence is finished.
148 A running Collector typically contains data that is received but not yet exported further
149 (e.g. data that is stored in the queues and other processors). Crashing or exiting the Collector
150 process will result in losing this data since typically the receiver has
151 already acknowledged the receipt for this data and the senders of the data will
152 not send that data again.
153
154 ## Bad Input Handling
155
156 Do not crash on bad input in receivers or elsewhere in the pipeline.
157 [Crash-only software](https://en.wikipedia.org/wiki/Crash-only_software)
158 is valid in certain cases; however, this is not a correct approach for Collector (except
159 during startup, see above). The reason is that many senders from which the Collector
160 receives data have built-in automatic retries of the _same_ data if no
161 acknowledgment is received from the Collector. If you crash on bad input
162 chances are high that after the Collector is restarted it will see the same
163 data in the input and will crash again. This will likely result in an infinite
164 crashing loop if you have automatic retries in place.
165
166 Typically bad input when detected in a receiver should be reported back to the
167 sender. If it is elsewhere in the pipeline it may be too late to send a response
168 to the sender (particularly in processors which are not synchronously processing
169 data). In either case, it is recommended to keep a metric that counts bad input data.
170
171 ## Error Handling and Retries
172
173 Be rigorous in error handling. Don't ignore errors. Think carefully about each
174 error and decide if it is a fatal problem or a transient problem that may go away
175 when retried. Fatal errors should be logged or recorded in an internal metric to
176 provide visibility to users of the Collector. For transient errors come up with a
177 retrying strategy and implement it. Typically you will
178 want to implement retries with some sort of exponential back-off strategy. For
179 connection or sending retries use jitter for back-off intervals to avoid overwhelming
180 your destination when the network is restored or the destination is recovered.
181 [Exponential Backoff](https://github.com/cenkalti/backoff) is a good library that
182 provides all this functionality.
183
184 ## Logging
185
186 Log your component startup and shutdown, including successful outcomes (but don't
187 overdo it, and keep the number of success messages to a minimum).
188 This can help to understand the context of failures if they occur elsewhere after
189 your code is successfully executed.
190
191 Use logging carefully for events that can happen frequently to avoid flooding
192 the logs. Avoid outputting logs per a received or processed data item since this can
193 amount to a very large number of log entries (Collector is designed to process
194 many thousands of spans and metrics per second). For such high-frequency events
195 instead of logging consider adding an internal metric and incrementing it when
196 the event happens.
197
198 Make log messages human readable and also include data that is needed for easier
199 understanding of what happened and in what context.
200
201 ## Executing External Processes
202
203 The components should avoid executing arbitrary external processes with arbitrary command
204 line arguments based on user input, including input received from the network or input
205 read from the configuration file. Failure to follow this rule can result in arbitrary
206 remote code execution, compelled by malicious actors that can craft the input.
207
208 The following limitations are recommended:
209 - If an external process needs to be executed limit and hard-code the location where
210 the executable file may be located, instead of allowing the input to dictate the
211 full path to the executable.
212 - If possible limit the name of the executable file to be pulled from a hard-coded
213 list defined at compile time.
214 - If command line arguments need to be passed to the process do not take the arguments
215 from the user input directly. Instead, compose the command line arguments indirectly,
216 if necessary, deriving the value from the user input. Limit as much as possible the
217 size of the possible space of values for command line arguments.
218
219 ## Observability
220
221 Out of the box, your users should be able to observe the state of your
222 component. See [observability.md](observability.md) for more details.
223
224 When using the regular helpers, you should have some metrics added around key
225 events automatically. For instance, exporters should have
226 `otelcol_exporter_sent_spans` tracked without your exporter doing anything.
227
228 Custom metrics can be defined as part of the `metadata.yaml` for your component.
229 The authoritative source of information for this is [the
230 schema](https://github.com/open-telemetry/opentelemetry-collector/blob/main/cmd/mdatagen/metadata-schema.yaml),
231 but here are a few examples for reference, adapted from the tail sampling
232 processor:
233
234 ```yaml
235 telemetry:
236 metrics:
237 # example of a histogram
238 processor.tailsampling.samplingdecision.latency:
239 description: Latency (in microseconds) of a given sampling policy.
240 unit: µs # from https://ucum.org/ucum
241 enabled: true
242 histogram:
243 value_type: int
244 # bucket boundaries can be overridden
245 bucket_boundaries: [1, 2, 5, 10, 25, 50, 75, 100, 150, 200, 300, 400, 500, 750, 1000, 2000, 3000, 4000, 5000, 10000, 20000, 30000, 50000]
246
247 # example of a counter
248 processor.tailsampling.policyevaluation.errors:
249 description: Count of sampling policy evaluation errors.
250 unit: "{errors}"
251 enabled: true
252 sum:
253 value_type: int
254 monotonic: true
255
256 # example of a gauge
257 processor.tailsampling.tracesonmemory:
258 description: Tracks the number of traces current on memory.
259 unit: "{traces}"
260 enabled: true
261 gauge:
262 value_type: int
263 ```
264
265 Running `go generate ./...` at the root of your component should generate the
266 following files:
267
268 - `documentation.md`, with the metrics and their descriptions
269 - `internal/metadata/generated_telemetry.go`, with code that defines the metric
270 using the OTel API
271 - `internal/metadata/generated_telemetry_test.go`, with sanity tests for the
272 generated code
273
274 On your component's code, you can use the metric by initializing the telemetry
275 builder and storing it on a component's field:
276
277 ```go
278 type tailSamplingSpanProcessor struct {
279 ctx context.Context
280
281 telemetry *metadata.TelemetryBuilder
282 }
283
284 func newTracesProcessor(ctx context.Context, settings component.TelemetrySettings, nextConsumer consumer.Traces, cfg Config, opts ...Option) (processor.Traces, error) {
285 telemetry, err := metadata.NewTelemetryBuilder(settings)
286 if err != nil {
287 return nil, err
288 }
289
290 tsp := &tailSamplingSpanProcessor{
291 ctx: ctx,
292 telemetry: telemetry,
293 }
294 }
295 ```
296
297 To record the measurement, you can then call the metric stored in the telemetry
298 builder:
299
300 ```go
301 tsp.telemetry.ProcessorTailsamplingSamplingdecisionLatency.Record(ctx, ...)
302 ```
303
304 ## Resource Usage
305
306 Limit usage of CPU, RAM, and other resources that the code can use. Do not write code
307 that consumes resources in an uncontrolled manner. For example, if you have a queue
308 that can contain unprocessed messages always limit the size of the queue unless you
309 have other ways to guarantee that the queue will be consumed faster than items are
310 added to it.
311
312 Performance test the code for both normal use-cases under acceptable load and also for
313 abnormal use-cases when the load exceeds acceptable limits many times over. Ensure that
314 your code performs predictably under abnormal use. For example, if the code
315 needs to process received data and cannot keep up with the receiving rate it is
316 not acceptable to keep allocating more memory for received data until the Collector
317 runs out of memory. Instead have protections for these situations, e.g. when hitting
318 resource limits drop the data and record the fact that it was dropped in a metric
319 that is exposed to users.
320
321 ## Graceful Shutdown
322
323 Collector does not yet support graceful shutdown but we plan to add it. All components
324 must be ready to shutdown gracefully via `Shutdown()` function that all component
325 interfaces require. If components contain any temporary data they need to process
326 and export it out of the Collector before shutdown is completed. The shutdown process
327 will have a maximum allowed duration so put a limit on how long your shutdown
328 operation can take.
329
330 ## Unit Tests
331
332 Cover important functionality with unit tests. We require that contributions
333 do not decrease the overall code coverage of the codebase - this is aligned with our
334 goal to increase coverage over time. Keep track of execution time for your unit
335 tests and try to keep them as short as possible.
336
337 ## Semantic Conventions compatibility
338
339 When adding new metrics, attributes or entity attributes to a Collector's component (receiver, processor etc), the
340 [Semantic Conventions](https://github.com/open-telemetry/semantic-conventions) project should be checked first
341 to see if those are already defined as Semantic Conventions.
342 It's also important to check for any open issues that may already propose these or similar Semantic Conventions.
343 If no such Semantic Conventions are defined in the Semantic Conventions project, the component’s code owners
344 should consider initiating that process first
345 (refer to Semantic Conventions'
346 [contribution guidelines](https://github.com/open-telemetry/semantic-conventions/blob/main/CONTRIBUTING.md)
347 for specific details).
348 The implementation of the component can still be submitted as a draft PR to demonstrate how the proposed
349 Semantic Conventions would be used while working in parallel to contribute the relevant updates to
350 the Semantic Conventions project.
351 The components's code owners can review the Semantic Conventions PR in collaboration with any existing domain-specific
352 SemConv approvers.
353 At their discretion, the code owners may choose to block the component’s implementation PR until the related
354 Semantic Conventions changes are completed.
355
356 ### Testing Library Recommendations
357
358 To keep testing practices consistent across the project, it is advised to use these libraries under
359 these circumstances:
360
361 - For assertions to validate expectations, use `"github.com/stretchr/testify/assert"`
362 - For assertions that are required to continue the test, use `"github.com/stretchr/testify/require"`
363 - For mocking external resources, use `"github.com/stretchr/testify/mock"`
364 - For validating HTTP traffic interactions, `"net/http/httptest"`
365
366 ## Integration Testing
367
368 Integration testing is encouraged throughout the project, container images can be used in order to facilitate
369 a local version. In their absence, it is strongly advised to mock the integration.
370
371 ## Using CGO
372
373 Using CGO is prohibited due to the lack of portability and complexity
374 that comes with managing external libraries with different operating systems and configurations.
375 However, if the package MUST use CGO, this should be explicitly called out within the readme
376 with clear instructions on how to install the required libraries.
377 Furthermore, if your package requires CGO, it MUST be able to compile and operate in a no-op mode
378 or report a warning back to the collector with a clear error saying CGO is required to work.
379
380 ## Breaking changes
381
382 Whenever possible, we adhere to [semver](https://semver.org/) as our minimum standards. Even before v1, we strive not to break compatibility
383 without a good reason. Hence, when a change is known to cause a breaking change, we intend to follow these principles:
384
385 - Breaking changes MUST have migration guidelines that clearly explain how to adapt to them.
386 - Users SHOULD be able to adopt the breaking change at their own pace, independent of other Collector updates.
387 - Users SHOULD be proactively notified about the breaking change before a migration is required.
388 - Users SHOULD be able to easily tell whether they have completed the migration for a breaking change.
389
390 Not all changes have the same effects on users, so some of the steps may be unnecessary for some changes.
391
392 ### API breaking changes
393
394 We strive to perform API breaking changes in two stages, deprecating it first (`vM.N`) and breaking it in a subsequent
395 version (`vM.N+1`).
396
397 - when we need to remove something, we MUST mark a feature as deprecated in one version and MAY remove it in a
398 subsequent one
399 - when renaming or refactoring types, functions, or attributes, we MUST create the new name and MUST deprecate the old
400 one in one version (step 1), and MAY remove it in a subsequent version (step 2). For simple renames, the old name
401 SHALL call the new one.
402 - when a feature is being replaced in favor of an existing one, we MUST mark a feature as deprecated in one version, and
403 MAY remove it in a subsequent one.
404
405 Deprecation notice SHOULD contain a version starting from which the deprecation takes effect for tracking purposes. For
406 example, if `GetFoo` function is going to be deprecated in `v0.45.0` version, it gets the following godoc line:
407
408 ```golang
409 package test
410
411 // Deprecated: [v0.45.0] Use MustDoFoo instead.
412 func DoFoo() {}
413 ```
414
415 #### Example #1 - Renaming a function
416
417 1. Current version `v0.N` has `func GetFoo() Bar`
418 1. We now decided that `GetBar` is a better name. As such, on `v0.N+1` we add a new `func GetBar() Bar` function,
419 changing the existing `func GetFoo() Bar` to be an alias of the new function. Additionally, a log entry with a
420 warning is added to the old function, along with an entry to the changelog.
421 1. On `v0.N+2`, we MAY remove `func GetFoo() Bar`.
422
423 #### Example #2 - Changing the return values of a function
424
425 1. Current version `v0.N` has `func GetFoo() Foo`
426 1. We now need to also return an error. We do it by creating a new function that will be equivalent to the existing one
427 so that current users can easily migrate to that: `func MustGetFoo() Foo`, which panics on errors. We release this in
428 `v0.N+1`, deprecating the existing `func GetFoo() Foo` with it, adding an entry to the changelog and perhaps a log
429 entry with a warning.
430 1. On `v0.N+2`, we change `func GetFoo() Foo` to `func GetFoo() (Foo, error)`.
431
432 #### Example #3 - Changing the arguments of a function
433
434 1. Current version `v0.N` has `func GetFoo() Foo`
435 2. We now decide to do something that might be blocking as part of `func GetFoo() Foo`, so, we start accepting a
436 context: `func GetFooWithContext(context.Context) Foo`. We release this in `v0.N+1`, deprecating the existing `func
437 GetFoo() Foo` with it, adding an entry to the changelog and perhaps a log entry with a warning. The existing `func
438 GetFoo() Foo` is changed to call `func GetFooWithContext(context.Background()) Foo`.
439 3. On `v0.N+2`, we change `func GetFoo() Foo` to `func GetFoo(context.Context) Foo` if desired or remove it entirely if
440 needed.
441
442 #### Exceptions
443
444 For changes to modules that do not have a version of `v1` or higher, we may skip the deprecation process described above
445 for the following situations. Note that these changes should still be recorded as breaking changes in the changelog.
446
447 * **Variadic arguments.** Functions that are not already variadic may have a variadic parameter added as a method of
448 supporting optional parameters, particularly through the functional options pattern. If a variadic parameter is
449 added to a function with no change in functionality when no variadic arguments are passed, the deprecation process
450 may be skipped. Calls to updated functions without the new argument will continue to work before, but users who depend
451 on the exact function signature as a type, for example as an argument to another function, will experience a
452 breaking change. For this reason, the deprecation process should only be skipped when it is not expected that
453 the function is commonly passed as a value.
454
455 ### End-user impacting changes
456
457 For end user breaking changes, we follow the [feature gate](https://github.com/open-telemetry/opentelemetry-collector/tree/main/featuregate#feature-lifecycle)
458 approach. This is a well-known approach in other projects such as Kubernetes. A feature gate has
459 three stages: alpha, beta and stable. The intent of these stages is to decouple other software
460 changes from the breaking change; some users may adopt the change early, while other users may delay
461 its adoption.
462
463 #### Feature gate IDs
464
465 Feature gate IDs should be namespaced using dots to denote the hierarchy. The namespace should be as
466 specific as possible; in particular, for feature gates specific to a certain component the ID should
467 have the following structure: `<component kind>.<component type>.<base ID>`. The "base ID" should be
468 written with a verb that describes what happens when the feature gate is enabled. For example, if
469 you want to add a feature gate for the OTLP receiver that changes the default endpoint to bind to an
470 unspecified host, you could name your feature gate `receiver.otlp.UseUnspecifiedHostAsDefaultHost`.
471
472 #### Lifecycle of a breaking change
473
474 ##### Alpha stage
475
476 At the alpha stage, the change is opt-in. At this stage we want to notify users that a change is
477 coming, so they can start preparing for it and we have some early adopters that provide us with
478 feedback. Consider the following items before the initial release of an alpha feature gate:
479
480 * If **docs and examples** can be updated in a way that prevents the breaking change from affecting
481 users, this is the time to update them!
482 * Provide users with tools to understand the breaking change
483 * (Optional) Create or update a **Github issue** to document what the change is about, who it
484 affects and what its effects are
485 * (Optional) Consider adding **telemetry** that allows users to track their migration. For
486 example, you can add a counter for the times that you see a payload that would be affected by
487 the breaking change.
488 * Notify users about the upcoming change
489 * Add a **changelog entry** that describes the feature gate. It should include its name, when you
490 may want to use it, and what its effects are. The changelog entry can be given the `enhancement`
491 classification at this stage.
492 * (Optional but strongly recommended) Log a **warning** if the user is using the software in a way
493 that would be affected by the breaking change. Point the user to the feature gate and any
494 official docs.
495 * (Optional) Try to **test this in a realistic setting.** If this solves an issue, ask the poster to
496 try to use it and check that everything works.
497
498 ##### Beta stage
499
500 At the beta stage, the change is opt-out. At this stage we want to notify users that the change is
501 happening, and help them understand how to revert back to the previous behavior temporarily if they
502 need to do so. You may directly start from this stage for breaking changes that are less impactful
503 or for changes that should not have a functional impact such as performance changes. Consider the
504 following items before moving from alpha to beta:
505
506 * Schedule the **docs and examples** update to align with the breaking change release if you
507 couldn’t do it before
508 * Provide users with tools to understand the breaking change
509 * Update the **Github issue** with the new default behavior (or create one if starting from here)
510 * Update the feature gate to add the ‘to version’ to the feature gate
511 * Notify users about the change
512 * Add a second **changelog entry** that describes the change one more time and is marked as
513 ‘breaking’.
514 * If applicable, add an **error message** that tells you this is the result of a breaking change
515 that can be temporarily reverted disabling the feature gate and points to any issue or docs
516 about it.
517
518 ##### Stable stage
519
520 At the stable stage, the change cannot be reverted. In some cases, you may directly start here and
521 just do the change, in which case you do not need a feature gate, but you should still follow the
522 checklist below (notify, update docs and examples). Consider the following items before moving from
523 beta to stable:
524
525 * Remove the dead code
526 * Provide users with tools to understand the breaking change
527 * Update the **documentation** **and examples** to remove any references to the feature gate and
528 the previous behavior. Close the **Github issue** if you opened one before.
529 * Notify users about the change
530 * Add one last **changelog entry** so users know the range where the feature gate was in beta
531 * Amend the **error message** to remove any references to the feature gate.
532
533 ## Specification Tracking
534
535 The [OpenTelemetry Specification](https://github.com/open-telemetry/opentelemetry-specification) can be a rapidly
536 moving target at times. While it may seem efficient to get an early start on implementing new features or
537 functionality under development in the specification, this can also lead to significant churn and a risk that
538 changes in the specification can result in breaking changes to the implementation. For this reason, it is the
539 policy of the Collector SIG to not implement, or accept implementations of, new or changed specification language
540 prior to inclusion in a stable release of the specification.