Beispiel #1
0
        internal void StartDiagnosticObserversInternal()
        {
            DiagnosticManager?.Stop();

            var observers = new List <DiagnosticObserver>();

#if NETSTANDARD
            if (Settings.IsIntegrationEnabled(AspNetCoreDiagnosticObserver.IntegrationName))
            {
                Log.Debug("Adding AspNetCoreDiagnosticObserver");

                var aspNetCoreDiagnosticOptions = new AspNetCoreDiagnosticOptions();
                observers.Add(new AspNetCoreDiagnosticObserver(this, aspNetCoreDiagnosticOptions));
            }
#endif

            if (observers.Count == 0)
            {
                Log.Debug("DiagnosticManager not started, zero observers added.");
            }
            else
            {
                Log.Debug("Starting DiagnosticManager with {0} observers.", observers.Count);

                var diagnosticManager = new DiagnosticManager(observers);
                diagnosticManager.Start();
                DiagnosticManager = diagnosticManager;
            }
        }
Beispiel #2
0
        private static void ConfigureHttpInRequestFiltering(AspNetCoreDiagnosticOptions diagnosticOptions, DeimosOptions options)
        {
            if (options == null)
            {
                return;
            }

            foreach (string httpIgnoredEndpoint in options.Http.IgnoredInEndpoints)
            {
                DeimosLogger.JaegerLogger.ConfigureRequestFiltering(httpIgnoredEndpoint);
                diagnosticOptions.Hosting.IgnorePatterns.Add(context => context.Request.Path
                                                             .ToUriComponent()
                                                             .Contains(PathString.FromUriComponent(httpIgnoredEndpoint)));
            }
        }
Beispiel #3
0
        public HostingTest(ITestOutputHelper output)
        {
            _tracer = new MockTracer();

            var aspNetCoreOptions = new AspNetCoreDiagnosticOptions();

            _options = aspNetCoreOptions.Hosting;

            _serviceProvider = new ServiceCollection()
                               .AddLogging(logging =>
            {
                logging.AddXunit(output);
                logging.AddFilter("OpenTracing", LogLevel.Trace);
            })
                               .AddOpenTracingCoreServices(builder =>
            {
                builder.AddAspNetCore();

                builder.Services.AddSingleton <ITracer>(_tracer);
                builder.Services.AddSingleton(Options.Create(aspNetCoreOptions));
            })
                               .BuildServiceProvider();

            _diagnosticManager = _serviceProvider.GetRequiredService <DiagnosticManager>();
            _diagnosticManager.Start();

            // Request

            _httpContext = new DefaultHttpContext();
            SetRequest();

            // Hosting Application

            var diagnosticSource = new DiagnosticListener("Microsoft.AspNetCore");

            _features = new FeatureCollection();
            _features.Set <IHttpRequestFeature>(new HttpRequestFeature());

            var httpContextFactory = Substitute.For <IHttpContextFactory>();

            httpContextFactory.Create(_features).Returns(_httpContext);

            _hostingApplication = new HostingApplication(
                ctx => Task.FromResult(0),
                _serviceProvider.GetRequiredService <ILogger <HostingTest> >(),
                diagnosticSource,
                httpContextFactory);
        }
Beispiel #4
0
        public void HttpRequestIn_FilterRequest()
        {
            var tracer      = GetTracer();
            var httpContext = GetHttpContext();

            var options = new AspNetCoreDiagnosticOptions();

            options.IgnorePatterns.Add(h => object.ReferenceEquals(h, httpContext));

            IObserver <KeyValuePair <string, object> > observer = new AspNetCoreDiagnosticObserver(tracer, options);

            var context = new HostingApplication.Context {
                HttpContext = httpContext
            };

            observer.OnNext(new KeyValuePair <string, object>("Microsoft.AspNetCore.Hosting.HttpRequestIn.Start", context));

            var scope = tracer.ActiveScope;

            Assert.Null(scope);
        }
Beispiel #5
0
 public AspNetCoreDiagnostics(ILoggerFactory loggerFactory, ITracer tracer, IOptions <AspNetCoreDiagnosticOptions> options)
     : base(loggerFactory, tracer, options?.Value)
 {
     _options = options?.Value ?? throw new ArgumentNullException(nameof(options));
 }