Skip to content

Commit

Permalink
Zipkin/refactor (#114)
Browse files Browse the repository at this point in the history
* Don't await task if unused

* Supress exception at the API entry
bruno-garcia authored and SergeyKanzhelev committed Jun 21, 2019
1 parent 0869961 commit 27d9b98
Showing 1 changed file with 21 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -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)
@@ -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)
@@ -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()

0 comments on commit 27d9b98

Please sign in to comment.