This directory contains the build configuration and generated code for the Alloy Collector Distro, an OpenTelemetry Collector distribution that embeds Alloy's OTel components and integrates with the Alloy CLI. This also means that it contains the generated build root of the Alloy project.
The Alloy Collector Distro is built using the OpenTelemetry Collector Builder (OCB) tool. Components are defined in an OCB configuration file, and the build process generates the necessary Go code, including the main.go file and go.mod dependencies.
collector/
├── builder-config.yaml # OCB configuration file (source)
├── generate.go # Entry point for code generation (source)
├── version.go # Exposes the current version of the collector distro (source)
├── generator/ # Custom templating and generation code (source)
│ ├── generator.go # Generator tool that post-processes OCB output
│ └── main_alloy.tpl # Template for main_alloy.go
│
├── main.go # Generated by OCB (DO NOT EDIT)
├── main_alloy.go # Generated by generator (DO NOT EDIT)
├── main_others.go # Generated by OCB (DO NOT EDIT)
├── main_windows.go # Generated by OCB (DO NOT EDIT)
├── components.go # Generated by OCB (DO NOT EDIT)
├── go.mod # Generated by OCB (DO NOT EDIT)
└── go.sum # Generated by OCB (DO NOT EDIT)
The build process consists of three main steps:
The BUILDER_VERSION is defined in the root Makefile, and should be kept in sync with our general OTel component versioning
The OCB tool reads builder-config.yaml and generates:
main.go- The main entry point for the collectorcomponents.go- Component factories and registrationsgo.modandgo.sum- Module dependencies- Other platform-specific main files (
main_others.go,main_windows.go)
The builder-config.yaml file defines:
- General collector distribution metadata
- The Open Telemetry components to include in the distribution (receivers/processors/exporters etc)
- Replace directives, which are automated/generated to keep in sync with
dependency-replacements.yamlin the root of the project
Ensures the generated go.mod is properly formatted and all dependencies are resolved.
The custom generator performs two tasks:
- Generates
main_alloy.go- Creates a wrapper that integrates the OTel collector command into Alloy's CLI as a subcommand (alloy otel) - Modifies
main.go- Replacesotelcol.NewCommand(params)withnewAlloyCommand(params)to use the Alloy-integrated command
make alloy runs the code generation steps described above automatically before building. Generation is skipped when SKIP_CODE_GENERATION=1 is set.
To regenerate only (without building):
make generate-otel-collector-distroTo build without regenerating:
SKIP_CODE_GENERATION=1 make alloyIf your work involves anything that would modify the generated files, please commit them with your changes before pushing to github. We have a github workflow that will check that the output of the collector generation matches what has been checked in, and this will fail if you do not include changes to these files.
The replaces section in builder-config.yaml must be kept in sync with the replace directives in the root go.mod file as well as the go.mod file in the alloy engine extension. The Alloy project uses the dependency-replacements.yaml file found in the root of the project to generate replace directives. If you modify a replacement, please run make generate-module-dependencies to sync things up. There is also a github workflow that will check against this.