2626 function_wrapper ,
2727 wrap_function_wrapper ,
2828)
29+ from newrelic .common .package_version_utils import get_package_version
2930
3031HEARTBEAT_POLL = "MessageBroker/Kafka/Heartbeat/Poll"
3132HEARTBEAT_SENT = "MessageBroker/Kafka/Heartbeat/Sent"
@@ -48,6 +49,8 @@ def wrap_KafkaProducer_send(wrapped, instance, args, kwargs):
4849 topic , value , key , headers , partition , timestamp_ms = _bind_send (* args , ** kwargs )
4950 headers = list (headers ) if headers else []
5051
52+ transaction .add_messagebroker_info ("Kafka-Python" , get_package_version ("kafka-python" ))
53+
5154 with MessageTrace (
5255 library = "Kafka" ,
5356 operation = "Produce" ,
@@ -112,6 +115,7 @@ def wrap_kafkaconsumer_next(wrapped, instance, args, kwargs):
112115 message_count = 1
113116
114117 transaction = current_transaction (active_only = False )
118+
115119 if not transaction :
116120 transaction = MessageTransaction (
117121 application = application_instance (),
@@ -124,7 +128,7 @@ def wrap_kafkaconsumer_next(wrapped, instance, args, kwargs):
124128 source = wrapped ,
125129 )
126130 instance ._nr_transaction = transaction
127- transaction .__enter__ ()
131+ transaction .__enter__ () # pylint: disable=C2801
128132
129133 # Obtain consumer client_id to send up as agent attribute
130134 if hasattr (instance , "config" ) and "client_id" in instance .config :
@@ -143,12 +147,13 @@ def wrap_kafkaconsumer_next(wrapped, instance, args, kwargs):
143147 name = "Named/%s" % destination_name
144148 transaction .record_custom_metric ("%s/%s/Received/Bytes" % (group , name ), received_bytes )
145149 transaction .record_custom_metric ("%s/%s/Received/Messages" % (group , name ), message_count )
150+ transaction .add_messagebroker_info ("Kafka-Python" , get_package_version ("kafka-python" ))
146151
147152 return record
148153
149154
150155def wrap_KafkaProducer_init (wrapped , instance , args , kwargs ):
151- get_config_key = lambda key : kwargs .get (key , instance .DEFAULT_CONFIG [key ]) # noqa: E731
156+ get_config_key = lambda key : kwargs .get (key , instance .DEFAULT_CONFIG [key ]) # pylint: disable=C3001 # noqa: E731
152157
153158 kwargs ["key_serializer" ] = wrap_serializer (
154159 instance , "Serialization/Key" , "MessageBroker" , get_config_key ("key_serializer" )
@@ -162,13 +167,13 @@ def wrap_KafkaProducer_init(wrapped, instance, args, kwargs):
162167
163168class NewRelicSerializerWrapper (ObjectProxy ):
164169 def __init__ (self , wrapped , serializer_name , group_prefix ):
165- ObjectProxy .__init__ .__get__ (self )(wrapped )
170+ ObjectProxy .__init__ .__get__ (self )(wrapped ) # pylint: disable=W0231
166171
167172 self ._nr_serializer_name = serializer_name
168173 self ._nr_group_prefix = group_prefix
169174
170175 def serialize (self , topic , object ):
171- wrapped = self .__wrapped__ .serialize
176+ wrapped = self .__wrapped__ .serialize # pylint: disable=W0622
172177 args = (topic , object )
173178 kwargs = {}
174179
0 commit comments