Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ private static bool IsInstrumentableClientType(IInvocation invocation)
return true;
}

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

internal async ValueTask<T> InstrumentOperationInterceptor<T>(IInvocation invocation, Func<ValueTask<T>> innerTask)
Expand Down
26 changes: 25 additions & 1 deletion sdk/core/Azure.Core.TestFramework/src/Shared/TestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,19 @@ public virtual TestClient GetAnotherTestClient()
{
return new TestClient();
}

public virtual TestClient GetInternalClient()
{
return new TestClient();
}
public virtual TestClientOperations SubProperty => new TestClientOperations();

public virtual AnotherType SubClientProperty => new AnotherType();

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

public virtual InternalType GetInternalType() => new InternalType();

public virtual string MethodA()
{
using DiagnosticScope scope = _diagnostics.CreateScope($"{nameof(TestClient)}.{nameof(MethodA)}");
Expand Down Expand Up @@ -125,7 +132,24 @@ public virtual async Task<string> MethodBAsync()
}

#pragma warning disable SA1402
internal class AnotherType
public class AnotherType
#pragma warning restore SA1402
{
public virtual HttpPipeline Pipeline { get; }

public virtual Task<string> MethodAsync(int i, CancellationToken cancellationToken = default)
{
return Task.FromResult("Async " + i + " " + cancellationToken.CanBeCanceled);
}

public virtual string Method(int i, CancellationToken cancellationToken = default)
{
return "Sync " + i + " " + cancellationToken.CanBeCanceled;
}
}

#pragma warning disable SA1402
internal class InternalType
#pragma warning restore SA1402
{
public virtual HttpPipeline Pipeline { get; }
Expand Down
11 changes: 11 additions & 0 deletions sdk/core/Azure.Core.TestFramework/tests/ClientTestBaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ public async Task SubClientPropertyCallsAreAutoInstrumented()
Assert.AreEqual(IsAsync ? "Async 123 False" : "Sync 123 False", result);
}

[Test]
public void NonPublicSubClientPropertyCallsAreNotAutoInstrumented()
{
TestClient client = InstrumentClient(new TestClient());

InternalType subClient = client.GetInternalType();
// should not throw
var result = subClient.Method(123);
Assert.AreEqual("Sync 123 False", result);
}

[Test]
public void CanGetUninstrumentedClient()
{
Expand Down