class DummyWriter(AgentWriter): """DummyWriter is a small fake writer used for tests. not thread-safe.""" def __init__(self, *args, **kwargs): # original call if len(args) == 0 and "agent_url" not in kwargs: kwargs["agent_url"] = "http://localhost:8126" super(DummyWriter, self).__init__(*args, **kwargs) self.spans = [] self.traces = [] self.json_encoder = JSONEncoder() self.msgpack_encoder = MsgpackEncoder() def write(self, spans=None): if spans: # the traces encoding expect a list of traces so we # put spans in a list like we do in the real execution path # with both encoders trace = [spans] self.json_encoder.encode_traces(trace) self.msgpack_encoder.encode_traces(trace) self.spans += spans self.traces += trace def pop(self): # type: () -> List[Span] s = self.spans self.spans = [] return s def pop_traces(self): # type: () -> List[List[Span]] traces = self.traces self.traces = [] return traces
class DummyWriter(AgentWriter): """DummyWriter is a small fake writer used for tests. not thread-safe.""" def __init__(self, *args, **kwargs): # original call super(DummyWriter, self).__init__(*args, **kwargs) # dummy components self.spans = [] self.traces = [] self.services = {} self.json_encoder = JSONEncoder() self.msgpack_encoder = MsgpackEncoder() def write(self, spans=None, services=None): if spans: # the traces encoding expect a list of traces so we # put spans in a list like we do in the real execution path # with both encoders trace = [spans] self.json_encoder.encode_traces(trace) self.msgpack_encoder.encode_traces(trace) self.spans += spans self.traces += trace if services: self.json_encoder.encode_services(services) self.msgpack_encoder.encode_services(services) self.services.update(services) def pop(self): # dummy method s = self.spans self.spans = [] return s def pop_traces(self): # dummy method traces = self.traces self.traces = [] return traces def pop_services(self): # dummy method # Setting service info has been deprecated, we want to make sure nothing ever gets written here assert self.services == {} s = self.services self.services = {} return s