Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not export zipkin exporter calls to zipkin endpoint #167

Merged
merged 3 commits into from
Jul 30, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lmolkova I might be reading the code incorrectly, but there appears to be a possibility that SendSpansAsync can be called with an empty span list, resulting in a HTTP call to Zipkin, which still causes a invisible loop.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnduhart sorry, this is merged already...

Would you mind sending very short PR to return from ExportAsync immediately if Span batch is empty?
It seems it should not ever happen (but seems to be reasonable anyway), see here:

if (this.spans.TryTake(out var item, this.scheduleDelay))

And also after loop runs we should make sure zipkinSpans are not empty.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also after loop runs we should make sure zipkinSpans are not empty.

This was my main concern, given we're selectively including spans in this method.

Sure, I'll cut a PR to add that.

}
}

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