Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generic constraint for RegisterXRay<T> such that T is constrained to IAmazonService #241

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions sdk/src/Handlers/AwsSdk/AWSSDKHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// permissions and limitations under the License.
// </copyright>
//-----------------------------------------------------------------------------
using Amazon.Runtime;
using Amazon.Runtime.Internal;
using Amazon.XRay.Recorder.Handlers.AwsSdk.Internal;
using System;
Expand Down Expand Up @@ -51,10 +52,10 @@ public static void RegisterXRayForAllServices(String path)
/// <summary>
/// Registers X-Ray for the given type of <see cref="Runtime.AmazonServiceClient"/>.
/// </summary>
public static void RegisterXRay<T>()
public static void RegisterXRay<T>() where T : IAmazonService
{
_customizer = GetCustomizer();
_customizer.AddType(typeof(T));
_customizer.AddType<T>();
}

/// <summary>
Expand Down
18 changes: 9 additions & 9 deletions sdk/src/Handlers/AwsSdk/Internal/XRayPipelineHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class XRayPipelineHandler : PipelineHandler
public XRayPipelineHandler()
{
_recorder = AWSXRayRecorder.Instance;
AWSServiceHandlerManifest = GetDefaultAWSWhitelist();
AWSServiceHandlerManifest = GetDefaultAWSWhitelist();
}

/// <summary>
Expand Down Expand Up @@ -342,9 +342,9 @@ private void ProcessEndRequest(IExecutionContext executionContext)
{
subsegment = _recorder.GetEntity();
}
catch(EntityNotAvailableException e)
catch (EntityNotAvailableException e)
{
_recorder.TraceContext.HandleEntityMissing(_recorder,e,"Cannot get entity from the trace context while processing response of AWS SDK request.");
_recorder.TraceContext.HandleEntityMissing(_recorder, e, "Cannot get entity from the trace context while processing response of AWS SDK request.");
return;
}

Expand Down Expand Up @@ -665,7 +665,7 @@ private bool ExcludeServiceOperation(IExecutionContext executionContext)
var serviceName = RemoveAmazonPrefixFromServiceName(requestContext.Request.ServiceName);
var operation = RemoveSuffix(requestContext.OriginalRequest.GetType().Name, "Request");

return AWSXRaySDKUtils.IsBlacklistedOperation(serviceName,operation);
return AWSXRaySDKUtils.IsBlacklistedOperation(serviceName, operation);
}

private bool IsTracingDisabled()
Expand Down Expand Up @@ -719,13 +719,13 @@ public override async Task<T> InvokeAsync<T>(IExecutionContext executionContext)
/// Pipeline Customizer for registering <see cref="AmazonServiceClient"/> instances with AWS X-Ray.
/// Note: This class should not be instantiated or used in anyway. It is used internally within SDK.
/// </summary>
public class XRayPipelineCustomizer : IRuntimePipelineCustomizer
internal class XRayPipelineCustomizer : IRuntimePipelineCustomizer
{
public string UniqueName { get { return "X-Ray Registration Customization"; } }
private Boolean registerAll;
private List<Type> types = new List<Type>();
private ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim();

public bool RegisterAll { get => registerAll; set => registerAll = value; }
public string Path { get; set; } // TODO :: This is not used anymore, remove in next breaking change
public XRayPipelineHandler XRayPipelineHandler { get; set; } = null; // TODO :: This is not used anymore, remove in next breaking change
Expand Down Expand Up @@ -779,14 +779,14 @@ private bool ProcessType(Type serviceClientType, bool addCustomization)
/// <summary>
/// Adds type to the list of <see cref="Type" />.
/// </summary>
/// <param name="type"> Type of <see cref="Runtime.AmazonServiceClient"/> to be registered with X-Ray.</param>
public void AddType(Type type)
/// <typeparam name="T">Type of <see cref="IAmazonService"/> to be registered with X-Ray.</typeparam>
public void AddType<T>() where T : IAmazonService
{
rwLock.EnterWriteLock();

try
{
types.Add(type);
types.Add(typeof(T));
}
finally
{
Expand Down