Skip to content

Commit

Permalink
Print trace id to console and possible URL with the zipkin trace (#7313)
Browse files Browse the repository at this point in the history
### Problem
It is not obvious for the user how to find the zipkin trace after a pants run.

### Solution
One of the solutions is to print zipkin trace in the console. 
The better one could be to print a link to the Zipkin API with the trace. But endpoints to send spans to Zipkin API and to view the resulting trace may be different. The set up is not unique. 
One of the solutions is to have two flags:
--reporter-zipkin-send-endpoint  and
--reporter-zipkin-view-endpoint
Current implementation suggests a link that can point to the current zipkin trace.

I would be grateful for your comments in regard to it
  • Loading branch information
cattibrie authored and illicitonion committed Mar 6, 2019
1 parent e8ccd90 commit 304691b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/python/pants/reporting/zipkin_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pants.reporting.reporter import Reporter


log = logging.getLogger(__name__)
logger = logging.getLogger(__name__)


class HTTPTransportHandler(BaseTransportHandler):
Expand All @@ -34,7 +34,7 @@ def send(self, payload):
headers={'Content-Type': 'application/x-thrift'},
)
except Exception as err:
log.error("Failed to post the payload to zipkin server. Error {}".format(err))
logger.error("Failed to post the payload to zipkin server. Error {}".format(err))


class ZipkinReporter(Reporter):
Expand Down Expand Up @@ -63,6 +63,7 @@ def __init__(self, run_tracker, settings, endpoint, trace_id, parent_id, sample_
self.trace_id = trace_id
self.parent_id = parent_id
self.sample_rate = float(sample_rate)
self.endpoint = endpoint

def start_workunit(self, workunit):
"""Implementation of Reporter callback."""
Expand All @@ -89,6 +90,8 @@ def start_workunit(self, workunit):
zipkin_attrs = create_attrs_for_span(
sample_rate=self.sample_rate, # Value between 0.0 and 100.0
)
self.trace_id = zipkin_attrs.trace_id


span = zipkin_span(
service_name=service_name,
Expand All @@ -115,3 +118,9 @@ def end_workunit(self, workunit):
if workunit in self._workunits_to_spans:
span = self._workunits_to_spans.pop(workunit)
span.stop()

def close(self):
"""End the report."""
endpoint = self.endpoint.replace("/api/v1/spans", "")

logger.debug("Zipkin trace may be located at this URL {}/traces/{}".format(endpoint, self.trace_id))

0 comments on commit 304691b

Please sign in to comment.