public void SendTrace(EpsagonTrace trace) { Utils.DebugLogIfEnabled("sending trace, url: {url}", this.CollectorUrl); var client = new RestClient(this.CollectorUrl) { Timeout = Utils.CurrentConfig.SendTimeout * 1000 }; var request = new RestRequest(Method.POST); request .AddHeader("Authorization", $"Bearer {this.Token}") .AddHeader("Content-Type", "application/json") .AddJsonBody(Utils.SerializeObject(trace)); var res = client.Execute(request); Utils.DebugLogIfEnabled("sent trace, {trace}", Utils.SerializeObject(trace)); if (!res.IsSuccessful) { Utils.DebugLogIfEnabled("request - method: {@method}, endpoint: {@ep}, timeout: {@to}", request.Method, request.Resource, request.Timeout); Utils.DebugLogIfEnabled("request body: {@body}", request.Body); Utils.DebugLogIfEnabled("response - headers: {@h}, status: {@s}, error: {@e}", res.Headers, res.StatusCode, res.ErrorMessage); Utils.DebugLogIfEnabled("response content: {@content}", res.Content); } JaegerTracer.Clear(); }
private static void CreateTraceAndSend() { var trace = EpsagonConverter.CreateTrace(JaegerTracer.GetSpans()); EpsagonTrace.SendTrace(trace); JaegerTracer.Clear(); EpsagonUtils.ClearTraceUrl(); }
public void SendTrace(EpsagonTrace trace) { Utils.DebugLogIfEnabled("sending trace, url: {url}"); var traceJsonString = Convert.ToBase64String(Encoding.UTF8.GetBytes(Utils.SerializeObject(trace))); System.Console.WriteLine("EPSAGON_TRACE: {0}", traceJsonString); Utils.DebugLogIfEnabled("sent trace, {trace}", Utils.SerializeObject(trace)); Utils.DebugLogIfEnabled("trace base64, {trace}", traceJsonString); JaegerTracer.Clear(); }
public static TRes Handle <TEvent, TRes>(TEvent input, ILambdaContext context, Func <TRes> handlerFn) { if (Utils.CurrentConfig == null || Utils.CurrentConfig.IsEpsagonDisabled) { return(handlerFn()); } var clientCodeExecuted = false; var returnValue = default(TRes); Exception exception = null; try { Utils.DebugLogIfEnabled("entered epsagon lambda handler"); // handle trigger event using (var scope = GlobalTracer.Instance.BuildSpan("").StartActive(finishSpanOnDispose: true)) { var trigger = TriggerFactory.CreateInstance(input.GetType(), input); trigger.Handle(context, scope); } // handle invocation event using (var scope = GlobalTracer.Instance.BuildSpan((typeof(TEvent).Name)).StartActive(finishSpanOnDispose: true)) using (var handler = new LambdaTriggerHandler <TEvent, TRes>(input, context, scope)) { handler.HandleBefore(); try { clientCodeExecuted = true; returnValue = handlerFn(); } catch (Exception e) { scope.Span.AddException(e); exception = e; } handler.HandleAfter(returnValue); } var trace = EpsagonConverter.CreateTrace(JaegerTracer.GetSpans()); EpsagonTrace.SendTrace(trace); JaegerTracer.Clear(); Utils.DebugLogIfEnabled("finishing epsagon lambda handler"); } catch (Exception ex) { HandleInstrumentationError(ex); } finally { if (exception != null) { throw exception; } if (!clientCodeExecuted) { returnValue = handlerFn(); } } return(returnValue); }
public void SendTrace(EpsagonTrace trace) { Utils.DebugLogIfEnabled("sending trace, url: {url}", this.CollectorUrl); var client = new RestClient(this.CollectorUrl) { Timeout = 5000 }; var request = new RestRequest(Method.POST); request .AddHeader("Authorization", $"Bearer {this.Token}") .AddHeader("Content-Type", "application/json") .AddJsonBody(Utils.SerializeObject(trace)); var res = client.Execute(request); Utils.DebugLogIfEnabled("sent trace, {trace}", Utils.SerializeObject(trace)); Utils.DebugLogIfEnabled("request: {@request}", request); Utils.DebugLogIfEnabled("response: {@response}", res); JaegerTracer.Clear(); }
public static T Handle <T>(Func <T> clientFn, HttpContext context) { if (Utils.CurrentConfig == null || Utils.CurrentConfig.IsEpsagonDisabled) { return(clientFn()); } T result; var startTime = new DateTimeOffset(DateTime.UtcNow); using (var scope = CreateRunner(context)) { result = ExecuteClientCode(clientFn, scope); } CreateTrigger(context, startTime); var trace = EpsagonConverter.CreateTrace(JaegerTracer.GetSpans()); EpsagonTrace.SendTrace(trace); JaegerTracer.Clear(); EpsagonUtils.ClearTraceUrl(); return(result); }
public static async Task Handle <TEvent>(TEvent input, ILambdaContext context, Func <Task> handlerFn) { if (Utils.CurrentConfig == null || Utils.CurrentConfig.IsEpsagonDisabled) { await handlerFn(); return; } var clientCodeExecuted = false; Exception exception = null; try { if (Utils.CurrentConfig.IsEpsagonDisabled) { await handlerFn(); } Utils.DebugLogIfEnabled("entered epsagon lambda handler"); Utils.DebugLogIfEnabled("handling trigger event"); using (var scope = GlobalTracer.Instance.BuildSpan("").StartActive(finishSpanOnDispose: true)) { var trigger = TriggerFactory.CreateInstance(input.GetType(), input); trigger.Handle(context, scope); } // handle invocation event Utils.DebugLogIfEnabled("handling invocation event"); using (var scope = GlobalTracer.Instance.BuildSpan((typeof(TEvent).Name)).StartActive(finishSpanOnDispose: true)) using (var handler = new LambdaTriggerHandler <TEvent, string>(input, context, scope)) { Utils.DebugLogIfEnabled("handling before execution"); handler.HandleBefore(); Utils.DebugLogIfEnabled("calling client handler"); try { clientCodeExecuted = true; await handlerFn(); } catch (Exception e) { scope.Span.AddException(e); exception = e; } Utils.DebugLogIfEnabled("handling after execution"); handler.HandleAfter(""); } Utils.DebugLogIfEnabled("creating trace"); var trace = EpsagonConverter.CreateTrace(JaegerTracer.GetSpans()); EpsagonTrace.SendTrace(trace); JaegerTracer.Clear(); Utils.DebugLogIfEnabled("finishing epsagon lambda handler"); } catch (Exception ex) { HandleInstrumentationError(ex); } finally { if (exception != null) { throw exception; } if (!clientCodeExecuted) { await handlerFn(); } } }