public void TestGet() { var lambdaFunction = new LambdaEntryPoint(); var request = GetTestRequest("./SampleRequests/ValuesController-Get.json"); var context = new TestLambdaContext { FunctionName = "ServerlessFunction", InvokedFunctionArn = "arn:aws:lambda:us-east-2:123456789012:function:my-function:1", }; APIGatewayProxyResponse response = null; var spans = BackendMock.CollectSpans( async() => response = await lambdaFunction.FunctionHandlerAsync(request, context)); // Check response. Assert.Equal(200, response.StatusCode); Assert.Equal("[\"value1\",\"value2\"]", response.Body); Assert.True(response.MultiValueHeaders.ContainsKey("Content-Type")); Assert.Equal("application/json; charset=utf-8", response.MultiValueHeaders["Content-Type"][0]); // Check trace. Assert.Single(spans); var span = spans.First(); Assert.Equal("api/Values", span.Name); Assert.True(span.Tags.TryGetValue("span.kind", out var spanKind)); Assert.Equal("server", spanKind); Assert.True(span.Tags.TryGetValue("http.method", out var httpMethod)); Assert.Equal("GET", httpMethod); }
public void TestGetIdException() { var lambdaFunction = new LambdaEntryPoint(); var request = GetTestRequest("./SampleRequests/ValuesController-GetNegativeId.json"); var context = new TestLambdaContext { FunctionName = "ServerlessFunction", InvokedFunctionArn = "arn:aws:lambda:us-east-2:123456789012:function:my-function:1", }; APIGatewayProxyResponse response = null; var spans = BackendMock.CollectSpans( async() => response = await lambdaFunction.FunctionHandlerAsync(request, context)); // Check response. Assert.Equal(500, response.StatusCode); // Check trace. Assert.Single(spans); var span = spans.First(); Assert.Equal("api/Values/{id}", span.Name); Assert.True(span.Tags.TryGetValue("error", out var errorValue)); Assert.Equal("true", errorValue); Assert.True(span.Tags.TryGetValue("sfx.error.kind", out var actualErrorKind)); Assert.Equal(typeof(ArgumentOutOfRangeException).FullName, actualErrorKind); }
public void TestAsyncFunction() { var functions = new Functions(); var context = GetTestContext(); var spans = BackendMock.CollectSpans( async() => await functions.AsyncFunction("hello world", context)); AssertRootSpan(spans, exceptionRaised: false); }
public void TestGetId() { var lambdaFunction = new LambdaEntryPoint(); var request = GetTestRequest("./SampleRequests/ValuesController-GetId.json"); var context = new TestLambdaContext { FunctionName = "ServerlessFunction", InvokedFunctionArn = "arn:aws:lambda:us-east-2:123456789012:function:my-function:1", }; APIGatewayProxyResponse response = null; IImmutableList <IMockSpan> spans = null; const string propagatedTraceId = "0123456789abceff"; const string parentSpanId = "0123456789abceff"; try { TelemetryConfiguration.ContextPropagationEnabled = true; request.Headers = new Dictionary <string, string> { { HttpHeaderNames.B3TraceId, propagatedTraceId }, { HttpHeaderNames.B3SpanId, parentSpanId }, { HttpHeaderNames.B3Sampled, "1" }, }; spans = BackendMock.CollectSpans( async() => response = await lambdaFunction.FunctionHandlerAsync(request, context)); } finally { TelemetryConfiguration.ContextPropagationEnabled = false; } // Check response. Assert.Equal(200, response.StatusCode); Assert.Equal("value_56", response.Body); Assert.True(response.MultiValueHeaders.ContainsKey("Content-Type")); Assert.Equal("text/plain; charset=utf-8", response.MultiValueHeaders["Content-Type"][0]); // Check trace. Assert.Single(spans); var span = spans.First(); Assert.Equal("api/Values/{id}", span.Name); Assert.True(span.Tags.TryGetValue("span.kind", out var spanKind)); Assert.Equal("server", spanKind); Assert.True(span.Tags.TryGetValue("http.method", out var httpMethod)); Assert.Equal("GET", httpMethod); // Check context propagation. Assert.True(span.ParentId.HasValue); Assert.Equal(propagatedTraceId, span.TraceId.ToString("x16")); Assert.Equal(parentSpanId, span.ParentId.Value.ToString("x16")); }
public void TestFunctionWithReturn() { var functions = new Functions(); var context = GetTestContext(); string upperCase = null; var spans = BackendMock.CollectSpans( () => upperCase = functions.FunctionWithReturn("hello world", context)); AssertRootSpan(spans, exceptionRaised: false); Assert.Equal("HELLO WORLD", upperCase); }
public void TestFunctionWithReturnException() { var functions = new Functions(); var context = GetTestContext(); Exception actualException = null; var spans = BackendMock.CollectSpans(() => { try { functions.FunctionWithReturn(null, context); } catch (Exception e) { actualException = e; } }); AssertRootSpan(spans, exceptionRaised: true); var expectedException = new ArgumentNullException("input"); Assert.Equal(expectedException.Message, actualException.Message); }