Esempio n. 1
0
class JaegerReporter(SpanReporter):
  "Send spans to a jaeger instance."

  options_scope = 'jaeger-reporter'

  @classmethod
  def register_options(cls, register):
    super(JaegerReporter, cls).register_options(register)
    register('--host', default='localhost')
    register('--port', default=5775, type=int)

  def __init__(self, *args, **kwargs):
    super(JaegerReporter, self).__init__(*args, **kwargs)
    if self.opts.enabled:
      # TODO(awinter): document if this is creating global state.
      logging.getLogger('jaeger_tracing').setLevel(logging.WARNING)
      self.tracer = Config(
        config={
          'sampler': {'type': 'const', 'param': 1},
          'local_agent': {
            'reporting_host': self.opts.host,
            'reporting_port': self.opts.port,
          },
          'logging': False,  # note: this doesn't seem to do anything
        },
        service_name='pants'
      ).initialize_tracer()

  def close(self):
    super(JaegerReporter, self).close()
    if self.opts.enabled:
      self.tracer.close()

  def mkspan(self, name, parent=None, tags={}):
    span = opentracing.start_child_span(parent, operation_name=name) \
      if parent \
      else self.tracer.start_span(operation_name=name)
    for k, v in tags.items():
      span.set_tag(k, v)
    return span

  @staticmethod
  def span_name(span):
    return span.operation_name

  @staticmethod
  def stop_span(span):
    span.finish()
Esempio n. 2
0
def init_tracer():
    """Initializes and registers global tracer.
    """
    tracer = Config(
        config={
            "sampler": {
                "type": "const",
                "param": 1
            },
            "logging": True
        },
        service_name="pie-users",
        validate=True,
    ).initialize_tracer()

    atexit.register(lambda: tracer.close())