Skip to content

Custom Components

llms.txt lists every page for an agent
Optional: hand this page to your coding agentThe steps work by hand too.
Show the whole prompt
Read https://intentius.io/chant/lexicons/otel/custom-components/.
Declare the collector component I name with `defineComponent`, with its config type, a `pin` naming the source and version that type follows, and a `validate` function, in this project's src/.
Use it in a pipeline, run `npx chant build src --lexicon otel -o collector.yaml` and `npx chant lint src` until both are clean, and open a pull request.
Never deploy to a real cloud account or shared environment (with `chant run`, `chant components` or a platform's own CLI), approve (a pull request review, `chant approve` or `chant run approve`), override a policy denial (`chant approve policy-override`), or merge; never cut or publish a release (`chant release cut --yes` or `chant release publish`), push or delete a `ci/*` tag (`chant ci tick` pushes them), or change the value of an existing flag; never touch `.chant/allowed_signers` or `chant/lifecycle`.

chant ships a core set of components. A team or a plugin package adds any other component with defineComponent, and the result behaves like a built-in: the same serializer emits it, the same checks run over it, and collectorTopology() reports it.

src/vendor-exporter.ts
/**
* A component chant doesn't ship, defined once by the team that uses it.
*
* In real use this file lives in a package (say `@acme/otel-components`), and
* the package version is what pins the definition for every project that
* imports it. `pin` records which schema the config type follows; it is
* written above the emitted config and returned by `collectorTopology()`.
*/
import { defineComponent } from "@intentius/chant-lexicon-otel";
export interface SplunkHecExporterConfig {
token: string;
endpoint: string;
source?: string;
sourcetype?: string;
index?: string;
tls?: { insecure_skip_verify?: boolean; ca_file?: string };
}
export const SplunkHecExporter = defineComponent<SplunkHecExporterConfig>()({
kind: "exporter",
type: "splunk_hec",
pin: {
source: "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/splunkhecexporter",
version: "v0.130.0",
},
description: "Sends logs, metrics and traces to a Splunk HTTP Event Collector",
validate: (c) => {
const problems: string[] = [];
if (!c.token.includes("${")) problems.push("token must be an ${env:...} or ${file:...} reference");
if (!c.endpoint.startsWith("https://")) problems.push("endpoint should be https://");
return problems;
},
endpoints: (c) => [c.endpoint],
});

defineComponent<Config>() is curried so you name the config type while kind and type are still inferred from the literal.

OptionRequiredMeaning
kindyesreceiver, processor, exporter, connector or extension
typeyesthe collector type, the part of the id before /; letters, digits and _
pinyes{ source, version, digest? }, see below
validatenoa function returning a list of problems, or any schema with safeParse (a zod schema works); failures are OTEL107
endpointsnoa function returning where the component sends or listens, for collectorTopology()
connectsnoconnectors only: the signal pairs it supports, e.g. [{ from: "traces", to: "metrics" }]; OTEL112 checks pipelines against them and collectorTopology() reports edges only for them
descriptionnoone line for docs and hover
src/collector.ts
/**
* The custom exporter used next to built-ins: same constructor shape, same
* pipeline references, same checks.
*/
import { OtlpReceiver, BatchProcessor, Pipeline, type OtlpReceiverConfig } from "@intentius/chant-lexicon-otel";
import { SplunkHecExporter } from "./vendor-exporter";
const protocols: OtlpReceiverConfig["protocols"] = { http: { endpoint: "0.0.0.0:4318" } };
const otlp = new OtlpReceiver({ protocols });
const batch = new BatchProcessor({ timeout: "5s" });
const splunk = new SplunkHecExporter({
name: "security",
token: "${env:SPLUNK_HEC_TOKEN}",
endpoint: "https://hec.splunk.example:8088/services/collector",
index: "otel",
sourcetype: "otel",
});
const logs = new Pipeline({
signal: "logs",
receivers: [otlp],
processors: [batch],
exporters: [splunk],
});
export { otlp, batch, splunk, logs };

A pin names the source a component’s config type was written against and the version of that source:

FieldExampleMeaning
sourcegithub.com/open-telemetry/opentelemetry-collector-contrib/exporter/splunkhecexporterthe Go module, npm package or URL that defines the config
versionv0.130.0the release of source the TypeScript type follows
digestsha256:...optional; a digest of the schema document, recorded as given

Built-ins all share COLLECTOR_PIN, so the otel package version pins them. A custom definition carries its own pin, and when the definition ships in a package, that package’s version pins the definition for every project that imports it.

The pin is recorded in three places:

  1. The emitted YAML starts with one comment line per custom component, for example # chant: exporter splunk_hec/security schema github.com/.../splunkhecexporter@v0.130.0. The collector ignores comments, so the file runs unchanged, and anyone reading it can see which schema each non-built-in component was checked against. Built-ins add no line.
  2. collectorTopology() returns the pin as schema on every component whose definition is loaded, built-in or custom.
  3. OTEL109 fails the build when a custom definition has no usable pin (an empty source or version, for instance after an untyped call).

chant records the pin. It does not fetch the schema or verify the digest.

A component chant doesn’t ship is often in no published collector image either. A team then builds its own collector with ocb, the OpenTelemetry Collector Builder, from a builder manifest. Distribution declares that manifest (#3374):

src/distribution.ts
import { Distribution, OtlpReceiver, BatchProcessor, OtlpExporter } from "@intentius/chant-lexicon-otel";
import { SplunkHecExporter } from "./vendor-exporter";
export const dist = new Distribution({
dist: { name: "otelcol-acme", description: "Acme collector", output_path: "./_build", version: "1.0.0" },
receivers: [OtlpReceiver],
processors: [BatchProcessor],
exporters: [OtlpExporter, SplunkHecExporter],
});

The fields are the builder’s own, as read at v0.130.0: dist (module, name, go, description, output_path, version, build_tags, debug_compilation, cgo_enabled, use_absolute_replace_paths), one list per component kind, providers, converters, replaces, excludes and conf_resolver. A component list takes component classes or modules ({ gomod, import?, name?, path? }). A built-in class writes its Go module at COLLECTOR_PIN, so OtlpReceiver becomes go.opentelemetry.io/collector/receiver/otlpreceiver v0.130.0. A defineComponent class writes its pin’s source and version, so the pin has to name the Go module for this to work.

chant build writes the manifest as builder-config.yaml beside the collector config. OTEL128 then reports any component the collector config declares that the distribution doesn’t build, because a collector built from it refuses that config with “unknown type”. When a list holds a module whose component type can’t be read from its path, OTEL128 reports a warning instead of an error and names the module. A project without a Distribution gets no extra file and no check.

To build the collector as a component, use the ocb-build verb the otel lexicon contributes: build: ocbBuild({ config: "dist/builder-config.yaml" }). It runs ocb --config in the manifest’s directory and returns { kind: "dir", dir, manifestDigest }, where dir is the manifest’s dist.output_path. A manifest without output_path is refused, since ocb would otherwise write to a temporary directory that no later step could name. A docker-build step with dir as its context and a Dockerfile you provide builds the image, and from there it takes the same path as any other image.

  • A built-in type can’t be redefined. Declare a named instance instead, such as new OtlpExporter({ name: "vendor", ... }).
  • A definition registers when its module loads. A config parsed from YAML that uses a type no loaded definition covers is still checked for references (OTEL101 to OTEL106) and still appears in the topology, with builtin: false, no schema, and its endpoint key as its endpoint when it has one.

chant