Open
Description
Description
While publishing message to apache kafka , getting error with Newrelic Message Transaction - Error 'MessageTransaction' object has no attribute 'destination_name'
code
producer = KafkaProducer(
bootstrap_servers=bootstrap_servers,
value_serializer=lambda x: json.dumps(x).encode("utf-8"),
)
producer.send(topic, value=event_data).get()
Error Stack Trace
File "/Users/mishika/supply-metrics/app/kafka_manager/base_consumer_v2.py", line 55, in produce
self.producer.send(topic, value=event_data, key=key).get()
File "/Users/mishika/miniconda3/envs/myenv/lib/python3.10/site-packages/newrelic/hooks/messagebroker_kafkapython.py", line 68, in wrap_KafkaProducer_send
return wrapped(
File "/Users/mishika/miniconda3/envs/myenv/lib/python3.10/site-packages/kafka/producer/kafka.py", line 581, in send
value_bytes = self._serialize(
File "/Users/mishika/miniconda3/envs/myenv/lib/python3.10/site-packages/kafka/producer/kafka.py", line 714, in _serialize
return f(data)
File "/Users/mishika/miniconda3/envs/myenv/lib/python3.10/site-packages/newrelic/hooks/messagebroker_kafkapython.py", line 203, in _wrap_serializer
topic = transaction.destination_name
AttributeError: 'MessageTransaction' object has no attribute 'destination_name'
newrelic.ini file
[newrelic]
log_level = debug
high_security = false
transaction_tracer.enabled = true
transaction_tracer.transaction_threshold = apdex_f
transaction_tracer.record_sql = obfuscated
transaction_tracer.stack_trace_threshold = 0.5
transaction_tracer.explain_enabled = true
transaction_tracer.explain_threshold = 0.5
transaction_tracer.function_trace =
error_collector.enabled = true
error_collector.ignore_errors = pycommon.exceptions.common_exceptions:DuplicateError rest_framework.exceptions:ValidationError rest_framework.exceptions:NotFound rest_framework.exceptions:ParseError
browser_monitoring.auto_instrument = true
thread_profiler.enabled = true
distributed_tracing.enabled = false
app_name =
monitor_mode = true
license_key =
Expected Behavior
Expected message should have sent to kafka topic
Steps to Reproduce
- kept newrelic.ini file locally and ran kafka consumer , will be able to above stack trace
- Converting topic = transaction.destination_name to topic = getattr(transaction, "destination_name","Default") in newrelic-python-agent lib seems to fix the issue
Your Environment
- Application Python version : 3.10
- kafka-python==2.0.2
- newrelic==9.4.0