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

Zipkin/refactor #114

Merged
merged 3 commits into from
Jun 21, 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 @@ -58,7 +58,14 @@ public async Task ExportAsync(IEnumerable<SpanData> spanDataList)
zipkinSpans.Add(zipkinSpan);
}

await this.SendSpansAsync(zipkinSpans);
try
{
await this.SendSpansAsync(zipkinSpans);
}
catch (Exception)
{
// Ignored
}
}

internal ZipkinSpan GenerateSpan(SpanData spanData, ZipkinEndpoint localEndpoint)
Expand Down Expand Up @@ -155,38 +162,24 @@ private ZipkinSpanKind ToSpanKind(SpanData spanData)
return ZipkinSpanKind.CLIENT;
}

private async Task SendSpansAsync(IEnumerable<ZipkinSpan> spans)
private Task SendSpansAsync(IEnumerable<ZipkinSpan> spans)
{
try
{
var requestUri = this.options.Endpoint;
var request = this.GetHttpRequestMessage(HttpMethod.Post, requestUri);
request.Content = this.GetRequestContent(spans);
await this.DoPost(this.httpClient, request);
}
catch (Exception)
{
}
var requestUri = this.options.Endpoint;
var request = this.GetHttpRequestMessage(HttpMethod.Post, requestUri);
request.Content = this.GetRequestContent(spans);
return this.DoPost(this.httpClient, request);
}

private async Task DoPost(HttpClient client, HttpRequestMessage request)
{
try
using (HttpResponseMessage response = await client.SendAsync(request))
{
using (HttpResponseMessage response = await client.SendAsync(request))
if (response.StatusCode != HttpStatusCode.OK &&
response.StatusCode != HttpStatusCode.Accepted)
{
if (response.StatusCode != HttpStatusCode.OK &&
response.StatusCode != HttpStatusCode.Accepted)
{
var statusCode = (int)response.StatusCode;
}

return;
var statusCode = (int)response.StatusCode;
}
}
catch (Exception)
{
}
}

private HttpRequestMessage GetHttpRequestMessage(HttpMethod method, Uri requestUri)
Expand All @@ -198,17 +191,17 @@ private HttpRequestMessage GetHttpRequestMessage(HttpMethod method, Uri requestU

private HttpContent GetRequestContent(IEnumerable<ZipkinSpan> toSerialize)
{
string content = string.Empty;
try
{
string json = JsonConvert.SerializeObject(toSerialize);

return new StringContent(json, Encoding.UTF8, "application/json");
content = JsonConvert.SerializeObject(toSerialize);
}
catch (Exception)
{
// Ignored
}

return new StringContent(string.Empty, Encoding.UTF8, "application/json");
return new StringContent(content, Encoding.UTF8, "application/json");
}

private ZipkinEndpoint GetLocalZipkinEndpoint()
Expand Down