# OpenTelemetry Collector Builder (ocb) This program generates a custom OpenTelemetry Collector binary based on a given configuration. ## TL;DR ```console $ go install go.opentelemetry.io/collector/cmd/builder@v0.129.0 $ cat > otelcol-builder.yaml < /tmp/otelcol.yaml < github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.128.0 ``` The builder also allows setting the scheme to use as the default URI scheme via `conf_resolver.default_uri_scheme`: ```yaml conf_resolver: default_uri_scheme: "env" ``` This tells the builder to produce a Collector that uses the `env` scheme when expanding configuration that does not provide a scheme, such as `${HOST}` (instead of doing `${env:HOST}`). ## Steps The builder has 3 steps: * Generate: generates the golang source code * Get modules: generates the go.mod file based on the imported modules in the generated golang source code * Compilation: builds the OpenTelemetry Collector executable Each step can be skipped independently: `--skip-generate`, `--skip-get-modules` and `--skip-compilation`. For instance, a code generation step could execute ```console ocb --skip-compilation --config=config.yaml ``` then commit the code in a git repo. A CI can sync the code and execute ```console ocb --skip-generate --skip-get-modules --config=config.yaml ``` to only execute the compilation step. ### Strict versioning checks The builder checks the relevant `go.mod` file for the following things after `go get`ing all components and calling `go mod tidy`: 1. The `dist::otelcol_version` field in the build configuration must have matching major and minor versions as the core library version calculated by the Go toolchain, considering all components. A mismatch could happen, for example, when the builder or one of the components depends on a newer release of the core collector library. 2. For each component in the build configuration, the major and minor versions included in the `gomod` module specifier must match the one calculated by the Go toolchain, considering all components. A mismatch could happen, for example, when the enclosing Go module uses a newer release of the core collector library. The `--skip-strict-versioning` flag disables these versioning checks. This flag is available temporarily and **will be removed in a future minor version**. ### Cgo disabled by default By default, the OpenTelemetry Collector binary is built with `CGO_ENABLED=0` in accordance with how the official OpenTelemetry Collector releases are built. This can be overridden by adding the following configuration option to the `dist` section of the builder configuration file: ```yaml dist: cgo_enabled: true ```