Esempio n. 1
0
        private static void CreateTraceAndSend()
        {
            var trace = EpsagonConverter.CreateTrace(JaegerTracer.GetSpans());

            EpsagonTrace.SendTrace(trace);
            JaegerTracer.Clear();
            EpsagonUtils.ClearTraceUrl();
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            EpsagonBootstrap.Bootstrap();

            var client          = new MongoClient("mongodb://*****:*****@test.com",
                PasswordHash = "secret"
            });


            var trace = EpsagonConverter.CreateTrace(JaegerTracer.GetSpans());

            Utils.DebugLogIfEnabled("sent trace, {trace}", Utils.SerializeObject(trace));
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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();
                }
            }
        }