This guide explains how to use OpenTelemetry Weaver to generate semantic conventions code and documentation from YAML schema definitions. Weaver is a tool that transforms OpenTelemetry semantic convention specifications into various output formats including code artifacts and documentation.
OpenTelemetry Weaver is a code generation and documentation tool that:
- Processes semantic convention YAML models
- Generates type-safe code for multiple programming languages
- Creates consistent documentation from schema definitions
- Validates and resolves semantic convention registries
First, pull the Weaver Docker image:
docker pull otel/weaver:v0.20.0This project expects the following directory structure:
model/- Contains YAML schema definitions (e.g.,attributes.yaml)templates/- Contains Jinja2 templates for code generationdocs/- Output directory for generated documentationsrc/- Output directory for generated source code
Purpose: Validates and resolves your semantic convention schema, checking for errors and dependencies.
docker run --rm \
--mount 'type=bind,source=./templates,target=/home/weaver/templates,readonly' \
--mount 'type=bind,source=./model,target=/home/weaver/model,readonly' \
otel/weaver:v0.20.0 \
registry resolve \
-r modelWhat this does:
- Mounts your local
templates/andmodel/directories into the container - Runs
registry resolveto validate the YAML schema files in themodel/directory - Checks for syntax errors, missing references, and schema compliance
- Outputs validation results and any errors found
When to use: Run this first to ensure your schema definitions are valid before generating code or docs.
Purpose: Creates markdown documentation from your semantic convention schemas using official OpenTelemetry templates.
docker run --rm \
--mount 'type=bind,source=./templates,target=/home/weaver/templates,readonly' \
--mount 'type=bind,source=./model,target=/home/weaver/source,readonly' \
--mount 'type=bind,source=./docs,target=/home/weaver/target' \
otel/weaver:v0.20.0 \
registry generate \
--registry=/home/weaver/source \
-Dregistry_base_url=/docs/registry/ \
--templates=/home/weaver/templates \
markdown \
--future \
/home/weaver/target/registry/What this does:
- Mounts your
model/directory (input schemas) anddocs/directory (output) - Generates markdown files documenting your semantic conventions
- Creates structured documentation following OpenTelemetry standards
Output: Markdown files in the docs/ directory describing your attributes, metrics, and other semantic conventions.
Purpose: Generates programming language-specific code artifacts (constants, enums, etc.) from your semantic conventions.
docker run --rm \
--mount 'type=bind,source=./templates,target=/home/weaver/templates,readonly' \
--mount 'type=bind,source=./model,target=/home/weaver/model,readonly' \
--mount 'type=bind,source=./src,target=/home/weaver/src' \
otel/weaver:v0.20.0 \
registry generate \
-c templates/registry/code/weaver.yaml \
-r model \
code src/What this does:
- Mounts
templates/,model/, andsrc/directories - Uses the configuration file
templates/registry/code/weaver.yamlto determine:- Which programming languages to generate code for
- What types of artifacts to create (constants, enums, classes)
- Output file naming and structure
- Processes your YAML schemas and generates type-safe code
- Outputs language-specific files to the
src/directory
Output: Source code files (e.g., Attributes.java, attributes.py, attributes.rs) containing constants and types for your semantic conventions.
Purpose: Demonstrates the generated semantic conventions in action by running a sample application that emits telemetry data using the generated code artifacts.
cd .. & docker compose --profile weaver-emit upNavigate to Jaeger at http://localhost:16686/ and check the received trace:
What this does:
- Changes to the parent directory where the Docker Compose configuration is located
- Starts the
weaver-emitprofile, which uses the generated semantic convention code to emit example telemetry data - Sends telemetry to Jaeger
Output: Live telemetry data (spans) that demonstrate your custom semantic conventions in action, visible in Jaeger.
Purpose: Tests the generated semantic conventions by running a validation service and triggering telemetry generation to verify everything works correctly.
This can be included in your CI/CD pipeline to ensure your team is producing telemetry following your internal semantic conventions.
cd .. && docker compose --profile weaver-check upIn another terminal, make a request to generate telemetry:
curl localhost:5000/songs/smells%20like%20teen%20spirit/nirvanaCheck the Docker Compose logs to see the telemetry validation output and any errors:
In this sample, the app is producing a span with the attributes media.song and media.artist.
Weaver complains and raise an error to inform that:
media.songis deprecatedmedia.artistdoes not exist in the registry
What this does:
- Starts the
weaver-checkprofile, which runs Weaver Live Check and a sample service - The service listens on port 5000 and is ready to process requests
- Making the
curlrequest triggers the service to emit a span containing a non-compliant attributes - Logs show that
media.artist - Does not exist in the registryandmedia.song - Is deprecated
Output: Console logs showing Weaver Live Check validation results, including error messages for non-compliant attributes (media.artist - Does not exist in the registry and media.song - Is deprecated), service startup messages, and real-time validation feedback that can be integrated into CI/CD pipelines to enforce semantic convention compliance.
- Define your schemas: Create or modify YAML files in the
model/directory - Validate: Run the resolve command to check for errors
- Generate documentation: Create readable docs for your team
- Generate code: Create source code artifacts for your applications
- Integrate: Use the generated code in your OpenTelemetry instrumentation
model/attributes.yaml- Defines semantic convention attributestemplates/registry/code/weaver.yaml- Controls code generation settings- Template files in
templates/registry/code/- Jinja2 templates for different languages
- Mount errors: Ensure all referenced directories exist before running commands
- Schema validation errors: Check YAML syntax and required fields in your model files
- Template errors: Verify template syntax and that all referenced model properties exist

