> For the complete documentation index, see [llms.txt](https://docs.lenses.io/latest/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lenses.io/latest/k2k/configuration-reference/observability.md).

# Observability

Metrics prefixes and exporter configuration.

To operate a replication pipeline, we need to know whether it is keeping up, which partitions are assigned, and when something fails. Kafka exposes broker metrics but not replication-specific signals, therefore K2K exports replication and JVM metrics through **Kafka** (for [Lenses HQ](https://lenses.io)), **OTLP**, and **Prometheus**.

Enable export with the `--telemetry` flag and standard `OTEL_*` environment variables; see [Command-line options](/latest/k2k/deployment.md#command-line-options). Customize name prefixes under `metrics.prefix`. For the metrics control topic, see [Topic creation](/latest/k2k/configuration-reference/topic-creation.md). Record lineage headers are separate; see [Record tracing](/latest/k2k/configuration-reference/record-tracing.md). For the Kafka metrics topic name, see the [Advanced](#advanced) section below.

## Prerequisites

* [License accepted](/latest/k2k/configuration-reference/licenses.md)
* [Kafka connectivity and authentication](/latest/k2k/configuration-reference/kafka-connectivity-authentication.md)
* At least one metrics exporter configured (Kafka with Lenses HQ, OTLP, or Prometheus)

## Example

```yaml
name: "my_pipeline"
source:
  kafka:
    common:
      "bootstrap.servers": "source:9092"
    consumer:
      "group.id": "my-k2k-group"
target:
  kafka:
    common:
      "bootstrap.servers": "target:9092"
metrics:
  prefix:
    assignment: "myapp.k2k."
replication:
  - source:
      topic: "orders.*"
  - sink:
      topic: source
      partition: source
```

## Configuration keys

Each prefix is prepended to the metrics emitted by one Kafka client or subsystem. **Defaults differ per application** — the offset mapper ships its own set, so the same key resolves differently depending on which application reads the pipeline.

| Key                               | Description                                   | Required | Replicator default      | Offset mapper default                 |
| --------------------------------- | --------------------------------------------- | -------- | ----------------------- | ------------------------------------- |
| `metrics.prefix.sourceConsumer`   | Metric prefix for the source consumer         | No       | `k2k.consumer.source.`  | (not used)                            |
| `metrics.prefix.targetConsumer`   | Metric prefix for the target control consumer | No       | `k2k.consumer.control.` | `k2k.offsetmapping.consumer.control.` |
| `metrics.prefix.targetProducer`   | Metric prefix for the target producer         | No       | `k2k.producer.`         | `k2k.offsetmapping.producer.`         |
| `metrics.prefix.assignment`       | Metric prefix for assignment metrics          | No       | `k2k.`                  | (not used)                            |
| `metrics.prefix.offsetMappingApp` | Metric prefix for offset mapper metrics       | No       | (not used)              | `k2k.offsetmapping.`                  |

When building dashboards or alerts across both applications, query the offset mapper under its `k2k.offsetmapping.` prefixes rather than the replicator defaults.

## Metric names

### K2K metrics

K2K emits these replication metrics under the `metrics.prefix.assignment` prefix (default `k2k.`, so the full name of the first is `k2k.topics-assigned`):

| Metric                | Meaning                                                 |
| --------------------- | ------------------------------------------------------- |
| `topics-assigned`     | Source topics currently assigned to this instance       |
| `partitions-assigned` | Source partitions currently assigned to this instance   |
| `offset-commit`       | Replication progress commits recorded in control topics |

Use `partitions-assigned` to confirm work is spread across instances — see [Horizontal scaling](/latest/k2k/configuration-reference/horizontal-scaling.md).

### Tags

K2K metrics carry these tags:

| Tag                | Meaning                                      |
| ------------------ | -------------------------------------------- |
| `source_topic`     | Topic name on the source Kafka cluster       |
| `source_partition` | Partition number on the source Kafka cluster |
| `target_topic`     | Topic name on the target Kafka cluster       |
| `target_partition` | Partition number on the target Kafka cluster |

Kafka client metrics passed through from the consumer, producer, and admin clients keep their standard Kafka names (`records-lag`, `records-consumed-rate`, `record-send-rate`, and so on) under the matching prefix, tagged with `topic` and `partition`. For their meaning, see the [Apache Kafka monitoring reference](https://kafka.apache.org/documentation/#monitoring).

JVM and runtime metrics are exported by the OpenTelemetry runtime instrumentation under their standard names.

## Advanced

### Kafka metrics topic

When using the Kafka metrics exporter with Lenses HQ, metrics are written to a control topic on the target Kafka cluster.

| Key                   | Description                    | Required | Default         | Used by    |
| --------------------- | ------------------------------ | -------- | --------------- | ---------- |
| `metrics.kafka.topic` | Topic for Kafka metrics export | No       | `__k2k_metrics` | Replicator |

For auto creating this topic with custom settings, see [Topic creation](/latest/k2k/configuration-reference/topic-creation.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.lenses.io/latest/k2k/configuration-reference/observability.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
