otelcol-integrator

OpenTelemetry Collector Integrator

Channel Revision Published Runs on
latest/edge 6 13 Mar 2026
Ubuntu 24.04 Ubuntu 22.04
latest/edge 5 13 Mar 2026
Ubuntu 24.04 Ubuntu 22.04
juju deploy otelcol-integrator --channel edge
Show information

Platform:

Ubuntu
24.04 22.04

charms.otelcol_integrator.v0.otelcol_integrator

OtelcolIntegrator charm library.

This library provides utilities for integrating with the Otelcol Integrator Charm through the external-config relation. It supports sharing configuration and secrets between charms.

Overview

This library provides three main components:

  • OtelcolIntegratorProviderAppData: Data model for validation
  • OtelcolIntegratorProviderRelationUpdater: Provider-side relation updates
  • OtelcolIntegratorRequirer: Requirer-side configuration retrieval
Usage
Provider Side (Sharing Configuration)

Use this side when your charm provides OpenTelemetry Collector configuration to other charms.

from charms.otelcol_integrator.v0.otelcol_integrator import (
    OtelcolIntegratorProviderAppData,
    OtelcolIntegratorProviderRelationUpdater,
    Pipeline,
)

1. Create and validate your configuration data

config_data = OtelcolIntegratorProviderAppData(
    config_yaml='''
exporters:
  splunk_hec:
    token: "secret://model-uuid/secret-id/token?render=inline"
    endpoint: "https://splunk:8088/services/collector"
    ''',
    pipelines=[Pipeline.METRICS, Pipeline.LOGS]
)

2. Update all relations with the configuration

relations = self.model.relations.get("external-config", [])
OtelcolIntegratorProviderRelationUpdater.update_relations_data(
    application=self.app,
    relations=relations,
    data=config_data
)

Secret URI Format:

  • Inline secrets: secret://model-uuid/secret-id/key?render=inline
  • File-based secrets: secret://model-uuid/secret-id/key?render=file
Requirer Side (Consuming Configuration)

Use this side when your charm consumes OpenTelemetry Collector configuration from another charm.

from charms.otelcol_integrator.v0.otelcol_integrator import (
    OtelcolIntegratorRequirer,
    Pipeline,
)

1. Initialize the requirer

self.requirer = OtelcolIntegratorRequirer(
    model=self.model,
    relation_name="external-config",
    secrets_dir="/etc/otelcol/secrets"  # Where secret files should go
)

2. Retrieve configurations from all relations

configs = self.requirer.retrieve_external_configs()

configs is a list of dicts:

[
    {
        "config_yaml": "...",  # Secrets resolved to values or paths
        "pipelines": [Pipeline.METRICS, Pipeline.LOGS]  # List of Pipeline enums
    }
]

3. Write secret files to disk

After calling retrieve_external_configs(), the library tracks all file-based secrets (those with render=file) in the secret_files property:

# Retrieve configs (this populates secret_files automatically)
configs = self.requirer.retrieve_external_configs()

# Access the tracked secret files
# secret_files is a Dict[str, str] mapping file paths to content
for file_path, content in self.requirer.secret_files.items():
    # Create parent directories if needed
    Path(file_path).parent.mkdir(parents=True, exist_ok=True)

    # Write the secret content to disk
    Path(file_path).write_text(content, mode=0o644)

Important Notes:

  • The library does NOT write files to disk automatically
  • It tracks file paths and content in the secret_files property
  • The charm is responsible for actually writing the files
  • Secret URIs with render=inline are embedded directly in config_yaml
  • Secret URIs with render=file are replaced with paths in config_yaml and tracked in secret_files
Data Validation

The OtelcolIntegratorProviderAppData model automatically validates:

  • config_yaml: Must be valid YAML

  • Secret URIs: Must follow format secret://<model-uuid>/<secret-id>/<key>?render=<inline|file>

    • Note that if render=inline, the key's value will be embedded directly in the config, on the other hand if render=file a filepath will be generated and the secret content will be tracked for writing by the charm.
  • pipelines: List of Pipeline enum values (Pipeline.METRICS, Pipeline.LOGS, Pipeline.TRACES)

Invalid data will raise a ValidationError with a descriptive message.

