From 4b91830d1cbf33b30eb9ce39c4085cae8520c2b0 Mon Sep 17 00:00:00 2001 From: martincostello Date: Fri, 3 Feb 2023 15:28:43 +0000 Subject: [PATCH] [Instrumentation.AWSLambda] Fix analysis warnings Fix/suppress code analysis warnings in OpenTelemetry.Contrib.Instrumentation.AWSLambda. Contributes to #950. --- .../AWSLambdaWrapper.cs | 7 +++++-- .../Implementation/AWSLambdaHttpUtils.cs | 2 +- .../SampleLambdaContext.cs | 14 +++++++------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/AWSLambdaWrapper.cs b/src/OpenTelemetry.Instrumentation.AWSLambda/AWSLambdaWrapper.cs index 9359fc17b5..9adbe92e0d 100644 --- a/src/OpenTelemetry.Instrumentation.AWSLambda/AWSLambdaWrapper.cs +++ b/src/OpenTelemetry.Instrumentation.AWSLambda/AWSLambdaWrapper.cs @@ -22,6 +22,7 @@ using System.Threading.Tasks; using Amazon.Lambda.Core; using OpenTelemetry.Instrumentation.AWSLambda.Implementation; +using OpenTelemetry.Internal; using OpenTelemetry.Trace; namespace OpenTelemetry.Instrumentation.AWSLambda; @@ -69,6 +70,7 @@ public static TResult Trace( ILambdaContext context, ActivityContext parentContext = default) { + Guard.ThrowIfNull(lambdaHandler); return TraceInternal(tracerProvider, lambdaHandler, input, context, parentContext); } @@ -125,7 +127,7 @@ public static Task TraceAsync( { Func> func = async (input, context) => { - await lambdaHandler(input, context); + await lambdaHandler(input, context).ConfigureAwait(false); return null; }; return TraceInternalAsync(tracerProvider, func, input, context, parentContext); @@ -154,6 +156,7 @@ public static Task TraceAsync( ILambdaContext context, ActivityContext parentContext = default) { + Guard.ThrowIfNull(lambdaHandler); return TraceInternalAsync(tracerProvider, lambdaHandler, input, context, parentContext); } @@ -239,7 +242,7 @@ private static async Task TraceInternalAsync( var activity = OnFunctionStart(input, context, parentContext); try { - var result = await handlerAsync(input, context); + var result = await handlerAsync(input, context).ConfigureAwait(false); AWSLambdaHttpUtils.SetHttpTagsFromResult(activity, result); return result; } diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaHttpUtils.cs b/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaHttpUtils.cs index 94742e8fd8..0982d20c9b 100644 --- a/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaHttpUtils.cs +++ b/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSLambdaHttpUtils.cs @@ -97,7 +97,7 @@ internal static string GetQueryString(APIGatewayProxyRequest request) { queryString.Append(separator) .Append(HttpUtility.UrlEncode(parameterKvp.Key)) - .Append("=") + .Append('=') .Append(HttpUtility.UrlEncode(value)); separator = '&'; } diff --git a/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/SampleLambdaContext.cs b/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/SampleLambdaContext.cs index bc36ca20d8..8b77918a75 100644 --- a/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/SampleLambdaContext.cs +++ b/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/SampleLambdaContext.cs @@ -23,23 +23,23 @@ public class SampleLambdaContext : ILambdaContext { public string AwsRequestId { get; } = "testrequestid"; - public IClientContext ClientContext { get; } = null; + public IClientContext ClientContext { get; } public string FunctionName { get; } = "testfunction"; public string FunctionVersion { get; } = "latest"; - public ICognitoIdentity Identity { get; } = null; + public ICognitoIdentity Identity { get; } public string InvokedFunctionArn { get; } = "arn:aws:lambda:us-east-1:111111111111:function:testfunction"; - public ILambdaLogger Logger { get; } = null; + public ILambdaLogger Logger { get; } - public string LogGroupName { get; } = null; + public string LogGroupName { get; } - public string LogStreamName { get; } = null; + public string LogStreamName { get; } - public int MemoryLimitInMB { get; } = 0; + public int MemoryLimitInMB { get; } - public TimeSpan RemainingTime { get; } = default; + public TimeSpan RemainingTime { get; } }