/// <summary>
        /// Add AWS Lambda configurations.
        /// </summary>
        /// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
        /// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
        public static TracerProviderBuilder AddAWSLambdaConfigurations(this TracerProviderBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.AddSource(AWSLambdaUtils.ActivitySourceName);
            builder.SetResourceBuilder(ResourceBuilder
                                       .CreateEmpty()
                                       .AddService(AWSLambdaUtils.GetFunctionName(), null, null, false)
                                       .AddTelemetrySdk()
                                       .AddAttributes(AWSLambdaResourceDetector.Detect()));

            return(builder);
        }
示例#2
0
        public void TestDetect()
        {
            Environment.SetEnvironmentVariable("AWS_REGION", "us-east-1");
            Environment.SetEnvironmentVariable("AWS_LAMBDA_FUNCTION_NAME", "testfunction");
            Environment.SetEnvironmentVariable("AWS_LAMBDA_FUNCTION_VERSION", "latest");

            var lambdaResourceDetector = new AWSLambdaResourceDetector();
            var resourceAttributes     = lambdaResourceDetector.Detect().ToDictionary(x => x.Key, x => x.Value);

            Assert.Equal("aws", resourceAttributes[AWSSemanticConventions.AttributeCloudProvider]);
            Assert.Equal("aws_lambda", resourceAttributes[AWSSemanticConventions.AttributeCloudPlatform]);
            Assert.Equal("us-east-1", resourceAttributes[AWSSemanticConventions.AttributeCloudRegion]);
            Assert.Equal("testfunction", resourceAttributes[AWSSemanticConventions.AttributeFaasName]);
            Assert.Equal("latest", resourceAttributes[AWSSemanticConventions.AttributeFaasVersion]);

            Environment.SetEnvironmentVariable("AWS_REGION", null);
            Environment.SetEnvironmentVariable("AWS_LAMBDA_FUNCTION_NAME", null);
            Environment.SetEnvironmentVariable("AWS_LAMBDA_FUNCTION_VERSION", null);
        }