class Threading(bm.Scenario): nthreads = bm.var(type=int) ntraces = bm.var(type=int) nspans = bm.var(type=int) def create_trace(self, tracer): # type: (Tracer) -> None with tracer.trace("root"): for _ in range(self.nspans - 1): with tracer.trace("child"): # Simulate work in each child random.random() def run(self): # type: () -> Generator[Callable[[int], None], None, None] from ddtrace import tracer # configure global tracer to drop traces rather tracer.configure(writer=NoopWriter()) def _(loops): # type: (int) -> None for _ in range(loops): with concurrent.futures.ThreadPoolExecutor(max_workers=self.nthreads) as executor: tasks = {executor.submit(self.create_trace, tracer) for i in range(self.ntraces)} for task in concurrent.futures.as_completed(tasks): task.result() yield _
class SamplingRules(bm.Scenario): num_iterations = bm.var(type=int) num_services = bm.var(type=int) num_operations = bm.var(type=int) def run(self): # Generate random service and operation names for the counts we requested services = [rands() for _ in range(self.num_services)] operation_names = [rands() for _ in range(self.num_operations)] # Generate all possible permutations of service and operation names spans = [ Span(tracer=None, service=service, name=name) for service, name in itertools.product(services, operation_names) ] # Create a single rule to use for all matches # Pick a random service/operation name rule = SamplingRule( service=random.choice(services), name=random.choice(operation_names), sample_rate=1.0, ) def _(loops): for _ in range(loops): for span in iter_n(spans, n=self.num_iterations): rule.matches(span) yield _
class HTTPPropagationInject(bm.Scenario): sampling_priority = bm.var(type=str) dd_origin = bm.var(type=str) meta = bm.var(type=str) def run(self): sampling_priority = None if self.sampling_priority != "": sampling_priority = int(self.sampling_priority) dd_origin = self.dd_origin or None meta = None if self.meta: meta = json.loads(self.meta) ctx = Context( trace_id=8336172473188639332, span_id=6804240797025004118, sampling_priority=sampling_priority, dd_origin=dd_origin, meta=meta, ) def _(loops): for _ in range(loops): # Just pass in a new/empty dict, we don't care about the result http.HTTPPropagator.inject(ctx, {}) yield _
class HTTPPropagationExtract(bm.Scenario): headers = bm.var(type=str) extra_headers = bm.var(type=int) wsgi_style = bm.var(type=bool) def generate_headers(self): headers = json.loads(self.headers) if self.wsgi_style: headers = { utils.get_wsgi_header(header): value for header, value in headers.items() } for i in range(self.extra_headers): header = "x-test-header-{}".format(i) if self.wsgi_style: header = utils.get_wsgi_header(header) headers[header] = str(i) return headers def run(self): headers = self.generate_headers() def _(loops): for _ in range(loops): http.HTTPPropagator.extract(headers) yield _
class Span(bm.Scenario): nspans = bm.var(type=int) ntags = bm.var(type=int) ltags = bm.var(type=int) nmetrics = bm.var(type=int) finishspan = bm.var_bool() def run(self): # run scenario to also set tags on spans tags = utils.gen_tags(self) settags = len(tags) > 0 # run scenario to also set metrics on spans metrics = utils.gen_metrics(self) setmetrics = len(metrics) > 0 # run scenario to include finishing spans finishspan = self.finishspan def _(loops): for _ in range(loops): for i in range(self.nspans): s = dd_Span(None, "test." + str(i), resource="resource", service="service") if settags: s.set_tags(tags) if setmetrics: s.set_metrics(metrics) if finishspan: s.finish() yield _
class FlaskSimple(bm.Scenario): tracer_enabled = bm.var(type=bool) profiler_enabled = bm.var(type=bool) def run(self): with utils.server(self) as get_response: def _(loops): for _ in range(loops): get_response() yield _
class Tracer(bm.Scenario): depth = bm.var(type=int) def run(self): # configure global tracer to drop traces rather than encoded and sent to # an agent from ddtrace import tracer tracer.configure(settings={"FILTERS": [_DropTraces()]}) def _(loops): for _ in range(loops): spans = [] for i in range(self.depth): spans.append(tracer.trace(str(i))) while len(spans) > 0: span = spans.pop() span.finish() yield _
class Encoder(bm.Scenario): ntraces = bm.var(type=int) nspans = bm.var(type=int) ntags = bm.var(type=int) ltags = bm.var(type=int) nmetrics = bm.var(type=int) dd_origin = bm.var(type=bool) encoding = bm.var(type=str) def run(self): encoder = utils.init_encoder(self.encoding) traces = utils.gen_traces(self) def _(loops): for _ in range(loops): for trace in traces: encoder.put(trace) encoder.encode() yield _