From 4ec65b4b9706e94483913cb33e0a585d3ffc3119 Mon Sep 17 00:00:00 2001
From: Henrique <999396+hjgraca@users.noreply.github.com>
Date: Thu, 31 Oct 2024 09:44:04 +0000
Subject: [PATCH 01/17] Remove dependency on IMethodAspectHandler. Add
WithTracing to source generator. add dependency
Amazon.Lambda.Serialization.SystemTextJson
---
.../AWS.Lambda.Powertools.Tracing.csproj | 1 +
.../Internal/TracingAspect.cs | 310 ++++++++++++++++++
.../Internal/TracingAspectFactory.cs | 33 ++
.../Internal/TracingAspectHandler.cs | 292 -----------------
.../PowertoolsTracingSerializer.cs | 108 ++++++
.../TracingSerializerExtensions.cs | 66 ++++
.../TracingAttribute.cs | 20 +-
.../Handlers/HandlerTests.cs | 2 +-
.../Handlers/Handlers.cs | 1 +
.../PowertoolsTracingSerializerTests.cs | 198 +++++++++++
.../Serializers/TestJsonContext.cs | 28 ++
.../TracingSerializerExtensionsTests.cs | 44 +++
.../TracingAspectTests.cs | 178 ++++++++++
.../TracingAttributeTest.cs | 32 +-
14 files changed, 1000 insertions(+), 313 deletions(-)
create mode 100644 libraries/src/AWS.Lambda.Powertools.Tracing/Internal/TracingAspect.cs
create mode 100644 libraries/src/AWS.Lambda.Powertools.Tracing/Internal/TracingAspectFactory.cs
delete mode 100644 libraries/src/AWS.Lambda.Powertools.Tracing/Internal/TracingAspectHandler.cs
create mode 100644 libraries/src/AWS.Lambda.Powertools.Tracing/Serializers/PowertoolsTracingSerializer.cs
create mode 100644 libraries/src/AWS.Lambda.Powertools.Tracing/Serializers/TracingSerializerExtensions.cs
create mode 100644 libraries/tests/AWS.Lambda.Powertools.Tracing.Tests/Serializers/PowertoolsTracingSerializerTests.cs
create mode 100644 libraries/tests/AWS.Lambda.Powertools.Tracing.Tests/Serializers/TestJsonContext.cs
create mode 100644 libraries/tests/AWS.Lambda.Powertools.Tracing.Tests/Serializers/TracingSerializerExtensionsTests.cs
create mode 100644 libraries/tests/AWS.Lambda.Powertools.Tracing.Tests/TracingAspectTests.cs
diff --git a/libraries/src/AWS.Lambda.Powertools.Tracing/AWS.Lambda.Powertools.Tracing.csproj b/libraries/src/AWS.Lambda.Powertools.Tracing/AWS.Lambda.Powertools.Tracing.csproj
index 9eb67d6c..550a8e83 100644
--- a/libraries/src/AWS.Lambda.Powertools.Tracing/AWS.Lambda.Powertools.Tracing.csproj
+++ b/libraries/src/AWS.Lambda.Powertools.Tracing/AWS.Lambda.Powertools.Tracing.csproj
@@ -16,6 +16,7 @@
+
diff --git a/libraries/src/AWS.Lambda.Powertools.Tracing/Internal/TracingAspect.cs b/libraries/src/AWS.Lambda.Powertools.Tracing/Internal/TracingAspect.cs
new file mode 100644
index 00000000..ca0e6df8
--- /dev/null
+++ b/libraries/src/AWS.Lambda.Powertools.Tracing/Internal/TracingAspect.cs
@@ -0,0 +1,310 @@
+/*
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License").
+ * You may not use this file except in compliance with the License.
+ * A copy of the License is located at
+ *
+ * http://aws.amazon.com/apache2.0
+ *
+ * or in the "license" file accompanying this file. This file is distributed
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+using System;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using AspectInjector.Broker;
+using AWS.Lambda.Powertools.Common;
+using AWS.Lambda.Powertools.Common.Utils;
+
+namespace AWS.Lambda.Powertools.Tracing.Internal;
+
+///
+/// Tracing Aspect
+/// Scope.Global is singleton
+///
+[Aspect(Scope.Global, Factory = typeof(TracingAspectFactory))]
+public class TracingAspect
+{
+ ///
+ /// The Powertools for AWS Lambda (.NET) configurations
+ ///
+ private readonly IPowertoolsConfigurations _powertoolsConfigurations;
+
+ ///
+ /// X-Ray Recorder
+ ///
+ private readonly IXRayRecorder _xRayRecorder;
+
+ ///
+ /// If true, then is cold start
+ ///
+ private static bool _isColdStart = true;
+
+ ///
+ /// If true, capture annotations
+ ///
+ private static bool _captureAnnotations = true;
+
+ ///
+ /// If true, annotations have been captured
+ ///
+ private bool _isAnnotationsCaptured;
+
+ ///
+ /// Aspect constructor
+ ///
+ ///
+ ///
+ public TracingAspect(IPowertoolsConfigurations powertoolsConfigurations, IXRayRecorder xRayRecorder)
+ {
+ _powertoolsConfigurations = powertoolsConfigurations;
+ _xRayRecorder = xRayRecorder;
+ }
+
+ ///
+ /// Surrounds the specific method with Tracing aspect
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ [Advice(Kind.Around)]
+ public object Around(
+ [Argument(Source.Instance)] object instance,
+ [Argument(Source.Name)] string name,
+ [Argument(Source.Arguments)] object[] args,
+ [Argument(Source.Type)] Type hostType,
+ [Argument(Source.Metadata)] MethodBase method,
+ [Argument(Source.ReturnType)] Type returnType,
+ [Argument(Source.Target)] Func