Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(capture-logs): keep instance label on remote-write metric rows (#102230)

Frank Hamandd40e6593c1f2
diff --git a/rust/capture-logs/src/endpoints/prometheus.rs b/rust/capture-logs/src/endpoints/prometheus.rs
index 84ef84e8bf8b..02d62a3de236 100644
--- a/rust/capture-logs/src/endpoints/prometheus.rs
+++ b/rust/capture-logs/src/endpoints/prometheus.rs
@@ -154,11 +154,12 @@ pub fn write_request_to_kafka_rows(req: WriteRequest) -> (Vec<KafkaMetricRow>, u
resource_attributes
.insert("service.name".to_string(), json!(label.value).to_string());
}
+ // `instance` is copied, not moved: Prometheus queries filter on
+ // `instance`, and OTel queries on `service.instance.id`.
INSTANCE_LABEL => {
- resource_attributes.insert(
- "service.instance.id".to_string(),
- json!(label.value).to_string(),
- );
+ let value = json!(label.value).to_string();
+ resource_attributes.insert("service.instance.id".to_string(), value.clone());
+ attributes.insert(label.name, value);
}
_ => {
attributes.insert(label.name, json!(label.value).to_string());
diff --git a/rust/capture-logs/tests/prometheus_remote_write_test.rs b/rust/capture-logs/tests/prometheus_remote_write_test.rs
index 0e8d7c9e69bc..5f055a00660c 100644
--- a/rust/capture-logs/tests/prometheus_remote_write_test.rs
+++ b/rust/capture-logs/tests/prometheus_remote_write_test.rs
@@ -65,7 +65,9 @@ fn maps_labels_to_name_service_and_attributes() {
"\"10.0.0.1:9100\""
);
assert_eq!(row.attributes.get("mode").unwrap(), "\"idle\"");
- // __name__/job/instance are not duplicated into the attributes map.
+ // `instance` stays in the attributes map so Prometheus-style filters keep working.
+ assert_eq!(row.attributes.get("instance").unwrap(), "\"10.0.0.1:9100\"");
+ // __name__/job are not duplicated into the attributes map.
assert!(!row.attributes.contains_key("__name__"));
assert!(!row.attributes.contains_key("job"));
}