def test_message_trace_params_dropped_in_hsm(hsm_enabled): @background_task() def _test(): with MessageTrace("library", "operation", "dest_type", "dest_name", params={"secret": "super secret"}): pass if hsm_enabled: _test = override_application_settings(_test_transaction_settings_hsm_enabled_capture_params)(_test) _test = validate_tt_segment_params(forgone_params=("secret",))(_test) else: _test = override_application_settings(_test_transaction_settings_hsm_disabled)(_test) _test = validate_tt_segment_params(present_params=("secret",))(_test) _test()
def test_function_trace_params_dropped_in_hsm(hsm_enabled): @background_task() def _test(): with FunctionTrace('trace', params={'secret': 'super secret'}): pass if hsm_enabled: _test = override_application_settings( _test_transaction_settings_hsm_enabled_capture_params)(_test) _test = validate_tt_segment_params(forgone_params=('secret', ))(_test) else: _test = override_application_settings( _test_transaction_settings_hsm_disabled)(_test) _test = validate_tt_segment_params(present_params=('secret', ))(_test) _test()
def test_httplib_multiple_requests_unique_distributed_tracing_id(server): connection = httplib.HTTPConnection('localhost', server.port) response_headers = [] @background_task(name='test_httplib:test_transaction') def test_transaction(): connection.request('GET', '/') response = connection.getresponse() response_headers.append(process_response(response.read())) connection.request('GET', '/') response = connection.getresponse() response_headers.append(process_response(response.read())) test_transaction = override_application_settings({ 'distributed_tracing.enabled': True, 'span_events.enabled': True, })(test_transaction) # make multiple requests with the same connection test_transaction() connection.close() dt_payloads = [ DistributedTracePayload.from_http_safe(header['newrelic']) for header in response_headers ] ids = set() for payload in dt_payloads: assert payload['d']['id'] not in ids ids.add(payload['d']['id'])
def test_httplib_multiple_requests_unique_distributed_tracing_id(server): connection = httplib.HTTPConnection("localhost", server.port) response_headers = [] @background_task(name="test_httplib:test_transaction") def test_transaction(): connection.request("GET", "/") response = connection.getresponse() response_headers.append(process_response(response.read())) connection.request("GET", "/") response = connection.getresponse() response_headers.append(process_response(response.read())) test_transaction = override_application_settings( { "distributed_tracing.enabled": True, "span_events.enabled": True, } )(test_transaction) # make multiple requests with the same connection test_transaction() connection.close() dt_payloads = [DistributedTracePayload.from_http_safe(header["newrelic"]) for header in response_headers] ids = set() for payload in dt_payloads: assert payload["d"]["id"] not in ids ids.add(payload["d"]["id"])
def test_requests_cross_process_request(distributed_tracing, span_events, server): @validate_transaction_errors(errors=[]) @background_task(name='test_requests:test_requests_cross_process_request') @cache_outgoing_headers @validate_cross_process_headers def _test(): requests.get('http://localhost:%d/' % server.port) _test = override_application_settings({ 'distributed_tracing.enabled': distributed_tracing, 'span_events.enabled': span_events, })(_test) _test()
def test_urlopen_cross_process_request(distributed_tracing, span_events, server): @validate_transaction_errors(errors=[]) @background_task(name='test_urllib3:test_urlopen_cross_process_request') @cache_outgoing_headers @validate_cross_process_headers def _test(): pool = urllib3.HTTPConnectionPool('localhost:%d' % server.port) pool.urlopen('GET', '/') _test = override_application_settings({ 'distributed_tracing.enabled': distributed_tracing, 'span_events.enabled': span_events, })(_test) _test()
def test_http_cross_process_request(distributed_tracing, span_events, server): @background_task(name='test_http:test_http_cross_process_request') @cache_outgoing_headers @validate_cross_process_headers def _test(): connection = httplib.HTTPConnection('localhost', server.port) connection.request('GET', '/') response = connection.getresponse() response.read() connection.close() _test = override_application_settings({ 'distributed_tracing.enabled': distributed_tracing, 'span_events.enabled': span_events, })(_test) _test()
def test_httplib2_cross_process_request(distributed_tracing, span_events, server): @background_task(name="test_httplib2:test_httplib2_cross_process_response") @cache_outgoing_headers @validate_cross_process_headers def _test(): connection = httplib2.HTTPConnectionWithTimeout("localhost", server.port) connection.request("GET", "/") response = connection.getresponse() response.read() connection.close() _test = override_application_settings( { "distributed_tracing.enabled": distributed_tracing, "cross_application_tracer.enabled": not distributed_tracing, "span_events.enabled": span_events, } )(_test) _test()
def test_urlopen_cross_process_request(distributed_tracing, span_events, server): @validate_transaction_errors(errors=[]) @background_task(name="test_urllib3:test_urlopen_cross_process_request") @cache_outgoing_headers @validate_cross_process_headers def _test(): pool = urllib3.HTTPConnectionPool("localhost:%d" % server.port) pool.urlopen("GET", "/") _test = override_application_settings({ "distributed_tracing.enabled": distributed_tracing, "cross_application_tracer.enabled": not distributed_tracing, "span_events.enabled": span_events, })(_test) _test()
def test_httplib_nr_headers_added(server): connection = httplib.HTTPConnection('localhost', server.port) key = 'newrelic' value = 'testval' headers = [] @background_task(name='test_httplib:test_transaction') def test_transaction(): connection.putrequest('GET', '/') connection.putheader(key, value) connection.endheaders() response = connection.getresponse() headers.append(process_response(response.read())) test_transaction = override_application_settings({ 'distributed_tracing.enabled': True, 'span_events.enabled': True, })(test_transaction) test_transaction() connection.close() # verify newrelic headers already added do not get overrode assert headers[0][key] == value
def set_trace_ids(): txn = current_transaction() if txn: txn._trace_id = "abcdefgh12345678" trace = current_trace() if trace: trace.guid = "abcdefgh" def exercise_record_log_event(message="A"): set_trace_ids() record_log_event(message, "ERROR") enable_log_forwarding = override_application_settings( {"application_logging.forwarding.enabled": True}) disable_log_forwarding = override_application_settings( {"application_logging.forwarding.enabled": False}) _common_attributes_service_linking = { "timestamp": None, "hostname": None, "entity.name": "Python Agent Test (agent_features)", "entity.guid": None } _common_attributes_trace_linking = { "span.id": "abcdefgh", "trace.id": "abcdefgh12345678" } _common_attributes_trace_linking.update(_common_attributes_service_linking) _test_record_log_event_inside_transaction_events = [{