def test_single_trace_single_span(self, tracer): s = tracer.trace("operation", service="my-svc") s.set_tag("k", "v") # numeric tag s.set_tag("num", 1234) s.set_metric("float_metric", 12.34) s.set_metric("int_metric", 4321) s.finish() tracer.shutdown()
def test_sampling(self, tracer): with tracer.trace("trace1"): with tracer.trace("child"): pass sampler = DatadogSampler(default_sample_rate=1.0) tracer.configure(sampler=sampler, writer=tracer.writer) with tracer.trace("trace2"): with tracer.trace("child"): pass sampler = DatadogSampler(default_sample_rate=0.000001) tracer.configure(sampler=sampler, writer=tracer.writer) with tracer.trace("trace3"): with tracer.trace("child"): pass sampler = DatadogSampler(default_sample_rate=1, rules=[SamplingRule(1.0)]) tracer.configure(sampler=sampler, writer=tracer.writer) with tracer.trace("trace4"): with tracer.trace("child"): pass sampler = DatadogSampler(default_sample_rate=1, rules=[SamplingRule(0)]) tracer.configure(sampler=sampler, writer=tracer.writer) with tracer.trace("trace5"): with tracer.trace("child"): pass sampler = DatadogSampler(default_sample_rate=1) tracer.configure(sampler=sampler, writer=tracer.writer) with tracer.trace("trace6"): with tracer.trace("child") as span: span.set_tag(MANUAL_DROP_KEY) sampler = DatadogSampler(default_sample_rate=1) tracer.configure(sampler=sampler, writer=tracer.writer) with tracer.trace("trace7"): with tracer.trace("child") as span: span.set_tag(MANUAL_KEEP_KEY) sampler = RateSampler(0.0000000001) tracer.configure(sampler=sampler, writer=tracer.writer) # This trace should not appear in the snapshot with tracer.trace("trace8"): with tracer.trace("child"): pass tracer.shutdown()
def test_multiple_traces(self, tracer): with tracer.trace("operation1", service="my-svc") as s: s.set_tag("k", "v") s.set_tag("num", 1234) s.set_metric("float_metric", 12.34) s.set_metric("int_metric", 4321) tracer.trace("child").finish() with tracer.trace("operation2", service="my-svc") as s: s.set_tag("k", "v") s.set_tag("num", 1234) s.set_metric("float_metric", 12.34) s.set_metric("int_metric", 4321) tracer.trace("child").finish() tracer.shutdown()
def test_filters(self, tracer): class FilterMutate(object): def __init__(self, key, value): self.key = key self.value = value def process_trace(self, trace): for s in trace: s.set_tag(self.key, self.value) return trace tracer.configure(settings={ "FILTERS": [FilterMutate("boop", "beep")], }) with tracer.trace("root"): with tracer.trace("child"): pass tracer.shutdown()
def test_user_specified_dd_mariadb_service_snapshot(): """ When a user specifies a service for the app The mariadb integration should not use it. """ import mariadb from ddtrace import config # noqa from ddtrace import patch from ddtrace import tracer patch(mariadb=True) from tests.contrib.config import MARIADB_CONFIG connection = mariadb.connect(**MARIADB_CONFIG) cursor = connection.cursor() cursor.execute("SELECT 1") rows = cursor.fetchall() assert len(rows) == 1 tracer.shutdown()
def test_synchronous_writer_shutdown(): tracer = Tracer() tracer.configure( writer=AgentWriter(tracer.writer.agent_url, sync_mode=True)) # Ensure this doesn't raise. tracer.shutdown()
async def shutdown_tracer(request): tracer.shutdown() return json({"success": True})
def pytest_sessionfinish(session, exitstatus): """Flush open tracer.""" if tracer is None: return tracer.shutdown()
def shutdown(request): # Endpoint used to flush traces to the agent when doing snapshots. tracer.shutdown() return HttpResponse(status=200)
def tracer_shutdown(request): tracer.shutdown() return Response("shutdown")