Skip to content

feat: send/receive relations for forwarding OTLP metrics #131

Merged
MichaelThamm merged 27 commits intomainfrom
feat/otlp-lib
Feb 12, 2026
Merged

feat: send/receive relations for forwarding OTLP metrics #131
MichaelThamm merged 27 commits intomainfrom
feat/otlp-lib

Conversation

@MichaelThamm
Copy link
Contributor

@MichaelThamm MichaelThamm commented Oct 9, 2025

Checklist

  • I have added or updated relevant documentation.
  • PR title makes an appropriate release note and follows conventional commits syntax.
  • Merge target is the correct branch, and relevant tandem backport PRs opened.
  • Merge this PR
    • First release this feature to dev/beta and let IS test it
  • Ping simme
  • Finish implementing OTLP #186

Issue

Being able to send metrics cross-model is currently not possible and a feature was attempted in:

However, we dropped this since OTLP can achieve the same thing and is collector-native.

Tandem ingress loadbalancing issue:

Solution

Tandem PR:

Since the workloads are handling the serving and receiving of the OTLP data, the databag only needs to communicate a few things:

  • Endpoint (host and port)
  • Protocol (gRPC or HTTP)
  • Telemetries (logs, metrics, traces)

It is the charm’s responsibility to handle the endpoint information accordingly. For example, writing the OTLP endpoint to config file. A concrete example is the opentelemetry-collector-k8s charm needs to enable receivers, exporters, and pipelines in its config based on OTLP requirements.

Note

Not all OTLP servers can handle all telemetries and all protocols, e.g. Loki only supports logs via HTTP.

We can encapsulate all information with 2 endpoints:

  • receive-otlp
  • send-otlp

Otelcol-k8s charm will use the k8s service address when providing endpoints to load balance across all pipelines.

Important

The VM charm cannot do this so it must provide each unit address since it has no "service" address like in k8s, unless ingressed. This is a future TODO for when we implement the receive-otlp endpoint for the VM charm.

Databags

The provider offers in app data:

{
    "grpc": {
        "endpoint": "http://provider-0.endpoint:4317",
        "telemetries": ["logs", "metrics"],
    },
    "http": {"endpoint": "http://provider-0.endpoint:4318", "telemetries": ["logs"]},
}

and the consumer does not offer anything:

{}

The consumer aggregates all the OtlpEndpoints from all relations in this format:

{
    123: {
        "grpc": {
            "endpoint": "http://provider-0.endpoint:4317",
            "telemetries": ["logs", "metrics"],
        },
        "http": {"endpoint": "http://provider-0.endpoint:4318", "telemetries": ["logs"]},
    },
    456: {...},
}

Pydantic models

The models validate that only supported protocols and telemetries are defined in the databag.

PR Scope

This feature PR for OTLP is incomplete because it enables forwarding only metrics telemetry data between 2 otel-collector charms. Other telemetries can easily be added by updating the provider usage:

OtlpProvider(supported_telemetries=[TelemetryType.metric])

The otlp.py file is local to otelcol and is not a published lib. The plan is to eventually move this to charmlibs. This means that, for now, only two otel-collector charms can communicate OTLP.

Ingress

I added a test that we can access the OTLP HTTP receiver through ingress. Since the Traefik charm can not handle gRPC, otel-collector will currently only support OTLP over HTTP.

TLS

We have an existing config builder feature which adds TLS to all receivers. OTLP exporter offers a tls:insecure config. We toggle this config based on the state of the scheme (http vs. https) of the provider/server address.

We could support mTLS in the future:

Context

Testing Instructions

I added integration tests for:

  1. test_ingress.py::test_push_otlp_logs_through_ingress
  2. test_otlp.py::test_otlp_forwarding_insecure
  3. test_otlp.py::test_otlp_forwarding_secure

I added unit tests for:

  1. test_config_manager.py::test_add_otlp_forwarding
  2. test_ingress.py::test_otlp_url_in_databag (ingress)
  3. test_otlp.py::test_provider_app_data_raises_validation_error
  4. test_otlp.py::test_send_otlp_multiple_relations_and_units
  5. test_otlp.py::test_send_otlp_invalid
  6. test_otlp.py::test_receive_otlp
  7. test_otlp.py::test_cyclic_relations

Manual

$ charmcraft pack
$ jd ./opentelemetry-collector-k8s_ubuntu@24.04-amd64.charm --resource opentelemetry-collector-image=ghcr.io/canonical/opentelemetry-collector:dev --trust otelcol-send
$ jd ./opentelemetry-collector-k8s_ubuntu@24.04-amd64.charm --resource opentelemetry-collector-image=ghcr.io/canonical/opentelemetry-collector:dev --trust otelcol-receive
$ jrel otelcol-send:send-otlp otelcol-receive:receive-otlp
$ jc otelcol-receive debug_exporter_for_metrics=true

# Check for the ingested metrics in the `otelcol-receive` metrics pipeline
$ jssh --container otelcol otelcol-receive/0 "pebble logs -f" | grep "juju_application=otelcol-send"
2026-01-30T21:37:42.566Z [otelcol] otelcol_process_runtime_heap_alloc_bytes{juju_application=otelcol-send,juju_charm=opentelemetry-collector-k8s,juju_model=demo,juju_model_uuid=d9fd7e13-ab5a-453e-873b-7a83143a7741,juju_unit=otelcol-send/0,service.instance.id=dcb7dbef-8abf-4e2f-b50e-68ead704fa9d,service.name=otelcol,service.version=0.144.0} 6.296248e+06

Testing for OTLP forwarding between VM to K8s otelcol is documented in:

Upgrade Notes

@MichaelThamm MichaelThamm changed the title draft: DO NOT MERGE draft: DO NOT MERGE – OTLP lib Oct 9, 2025
@MichaelThamm MichaelThamm mentioned this pull request Jan 30, 2026
3 tasks
@MichaelThamm MichaelThamm changed the title draft: DO NOT MERGE – OTLP lib feat: OTLP send/receive endpoints Jan 30, 2026
@MichaelThamm MichaelThamm mentioned this pull request Feb 2, 2026
3 tasks
@MichaelThamm MichaelThamm changed the title feat (DO NOT MERGE): OTLP send/receive endpoints (metrics only) feat(DO NOT MERGE): OTLP send/receive endpoints (metrics only) Feb 4, 2026
@MichaelThamm MichaelThamm marked this pull request as ready for review February 4, 2026 16:37
@MichaelThamm MichaelThamm requested a review from a team as a code owner February 4, 2026 16:37
@MichaelThamm MichaelThamm changed the title feat(DO NOT MERGE): OTLP send/receive endpoints (metrics only) feat: OTLP send/receive endpoints (metrics only) Feb 4, 2026
@MichaelThamm MichaelThamm changed the title feat: OTLP send/receive endpoints (metrics only) feat: send/receive relations for forwarding OTLP metrics Feb 5, 2026
@MichaelThamm
Copy link
Contributor Author

@copilot leave the functionality intact, but improve the code

Copy link

Copilot AI commented Feb 8, 2026

@MichaelThamm I've opened a new pull request, #189, to work on those changes. Once the pull request is ready, I'll request review from you.

@MichaelThamm MichaelThamm merged commit 22a7a46 into main Feb 12, 2026
43 of 44 checks passed
@MichaelThamm MichaelThamm deleted the feat/otlp-lib branch February 12, 2026 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants