From a35555a51daae6082b5ddbbd2f1fa90f67929a67 Mon Sep 17 00:00:00 2001
From: Henrique <999396+hjgraca@users.noreply.github.com>
Date: Thu, 27 Jun 2024 13:17:02 +0100
Subject: [PATCH 01/10] make project trimmable and aot ready
---
libraries/src/Directory.Build.props | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/libraries/src/Directory.Build.props b/libraries/src/Directory.Build.props
index 0260344d..8f412fa4 100644
--- a/libraries/src/Directory.Build.props
+++ b/libraries/src/Directory.Build.props
@@ -19,6 +19,14 @@
+
+
+
+ true
+ true
+ true
+
+
From 4c59bb60a0faf8c031cbf506e45d139f0657638d Mon Sep 17 00:00:00 2001
From: Henrique <999396+hjgraca@users.noreply.github.com>
Date: Tue, 2 Jul 2024 12:09:48 +0100
Subject: [PATCH 02/10] remove dependency on universal aspect wrapper, create a
new aspect and remove aspecthandler. refacor tests, still need to fix test
runner issues
---
...acingAspectHandler.cs => TracingAspect.cs} | 279 +++---
.../TracingAttribute.cs | 21 +-
.../Handlers/HandlerTests.cs | 29 +-
.../Handlers/Handlers.cs | 78 ++
.../TracingAttributeTest.cs | 894 ++++++++----------
.../XRayRecorderTests.cs | 2 +-
6 files changed, 605 insertions(+), 698 deletions(-)
rename libraries/src/AWS.Lambda.Powertools.Tracing/Internal/{TracingAspectHandler.cs => TracingAspect.cs} (50%)
create mode 100644 libraries/tests/AWS.Lambda.Powertools.Tracing.Tests/Handlers/Handlers.cs
diff --git a/libraries/src/AWS.Lambda.Powertools.Tracing/Internal/TracingAspectHandler.cs b/libraries/src/AWS.Lambda.Powertools.Tracing/Internal/TracingAspect.cs
similarity index 50%
rename from libraries/src/AWS.Lambda.Powertools.Tracing/Internal/TracingAspectHandler.cs
rename to libraries/src/AWS.Lambda.Powertools.Tracing/Internal/TracingAspect.cs
index e445ce8f..b7f4439b 100644
--- a/libraries/src/AWS.Lambda.Powertools.Tracing/Internal/TracingAspectHandler.cs
+++ b/libraries/src/AWS.Lambda.Powertools.Tracing/Internal/TracingAspect.cs
@@ -1,12 +1,12 @@
/*
* 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
@@ -14,152 +14,131 @@
*/
using System;
+using System.Linq;
+using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Text;
+using AspectInjector.Broker;
using AWS.Lambda.Powertools.Common;
namespace AWS.Lambda.Powertools.Tracing.Internal;
-///
-/// Class TracingAspectHandler.
-/// Implements the
-///
-///
-internal class TracingAspectHandler : IMethodAspectHandler
+[Aspect(Scope.Global)]
+public class TracingAspect
{
- ///
- /// If true, then is cold start
- ///
- private static bool _isColdStart = true;
-
- ///
- /// If true, capture annotations
- ///
- private static bool _captureAnnotations = true;
///
- /// If true, tracing is disabled
- ///
- private static bool? _isTracingDisabled;
-
- ///
- /// The capture mode
- ///
- private readonly TracingCaptureMode _captureMode;
-
- ///
- /// Tracing namespace
+ /// The Powertools for AWS Lambda (.NET) configurations
///
- private readonly string _namespace;
-
+ private static readonly IPowertoolsConfigurations _powertoolsConfigurations = _powertoolsConfigurations ?? PowertoolsConfigurations.Instance;
+
///
- /// The Powertools for AWS Lambda (.NET) configurations
+ /// X-Ray Recorder
///
- private readonly IPowertoolsConfigurations _powertoolsConfigurations;
-
+ private static readonly IXRayRecorder _xRayRecorder = _xRayRecorder ?? XRayRecorder.Instance;
+
///
- /// The segment name
+ /// If true, then is cold start
///
- private readonly string _segmentName;
+ private static bool _isColdStart = true;
///
- /// X-Ray Recorder
+ /// If true, capture annotations
///
- private readonly IXRayRecorder _xRayRecorder;
-
+ private static bool _captureAnnotations = true;
+
///
/// If true, annotations have been captured
///
private bool _isAnnotationsCaptured;
-
+
///
- /// Initializes a new instance of the class.
+ /// Tracing namespace
///
- /// Name of the segment.
- /// The namespace.
- /// The capture mode.
- /// The Powertools for AWS Lambda (.NET) configurations.
- /// The X-Ray recorder.
- internal TracingAspectHandler
- (
- string segmentName,
- string nameSpace,
- TracingCaptureMode captureMode,
- IPowertoolsConfigurations powertoolsConfigurations,
- IXRayRecorder xRayRecorder
- )
- {
- _segmentName = segmentName;
- _namespace = nameSpace;
- _captureMode = captureMode;
- _powertoolsConfigurations = powertoolsConfigurations;
- _xRayRecorder = xRayRecorder;
- }
-
+ private string _namespace;
+
///
- /// Handles the event.
+ /// The capture mode
///
- ///
- /// The instance containing the
- /// event data.
- ///
- public void OnEntry(AspectEventArgs eventArgs)
+ private TracingCaptureMode _captureMode;
+
+ [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