Debian Codegraph @

CONTRIBUTING.md

raw
1 # Contributing Guide
2
3 We'd love your help! Please join our weekly [SIG
4 meeting](https://github.com/open-telemetry/community#special-interest-groups).
5
6 ## Target audiences
7
8 The OpenTelemetry Collector has three main target audiences:
9
10 1. *End-users*, aiming to use an OpenTelemetry Collector binary.
11 1. *Component developers*, consuming the Go APIs to create components compatible with the OpenTelemetry Collector Builder.
12 1. *Collector library users*, consuming other Go APIs exposed by the opentelemetry-collector repository, for example to
13 build custom distributions or other projects building on top of the Collector Go APIs.
14
15 When the needs of these audiences conflict, end-users should be prioritized, followed by component developers, and
16 finally Collector library users.
17
18 ### End-users
19
20 End-users are the target audience for our binary distributions, as made available via the
21 [opentelemetry-collector-releases](https://github.com/open-telemetry/opentelemetry-collector-releases) repository, as
22 well as distributions created using the [OpenTelemetry Collector
23 Builder](https://github.com/open-telemetry/opentelemetry-collector/tree/main/cmd/builder). To them, stability in the
24 behavior is important, be it runtime, configuration, or [internal
25 telemetry](https://opentelemetry.io/docs/collector/internal-telemetry/). They are more numerous and harder to get in
26 touch with, making our changes to the Collector more disruptive to them than to other audiences. As a general rule,
27 whenever you are developing OpenTelemetry Collector components (extensions, receivers, processors, exporters,
28 connectors), you should have end-users' interests in mind. Similarly, changes to code within packages like `config` will
29 have an impact on this audience. Make sure to cause minimal disruption when doing changes here.
30
31 ### Component developers
32
33 Component developers create new extensions, receivers, processors, exporters, and connectors to be used with the
34 OpenTelemetry Collector. They are the primary audience for the opentelemetry-collector repository's public Go API. A
35 significant part of them will contribute to opentelemetry-collector-contrib. In addition to the end-user aspect
36 mentioned above, this audience also cares about Go API compatibility of Go modules such as the ones in the `pdata`,
37 `component`, `consumer`, `confmap`, `exporterhelper`, `config*` modules and others, even though such changes wouldn't cause any
38 impact to end-users. See the [Breaking changes](docs/coding-guidelines.md#breaking-changes) section
39 in the coding guidelines for more information on how to perform changes affecting this audience.
40
41 ### Collector library users
42
43 A third audience uses the OpenTelemetry Collector as a library to build their own distributions or other projects based
44 on the Collector. This audience is the main consumer of modules such as `service` or `otelcol`. They also share the same
45 concerns as component developers regarding Go API compatibility and are likewise interested in behavior stability. These
46 are our most advanced users and are the most equipped to deal with disruptive changes.
47
48 ## How to structure PRs to get expedient reviews?
49
50 We recommend that any PR (unless it is trivial) to be smaller than 500 lines
51 (excluding go mod/sum changes) in order to help reviewers to do a thorough and
52 reasonably fast reviews.
53
54 ### When adding a new component
55
56 Components refer to connectors, exporters, extensions, processors, and receivers. The key criteria for implementing a component is to:
57
58 * Implement the `component.Component` interface
59 * Provide a configuration structure which defines the configuration of the component
60 * Provide the implementation that performs the component operation
61
62 For more details on components, see the [Adding New Components](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#adding-new-components) document and the tutorial [Building a Trace Receiver](https://opentelemetry.io/docs/collector/trace-receiver/) which provides a detailed example of building a component.
63
64 When adding a new component to the OpenTelemetry Collector, ensure that any configuration structs used by the component include fields with the `configopaque.String` type for sensitive data. This ensures that the data is masked when serialized to prevent accidental exposure.
65
66 When submitting a component to the community, consider breaking it down into separate PRs as follows:
67
68 * **First PR** should include the overall structure of the new component:
69 * Readme, configuration, and factory implementation should usually use the helper
70 factory structs.
71 * This PR is usually trivial to review, so the size limit does not apply to
72 it.
73 * The component should use [`In Development` Stability](https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#development) in its README.
74 * **Second PR** should include the concrete implementation of the component. If the
75 size of this PR is larger than the recommended size consider splitting it into
76 multiple PRs.
77 * **Last PR** should mark the new component as `Alpha` stability and add it to the `otelcorecol`
78 binary by updating the `otelcorecol/components.go` file. The component must be enabled
79 only after sufficient testing and only when it meets [`Alpha` stability requirements.](https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#alpha)
80 * Once a new component has been added to the executable, please add the component
81 to the [OpenTelemetry.io registry](https://github.com/open-telemetry/opentelemetry.io#adding-a-project-to-the-opentelemetry-registry).
82 * intra-repository `replace` statements in `go.mod` files can be automatically inserted by running `make crosslink`. For more information
83 on the `crosslink` tool see the README [here](https://github.com/open-telemetry/opentelemetry-go-build-tools/tree/main/crosslink).
84
85 ### Refactoring Work
86
87 Any refactoring work must be split in its own PR that does not include any
88 behavior changes. It is important to do this to avoid hidden changes in large
89 and trivial refactoring PRs.
90
91 ## Report a bug or request a feature
92
93 Reporting bugs is an important contribution. Please make sure to include:
94
95 * Expected and actual behavior
96 * The OpenTelemetry version you are running
97 * If possible, steps to reproduce
98
99 ### Adding Labels via Comments
100
101 In order to facilitate proper label usage and to empower Code Owners, you are able to add labels to issues via comments. To add a label through a comment, post a new comment on an issue starting with `/label`, followed by a space-separated list of your desired labels. Supported labels come from the table below, or correspond to a component defined in the [CODEOWNERS file](.github/CODEOWNERS).
102
103 The following general labels are supported:
104
105 | Label | Label in Comment |
106 |--------------------------|--------------------------|
107 | `arm64` | `arm64` |
108 | `good first issue` | `good-first-issue` |
109 | `help wanted` | `help-wanted` |
110 | `discussion needed` | `discussion-needed` |
111 | `os:macos` | `os:macos` |
112 | `os:windows` | `os:windows` |
113 | `waiting for author` | `waiting-for-author` |
114 | `waiting-for-codeowners` | `waiting-for-codeowners` |
115 | `bug` | `bug` |
116 | `priority:p0` | `priority:p0` |
117 | `priority:p1` | `priority:p1` |
118 | `priority:p2` | `priority:p2` |
119 | `priority:p3` | `priority:p3` |
120 | `Stale` | `stale` |
121
122 To delete a label, prepend the label with `-`. Note that you must make a new comment to modify labels; you cannot edit an existing comment.
123
124 Example label comment:
125
126 ```
127 /label help-wanted -arm64
128 ```
129
130 ## How to contribute
131
132 ### Before you start
133
134 Please read the project contribution
135 [guide](https://github.com/open-telemetry/community/tree/main/guides/contributor)
136 for general practices for the OpenTelemetry project.
137
138 Select a good issue from the links below (ordered by difficulty/complexity):
139
140 * [Good First Issue](https://github.com/open-telemetry/opentelemetry-collector/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)
141 * [Help Wanted](https://github.com/open-telemetry/opentelemetry-collector/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22)
142
143 Comment on the issue that you want to work on so we can assign it to you and
144 clarify anything related to it.
145
146 If you would like to work on something that is not listed as an issue
147 (e.g. a new feature or enhancement) please first read our [vision](docs/vision.md)
148 to make sure your proposal aligns with the goals of the
149 Collector, then create an issue and describe your proposal. It is best to do this
150 in advance so that maintainers can decide if the proposal is a good fit for
151 this repository. This will help avoid situations when you spend significant time
152 on something that maintainers may decide this repo is not the right place for.
153
154 If you're new to the Collector, the [internal architecture](docs/internal-architecture.md) documentation may be helpful.
155
156 Follow the instructions below to create your PR.
157
158 ### Fork
159
160 In the interest of keeping this repository clean and manageable, you should
161 work from a fork. To create a fork, click the 'Fork' button at the top of the
162 repository, then clone the fork locally using `git clone
163 [email protected]:USERNAME/opentelemetry-collector.git`.
164
165 You should also add this repository as an "upstream" repo to your local copy,
166 in order to keep it up to date. You can add this as a remote like so:
167
168 `git remote add upstream https://github.com/open-telemetry/opentelemetry-collector.git`
169
170 Verify that the upstream exists:
171
172 `git remote -v`
173
174 To update your fork, fetch the upstream repo's branches and commits, then merge
175 your `main` with upstream's `main`:
176
177 ```
178 git fetch upstream
179 git checkout main
180 git merge upstream/main
181 ```
182
183 Remember to always work in a branch of your local copy, as you might otherwise
184 have to contend with conflicts in `main`.
185
186 Please also see [GitHub
187 workflow](https://github.com/open-telemetry/community/blob/main/guides/contributor/processes.md#github-workflow)
188 section of the general project contributing guide.
189
190 ## Required Tools
191
192 Working with the project sources requires the following tools:
193
194 1. [git](https://git-scm.com/)
195 2. [go](https://golang.org/) (version 1.24 and up)
196 3. [make](https://www.gnu.org/software/make/)
197 4. [docker](https://www.docker.com/)
198
199 ## Repository Setup
200
201 Fork the repo and checkout the upstream repo to your GOPATH by:
202
203 ```
204 $ git clone [email protected]:open-telemetry/opentelemetry-collector.git
205 ```
206
207 Add your fork as an origin:
208
209 ```shell
210 $ cd opentelemetry-collector
211 $ git remote add fork [email protected]:YOUR_GITHUB_USERNAME/opentelemetry-collector.git
212 ```
213
214 Run tests, fmt, and lint:
215
216 ```shell
217 $ make
218 ```
219
220 ## Creating a PR
221
222 Checkout a new branch, make modifications, build locally, and push the branch to your fork
223 to open a new PR:
224
225 ```shell
226 $ git checkout -b feature
227 # edit
228 $ make
229 $ make fmt
230 $ git commit
231 $ git push fork feature
232 ```
233
234 ### Commit Messages
235
236 Use descriptive commit messages. Here are [some recommendations](https://cbea.ms/git-commit/)
237 on how to write good commit messages.
238 When creating PRs GitHub will automatically copy commit messages into the PR description,
239 so it is a useful habit to write good commit messages before the PR is created.
240 Also, unless you actually want to tell a story with multiple commits make sure to squash
241 into a single commit before creating the PR.
242
243 When maintainers merge PRs with multiple commits, they will be squashed and GitHub will
244 concatenate all commit messages right before you hit the "Confirm squash and merge"
245 button. Maintainers must make sure to edit this concatenated message to make it right before merging.
246 In some cases, if the commit messages are lacking the easiest approach to have at
247 least something useful is copy/pasting the PR description into the commit message box
248 before merging (but see the above paragraph about writing good commit messages in the first place).
249
250 ## General Notes
251
252 This project uses Go 1.24.* and [Github Actions.](https://github.com/features/actions)
253
254 It is recommended to run `make gofmt all` before submitting your PR.
255
256 ## Coding Guidelines
257
258 See the [Coding Guidelines](docs/coding-guidelines.md) document for more information.
259
260 ## Changelog
261
262 ### Overview
263
264 There are two Changelogs for this repository:
265
266 - `CHANGELOG.md` is intended for users of the collector and lists changes that affect the behavior of the collector.
267 - `CHANGELOG-API.md` is intended for developers who are importing packages from the collector codebase.
268
269 ### When to add a Changelog Entry
270
271 An entry into the changelog is required for the following reasons:
272
273 - Changes made to the behaviour of the component
274 - Changes to the configuration
275 - Changes to default settings
276 - New components being added
277 - Changes to exported elements of a package
278
279 It is reasonable to omit an entry to the changelog under these circumstances:
280
281 - Updating test to remove flakiness or improve coverage
282 - Updates to the CI/CD process
283 - Updates to internal packages
284
285 If there is some uncertainty with regards to if a changelog entry is needed, the recommendation is to create
286 an entry to in the event that the change is important to the project consumers.
287
288 ### Adding a Changelog Entry
289
290 The [CHANGELOG.md](./CHANGELOG.md) and [CHANGELOG-API.md](./CHANGELOG-API.md) files in this repo is autogenerated from `.yaml` files in the `./.chloggen` directory.
291
292 Your pull request should add a new `.yaml` file to this directory. The name of your file must be unique since the last release.
293
294 During the collector release process, all `./chloggen/*.yaml` files are transcribed into `CHANGELOG.md` and `CHANGELOG-API.md` and then deleted.
295
296 **Recommended Steps**
297 1. Create an entry file using `make chlog-new`. This generates a file based on your current branch (e.g. `./.chloggen/my-branch.yaml`)
298 2. Fill in all fields in the new file
299 3. Run `make chlog-validate` to ensure the new file is valid
300 4. Commit and push the file
301
302 Alternatively, copy `./.chloggen/TEMPLATE.yaml`, or just create your file from scratch.
303
304 ## Local Testing
305
306 To manually test your changes, follow these steps to build and run the Collector
307 locally. Ensure that you execute these commands from the root of the repository:
308
309 1. Build the Collector:
310
311 ```shell
312 make otelcorecol
313 ```
314
315 2. Run the Collector with a local configuration file:
316
317 ```shell
318 ./bin/otelcorecol_<os>_<arch> --config ./examples/local/otel-config.yaml
319 ```
320
321 The actual name of the binary will depend on your platform, adjust accordingly
322 (e.g., `./bin/otelcorecol_darwin_arm64`).
323
324 Replace `otel-config.yaml` with the appropriate configuration file as needed.
325
326 3. Verify that your changes are reflected in the Collector's behavior by testing
327 it against the provided configuration.
328
329 ## Membership, Roles, and Responsibilities
330
331 ### Membership levels
332
333 See the [OpenTelemetry membership guide](https://github.com/open-telemetry/community/blob/main/guides/contributor/membership.md) for information on how to become a member of the OpenTelemetry organization and the different roles available. In addition to the roles listed there we also have a Collector-specific role: code owners.
334
335 ### Becoming a Code Owner
336
337 A Code Owner is responsible for one or multiple packages within the Collector. That responsibility includes maintaining the component, triaging and responding to issues, and reviewing pull requests.
338 Maintainers are expected to seek feedback from code owners for changes that are not trivial, but they may merge PRs without code owner approval.
339
340 Code Ownership does not have to be a full-time job. If you can find a couple hours to help out on a recurring basis, please consider pursuing Code Ownership.
341
342 #### Requirements
343
344 If you would like to help and become a Code Owner, you must meet the following requirements. These are more stringent requirements than those in the opentelemetry-collector-contrib repository due to the higher impact of changes in this repository:
345
346 1. [Be a member of the OpenTelemetry organization](https://github.com/open-telemetry/community/blob/main/guides/contributor/membership.md#member).
347 2. Be an existing [approver](https://github.com/open-telemetry/community/blob/main/guides/contributor/membership.md#approver) or [maintainer](https://github.com/open-telemetry/community/blob/main/guides/contributor/membership.md#maintainer) in at least one repository within the OpenTelemetry Github organization.
348 3. Have made significant contributions directly to the package you want to own.
349
350 #### How to become a Code Owner
351
352 To become a Code Owner, open a PR that adds you to the [.github/CODEOWNERS](.github/CODEOWNERS) file. Make sure to ping existing code owners for the package you want to own to get their approval.
353
354 ## Release
355
356 See [release](docs/release.md) for details.
357
358 ## Contributing Images
359 If you are adding any new images, please use [Excalidraw](https://excalidraw.com). It's a free and open-source web application and doesn't require any account to get started. Once you've created the design, while exporting the image, make sure to tick **"Embed scene into exported file"** option. This allows the image to be imported in an editable format for other contributors later.
360
361 ## Common Issues
362
363 Build fails due to dependency issues, e.g.
364
365 ```sh
366 go: github.com/golangci/[email protected] requires
367 github.com/tommy-muehle/[email protected]: invalid pseudo-version: git fetch --unshallow -f origin in /root/go/pkg/mod/cache/vcs/053b1e985f53e43f78db2b3feaeb7e40a2ae482c92734ba3982ca463d5bf19ce: exit status 128:
368 fatal: git fetch-pack: expected shallow list
369 ```
370
371 `go env GOPROXY` should return `https://proxy.golang.org,direct`. If it does not, set it as an environment variable:
372
373 `export GOPROXY=https://proxy.golang.org,direct`
374
375 ### Makefile Guidelines
376
377 When adding or modifying the `Makefile`'s in this repository, consider the following design guidelines.
378
379 Make targets are organized according to whether they apply to the entire repository, or only to an individual module.
380 The [Makefile](./Makefile) SHOULD contain "repo-level" targets. (i.e. targets that apply to the entire repo.)
381 Likewise, `Makefile.Common` SHOULD contain "module-level" targets. (i.e. targets that apply to one module at a time.)
382 Each module should have a `Makefile` at its root that includes `Makefile.Common`.
383
384 #### Module-level targets
385
386 Module-level targets SHOULD NOT act on nested modules. For example, running `make lint` at the root of the repo will
387 _only_ evaluate code that is part of the `go.opentelemetry.io/collector` module. This excludes nested modules such as
388 `go.opentelemetry.io/collector/component`.
389
390 Each module-level target SHOULD have a corresponding repo-level target. For example, `make golint` will run `make lint`
391 in each module. In this way, the entire repository is covered. The root `Makefile` contains some "for each module" targets
392 that can wrap a module-level target into a repo-level target.
393
394 #### Repo-level targets
395
396 Whenever reasonable, targets SHOULD be implemented as module-level targets (and wrapped with a repo-level target).
397 However, there are many valid justifications for implementing a standalone repo-level target.
398
399 1. The target naturally applies to the repo as a whole. (e.g. Building the collector.)
400 2. Interaction between modules would be problematic.
401 3. A necessary tool does not provide a mechanism for scoping its application. (e.g. `porto` cannot be limited to a specific module.)
402 4. The "for each module" pattern would result in incomplete coverage of the codebase. (e.g. A target that scans all files, not just `.go` files.)
403
404 #### Default targets
405
406 The default module-level target (i.e. running `make` in the context of an individual module), should run a substantial set of module-level
407 targets for an individual module. Ideally, this would include *all* module-level targets, but exceptions should be made if a particular
408 target would result in unacceptable latency in the local development loop.
409
410 The default repo-level target (i.e. running `make` at the root of the repo) should meaningfully validate the entire repo. This should include
411 running the default common target for each module as well as additional repo-level targets.
412
413 ## How to update the OTLP protocol version
414
415 When a new OTLP version is published, the following steps are required to update this code base:
416
417 1. Edit the top-level Makefile's `OPENTELEMETRY_PROTO_VERSION` variable
418 2. Run `make genproto`
419 3. Inspect modifications to the generated code in `pdata/internal/data/protogen`
420 4. When new fields are added in the protocol, make corresponding changes in `pdata/internal/cmd/pdatagen/internal`
421 5. Run `make genpdata`
422 6. Inspect modifications to the generated code in `pdata/*`
423 7. Run `make genproto-cleanup`, to remove temporary files
424 8. Update the supported OTLP version in [README.md](./README.md).
425
426 ## Exceptions
427
428 While the rules in this and other documents in this repository are what we strive to follow, we acknowledge that it may be unfeasible to apply these rules in some situations. Exceptions to the rules
429 on this and other documents are acceptable if consensus can be obtained from approvers in the pull request they are proposed.
430 A reason for requesting the exception MUST be given in the pull request. Until unanimity is obtained, approvers and maintainers are
431 encouraged to discuss the issue at hand. If a consensus (unanimity) cannot be obtained, the maintainers' group is then tasked with making a
432 decision using its regular means (voting, TC help, etc.).