Skip to content

Commit

Permalink
Do not export zipkin exporter calls to zipkin endpoint (#167)
Browse files Browse the repository at this point in the history
* Do not export calls to Zipkin

* up
  • Loading branch information
Liudmila Molkova authored Jul 30, 2019
1 parent e00bccb commit b94fc10
Showing 1 changed file with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ internal class TraceExporterHandler : IHandler
private readonly ZipkinTraceExporterOptions options;
private readonly ZipkinEndpoint localEndpoint;
private readonly HttpClient httpClient;
private readonly string serviceEndpoint;

public TraceExporterHandler(ZipkinTraceExporterOptions options, HttpClient client)
{
this.options = options;
this.localEndpoint = this.GetLocalZipkinEndpoint();
this.httpClient = client ?? new HttpClient();
this.serviceEndpoint = options.Endpoint?.ToString();
}

public async Task ExportAsync(IEnumerable<SpanData> spanDataList)
Expand All @@ -54,8 +56,26 @@ public async Task ExportAsync(IEnumerable<SpanData> spanDataList)

foreach (var data in spanDataList)
{
var zipkinSpan = this.GenerateSpan(data, this.localEndpoint);
zipkinSpans.Add(zipkinSpan);
bool shouldExport = true;
foreach (var label in data.Attributes.AttributeMap)
{
if (label.Key == "http.url")
{
if (label.Value is string urlStr && urlStr == this.serviceEndpoint)
{
// do not track calls to Zipkin
shouldExport = false;
}

break;
}
}

if (shouldExport)
{
var zipkinSpan = this.GenerateSpan(data, this.localEndpoint);
zipkinSpans.Add(zipkinSpan);
}
}

try
Expand Down Expand Up @@ -91,7 +111,7 @@ internal ZipkinSpan GenerateSpan(SpanData spanData, ZipkinEndpoint localEndpoint

foreach (var label in spanData.Attributes.AttributeMap)
{
spanBuilder.PutTag(label.Key, (string)label.Value);
spanBuilder.PutTag(label.Key, label.Value.ToString());
}

var status = spanData.Status;
Expand Down

0 comments on commit b94fc10

Please sign in to comment.