diff --git a/src/OpenTelemetry.Exporter.Zipkin/Implementation/TraceExporterHandler.cs b/src/OpenTelemetry.Exporter.Zipkin/Implementation/TraceExporterHandler.cs index 40d23324a78..8fffe4c7688 100644 --- a/src/OpenTelemetry.Exporter.Zipkin/Implementation/TraceExporterHandler.cs +++ b/src/OpenTelemetry.Exporter.Zipkin/Implementation/TraceExporterHandler.cs @@ -58,7 +58,14 @@ public async Task ExportAsync(IEnumerable 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 spans) + private Task SendSpansAsync(IEnumerable 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 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()