Examples
Provider with Inline Secret
# The secret token will be fetched and embedded directly in the config
config_data = OtelcolIntegratorProviderAppData(
    config_yaml='''
receivers:
  prometheus:
    config:
      scrape_configs:
        - bearer_token: "secret://model-uuid/secret-id/token?render=inline"
    ''',
    pipelines=[Pipeline.METRICS]
)
Provider with File-based Secret
# The secret will be written to a file, path replaces the URI
config_data = OtelcolIntegratorProviderAppData(
    config_yaml='''
exporters:
  otlp:
    tls:
      cert_file: "secret://model-uuid/secret-id/cert?render=file"
      key_file: "secret://model-uuid/secret-id/key?render=file"
    ''',
    pipelines=[Pipeline.TRACES]
)
Requirer Processing Multiple Relations
# Get configs from all related charms
configs = self.requirer.retrieve_external_configs()

# Merge or process each config
for config in configs:
    yaml_config = yaml.safe_load(config["config_yaml"])
    pipelines = config["pipelines"]  # List[Pipeline] enums

    # Convert to strings if needed
    pipeline_names = [p.value for p in pipelines]

    # Process configuration...
    # Note: config_yaml already has file-based secrets replaced with paths

# Write secret files to disk (for all relations)
# secret_files contains all file-based secrets from retrieve_external_configs()
for file_path, content in self.requirer.secret_files.items():
    Path(file_path).parent.mkdir(parents=True, exist_ok=True)
    Path(file_path).write_text(content)

class Pipeline

Description

OpenTelemetry Collector pipeline types. None

class SecretURI

Represents a validated Juju secret URI with key and render mode.

Attributes

model_uuid
The Juju model UUID.
secret_id
The Juju secret ID.
key
The key within the secret to access.
render
How to render the secret ('inline' or 'file').

Description

Format: secret://<model-uuid>/<secret-id>/<key>?render=<inline|file>

This class encapsulates the validation logic for secret URIs used in OpenTelemetry Collector configurations. It ensures that secret references are well-formed and contain all required components.

Methods

SecretURI. from_uri( cls , uri: str )

Parse and validate a secret URI string.

Arguments

uri

Secret URI string to parse.

Returns

Validated SecretURI instance.

SecretURI. __str__( self )

Convert back to URI string format.

Returns

The secret URI as a string.

class OtelcolIntegratorProviderAppData

Model representing data shared through external-config relation.

Attributes

config_yaml
OpenTelemetry Collector YAML configuration.
secret_ids
Set of Juju secret URIs referenced in the configuration.
pipelines
List of enabled pipeline names (metrics, logs, traces).

Methods

OtelcolIntegratorProviderAppData. validate_yaml( cls , v: str )

Validate that config_yaml is valid YAML and secret URIs have correct format.

Arguments

v

The config_yaml string to validate.

Returns

The validated config_yaml string.

OtelcolIntegratorProviderAppData. validate_pipelines( cls , v )

Validate pipelines list is not empty.

Arguments

v

List of pipelines to validate.

Returns

The validated list of pipelines.

class OtelcolIntegratorProviderRelationUpdater

Description

Updates relation data for Otelcol integrator provider relations. None

Methods

OtelcolIntegratorProviderRelationUpdater. update_relations_data( application: Application , relations , data: OtelcolIntegratorProviderAppData )

Update relation data with validated configuration.

Arguments

application

The application object to use for relation data.

relations

List of relations to update.

data

Validated relation data model.

class OtelcolIntegratorRequirer

Requirer side (e.g. otelcol) of the external-config relation.

Description

This class is used by charms that consume configuration from otelcol-integrator via the external-config relation.

Methods

OtelcolIntegratorRequirer. __init__( self , model: Model , relation_name: str , secrets_dir: str )

Initialize the requirer with the Juju model.

Arguments

model

The Juju model to use for resolving secrets.

relation_name

Name of the relation to use.

secrets_dir

Directory where secret files should be stored.

OtelcolIntegratorRequirer. secret_files( self )

Description

Get mapping of file paths to secret content for file-based secrets. None

OtelcolIntegratorRequirer. retrieve_external_configs( self )

Retrieve the config_yaml from the external-config relation.

Arguments

relations

List of relations to extract configurations from.

Returns

List of dictionaries containing config_yaml and pipelines. Secret URIs in config_yaml are replaced with actual values. Invalid relation data is skipped with a warning.

def extract_secret_uris(config_yaml: str)

Extract base secret URIs (without keys) from the config YAML.

Arguments

config_yaml

YAML configuration text that may contain secret URIs

Returns

Set of unique base secret URIs (secret://model-uuid/secret-id)

Description

Searches for secret URIs in the format: secret://model-uuid/secret-id