Skip to content

Commit fb8562f

Browse files
Exclude internal types (#53123)
1 parent e20f587 commit fb8562f

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

sdk/core/Azure.Core.TestFramework/src/Instrumentation/InstrumentResultInterceptor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ private static bool IsInstrumentableClientType(IInvocation invocation)
124124
return true;
125125
}
126126

127-
// Some libraries have subclients that do not end with Client. Instrument any type that has a Pipeline property.
127+
// Some libraries have subclients that do not end with Client. Instrument any public type that has a Pipeline property.
128128
// This is the most expensive check so we do it last.
129-
return type.GetProperty("Pipeline") != null;
129+
return type.IsPublic && type.GetProperty("Pipeline") != null;
130130
}
131131

132132
internal async ValueTask<T> InstrumentOperationInterceptor<T>(IInvocation invocation, Func<ValueTask<T>> innerTask)

sdk/core/Azure.Core.TestFramework/src/Shared/TestClient.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,19 @@ public virtual TestClient GetAnotherTestClient()
8383
{
8484
return new TestClient();
8585
}
86+
87+
public virtual TestClient GetInternalClient()
88+
{
89+
return new TestClient();
90+
}
8691
public virtual TestClientOperations SubProperty => new TestClientOperations();
8792

8893
public virtual AnotherType SubClientProperty => new AnotherType();
8994

9095
public virtual AnotherType GetAnotherType() => new AnotherType();
9196

97+
public virtual InternalType GetInternalType() => new InternalType();
98+
9299
public virtual string MethodA()
93100
{
94101
using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TestClient)}.{nameof(MethodA)}");
@@ -125,7 +132,24 @@ public virtual async Task<string> MethodBAsync()
125132
}
126133

127134
#pragma warning disable SA1402
128-
internal class AnotherType
135+
public class AnotherType
136+
#pragma warning restore SA1402
137+
{
138+
public virtual HttpPipeline Pipeline { get; }
139+
140+
public virtual Task<string> MethodAsync(int i, CancellationToken cancellationToken = default)
141+
{
142+
return Task.FromResult("Async " + i + " " + cancellationToken.CanBeCanceled);
143+
}
144+
145+
public virtual string Method(int i, CancellationToken cancellationToken = default)
146+
{
147+
return "Sync " + i + " " + cancellationToken.CanBeCanceled;
148+
}
149+
}
150+
151+
#pragma warning disable SA1402
152+
internal class InternalType
129153
#pragma warning restore SA1402
130154
{
131155
public virtual HttpPipeline Pipeline { get; }

sdk/core/Azure.Core.TestFramework/tests/ClientTestBaseTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,17 @@ public async Task SubClientPropertyCallsAreAutoInstrumented()
189189
Assert.AreEqual(IsAsync ? "Async 123 False" : "Sync 123 False", result);
190190
}
191191

192+
[Test]
193+
public void NonPublicSubClientPropertyCallsAreNotAutoInstrumented()
194+
{
195+
TestClient client = InstrumentClient(new TestClient());
196+
197+
InternalType subClient = client.GetInternalType();
198+
// should not throw
199+
var result = subClient.Method(123);
200+
Assert.AreEqual("Sync 123 False", result);
201+
}
202+
192203
[Test]
193204
public void CanGetUninstrumentedClient()
194205
{

0 commit comments

Comments
 (0)