Skip to content
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

Adding a "HOW-TO: Building your own collector" tutorial to the collector #1277

Merged
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a36de61
Adding a "HOW-TO: Building your own collector" tutorial to the collec…
rquedas Apr 5, 2022
51556ac
Update content/en/docs/collector/howto-custom-collector.md
rquedas Apr 8, 2022
600673f
Update content/en/docs/collector/howto-custom-collector.md
rquedas Apr 8, 2022
df00046
Update content/en/docs/collector/howto-custom-collector.md
rquedas Apr 8, 2022
4a5077b
Update content/en/docs/collector/howto-custom-collector.md
rquedas Apr 8, 2022
7dc73f1
Update content/en/docs/collector/howto-custom-collector.md
rquedas Apr 8, 2022
b85ac5a
Implementing @svrnm recommendations.
rquedas Apr 18, 2022
7d3d01b
Merge branch 'doc-collector-howto-custom-collector' of https://github…
rquedas Apr 18, 2022
71363d6
Update content/en/docs/collector/howto-custom-collector.md
rquedas Apr 18, 2022
2060068
Update content/en/docs/collector/howto-custom-collector.md
rquedas Apr 18, 2022
00e0fd2
Adding a "HOW-TO: Building your own collector" tutorial to the collec…
rquedas Apr 5, 2022
2243631
Implementing @svrnm recommendations.
rquedas Apr 18, 2022
97c79ea
Merge branch 'doc-collector-howto-custom-collector' of https://github…
rquedas Apr 18, 2022
9956e23
Implementing changes to support suggestions.
rquedas Apr 26, 2022
dd02cdf
Merge branch 'doc-collector-howto-custom-collector' of https://github…
rquedas Apr 26, 2022
eea50f6
update for "v0.53.0"
rquedas Jun 13, 2022
84f0ee9
Update content/en/docs/collector/howto-custom-collector.md
rquedas Jun 17, 2022
1130c7e
Update content/en/docs/collector/howto-custom-collector.md
rquedas Jun 17, 2022
8fb7711
Update content/en/docs/collector/howto-custom-collector.md
rquedas Jun 17, 2022
a81f75e
Update content/en/docs/collector/howto-custom-collector.md
rquedas Jun 17, 2022
104443c
Update content/en/docs/collector/howto-custom-collector.md
rquedas Jun 17, 2022
d478359
Update content/en/docs/collector/howto-custom-collector.md
rquedas Jun 17, 2022
89795a3
Rename file to match siblings
chalin Jun 28, 2022
c06a00a
Prettify markdown
chalin Jun 28, 2022
25fbcfe
More page tweaks
chalin Jun 28, 2022
cd427fd
removing the help output.
rquedas Jun 30, 2022
814fc68
Update title and weight
chalin Jun 30, 2022
5223d41
Run prettifier
chalin Jun 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions content/en/docs/collector/howto-custom-collector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# HOW-TO: Build your own Collector instance

If you are planning to build and debug your components, you are going to need your own Collector instance. That will allow you to launch and debug your Collector components directly within your favorite Golang IDE.

The other really cool aspect of approaching the component development this way is that you can use all the cool debugging features from your IDE (stack traces are great teachers!) to understand how the Collector itself interacts with your component code.

In order to me it easy for developers to create their own custom builds of the Collector, the OpenTelemetry Community has developed a tool called `OpenTelemetry Collector Builder`.

The `builder` is meant to help developers to quickly assemble and build their own collector's distributions, based on a given configuration file.

As part of the process the `builder` will generate the collector's source code, which you can borrow and steal as your own to help build and debug your own components, so let's get started.

## Step 1 - Install the builder

You can easily install the builder through the go install command.

Open your terminal and type:

```
go install go.opentelemetry.io/collector/cmd/builder@latest
```

The `builder` command will be installed on your `$GOPATH/bin`, which most likely is already added to your path.

To make sure it's there, go to your terminal and type `builder help`, and once you hit enter you should have the following output:

