@@ -25,17 +25,15 @@ def _run_validation_test():
2525 from newrelic .api .error_trace import error_trace
2626 from newrelic .api .external_trace import external_trace
2727 from newrelic .api .function_trace import function_trace
28- from newrelic .api .transaction import add_custom_parameter
2928 from newrelic .api .time_trace import notice_error
29+ from newrelic .api .transaction import add_custom_attribute
3030 from newrelic .api .wsgi_application import wsgi_application
3131
32- @external_trace (library = 'test' ,
33- url = 'http://localhost/test' , method = 'GET' )
32+ @external_trace (library = "test" , url = "http://localhost/test" , method = "GET" )
3433 def _external1 ():
3534 time .sleep (0.1 )
3635
37- @function_trace (label = 'label' ,
38- params = {'fun-key-1' : '1' , 'fun-key-2' : 2 , 'fun-key-3' : 3.0 })
36+ @function_trace (label = "label" , params = {"fun-key-1" : "1" , "fun-key-2" : 2 , "fun-key-3" : 3.0 })
3937 def _function1 ():
4038 _external1 ()
4139
@@ -47,33 +45,29 @@ def _function2():
4745 @error_trace ()
4846 @function_trace ()
4947 def _function3 ():
50- add_custom_parameter ( ' txn-key-1' , 1 )
48+ add_custom_attribute ( " txn-key-1" , 1 )
5149
5250 _function4 ()
5351
54- raise RuntimeError (' This is a test error and can be ignored.' )
52+ raise RuntimeError (" This is a test error and can be ignored." )
5553
5654 @function_trace ()
5755 def _function4 (params = None , application = None ):
5856 try :
5957 _function5 ()
6058 except :
61- notice_error (attributes = (params or {
62- 'err-key-2' : 2 , 'err-key-3' : 3.0 }),
63- application = application )
59+ notice_error (attributes = (params or {"err-key-2" : 2 , "err-key-3" : 3.0 }), application = application )
6460
6561 @function_trace ()
6662 def _function5 ():
67- raise NotImplementedError (
68- 'This is a test error and can be ignored.' )
63+ raise NotImplementedError ("This is a test error and can be ignored." )
6964
7065 @wsgi_application ()
7166 def _wsgi_application (environ , start_response ):
72- status = ' 200 OK'
73- output = ' Hello World!'
67+ status = " 200 OK"
68+ output = " Hello World!"
7469
75- response_headers = [('Content-type' , 'text/plain' ),
76- ('Content-Length' , str (len (output )))]
70+ response_headers = [("Content-type" , "text/plain" ), ("Content-Length" , str (len (output )))]
7771 start_response (status , response_headers )
7872
7973 for i in range (10 ):
@@ -107,16 +101,15 @@ def _background_task():
107101 def _start_response (* args ):
108102 pass
109103
110- _environ = { 'SCRIPT_NAME' : '' , 'PATH_INFO' : '/test' ,
111- 'QUERY_STRING' : 'key=value' }
104+ _environ = {"SCRIPT_NAME" : "" , "PATH_INFO" : "/test" , "QUERY_STRING" : "key=value" }
112105
113106 _iterable = _wsgi_application (_environ , _start_response )
114107 _iterable .close ()
115108
116109 _background_task ()
117110
118- _function4 (params = {' err-key-4' : 4 , ' err-key-5' : 5.0 },
119- application = application ())
111+ _function4 (params = {" err-key-4" : 4 , " err-key-5" : 5.0 }, application = application ())
112+
120113
121114_user_message = """
122115Running Python agent test.
@@ -136,19 +129,23 @@ def _start_response(*args):
136129data to the New Relic UI.
137130"""
138131
139- @command ('validate-config' , 'config_file [log_file]' ,
140- """Validates the syntax of <config_file>. Also tests connectivity to New
132+
133+ @command (
134+ "validate-config" ,
135+ "config_file [log_file]" ,
136+ """Validates the syntax of <config_file>. Also tests connectivity to New
141137Relic core application by connecting to the account corresponding to the
142138license key listed in the configuration file, and reporting test data under
143- the application name 'Python Agent Test'.""" )
139+ the application name 'Python Agent Test'.""" ,
140+ )
144141def validate_config (args ):
142+ import logging
145143 import os
146144 import sys
147- import logging
148145 import time
149146
150147 if len (args ) == 0 :
151- usage (' validate-config' )
148+ usage (" validate-config" )
152149 sys .exit (1 )
153150
154151 from newrelic .api .application import register_application
@@ -158,7 +155,7 @@ def validate_config(args):
158155 if len (args ) >= 2 :
159156 log_file = args [1 ]
160157 else :
161- log_file = ' /tmp/python-agent-test.log'
158+ log_file = " /tmp/python-agent-test.log" # nosec
162159
163160 log_level = logging .DEBUG
164161
@@ -168,21 +165,20 @@ def validate_config(args):
168165 pass
169166
170167 config_file = args [0 ]
171- environment = os .environ .get (' NEW_RELIC_ENVIRONMENT' )
168+ environment = os .environ .get (" NEW_RELIC_ENVIRONMENT" )
172169
173- if config_file == '-' :
174- config_file = os .environ .get (' NEW_RELIC_CONFIG_FILE' )
170+ if config_file == "-" :
171+ config_file = os .environ .get (" NEW_RELIC_CONFIG_FILE" )
175172
176- initialize (config_file , environment , ignore_errors = False ,
177- log_file = log_file , log_level = log_level )
173+ initialize (config_file , environment , ignore_errors = False , log_file = log_file , log_level = log_level )
178174
179175 _logger = logging .getLogger (__name__ )
180176
181- _logger .debug (' Starting agent validation.' )
177+ _logger .debug (" Starting agent validation." )
182178
183179 _settings = global_settings ()
184180
185- app_name = os .environ .get (' NEW_RELIC_TEST_APP_NAME' , ' Python Agent Test' )
181+ app_name = os .environ .get (" NEW_RELIC_TEST_APP_NAME" , " Python Agent Test" )
186182
187183 _settings .app_name = app_name
188184 _settings .transaction_tracer .transaction_threshold = 0
@@ -194,17 +190,17 @@ def validate_config(args):
194190
195191 print (_user_message % dict (app_name = app_name , log_file = log_file ))
196192
197- _logger .debug (' Register test application.' )
193+ _logger .debug (" Register test application." )
198194
199- _logger .debug (' Collector host is %r.' , _settings .host )
200- _logger .debug (' Collector port is %r.' , _settings .port )
195+ _logger .debug (" Collector host is %r." , _settings .host )
196+ _logger .debug (" Collector port is %r." , _settings .port )
201197
202- _logger .debug (' Proxy scheme is %r.' , _settings .proxy_scheme )
203- _logger .debug (' Proxy host is %r.' , _settings .proxy_host )
204- _logger .debug (' Proxy port is %r.' , _settings .proxy_port )
205- _logger .debug (' Proxy user is %r.' , _settings .proxy_user )
198+ _logger .debug (" Proxy scheme is %r." , _settings .proxy_scheme )
199+ _logger .debug (" Proxy host is %r." , _settings .proxy_host )
200+ _logger .debug (" Proxy port is %r." , _settings .proxy_port )
201+ _logger .debug (" Proxy user is %r." , _settings .proxy_user )
206202
207- _logger .debug (' License key is %r.' , _settings .license_key )
203+ _logger .debug (" License key is %r." , _settings .license_key )
208204
209205 _timeout = 30.0
210206
@@ -215,24 +211,25 @@ def validate_config(args):
215211 _duration = _end - _start
216212
217213 if not _application .active :
218- _logger .error ('Unable to register application for test, '
219- 'connection could not be established within %s seconds.' ,
220- _timeout )
214+ _logger .error (
215+ "Unable to register application for test, " "connection could not be established within %s seconds." ,
216+ _timeout ,
217+ )
221218 return
222219
223- if hasattr (_application .settings , ' messages' ):
220+ if hasattr (_application .settings , " messages" ):
224221 for message in _application .settings .messages :
225- if message [' message' ].startswith (' Reporting to:' ):
226- parts = message [' message' ].split (' Reporting to:' )
222+ if message [" message" ].startswith (" Reporting to:" ):
223+ parts = message [" message" ].split (" Reporting to:" )
227224 url = parts [1 ].strip ()
228- print (' Registration successful. Reporting to:' )
225+ print (" Registration successful. Reporting to:" )
229226 print ()
230- print (' %s' % url )
227+ print (" %s" % url )
231228 print ()
232229 break
233230
234- _logger .debug (' Registration took %s seconds.' , _duration )
231+ _logger .debug (" Registration took %s seconds." , _duration )
235232
236- _logger .debug (' Run the validation test.' )
233+ _logger .debug (" Run the validation test." )
237234
238235 _run_validation_test ()
0 commit comments