forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tracing instrumentation to storage (Azure#6962)
- Loading branch information
Showing
36 changed files
with
3,834 additions
and
1,878 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
sdk/core/Azure.Core/src/Shared/ForwardsClientCallsAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
|
||
namespace Azure.Core | ||
{ | ||
/// <summary> | ||
/// Marks methods that call methods on other client and don't need their diagnostics verified | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | ||
internal class ForwardsClientCallsAttribute : Attribute | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
sdk/core/Azure.Core/tests/TestFramework/DiagnosticScopeValidatingInterceptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Azure.Core.Tests; | ||
using Castle.DynamicProxy; | ||
|
||
namespace Azure.Core.Testing | ||
{ | ||
public class DiagnosticScopeValidatingInterceptor : IInterceptor | ||
{ | ||
public void Intercept(IInvocation invocation) | ||
{ | ||
var methodName = invocation.Method.Name; | ||
if (methodName.EndsWith("Async")) | ||
{ | ||
var expectedEventPrefix = invocation.Method.DeclaringType.FullName + "." + methodName.Substring(0, methodName.Length - 5); | ||
var expectedEvents = new List<string>(); | ||
expectedEvents.Add(expectedEventPrefix + ".Start"); | ||
|
||
TestDiagnosticListener diagnosticListener = new TestDiagnosticListener("Azure.Clients"); | ||
invocation.Proceed(); | ||
|
||
bool strict = !invocation.Method.GetCustomAttributes(true).Any(a => a.GetType().FullName == "Azure.Core.ConvenienceMethodAttribute"); | ||
if (invocation.Method.ReturnType.Name.Contains("AsyncCollection") || | ||
invocation.Method.ReturnType.Name.Contains("IAsyncEnumerable")) | ||
{ | ||
return; | ||
} | ||
|
||
var result = (Task)invocation.ReturnValue; | ||
try | ||
{ | ||
result.GetAwaiter().GetResult(); | ||
expectedEvents.Add(expectedEventPrefix + ".Stop"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
expectedEvents.Add(expectedEventPrefix + ".Exception"); | ||
|
||
if (ex is ArgumentException) | ||
{ | ||
// Don't expect scope for argument validation failures | ||
expectedEvents.Clear(); | ||
} | ||
} | ||
finally | ||
{ | ||
diagnosticListener.Dispose(); | ||
if (strict) | ||
{ | ||
foreach (var expectedEvent in expectedEvents) | ||
{ | ||
if (!diagnosticListener.Events.Any(e => e.Key == expectedEvent)) | ||
{ | ||
throw new InvalidOperationException($"Expected diagnostic event not fired {expectedEvent} {Environment.NewLine} fired events {string.Join(", ", diagnosticListener.Events)}"); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
if (!diagnosticListener.Events.Any()) | ||
{ | ||
throw new InvalidOperationException($"Expected some diagnostic event to fire found none"); | ||
} | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
invocation.Proceed(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.