public void TestLambdaHandlerException()
        {
            var processor = new Mock <BaseProcessor <Activity> >();

            using (var tracerProvider = Sdk.CreateTracerProviderBuilder()
                                        .AddAWSLambdaConfigurations()
                                        .AddProcessor(processor.Object)
                                        .Build())
            {
                try
                {
                    AWSLambdaWrapper.Trace(tracerProvider, this.sampleHandlers.SampleHandlerSyncNoReturnException, "TestException", this.sampleLambdaContext);
                }
                catch
                {
                    var resource = tracerProvider.GetResource();
                    this.AssertResourceAttributes(resource);
                }
            }

            // SetParentProvider -> OnStart -> OnEnd -> OnForceFlush -> OnShutdown -> Dispose
            Assert.Equal(6, processor.Invocations.Count);

            var activity = (Activity)processor.Invocations[1].Arguments[0];

            this.AssertSpanProperties(activity);
            this.AssertSpanAttributes(activity);
            this.AssertSpanException(activity);
        }
        public void TestLambdaHandlerNotSampled()
        {
            Environment.SetEnvironmentVariable("_X_AMZN_TRACE_ID", "Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=0");

            var processor = new Mock <BaseProcessor <Activity> >();

            using (var tracerProvider = Sdk.CreateTracerProviderBuilder()
                                        .AddAWSLambdaConfigurations()
                                        .AddProcessor(processor.Object)
                                        .Build())
            {
                var result   = AWSLambdaWrapper.Trace(tracerProvider, this.sampleHandlers.SampleHandlerSyncReturn, "TestStream", this.sampleLambdaContext);
                var resource = tracerProvider.GetResource();
                this.AssertResourceAttributes(resource);
            }

            // SetParentProvider -> OnForceFlush -> OnShutdown -> Dispose
            Assert.Equal(4, processor.Invocations.Count);

            var activities = processor.Invocations.Where(i => i.Method.Name == "OnEnd").Select(i => i.Arguments[0]).Cast <Activity>().ToArray();

            Assert.True(activities.Length == 0);
        }
Пример #3
0
 // use AwsSdkSample::AwsSdkSample.Function::TracingFunctionHandler as input Lambda handler instead
 public APIGatewayProxyResponse TracingFunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
 {
     return(AWSLambdaWrapper.Trace(tracerProvider, FunctionHandler, request, context));
 }