//----------------------------------------------------------------------------- // // Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"). // You may not use this file except in compliance with the License. // A copy of the License is located at // // http://aws.amazon.com/apache2.0 // // or in the "license" file accompanying this file. This file is distributed // on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either // express or implied. See the License for the specific language governing // permissions and limitations under the License. // //----------------------------------------------------------------------------- using Amazon.Runtime.Internal; using Amazon.XRay.Recorder.Handlers.AwsSdk.Internal; using System; using System.IO; namespace Amazon.XRay.Recorder.Handlers.AwsSdk { /// /// The AWS SDK handler to register X-Ray with which can intercept downstream requests and responses. /// public static class AWSSDKHandler { private static XRayPipelineCustomizer _customizer; /// /// Registers X-Ray for all instances of . /// public static void RegisterXRayForAllServices() { _customizer = GetCustomizer(); _customizer.RegisterAll = true; } /// /// Registers X-Ray for all instances of with a given custom AWS Service Manifest File. /// /// Absolute path to the file which contains the operation parameter whitelist configuration. public static void RegisterXRayForAllServices(String path) { _customizer = GetCustomizer(); _customizer.RegisterAll = true; _customizer.AWSServiceHandlerManifest = XRayPipelineHandler.GetAWSServiceManifest(path); } /// /// Registers X-Ray for the given type of . /// public static void RegisterXRay() { _customizer = GetCustomizer(); _customizer.AddType(typeof(T)); } /// /// Registers file path of AWS Service Manifest file. This file would be used for all the registered instances. /// /// Absolute path to the file which contains the operation parameter whitelist configuration. public static void RegisterXRayManifest(String path) { _customizer = GetCustomizer(); _customizer.AWSServiceHandlerManifest = XRayPipelineHandler.GetAWSServiceManifest(path); } /// /// Registers AWS Service Manifest resource stream. This stream would be used for all the registered instances. /// /// stream for manifest which contains the operation parameter whitelist configuration. public static void RegisterXRayManifest(Stream stream) { _customizer = GetCustomizer(); _customizer.AWSServiceHandlerManifest = XRayPipelineHandler.GetAWSServiceManifest(stream); } private static XRayPipelineCustomizer GetCustomizer() { if (_customizer == null) { _customizer = new XRayPipelineCustomizer(); RuntimePipelineCustomizerRegistry.Instance.Register(_customizer); } return _customizer; } } }