public static T LogExceptions <T>( this ISpan span, Func <T> action) { try { return(action()); } catch (Exception e) { span.LogError(e); throw; } }
public static void LogExceptions( this ISpan span, Action action) { try { action(); } catch (Exception e) { span.LogError(e); throw; } }
public static async Task <T> LogExceptionsAsync <T>( this ISpan span, Func <Task <T> > action) { try { return(await action().ConfigureAwait(false)); } catch (Exception e) { span.LogError(e); throw; } }
public async Task SayHello(string helloTo) { using (IScope scope = _tracer.BuildActiveSpan("Call-web-app")) // BuildActiveSpan: From common extensions. { ISpan span = scope.Span; span.SetBaggageItem("baggage", "baggage-value"); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, $"Hello/{helloTo}"); request.Headers.InjectTracing( // InjectTracing: From common extensions. request.Method.Method, $"{_httpClient.BaseAddress}{request.RequestUri}"); HttpResponseMessage response = null; try { response = await _httpClient.SendAsync(request); } catch (Exception ex) { span.LogError(ex, "Failed to call say hello."); // LogError: From common extensions. Console.WriteLine(ex.Message); return; } span.SetTag(Tags.HttpStatus, (int)response.StatusCode); string responseString = await response.Content.ReadAsStringAsync(); span.LogMessage("response", responseString); // LogMessage: From common extensions. Console.WriteLine(responseString); } }