def test_list_no_match(self): span = Span(name='Name', tracer=None) span.set_tag(URL, r'http://cooldomain.example.com') filtr = FilterRequestsOnUrl([ 'http://domain\.example\.com', 'http://anotherdomain\.example\.com' ]) trace = filtr.process_trace([span]) self.assertIsNotNone(trace)
def test_list_match(self): span = Span(name="Name", tracer=None) span.set_tag(URL, r"http://anotherdomain.example.com") filtr = FilterRequestsOnUrl([ r"http://domain\.example\.com", r"http://anotherdomain\.example\.com" ]) trace = filtr.process_trace([span]) self.assertIsNone(trace)
def get_settings(self): # update tracer settings return { "datadog_trace": { "default_service": "custom-tornado", "tags": {"env": "production", "debug": "false"}, "enabled": False, "agent_hostname": "dd-agent.service.consul", "agent_port": 8126, "settings": { "FILTERS": [ FilterRequestsOnUrl(r"http://test\.example\.com"), ], }, }, }
def get_settings(self): # update tracer settings return { 'datadog_trace': { 'default_service': 'custom-tornado', 'tags': {'env': 'production', 'debug': 'false'}, 'enabled': False, 'agent_hostname': 'dd-agent.service.consul', 'agent_port': 8126, 'settings': { 'FILTERS': [ FilterRequestsOnUrl(r'http://test\.example\.com'), ], }, }, }
def test_worker_filter_request(self): self.tracer.configure(settings={ FILTERS_KEY: [FilterRequestsOnUrl(r"http://example\.com/health")] }) # spy the send() method span = self.tracer.trace("testing.filteredurl") span.set_tag(http.URL, "http://example.com/health") span.finish() span = self.tracer.trace("testing.nonfilteredurl") span.set_tag(http.URL, "http://example.com/api/resource") span.finish() self._wait_thread_flush() # Only the second trace should have been sent assert self.api._put.call_count == 1 # check and retrieve the right call endpoint, payload = self._get_endpoint_payload( self.api._put.call_args_list, "/v0.4/traces") assert endpoint == "/v0.4/traces" assert len(payload) == 1 assert payload[0][0][b"name"] == b"testing.nonfilteredurl"
def test_worker_filter_request(self): self.tracer.configure(settings={FILTERS_KEY: [FilterRequestsOnUrl(r'http://example\.com/health')]}) # spy the send() method self.api = self.tracer.writer.api self.api._put = mock.Mock(self.api._put, wraps=self.api._put) span = self.tracer.trace('testing.filteredurl') span.set_tag(http.URL, 'http://example.com/health') span.finish() span = self.tracer.trace('testing.nonfilteredurl') span.set_tag(http.URL, 'http://example.com/api/resource') span.finish() self._wait_thread_flush() # Only the second trace should have been sent eq_(self.api._put.call_count, 1) # check and retrieve the right call endpoint, payload = self._get_endpoint_payload(self.api._put.call_args_list, '/v0.3/traces') eq_(endpoint, '/v0.3/traces') eq_(len(payload), 1) eq_(payload[0][0]['name'], 'testing.nonfilteredurl')
def test_is_match(self): span = Span(name='Name', tracer=None) span.set_tag(URL, r'http://example.com') filtr = FilterRequestsOnUrl('http://examp.*.com') trace = filtr.process_trace([span]) self.assertIsNone(trace)
def test_is_not_match(self): span = Span(name="Name", tracer=None) span.set_tag(URL, r"http://anotherexample.com") filtr = FilterRequestsOnUrl("http://examp.*.com") trace = filtr.process_trace([span]) self.assertIsNotNone(trace)
) # Datadog DATADOG_SETTINGS = { 'host_name': env.str('DD_AGENT_HOST', None), 'api_key': env.str('DATADOG_API_KEY', None), 'app_key': env.str('DATADOG_APP_KEY', None), } if not DEBUG: tracer.configure( hostname=env.str('DD_AGENT_HOST'), port=env.str('DD_TRACE_AGENT_PORT'), settings={ 'FILTERS': [ FilterRequestsOnUrl( [r'http://api\\.nephrogo\\.com/health/', r'http://localhost:8080/health/']) ], } ) config.django['service_name'] = 'nephrogo-api' config.django['instrument_databases'] = True config.django['instrument_caches'] = True config.django['trace_query_string'] = True config.django['analytics_enabled'] = True config.trace_headers([ 'user-agent', 'transfer-encoding', 'time-zone-name', 'accept-encoding', ])