Skip to content

Commit 5680026

Browse files
authored
Bugfix/handle parameters that are generic and/or arrays (#9)
1 parent 27b5420 commit 5680026

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

SpanUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ static string BuildParameterTypes(MethodInfo methodInfo)
2020
return "";
2121
}
2222

23-
return string.Join('|', paramInfos.Select(pi => pi.ParameterType.FullName));
23+
return string.Join('|', paramInfos.Select(pi => pi.ParameterType.Name));
2424
}
2525
}

Tests/Stubs/DecoratedService.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ public interface IDecoratedService
1010
public Task AsyncMethodExplicitlyMarkedForTracing(Action stateValidation);
1111

1212
public void MethodNotExplicitlyMarkedForTracing(Action stateValidation);
13+
14+
public void MethodWithStrangeParams1(Action stateValidation,
15+
IList<string>[] arrayOfList, ISet<int[]> setOfArray, IDictionary<int, ICollection<string>> dict,
16+
ref int intVal);
17+
18+
public void MethodJaggedAndMultiDimArraysParams(Action stateValidation, out string strVal,
19+
bool[][][] jaggedArrayOfBools, short[,,,][,][,,] multiDimArrayOfShorts,
20+
long[,,][][,][] mixMultiDimAndJaggedArraysOfLongs
21+
);
1322
}
1423

1524
public class DecoratedService : IDecoratedService
@@ -31,4 +40,18 @@ public void MethodNotExplicitlyMarkedForTracing(Action stateValidation)
3140
{
3241
stateValidation();
3342
}
43+
44+
public void MethodWithStrangeParams1(Action stateValidation,
45+
IList<string>[] arrayOfList, ISet<int[]> setOfArray, IDictionary<int, ICollection<string>> dict, ref int intVal)
46+
{
47+
stateValidation();
48+
}
49+
50+
public void MethodJaggedAndMultiDimArraysParams(Action stateValidation, out string strVal,
51+
bool[][][] jaggedArrayOfBools, short[,,,][,][,,] multiDimArrayOfShorts,
52+
long[,,][][,][] mixMultiDimAndJaggedArraysOfLongs)
53+
{
54+
strVal = "hello";
55+
stateValidation();
56+
}
3457
}

Tests/TestTracingDecorator.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void Activity_Created_For_Attribute_Marked_Method()
2222
{
2323
Assert.IsNotNull(Activity.Current);
2424
AssertHasCommonTags(Activity.Current, ServiceInterfaceFqn,
25-
"MethodExplicitlyMarkedForTracing", "System.Action");
25+
"MethodExplicitlyMarkedForTracing", "Action");
2626
});
2727
}
2828

@@ -46,10 +46,42 @@ await tracingDecorator.AsyncMethodExplicitlyMarkedForTracing(() =>
4646
{
4747
Assert.IsNotNull(Activity.Current);
4848
AssertHasCommonTags(Activity.Current, ServiceInterfaceFqn,
49-
"AsyncMethodExplicitlyMarkedForTracing", "System.Action");
49+
"AsyncMethodExplicitlyMarkedForTracing", "Action");
5050
});
5151
}
5252

53+
[TestMethod]
54+
public void Activity_Created_MethodWithStrangeParams1()
55+
{
56+
DecoratedService service = new DecoratedService();
57+
IDecoratedService tracingDecorator = TraceDecorator<IDecoratedService>.Create(service);
58+
int intVal = 5;
59+
tracingDecorator.MethodWithStrangeParams1(() =>
60+
{
61+
Assert.IsNotNull(Activity.Current);
62+
AssertHasCommonTags(Activity.Current, ServiceInterfaceFqn, "MethodWithStrangeParams1",
63+
"Action|IList`1[]|ISet`1|IDictionary`2|Int32&");
64+
},
65+
new List<string>[] { }, new HashSet<int[]>(), new Dictionary<int, ICollection<string>>(), ref intVal
66+
);
67+
}
68+
69+
[TestMethod]
70+
public void Activity_Created_MethodJaggedAndMultiDimArraysParams()
71+
{
72+
DecoratedService service = new DecoratedService();
73+
IDecoratedService tracingDecorator = TraceDecorator<IDecoratedService>.Create(service);
74+
string strVal;
75+
tracingDecorator.MethodJaggedAndMultiDimArraysParams(() =>
76+
{
77+
Assert.IsNotNull(Activity.Current);
78+
AssertHasCommonTags(Activity.Current, ServiceInterfaceFqn, "MethodJaggedAndMultiDimArraysParams",
79+
"Action|String&|Boolean[][][]|Int16[,,][,][,,,]|Int64[][,][][,,]");
80+
},
81+
out strVal, new bool[][][] { }, new short[,,,][,][,,] { }, new long[,,][][,][] { }
82+
);
83+
}
84+
5385
[TestMethod]
5486
public void Activity_Not_Created_For_Non_Attribute_Marked_Method_If_All_Methods_False()
5587
{

0 commit comments

Comments
 (0)