public void HandleBefore()
        {
            Utils.DebugLogIfEnabled("lambda invoke event - START");
            var coldStart = _coldStart;

            _coldStart = false;

            var awsRequestId = context.AwsRequestId != "1234567890" ? context.AwsRequestId : $"local-{Guid.NewGuid()}";
            var awsAccount   = this.context.InvokedFunctionArn.Split(':')[AWS_ACCOUNT_INDEX];
            var awsRegion    = Environment.GetEnvironmentVariable("AWS_REGION");

            this.scope.Span.SetTag("event.id", awsRequestId);
            this.scope.Span.SetTag("event.origin", "runner");
            this.scope.Span.SetTag("event.error_code", 0); // OK
            this.scope.Span.SetTag("resource.type", "lambda");
            this.scope.Span.SetTag("resource.name", this.context.FunctionName);
            this.scope.Span.SetTag("aws.agent", "aws-sdk");
            this.scope.Span.SetTag("aws.service", "lambda");
            this.scope.Span.SetTag("resource.operation", "invoke");
            this.scope.Span.SetTag("aws.lambda.aws_account", awsAccount);
            this.scope.Span.SetTag("aws.lambda.region", awsRegion);
            this.scope.Span.SetTag("aws.lambda.memory", this.context.MemoryLimitInMB.ToString());
            this.scope.Span.SetTag("aws.lambda.function_version", this.context.FunctionVersion);
            this.scope.Span.SetTag("aws.lambda.log_group_name", this.context.LogGroupName);
            this.scope.Span.SetTag("aws.lambda.log_stream_name", this.context.LogStreamName);
            this.scope.Span.SetTag("aws.lambda.cold_start", coldStart);
            EpsagonUtils.SetLambdaTraceUrl(awsAccount, awsRegion, this.context.FunctionName, awsRequestId);
        }
Example #2
0
        private static void CreateTraceAndSend()
        {
            var trace = EpsagonConverter.CreateTrace(JaegerTracer.GetSpans());

            EpsagonTrace.SendTrace(trace);
            JaegerTracer.Clear();
            EpsagonUtils.ClearTraceUrl();
        }
        public void HandleAfter(TRes returnValue)
        {
            this.scope.Span.SetTag("aws.lambda.return_value", JsonConvert.SerializeObject(returnValue, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            }));

            EpsagonUtils.ClearTraceUrl();
            Utils.DebugLogIfEnabled("lambda invoke event - FINISHED");
        }
Example #4
0
        private static IScope CreateRunner(string methodName)
        {
            var    scope     = GlobalTracer.Instance.BuildSpan("invoke").StartActive(finishSpanOnDispose: true);
            string traceId   = Guid.NewGuid().ToString();
            string startTime = ((int)DateTime.UtcNow.ToUnixTime()).ToString();

            scope.Span.SetTag("event.id", Guid.NewGuid().ToString());
            scope.Span.SetTag("event.origin", "runner");
            scope.Span.SetTag("resource.name", methodName);
            scope.Span.SetTag("resource.type", "dotnet_function");
            scope.Span.SetTag("resource.operation", "invoke");
            scope.Span.SetTag("trace_id", traceId);
            EpsagonUtils.SetTraceUrl(traceId, startTime);
            return(scope);
        }
Example #5
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);
        }