Skip to content

Commit 9799069

Browse files
fix(kafka): activate NR app in standalone producer (no-transaction path)
Call app.activate() when transaction is None so the agent connects to the collector and record_custom_metric actually sends data.
1 parent 8bb45fe commit 9799069

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

newrelic/hooks/messagebroker_kafkapython.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ def wrap_KafkaProducer_send(wrapped, instance, args, kwargs):
5454
transaction = current_transaction()
5555

5656
if transaction is None:
57+
app = application_instance()
58+
if not app.active:
59+
app.activate()
60+
servers = instance.config.get("bootstrap_servers", []) if hasattr(instance, "config") else []
61+
if app.active and servers:
62+
cache_key = _bootstrap_cache_key(servers)
63+
cluster_id = _kafka_cluster_id_cache.get(cache_key)
64+
if cluster_id:
65+
topic = (_bind_send(*args, **kwargs)[0] or "Default")
66+
app.record_custom_metric(KAFKA_CLUSTER_METRIC_PRODUCE.format(cluster_id, topic), 1)
5767
return wrapped(*args, **kwargs)
5868

5969
topic, value, key, headers, partition, timestamp_ms = _bind_send(*args, **kwargs)

0 commit comments

Comments
 (0)