Esempio n. 1
0
        public static XRayAutoInstrumentationOptions Register()
        {
            var serviceName       = GetSettingServiceName("ServiceName");
            var daemonAddress     = GetSettingDaemonAddress("DaemonAddress");
            var traceHttpRequests = GetSettingBool("TraceHttpRequests");
            var traceAWSRequests  = GetSettingBool("TraceAWSRequests");
            var traceSqlRequests  = GetSettingBool("TraceSqlRequests");
            var traceEFRequests   = GetSettingBool("TraceEFRequests");

            var xrayAutoInstrumentationOptions = new XRayAutoInstrumentationOptions(serviceName, daemonAddress, traceHttpRequests, traceAWSRequests, traceSqlRequests, traceEFRequests);

            return(xrayAutoInstrumentationOptions);
        }
Esempio n. 2
0
        /// <summary>
        /// Initialize Auto-Instrumentation configuration items from instance <see cref="IConfiguration"/>.
        /// </summary>
        public static XRayAutoInstrumentationOptions GetXRayAutoInstrumentationOptions(IConfiguration configuration)
        {
            IConfiguration xraySection = configuration?.GetSection("XRay");

            if (xraySection == null)
            {
                return(new XRayAutoInstrumentationOptions());
            }

            // Get Auto-Instrumentation related configuration items from appsetting.json file
            var serviceName       = GetSettingServiceName("ServiceName", xraySection);
            var daemonAddress     = GetSettingDaemonAddress("DaemonAddress", xraySection);
            var traceHttpRequests = GetSettingBool("TraceHttpRequests", xraySection);
            var traceAWSRequests  = GetSettingBool("TraceAWSRequests", xraySection);
            var traceSqlRequests  = GetSettingBool("TraceSqlRequests", xraySection);
            var traceEFRequests   = GetSettingBool("TraceEFRequests", xraySection);

            var xrayAutoInstrumentationOptions = new XRayAutoInstrumentationOptions(serviceName, daemonAddress, traceHttpRequests, traceAWSRequests, traceSqlRequests, traceEFRequests);

            return(xrayAutoInstrumentationOptions);
        }
        /// <summary>
        /// 1.Add HttpOutDiagnosticListenerNetframework, EntityFramework and Sql tracing handler for tracing Http outgping request and Sql query.
        /// 2.Register XRay for AWS services
        /// </summary>
        internal static void Initialize(XRayAutoInstrumentationOptions options)
        {
            if (options.TraceHttpRequests)
            {
                DiagnosticListenerBase[] subscriptions = { new HttpOutDiagnosticListenerNetframework() };

                DiagnosticListener.AllListeners.Subscribe(new DiagnosticListenerObserver(subscriptions));
            }

            if (options.TraceSqlRequests)
            {
                _ = new SqlEventListener();
            }

            if (options.TraceEFRequests)
            {
                DbInterception.Add(new EntityFrameworkHandler());
            }

            if (options.TraceAWSRequests)
            {
                AWSSDKRequestRegister.Register();
            }
        }