Skip to content

Commit

Permalink
Bugfix/handle parameters that are generic and/or arrays (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
arik-dig authored Jul 28, 2022
1 parent 27b5420 commit 5680026
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion SpanUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
23 changes: 23 additions & 0 deletions Tests/Stubs/DecoratedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ public interface IDecoratedService
public Task AsyncMethodExplicitlyMarkedForTracing(Action stateValidation);

public void MethodNotExplicitlyMarkedForTracing(Action stateValidation);

public void MethodWithStrangeParams1(Action stateValidation,
IList<string>[] arrayOfList, ISet<int[]> setOfArray, IDictionary<int, ICollection<string>> dict,
ref int intVal);

public void MethodJaggedAndMultiDimArraysParams(Action stateValidation, out string strVal,
bool[][][] jaggedArrayOfBools, short[,,,][,][,,] multiDimArrayOfShorts,
long[,,][][,][] mixMultiDimAndJaggedArraysOfLongs
);
}

public class DecoratedService : IDecoratedService
Expand All @@ -31,4 +40,18 @@ public void MethodNotExplicitlyMarkedForTracing(Action stateValidation)
{
stateValidation();
}

public void MethodWithStrangeParams1(Action stateValidation,
IList<string>[] arrayOfList, ISet<int[]> setOfArray, IDictionary<int, ICollection<string>> dict, ref int intVal)
{
stateValidation();
}

public void MethodJaggedAndMultiDimArraysParams(Action stateValidation, out string strVal,
bool[][][] jaggedArrayOfBools, short[,,,][,][,,] multiDimArrayOfShorts,
long[,,][][,][] mixMultiDimAndJaggedArraysOfLongs)
{
strVal = "hello";
stateValidation();
}
}
36 changes: 34 additions & 2 deletions Tests/TestTracingDecorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
}

Expand All @@ -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<IDecoratedService>.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<string>[] { }, new HashSet<int[]>(), new Dictionary<int, ICollection<string>>(), ref intVal
);
}

[TestMethod]
public void Activity_Created_MethodJaggedAndMultiDimArraysParams()
{
DecoratedService service = new DecoratedService();
IDecoratedService tracingDecorator = TraceDecorator<IDecoratedService>.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()
{
Expand Down

0 comments on commit 5680026

Please sign in to comment.