public TraceEndpointOwinMiddleware(OwinMiddleware next, TraceEndpoint endpoint, IEnumerable <IManagementOptions> mgmtOptions, ILogger <TraceEndpointOwinMiddleware> logger = null)
     : base(next, endpoint, mgmtOptions, new List <HttpMethod> {
     HttpMethod.Get
 }, true, logger: logger)
 {
     _endpoint = endpoint ?? throw new ArgumentNullException(nameof(endpoint));
 }
Exemplo n.º 2
0
        private static IAppBuilder UseTraceActuatorComponents(this IAppBuilder builder, IConfiguration config, ITraceRepository traceRepository, ILoggerFactory loggerFactory)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            ITraceOptions options = new TraceEndpointOptions(config);

            var mgmtOptions = ManagementOptions.Get(config);

            foreach (var mgmt in mgmtOptions)
            {
                mgmt.EndpointOptions.Add(options);
            }

            traceRepository = traceRepository ?? new TraceDiagnosticObserver(options, loggerFactory?.CreateLogger <TraceDiagnosticObserver>());
            DiagnosticsManager.Instance.Observers.Add((IDiagnosticObserver)traceRepository);
            var endpoint = new TraceEndpoint(options, traceRepository, loggerFactory?.CreateLogger <TraceEndpoint>());
            var logger   = loggerFactory?.CreateLogger <TraceEndpointOwinMiddleware>();

            return(builder.Use <TraceEndpointOwinMiddleware>(endpoint, mgmtOptions, logger));
        }
Exemplo n.º 3
0
        public void DoInvoke_CallsTraceRepo()
        {
            var repo   = new TestTraceRepo();
            var ep     = new TraceEndpoint(new TraceOptions(), repo);
            var result = ep.DoInvoke(repo);

            Assert.NotNull(result);
            Assert.True(repo.GetTracesCalled);
        }
Exemplo n.º 4
0
        public static void UseTraceActuator(IConfiguration configuration, ITraceRepository traceRepository = null, ILoggerFactory loggerFactory = null)
        {
            var options = new TraceOptions(configuration);

            traceRepository = traceRepository ?? new TraceDiagnosticObserver(options, CreateLogger <TraceDiagnosticObserver>(loggerFactory));
            DiagnosticsManager.Instance.Observers.Add((IDiagnosticObserver)traceRepository);
            var ep      = new TraceEndpoint(options, traceRepository, CreateLogger <TraceEndpoint>(loggerFactory));
            var handler = new TraceHandler(ep, SecurityService, CreateLogger <TraceHandler>(loggerFactory));

            ConfiguredHandlers.Add(handler);
        }
Exemplo n.º 5
0
        public void TraceEndpointMiddleware_PathAndVerbMatching_ReturnsExpected()
        {
            var opts = new TraceOptions();
            TraceDiagnosticObserver obs = new TraceDiagnosticObserver(opts);
            var ep     = new TraceEndpoint(opts, obs);
            var middle = new TraceEndpointMiddleware(null, ep);

            Assert.True(middle.RequestVerbAndPathMatch("GET", "/trace"));
            Assert.False(middle.RequestVerbAndPathMatch("PUT", "/trace"));
            Assert.False(middle.RequestVerbAndPathMatch("GET", "/badpath"));
        }
        public void TraceEndpointMiddleware_PathAndVerbMatching_ReturnsExpected()
        {
            var opts  = new TraceEndpointOptions();
            var mopts = TestHelpers.GetManagementOptions(opts);
            TraceDiagnosticObserver obs = new TraceDiagnosticObserver(opts);
            var ep     = new TraceEndpoint(opts, obs);
            var middle = new TraceEndpointMiddleware(null, ep, mopts);

            Assert.True(middle.RequestVerbAndPathMatch("GET", "/cloudfoundryapplication/trace"));
            Assert.False(middle.RequestVerbAndPathMatch("PUT", "/cloudfoundryapplication/trace"));
            Assert.False(middle.RequestVerbAndPathMatch("GET", "/cloudfoundryapplication/badpath"));
        }
Exemplo n.º 7
0
        private static void UseTraceActuatorComponents(IConfiguration configuration, ITraceRepository traceRepository, ILoggerFactory loggerFactory)
        {
            var options = new TraceEndpointOptions(configuration);

            _mgmtOptions.RegisterEndpointOptions(configuration, options);
            traceRepository = traceRepository ?? new TraceDiagnosticObserver(options, CreateLogger <TraceDiagnosticObserver>(loggerFactory));
            DiagnosticsManager.Instance.Observers.Add((IDiagnosticObserver)traceRepository);
            var ep      = new TraceEndpoint(options, traceRepository, CreateLogger <TraceEndpoint>(loggerFactory));
            var handler = new TraceHandler(ep, SecurityServices, _mgmtOptions, CreateLogger <TraceHandler>(loggerFactory));

            ConfiguredHandlers.Add(handler);
        }
Exemplo n.º 8
0
        public void IsTraceRequest_ReturnsExpected()
        {
            var opts = new TraceOptions();
            DiagnosticListener listener = new DiagnosticListener("test");

            TraceObserver obs     = new TraceObserver(listener, opts);
            var           ep      = new TraceEndpoint(opts, obs);
            var           middle  = new TraceEndpointMiddleware(null, ep);
            var           context = CreateRequest("GET", "/trace");

            Assert.True(middle.IsTraceRequest(context));
            var context2 = CreateRequest("PUT", "/trace");

            Assert.False(middle.IsTraceRequest(context2));
            var context3 = CreateRequest("GET", "/badpath");

            Assert.False(middle.IsTraceRequest(context3));
            listener.Dispose();
        }
        /// <summary>
        /// Add Request Trace actuator endpoint to OWIN Pipeline
        /// </summary>
        /// <param name="builder">OWIN <see cref="IAppBuilder" /></param>
        /// <param name="config"><see cref="IConfiguration"/> of application for configuring thread dump endpoint</param>
        /// <param name="traceRepository">repository to put traces in</param>
        /// <param name="loggerFactory">For logging within the middleware</param>
        /// <returns>OWIN <see cref="IAppBuilder" /> with Trace Endpoint added</returns>
        public static IAppBuilder UseTraceActuator(this IAppBuilder builder, IConfiguration config, ITraceRepository traceRepository = null, ILoggerFactory loggerFactory = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var options = new TraceOptions(config);

            traceRepository = traceRepository ?? new TraceDiagnosticObserver(options, loggerFactory?.CreateLogger <TraceDiagnosticObserver>());
            DiagnosticsManager.Instance.Observers.Add((IDiagnosticObserver)traceRepository);
            var endpoint = new TraceEndpoint(options, traceRepository, loggerFactory?.CreateLogger <TraceEndpoint>());
            var logger   = loggerFactory?.CreateLogger <EndpointOwinMiddleware <TraceEndpoint, List <TraceResult> > >();

            return(builder.Use <EndpointOwinMiddleware <List <TraceResult> > >(endpoint, new List <HttpMethod> {
                HttpMethod.Get
            }, true, logger));
        }
Exemplo n.º 10
0
 public TraceHandler(TraceEndpoint endpoint, IEnumerable <ISecurityService> securityServices, ILogger <TraceHandler> logger = null)
     : base(endpoint, securityServices, null, true, logger)
 {
 }
Exemplo n.º 11
0
 public TraceHandler(TraceEndpoint endpoint, ISecurityService securityService, ILogger <TraceHandler> logger = null)
     : base(endpoint, securityService, null, true, logger)
 {
 }