示例#1
0
        public async Task<APIGatewayProxyResponse> InvokeAPIGatewayProxyAsync(
            Func<APIGatewayProxyRequest, ILambdaContext, Task<APIGatewayProxyResponse>> asyncHandler,
            APIGatewayProxyRequest request,
            ILambdaContext context,
            string operationName = null,
            IEnumerable<KeyValuePair<string, string>> tags = null)
        {
            using (var tracker = new TelemetryTracker(context, operationName, tags, request.Headers))
            {
                try
                {
                    APIGatewayProxyResponse apiGatewayProxyResponse = await asyncHandler(request, context);
                    if (!apiGatewayProxyResponse.IsSuccessStatusCode())
                    {
                        tracker.SetErrorCounter();

                        // Preserve the legacy logging.
                        LambdaLogger.Log($"[ERR] Invoking lambda function. Http status code: {apiGatewayProxyResponse.StatusCode}. Response body: {apiGatewayProxyResponse.Body}{Environment.NewLine}");
                    }

                    return apiGatewayProxyResponse;
                }
                catch (Exception e)
                {
                    tracker.SetException(e);
                    throw;
                }
            }
        }
示例#2
0
 public async Task <TOutput> InvokeAsync <TInput, TOutput>(
     Func <TInput, ILambdaContext, Task <TOutput> > asyncHandler,
     TInput input,
     ILambdaContext context,
     string operationName = null,
     IEnumerable <KeyValuePair <string, string> > tags = null)
 {
     using (var tracker = new TelemetryTracker(context, operationName, tags))
     {
         try
         {
             return(await asyncHandler(input, context));
         }
         catch (Exception e)
         {
             tracker.SetException(e);
             throw;
         }
     }
 }
示例#3
0
 public void Invoke <TInput>(
     Action <TInput, ILambdaContext> handler,
     TInput input,
     ILambdaContext context,
     string operationName = null,
     IEnumerable <KeyValuePair <string, string> > tags = null)
 {
     using (var tracker = new TelemetryTracker(context, operationName, tags))
     {
         try
         {
             handler(input, context);
         }
         catch (Exception e)
         {
             tracker.SetException(e);
             throw;
         }
     }
 }
示例#4
0
        public async Task <APIGatewayHttpApiV2ProxyResponse> InvokeAPIGatewayHttpApiV2ProxyAsync(
            Func <APIGatewayHttpApiV2ProxyRequest, ILambdaContext, Task <APIGatewayHttpApiV2ProxyResponse> > asyncHandler,
            APIGatewayHttpApiV2ProxyRequest request,
            ILambdaContext context,
            string operationName = null,
            IDictionary <string, string> tags = null)
        {
            IHeadersCollection headersCollection = null;

            if (TelemetryConfiguration.ContextPropagationEnabled)
            {
                headersCollection = new CommaDelimitedValueHeaders(request.Headers);
            }

            using (var tracker = new TelemetryTracker(context, operationName, tags, headersCollection))
            {
                try
                {
                    APIGatewayHttpApiV2ProxyResponse apiGatewayProxyResponse = await asyncHandler(request, context);

                    if (!apiGatewayProxyResponse.IsSuccessStatusCode())
                    {
                        tracker.SetErrorCounter();

                        // Preserve the legacy logging.
                        LambdaLogger.Log($"[ERR] Invoking lambda function. Http status code: {apiGatewayProxyResponse.StatusCode}. Response body: {apiGatewayProxyResponse.Body}{Environment.NewLine}");
                    }

                    return(apiGatewayProxyResponse);
                }
                catch (Exception e)
                {
                    tracker.SetException(e);
                    throw;
                }
            }
        }