> ## Documentation Index
> Fetch the complete documentation index at: https://docs.localdev.build/llms.txt
> Use this file to discover all available pages before exploring further.

# Custom collectors

> Create your own custom collector

A custom collector replaces the `localdevcollector` binary with one you build yourself. This page lists what it must contain, and shows how to build and use it. It assumes you know the OpenTelemetry Collector.

Localdev still generates the collector's configuration, so your collector runs the same pipeline as `localdevcollector` (see [Use it in your project](#use-it-in-your-project)).

> [!WARNING]
>
> Adding your own components to that pipeline, for example by passing a second `--config` in `collector.command`, hasn't been tested.

## Default configuration for Localdev's collector

`localdevcollector` is built with the [OpenTelemetry Collector Builder](https://opentelemetry.io/docs/collector/custom-collector/) (OCB) 0.165.0 from
[`builder-config.yaml`](https://github.com/localdev-build/localdev/blob/main/builder-config.yaml) in the Localdev repository.
It contains a minimal set of components, shown below, which may not be enough for your needs.

```yaml builder-config.yaml theme={null}
dist:
  name: localdevcollector
  description: Localdev OTel Collector distribution for Developers
  output_path: ./collector

exporters:
  - gomod:
      # NOTE: Prior to v0.86.0 use the `loggingexporter` instead of `debugexporter`.
      go.opentelemetry.io/collector/exporter/debugexporter v0.165.0
  - gomod: go.opentelemetry.io/collector/exporter/otlpexporter v0.165.0

processors:
  - gomod: go.opentelemetry.io/collector/processor/batchprocessor v0.165.0

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

providers:
  - gomod: go.opentelemetry.io/collector/confmap/provider/envprovider v1.71.0
  - gomod: go.opentelemetry.io/collector/confmap/provider/fileprovider v1.71.0
  - gomod: go.opentelemetry.io/collector/confmap/provider/httpprovider v1.71.0
  - gomod: go.opentelemetry.io/collector/confmap/provider/httpsprovider v1.71.0
  - gomod: go.opentelemetry.io/collector/confmap/provider/yamlprovider v1.71.0
```

## Requirements

Localdev generates the collector's configuration, so your collector must contain at least these components:

| Kind | Component | Name in the configuration |
| - | - | - |
| Receiver | `otlpreceiver` | `otlp` |
| Processor | `batchprocessor` | `batch` |
| Exporter | `otlpexporter` | `otlp_grpc` |
| Exporter | `debugexporter` | `debug` |

Build it with **OCB 0.165.0 or newer**. The generated configuration uses the `otlp_grpc` exporter name, which older versions don't recognise.

## Build your own collector

1. Download OCB for your platform. The release assets are named `ocb_<version>_<darwin|linux>_<amd64|arm64>`:

   ```sh theme={null}
   V=0.165.0
   curl --proto '=https' --tlsv1.2 -fL -o ocb \
     "https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/cmd%2Fbuilder%2Fv${V}/ocb_${V}_darwin_arm64"
   chmod +x ocb
   ```

2. Copy the `builder-config.yaml` above, change `dist.name` and `dist.output_path`, and add your components.

3. Build it:

   ```sh theme={null}
   ./ocb --config builder-config.yaml
   ```

## Use it in your project

Point `collector.command` in the Projectfile to your collector:

```yaml theme={null}
collector:
    command: /absolute/path/to/mycollector
services:
    api:
        command: ./main
```

* Use an absolute path, or a name found on `PATH`. A relative path is resolved from the directory you run `ldev` in, not the Projectfile's directory.
* Localdev adds `--config=<generated file>` to your command. Other arguments in `command` are kept, and are split the same way as a service's [`command`](https://docs.localdev.build/configuration/introduction#how-command-is-run).

The generated configuration:

* Receives OTLP gRPC on `localhost:4998` and OTLP HTTP on `localhost:4999`, or on the ports in [`collector.receivers`](https://docs.localdev.build/configuration/introduction#collector).
* Sends traces, metrics and logs through `batch` and exports them over OTLP gRPC to Localdev (`-collector-address`, `localhost:50000` by default), without TLS.
* Can't be replaced from the Projectfile. You can see its path in the UI under **Project → Collector**.

The collector's own log is `localdevcollector-out.log` in Localdev's temporary directory.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.