Skip to content

Doc/go tool for builder #12990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

DoppleDankster
Copy link

@DoppleDankster DoppleDankster commented May 7, 2025

Description

go get --tool`added with go 1.24 helps ensuring compatibility between the builder CLI and the libs imported in a go project using OTEL.

Issue Link

Resolves #12973

Testing

create a simple OTEL extension and compile it with go tool builder --config=builder-config.yaml

Documentation

Updated Documentation with mention of the go get --tooladded with go 1.24.

@DoppleDankster DoppleDankster requested a review from a team as a code owner May 7, 2025 13:03
Copy link

linux-foundation-easycla bot commented May 7, 2025

CLA Missing ID CLA Not Signed

Copy link
Contributor

@jade-guiton-dd jade-guiton-dd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR! I have a few comments before we can get this merged.

@@ -42,3 +42,5 @@ retract (
v0.57.1 // Release failed, use v0.57.2
v0.57.0 // Release failed, use v0.57.2
)

tool go.opentelemetry.io/collector/cmd/builder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it makes sense to add OCB as a tool in its own mod file? My assumption is that this would only be useful if we use the builder to build the builder.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't have enough knowledge about OTEL to answer that question.

It's my first time using the OCB, i was fighting for a couple hours with binary versions and when i though about go tool and noticed how good the experience was i came here to open an issue and a PR.

This should be discussed separately i think

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW about your other comment about running the go get --tool,
i've cleaned up all my deps and my cache just in case and it's working just fine.

i'm using:

  • go version go1.24.0 darwin/arm64
  • go version go1.24.2 linux/amd64

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I tried creating a brand new Go project and go get --tools works, whereas it doesn't work in my existing project. It seems like the existing dependencies can interfere with it; maybe we should call this out?

Copy link
Contributor

@jade-guiton-dd jade-guiton-dd May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding this line, I think we should remove it from the PR. The tool directive only makes sense in the module where we plan to use the tool.

Comment on lines 116 to 133
### `go get --tool` (go version >= 1.24)

You need to have a `go` compiler in your PATH as well as a go project.

Run the following command to register the `builder` CLI as a go tool.

```console
go get --tool go.opentelemetry.io/collector/cmd/builder
```

If Installed through this method, the binary can be called with `go tool builder` (only accessible from within your go project)

The upside of using `go get --tool` over the other aforementioned method is that the go toolchain manages the binary like any other dependency.

This has a couple upsides:

- Your imports of otel libraries such as otel-core within your code will use the same version used to build the `builder` binary ensuring compatibility.
- Different go projects using different versions will use different `builder` managed automatically instead of forcing the user to download multiple versions of the binary.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: A few formatting suggestions:

Suggested change
### `go get --tool` (go version >= 1.24)
You need to have a `go` compiler in your PATH as well as a go project.
Run the following command to register the `builder` CLI as a go tool.
```console
go get --tool go.opentelemetry.io/collector/cmd/builder
```
If Installed through this method, the binary can be called with `go tool builder` (only accessible from within your go project)
The upside of using `go get --tool` over the other aforementioned method is that the go toolchain manages the binary like any other dependency.
This has a couple upsides:
- Your imports of otel libraries such as otel-core within your code will use the same version used to build the `builder` binary ensuring compatibility.
- Different go projects using different versions will use different `builder` managed automatically instead of forcing the user to download multiple versions of the binary.
### `go get --tool` (Go version >= 1.24)
You need to have a `go` compiler in your PATH, as well as a Go project containing a `go.mod` file.
Run the following command to register the `builder` CLI as a Go tool.
```console
go get --tool go.opentelemetry.io/collector/cmd/builder
```
If Installed through this method, the binary can be called with `go tool builder`. Note that it will only be accessible from within your Go project.
The upside of using `go get --tool` over the other aforementioned method is that the Go toolchain manages the binary like any other dependency.
This has a couple upsides:
- Imports of OTel libraries such as opentelemetry-collector within your code will use the same version used to build the `builder` binary, ensuring compatibility.
- Different Go projects using different versions will use different `builder` managed automatically instead of forcing the user to download multiple versions of the binary.

Copy link
Author

@DoppleDankster DoppleDankster May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go get --tool (Go version >= 1.24)

i meant go version as like writting in your terminal go version so i think i'd like to keep it as it is i think ? ( no strong opinion though, feel free to request a change nonetheless if you disagree).


i'm fine with your other points :)

Copy link
Contributor

@jade-guiton-dd jade-guiton-dd May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that works. Maybe put it in an inline monospace block to emphasize the fact that it's a command?

@jade-guiton-dd
Copy link
Contributor

This may be a setup issue on my part, but I tried running go get --tool go.opentelemetry.io/collector/cmd/builder, and got an error about an ambiguous import (github.com/knadh/koanf/maps module vs. maps package in github.com/knadh/koanf module). This doesn't seem to happen when using go install. Does the command work on your end?

David Medioni added 4 commits May 8, 2025 14:26
- Use the  method
- Updated the versions of the libs to the latest current version
- wording in go install section
- Moved the ocb --help line to the released binary section
@DoppleDankster DoppleDankster force-pushed the doc/go-tool-for-builder branch from ab9826d to 387a016 Compare May 8, 2025 12:30
@DoppleDankster
Copy link
Author

i've pushed your change requests, if you have further comments please go ahead :)

Comment on lines +126 to +128
If Installed through this method, the binary can be called with `go tool builder`. Note that it will only be accessible from within your Go project.

The upside of using `go get --tool` over the other aforementioned method is that the go toolchain manages the binary like any other dependency.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two more suggestions, to make clear what "managed like any other dependency" means.

Suggested change
If Installed through this method, the binary can be called with `go tool builder`. Note that it will only be accessible from within your Go project.
The upside of using `go get --tool` over the other aforementioned method is that the go toolchain manages the binary like any other dependency.
If installed through this method, the binary can be called with `go tool builder`. Note that it will only be accessible from within your Go project.
The upside of using `go get --tool` over the other aforementioned method is that the go toolchain manages the binary like any other dependency: a `tool` directive will be added to your `go.mod` file.

@jade-guiton-dd
Copy link
Contributor

Thank you for the changes, this seems almost ready! In the meantime, could you please make sure to sign the CLA?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use the go tool directive from go 1.24 to help when compiling the OCB
2 participants