ollygarden-otel-declarative-config
Declarative Configuration Conventions
Why declarative config is the default for new projects
Prefer declarative YAML configuration over scattered OTEL_* environment variables and over
programmatic SDK construction:
- It's language-agnostic (same YAML works across Go, Java, JS, etc.)
- It's version-controlled alongside application code
- It expresses things env vars cannot: views, composite samplers, multiple exporters
- It supports
${VAR}substitution for secrets and environment-specific values
When to recommend declarative config
Recommend it when the user is setting up the OTel SDK for Go, Java, or JS. These SDKs have stable or near-stable implementations.
For .NET and Python, fall back to environment variables or programmatic setup — declarative
config is still in development. To check the current per-language status, fetch the SDK
compatibility matrix listed in the general/declarative-config reference skill's Sources of Truth.
Common Patterns
These patterns describe the shape of a correct config. For exact field names and
exporter syntax, fetch examples/otel-sdk-config.yaml (see the general/declarative-config
reference skill's Sources of Truth) — those details vary by schema version.
One config file, vary with env vars
resource:
attributes:
- name: deployment.environment.name
value: "${DEPLOY_ENV:-development}"
tracer_provider:
sampler:
parent_based:
root:
trace_id_ratio_based:
ratio: ${SAMPLE_RATE:-1.0}
Secrets via env var substitution
# Inside an exporter block (exact field names: see canonical example)
headers:
- name: api-key
value: "${API_KEY}"
endpoint: "${OTEL_ENDPOINT}"
Anti-Patterns
Missing parent_based wrapper
# BAD: ignores upstream sampling decisions, breaks distributed traces
tracer_provider:
sampler:
trace_id_ratio_based:
ratio: 0.1
# GOOD: respects parent sampling, applies ratio only to root spans
tracer_provider:
sampler:
parent_based:
root:
trace_id_ratio_based:
ratio: 0.1
Using simple processor in production
# BAD: exports synchronously, blocks the application
tracer_provider:
processors:
- simple:
exporter: { ... }
# GOOD: exports asynchronously in batches
tracer_provider:
processors:
- batch:
exporter: { ... }
Hardcoded secrets
# BAD: secrets in version control
headers:
- name: api-key
value: "sk-1234567890abcdef"
Mixing env vars and config file
# BAD: OTEL_TRACES_SAMPLER is ignored when OTEL_CONFIG_FILE is set
export OTEL_CONFIG_FILE="/app/otel.yaml"
export OTEL_TRACES_SAMPLER="always_off" # This has NO effect
Cross-References
- Reference:
otel-declarative-configskill — schema sources of truth, env-var substitution, configuration precedence. - Language conventions:
ollygarden-otel-go-setup,ollygarden-otel-java-setup,ollygarden-otel-js-setup.
More from ollygarden/skills
ollygarden-otel-js-setup
Ollygarden's recommended pattern for setting up OpenTelemetry in Node.js services. Covers project structure, which auto-instrumentations to disable, the entry-point ordering, and the programmatic NodeSDK fallback. Use when adding OTel to a Node.js project, structuring telemetry code, or reviewing an existing setup. Triggers on "node otel setup", "NodeSDK pattern", "auto instrumentation node".
1ollygarden-otel-sdk-setup
OpenTelemetry SDK initialization and configuration. Use when setting up or reviewing TracerProvider, MeterProvider, or LoggerProvider; choosing exporters, processors, or propagators; configuring OTLP transport; or extending an existing SDK setup for new signals. Use this skill whenever the task involves wiring up the OpenTelemetry SDK, even if the user only mentions "add tracing" or "set up metrics" without saying "SDK.
1