```

OpenTelemetry Collector distribution builder (dev)

Usage:
builder [flags]
builder [command]

Available Commands:
completion Generate the autocompletion script for the specified shell
help Help about any command
version Version of opentelemetry-collector-builder

Flags:
--config string config file (default is $HOME/.otelcol-builder.yaml)
--description string A descriptive name for the OpenTelemetry Collector distribution (default "Custom OpenTelemetry Collector distribution")
--go string The Go binary to use during the compilation phase. Default: go from the PATH
-h, --help help for builder
--module string The Go module for the new distribution (default "go.opentelemetry.io/collector/cmd/builder")
--name string The executable name for the OpenTelemetry Collector distribution (default "otelcol-custom")
--otelcol-version string Which version of OpenTelemetry Collector to use as base (default "0.42.0")
--output-path string Where to write the resulting files (default "/var/folders/86/s7l1czb16g124tng0d7wyrtw0000gn/T/otelcol-distribution3618633831")
--skip-compilation Whether builder should only generate go code with no compile of the collector (default false)
--version string The version for the OpenTelemetry Collector distribution (default "1.0.0")

Use "builder [command] --help" for more information about a command.
```

## Step 2 - Create a builder config file

The builder config file is a `yaml` where you basically pass information about the code generation and compile process combined with the components that you would like to add to your collector's distribution.

Go ahead and create a `builder-config.yaml` with the following content:

> builder-config.yaml
```yaml
dist:
module: github.com/open-telemetry/opentelemetry-collector # the module name for the new distribution, following Go mod conventions. Optional, but recommended.
name: otelcol-mybuild # the binary name. Optional.
description: "Custom OpenTelemetry Collector distribution" # a long name for the application. Optional.
otelcol_version: "0.41.0" # the OpenTelemetry Collector version to use as base for the distribution. Optional.
output_path: ./otelcol-mybuild # the path to write the output (sources and binary). Optional.
version: "1.0.0" # the version for your custom OpenTelemetry Collector. Optional.
go: "/usr/local/go/bin/go" # which Go binary to use to compile the generated sources. Optional.
exporters:
- gomod: "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/jaegerexporter v0.41.0"
- import: go.opentelemetry.io/collector/exporter/loggingexporter
gomod: go.opentelemetry.io/collector v0.41.0

receivers:
- import: go.opentelemetry.io/collector/receiver/otlpreceiver
gomod: go.opentelemetry.io/collector v0.41.0

processors:
- import: go.opentelemetry.io/collector/processor/batchprocessor
gomod: go.opentelemetry.io/collector v0.41.0
```

For more information on how to create your builder config file, checkout [OpenTelemetry Collector builder](https://github.com/open-telemetry/opentelemetry-collector/tree/main/cmd/builder) folder inside the Collector's project in GitHub.

## Step 3 - Generating the Code and Building your Collector's distribution.

All you need now is to let the `builder` do it's job, so go to your terminal and type the following command:

```
builder --config builder-config.yaml
```

If everything went well, here is what the output of the command should look like:

```

2022-01-13T10:21:01.777-0600 INFO internal/command.go:82 OpenTelemetry Collector distribution builder {"version": "dev", "date": "unknown"}
2022-01-13T10:21:01.779-0600 INFO internal/command.go:102 Using config file {"path": "builder-config.yaml"}
2022-01-13T10:21:02.239-0600 INFO builder/config.go:103 Using go {"go-executable": "/usr/local/go/bin/go"}
2022-01-13T10:21:02.239-0600 INFO builder/main.go:52 You're building a distribution with non-aligned version of the builder. Compilation may fail due to API changes. Please upgrade your builder or API {"builder-version": "0.42.0"}
2022-01-13T10:21:02.241-0600 INFO builder/main.go:76 Sources created{"path": "./otelcol-mybuild"}
2022-01-13T10:21:02.841-0600 INFO builder/main.go:108 Getting go modules
2022-01-13T10:21:03.131-0600 INFO builder/main.go:87 Compiling
2022-01-13T10:21:07.816-0600 INFO builder/main.go:94 Compiled {"binary": "./otelcol-mybuild/otelcol-mybuild"}

```

As defined in the `dist` section of your config file, you now have a folder named `otelcol-mybuild` containing all the source code and the binary for your collector's distribution.

You can now use the generated code to bootstrap your component development projects and easily build and distribute your own collector distribution with your components.