Skip to content

OpenTelemetry Collector

DockerOtelCollector adds an OpenTelemetry Collector to a Compose project. The collector config is declared with the otel lexicon and rendered with collectorYaml(). The composite carries the rendered YAML inline in a top-level Compose config and mounts it into the service at /etc/otel/config.yaml, so there is no config file to keep next to docker-compose.yml.

import { Service, DockerOtelCollector } from "@intentius/chant-lexicon-docker";
import { OtlpExporter, type TLSClientSettings } from "@intentius/chant-lexicon-otel";
const jaeger = new Service({ image: "jaegertracing/all-in-one:1.62.0", ports: ["16686:16686"] });
const plaintext: TLSClientSettings = { insecure: true };
const otel = DockerOtelCollector({
exporters: [new OtlpExporter({ name: "jaeger", endpoint: "jaeger:4317", tls: plaintext })],
signals: ["traces"],
});
export { jaeger, otel };

The composite returns two members, service and config. Their Compose keys are the export name followed by the member name, so the example above emits a service otelService and a config otelConfig. Other services on the Compose network send OTLP to otelService:4317 or otelService:4318.

PropDefaultMeaning
exportersone debug exporterWhere the default config sends telemetry
signalstraces, metrics and logsWhich signals get a pipeline in the default config
confignoneA full config as otel entities; replaces the default, and exporters and signals are ignored
imagethe contrib image at the otel lexicon’s pinned versionCollector image
publishPortstruePublish the ports the config listens on (receivers and the prometheus exporter), UDP ones as /udp
restartunless-stoppedRestart policy
defaultsnonePer-member overrides for service and config

Without config, the composite uses otlpCollector() from the otel lexicon. It has an otlp receiver on 4317 (gRPC) and 4318 (HTTP), memory_limiter then batch, the given exporters, and a health_check extension on 13133, with one pipeline per signal.

The published ports are read back from the rendered config, one per receiver endpoint. A config whose OTLP receiver listens only on 0.0.0.0:14317 publishes 14317:14317 and nothing else. Set publishPorts: false when only services on the Compose network should reach the collector.

The contrib image has no shell, so the service carries no Compose healthcheck. The health_check extension still answers on 13133 inside the network.

Terminal window
chant build src --lexicon docker -o docker-compose.yml
docker compose up

The example project is lexicons/docker/examples/otel-collector.