From 568002607ae42a8dc7bbd639a5dd49bdf612d42f Mon Sep 17 00:00:00 2001 From: Arik Sher <104715391+arik-dig@users.noreply.github.com> Date: Thu, 28 Jul 2022 16:29:24 +0300 Subject: [PATCH] Bugfix/handle parameters that are generic and/or arrays (#9) --- SpanUtils.cs | 2 +- Tests/Stubs/DecoratedService.cs | 23 +++++++++++++++++++++ Tests/TestTracingDecorator.cs | 36 +++++++++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/SpanUtils.cs b/SpanUtils.cs index 2312b5b..51b3033 100644 --- a/SpanUtils.cs +++ b/SpanUtils.cs @@ -20,6 +20,6 @@ static string BuildParameterTypes(MethodInfo methodInfo) return ""; } - return string.Join('|', paramInfos.Select(pi => pi.ParameterType.FullName)); + return string.Join('|', paramInfos.Select(pi => pi.ParameterType.Name)); } } \ No newline at end of file diff --git a/Tests/Stubs/DecoratedService.cs b/Tests/Stubs/DecoratedService.cs index e4dc2ee..8f44a3c 100644 --- a/Tests/Stubs/DecoratedService.cs +++ b/Tests/Stubs/DecoratedService.cs @@ -10,6 +10,15 @@ public interface IDecoratedService public Task AsyncMethodExplicitlyMarkedForTracing(Action stateValidation); public void MethodNotExplicitlyMarkedForTracing(Action stateValidation); + + public void MethodWithStrangeParams1(Action stateValidation, + IList[] arrayOfList, ISet setOfArray, IDictionary> dict, + ref int intVal); + + public void MethodJaggedAndMultiDimArraysParams(Action stateValidation, out string strVal, + bool[][][] jaggedArrayOfBools, short[,,,][,][,,] multiDimArrayOfShorts, + long[,,][][,][] mixMultiDimAndJaggedArraysOfLongs + ); } public class DecoratedService : IDecoratedService @@ -31,4 +40,18 @@ public void MethodNotExplicitlyMarkedForTracing(Action stateValidation) { stateValidation(); } + + public void MethodWithStrangeParams1(Action stateValidation, + IList[] arrayOfList, ISet setOfArray, IDictionary> dict, ref int intVal) + { + stateValidation(); + } + + public void MethodJaggedAndMultiDimArraysParams(Action stateValidation, out string strVal, + bool[][][] jaggedArrayOfBools, short[,,,][,][,,] multiDimArrayOfShorts, + long[,,][][,][] mixMultiDimAndJaggedArraysOfLongs) + { + strVal = "hello"; + stateValidation(); + } } \ No newline at end of file diff --git a/Tests/TestTracingDecorator.cs b/Tests/TestTracingDecorator.cs index f454351..dc6f274 100644 --- a/Tests/TestTracingDecorator.cs +++ b/Tests/TestTracingDecorator.cs @@ -22,7 +22,7 @@ public void Activity_Created_For_Attribute_Marked_Method() { Assert.IsNotNull(Activity.Current); AssertHasCommonTags(Activity.Current, ServiceInterfaceFqn, - "MethodExplicitlyMarkedForTracing", "System.Action"); + "MethodExplicitlyMarkedForTracing", "Action"); }); } @@ -46,10 +46,42 @@ await tracingDecorator.AsyncMethodExplicitlyMarkedForTracing(() => { Assert.IsNotNull(Activity.Current); AssertHasCommonTags(Activity.Current, ServiceInterfaceFqn, - "AsyncMethodExplicitlyMarkedForTracing", "System.Action"); + "AsyncMethodExplicitlyMarkedForTracing", "Action"); }); } + [TestMethod] + public void Activity_Created_MethodWithStrangeParams1() + { + DecoratedService service = new DecoratedService(); + IDecoratedService tracingDecorator = TraceDecorator.Create(service); + int intVal = 5; + tracingDecorator.MethodWithStrangeParams1(() => + { + Assert.IsNotNull(Activity.Current); + AssertHasCommonTags(Activity.Current, ServiceInterfaceFqn, "MethodWithStrangeParams1", + "Action|IList`1[]|ISet`1|IDictionary`2|Int32&"); + }, + new List[] { }, new HashSet(), new Dictionary>(), ref intVal + ); + } + + [TestMethod] + public void Activity_Created_MethodJaggedAndMultiDimArraysParams() + { + DecoratedService service = new DecoratedService(); + IDecoratedService tracingDecorator = TraceDecorator.Create(service); + string strVal; + tracingDecorator.MethodJaggedAndMultiDimArraysParams(() => + { + Assert.IsNotNull(Activity.Current); + AssertHasCommonTags(Activity.Current, ServiceInterfaceFqn, "MethodJaggedAndMultiDimArraysParams", + "Action|String&|Boolean[][][]|Int16[,,][,][,,,]|Int64[][,][][,,]"); + }, + out strVal, new bool[][][] { }, new short[,,,][,][,,] { }, new long[,,][][,][] { } + ); + } + [TestMethod] public void Activity_Not_Created_For_Non_Attribute_Marked_Method_If_All_Methods_False() {