diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/AWSLambdaWrapper.cs b/src/OpenTelemetry.Instrumentation.AWSLambda/AWSLambdaWrapper.cs index 7d34561c5e..ed222d95cd 100644 --- a/src/OpenTelemetry.Instrumentation.AWSLambda/AWSLambdaWrapper.cs +++ b/src/OpenTelemetry.Instrumentation.AWSLambda/AWSLambdaWrapper.cs @@ -98,65 +98,61 @@ public static void Trace( } /// - /// Tracing wrapper for async Lambda handler. + /// Tracing wrapper for Lambda handler. /// - /// Input. /// TracerProvider passed in. /// Lambda handler function passed in. - /// Instance of input. - /// Lambda context (optional, but strongly recommended). + /// Instance of lambda context. /// /// The optional parent context is used for Activity object creation. /// If no parent context provided, incoming request is used to extract one. /// If parent is not extracted from incoming request then X-Ray propagation is used to extract one /// unless X-Ray propagation is disabled in the configuration for this wrapper. /// - /// Task. - public static Task Trace( + public static void Trace( TracerProvider tracerProvider, - Func lambdaHandler, - TInput input, + Action lambdaHandler, ILambdaContext context, ActivityContext parentContext = default) { - Func action = async () => await lambdaHandler(input, context); - return TraceInternalAsync(tracerProvider, action, input, context, parentContext); + Action action = () => lambdaHandler(context); + TraceInternal(tracerProvider, action, null, context, parentContext); } /// /// Tracing wrapper for async Lambda handler. /// /// Input. - /// Output result. /// TracerProvider passed in. /// Lambda handler function passed in. /// Instance of input. - /// Instance of lambda context. + /// Lambda context (optional, but strongly recommended). /// /// The optional parent context is used for Activity object creation. /// If no parent context provided, incoming request is used to extract one. /// If parent is not extracted from incoming request then X-Ray propagation is used to extract one /// unless X-Ray propagation is disabled in the configuration for this wrapper. /// - /// Task of result. - public static async Task Trace( + /// Task. + public static Task TraceAsync( TracerProvider tracerProvider, - Func> lambdaHandler, + Func lambdaHandler, TInput input, ILambdaContext context, ActivityContext parentContext = default) { - TResult result = default; - Func action = async () => result = await lambdaHandler(input, context); - await TraceInternalAsync(tracerProvider, action, input, context, parentContext); - return result; + Func action = async () => await lambdaHandler(input, context); + return TraceInternalAsync(tracerProvider, action, input, context, parentContext); } /// - /// Tracing wrapper for Lambda handler. + /// Tracing wrapper for async Lambda handler. /// + /// Input. + /// Output result. /// TracerProvider passed in. /// Lambda handler function passed in. + /// Instance of input. /// Instance of lambda context. /// /// The optional parent context is used for Activity object creation. @@ -164,14 +160,18 @@ public static async Task Trace( /// If parent is not extracted from incoming request then X-Ray propagation is used to extract one /// unless X-Ray propagation is disabled in the configuration for this wrapper. /// - public static void Trace( + /// Task of result. + public static async Task TraceAsync( TracerProvider tracerProvider, - Action lambdaHandler, + Func> lambdaHandler, + TInput input, ILambdaContext context, ActivityContext parentContext = default) { - Action action = () => lambdaHandler(context); - TraceInternal(tracerProvider, action, null, context, parentContext); + TResult result = default; + Func action = async () => result = await lambdaHandler(input, context); + await TraceInternalAsync(tracerProvider, action, input, context, parentContext); + return result; } /// @@ -187,7 +187,7 @@ public static void Trace( /// unless X-Ray propagation is disabled in the configuration. /// /// Task. - public static Task Trace( + public static Task TraceAsync( TracerProvider tracerProvider, Func lambdaHandler, ILambdaContext context, diff --git a/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/AWSLambdaWrapperTests.cs b/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/AWSLambdaWrapperTests.cs index 1ad6b06310..3e3d9d633a 100644 --- a/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/AWSLambdaWrapperTests.cs +++ b/test/OpenTelemetry.Instrumentation.AWSLambda.Tests/AWSLambdaWrapperTests.cs @@ -137,7 +137,7 @@ public async Task TraceAsyncWithInputAndReturn(bool setCustomParent) .Build()) { var parentContext = setCustomParent ? CreateParentContext() : default; - var result = await AWSLambdaWrapper.Trace(tracerProvider, this.sampleHandlers.SampleHandlerAsyncInputAndReturn, "TestStream", this.sampleLambdaContext, parentContext); + var result = await AWSLambdaWrapper.TraceAsync(tracerProvider, this.sampleHandlers.SampleHandlerAsyncInputAndReturn, "TestStream", this.sampleLambdaContext, parentContext); var resource = tracerProvider.GetResource(); this.AssertResourceAttributes(resource); } @@ -163,7 +163,7 @@ public async Task TraceAsyncWithInputAndNoReturn(bool setCustomParent) .Build()) { var parentContext = setCustomParent ? CreateParentContext() : default; - await AWSLambdaWrapper.Trace(tracerProvider, this.sampleHandlers.SampleHandlerAsyncInputAndNoReturn, "TestStream", this.sampleLambdaContext, parentContext); + await AWSLambdaWrapper.TraceAsync(tracerProvider, this.sampleHandlers.SampleHandlerAsyncInputAndNoReturn, "TestStream", this.sampleLambdaContext, parentContext); var resource = tracerProvider.GetResource(); this.AssertResourceAttributes(resource); } @@ -189,7 +189,7 @@ public async Task TraceAsyncWithNoInputAndNoReturn(bool setCustomParent) .Build()) { var parentContext = setCustomParent ? CreateParentContext() : default; - await AWSLambdaWrapper.Trace(tracerProvider, this.sampleHandlers.SampleHandlerAsyncNoInputAndNoReturn, this.sampleLambdaContext, parentContext); + await AWSLambdaWrapper.TraceAsync(tracerProvider, this.sampleHandlers.SampleHandlerAsyncNoInputAndNoReturn, this.sampleLambdaContext, parentContext); var resource = tracerProvider.GetResource(); this.AssertResourceAttributes(resource); }