コード例 #1
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);
        }
コード例 #2
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();
                }
            }
        }