private static Activity OnFunctionStart(ILambdaContext context = null)
        {
            Activity activity = null;

            var parentContext = AWSLambdaUtils.GetParentContext();

            if (parentContext != default)
            {
                var activityName = AWSLambdaUtils.GetFunctionName(context);
                activity = AWSLambdaActivitySource.StartActivity(activityName, ActivityKind.Server, parentContext);

                if (activity != null && context != null)
                {
                    if (activity.IsAllDataRequested)
                    {
                        if (context.AwsRequestId != null)
                        {
                            activity.SetTag(AWSLambdaSemanticConventions.AttributeFaasExecution, context.AwsRequestId);
                        }

                        var functionArn = context.InvokedFunctionArn;
                        if (functionArn != null)
                        {
                            activity.SetTag(AWSLambdaSemanticConventions.AttributeFaasID, functionArn);

                            var accountId = AWSLambdaUtils.GetAccountId(functionArn);
                            if (accountId != null)
                            {
                                activity.SetTag(AWSLambdaSemanticConventions.AttributeCloudAccountID, accountId);
                            }
                        }
                    }
                }
            }

            return(activity);
        }
예제 #2
0
        /// <summary>
        /// Detect the resource attributes for AWS Lambda.
        /// </summary>
        /// <returns>List of resource attributes pairs.</returns>
        internal static IEnumerable <KeyValuePair <string, object> > Detect()
        {
            var resourceAttributes = new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>(AWSLambdaSemanticConventions.AttributeCloudProvider, AWSLambdaUtils.GetCloudProvider()),
                new KeyValuePair <string, object>(AWSLambdaSemanticConventions.AttributeCloudRegion, AWSLambdaUtils.GetAWSRegion()),
                new KeyValuePair <string, object>(AWSLambdaSemanticConventions.AttributeFaasName, AWSLambdaUtils.GetFunctionName()),
                new KeyValuePair <string, object>(AWSLambdaSemanticConventions.AttributeFaasVersion, AWSLambdaUtils.GetFunctionVersion()),
            };

            return(resourceAttributes);
        }