1818from newrelic import version
1919from newrelic .common import system_info
2020from newrelic .common .agent_http import ApplicationModeClient , ServerlessModeClient
21- from newrelic .core .internal_metrics import internal_count_metric
2221from newrelic .common .encoding_utils import (
2322 json_decode ,
2423 json_encode ,
3231 KubernetesUtilization ,
3332 PCFUtilization ,
3433)
34+ from newrelic .core .attribute import truncate
3535from newrelic .core .config import (
3636 fetch_config_setting ,
3737 finalize_application_settings ,
3838 global_settings_dump ,
3939)
40+ from newrelic .core .internal_metrics import internal_count_metric
4041from newrelic .network .exceptions import (
4142 DiscardDataForRequest ,
4243 ForceAgentDisconnect ,
@@ -135,9 +136,7 @@ class AgentProtocol(object):
135136 ),
136137 ),
137138 }
138- PARAMS_ALLOWLIST = frozenset (
139- ("method" , "protocol_version" , "marshal_format" , "run_id" )
140- )
139+ PARAMS_ALLOWLIST = frozenset (("method" , "protocol_version" , "marshal_format" , "run_id" ))
141140
142141 SECURITY_SETTINGS = (
143142 "capture_params" ,
@@ -219,9 +218,7 @@ def send(self, method, payload=()):
219218 params , headers , payload = self ._to_http (method , payload )
220219
221220 try :
222- response = self .client .send_request (
223- params = params , headers = headers , payload = payload
224- )
221+ response = self .client .send_request (params = params , headers = headers , payload = payload )
225222 except NetworkInterfaceException :
226223 # All HTTP errors are currently retried
227224 raise RetryDataForRequest
@@ -245,10 +242,8 @@ def send(self, method, payload=()):
245242 "method" : method ,
246243 "status_code" : status ,
247244 "headers" : headers ,
248- "params" : {
249- k : v for k , v in params .items () if k in self .PARAMS_ALLOWLIST
250- },
251- "content" : data ,
245+ "params" : {k : v for k , v in params .items () if k in self .PARAMS_ALLOWLIST },
246+ "content" : truncate (data , 1024 ),
252247 "agent_run_id" : self ._run_token ,
253248 },
254249 )
@@ -277,26 +272,18 @@ def _connect_payload(app_name, linked_applications, environment, settings):
277272 ip_address = system_info .getips ()
278273
279274 connect_settings = {}
280- connect_settings ["browser_monitoring.loader" ] = settings [
281- "browser_monitoring.loader"
282- ]
283- connect_settings ["browser_monitoring.debug" ] = settings [
284- "browser_monitoring.debug"
285- ]
275+ connect_settings ["browser_monitoring.loader" ] = settings ["browser_monitoring.loader" ]
276+ connect_settings ["browser_monitoring.debug" ] = settings ["browser_monitoring.debug" ]
286277
287278 security_settings = {}
288279 security_settings ["capture_params" ] = settings ["capture_params" ]
289280 security_settings ["transaction_tracer" ] = {}
290- security_settings ["transaction_tracer" ]["record_sql" ] = settings [
291- "transaction_tracer.record_sql"
292- ]
281+ security_settings ["transaction_tracer" ]["record_sql" ] = settings ["transaction_tracer.record_sql" ]
293282
294283 utilization_settings = {}
295284 # metadata_version corresponds to the utilization spec being used.
296285 utilization_settings ["metadata_version" ] = 5
297- utilization_settings [
298- "logical_processors"
299- ] = system_info .logical_processor_count ()
286+ utilization_settings ["logical_processors" ] = system_info .logical_processor_count ()
300287 utilization_settings ["total_ram_mib" ] = system_info .total_physical_memory ()
301288 utilization_settings ["hostname" ] = hostname
302289 if ip_address :
@@ -451,9 +438,7 @@ def connect(
451438 with cls (settings , host = redirect_host , client_cls = client_cls ) as protocol :
452439 configuration = protocol .send (
453440 "connect" ,
454- cls ._connect_payload (
455- app_name , linked_applications , environment , settings
456- ),
441+ cls ._connect_payload (app_name , linked_applications , environment , settings ),
457442 )
458443
459444 # Apply High Security Mode to server_config, so the local
@@ -487,9 +472,7 @@ def finalize(self):
487472
488473class ServerlessModeProtocol (AgentProtocol ):
489474 def __init__ (self , settings , host = None , client_cls = ServerlessModeClient ):
490- super (ServerlessModeProtocol , self ).__init__ (
491- settings , host = host , client_cls = client_cls
492- )
475+ super (ServerlessModeProtocol , self ).__init__ (settings , host = host , client_cls = client_cls )
493476 self ._metadata = {
494477 "protocol_version" : self .VERSION ,
495478 "execution_environment" : os .environ .get ("AWS_EXECUTION_ENV" , None ),
@@ -525,9 +508,7 @@ def connect(
525508 client_cls = ServerlessModeClient ,
526509 ):
527510 aws_lambda_metadata = settings .aws_lambda_metadata
528- settings = finalize_application_settings (
529- {"cross_application_tracer.enabled" : False }, settings
530- )
511+ settings = finalize_application_settings ({"cross_application_tracer.enabled" : False }, settings )
531512 # Metadata must come from the original settings object since it
532513 # can be modified later
533514 settings .aws_lambda_metadata = aws_lambda_metadata
0 commit comments