public void When_Tracing_Enabled_Custom_To_CustomTraceListener() { using var listener = new CustomTraceListener(); var options = new ClusterOptions(); options.WithThresholdTracing(new ThresholdOptions { Enabled = true, ThresholdListener = listener }); using var context = new ClusterContext(Mock.Of <ICluster>(), new CancellationTokenSource(), options); context.Start(); var tracer = context.ServiceProvider.GetRequiredService <IRequestTracer>(); var span = tracer.RequestSpan("works"); span.Dispose(); var activities = listener.GetActivities().Where(x => x.OperationName == "works").ToArray(); foreach (var activity in activities) { _output.WriteLine($"The name of the activity is '{activity.DisplayName}'"); } Assert.Single(activities); }
internal Cluster(ClusterOptions clusterOptions) { if (clusterOptions == null) { throw new InvalidConfigurationException("ClusterOptions is null."); } if (string.IsNullOrWhiteSpace(clusterOptions.Password) || string.IsNullOrWhiteSpace(clusterOptions.UserName)) { throw new InvalidConfigurationException("Username and password are required."); } var configTokenSource = new CancellationTokenSource(); _context = new ClusterContext(this, configTokenSource, clusterOptions); _context.Start(); LazyQueryClient = new Lazy <IQueryClient>(() => _context.ServiceProvider.GetRequiredService <IQueryClient>()); LazyAnalyticsClient = new Lazy <IAnalyticsClient>(() => _context.ServiceProvider.GetRequiredService <IAnalyticsClient>()); LazySearchClient = new Lazy <ISearchClient>(() => _context.ServiceProvider.GetRequiredService <ISearchClient>()); LazyQueryManager = new Lazy <IQueryIndexManager>(() => _context.ServiceProvider.GetRequiredService <IQueryIndexManager>()); LazyBucketManager = new Lazy <IBucketManager>(() => _context.ServiceProvider.GetRequiredService <IBucketManager>()); LazyUserManager = new Lazy <IUserManager>(() => _context.ServiceProvider.GetRequiredService <IUserManager>()); LazySearchManager = new Lazy <ISearchIndexManager>(() => _context.ServiceProvider.GetRequiredService <ISearchIndexManager>()); LazyAnalyticsIndexManager = new Lazy <IAnalyticsIndexManager>(() => _context.ServiceProvider.GetRequiredService <IAnalyticsIndexManager>()); LazyEventingFunctionManager = new Lazy <IEventingFunctionManager>(() => _context.ServiceProvider.GetRequiredService <IEventingFunctionManager>()); _logger = _context.ServiceProvider.GetRequiredService <ILogger <Cluster> >(); _retryOrchestrator = _context.ServiceProvider.GetRequiredService <IRetryOrchestrator>(); _redactor = _context.ServiceProvider.GetRequiredService <IRedactor>(); _tracer = _context.ServiceProvider.GetRequiredService <IRequestTracer>(); _retryStrategy = _context.ServiceProvider.GetRequiredService <IRetryStrategy>(); var meter = _context.ServiceProvider.GetRequiredService <IMeter>(); if (meter is not NoopMeter) { // Don't instantiate the meter forwarder if we're using the NoopMeter, since the meter forwarder // will create subscriptions to the .NET metrics and start collecting/forwarding data. We can avoid // this performance penalty when we know we're doing nothing with the data. _meterForwarder = new MeterForwarder(meter); } var bootstrapperFactory = _context.ServiceProvider.GetRequiredService <IBootstrapperFactory>(); _bootstrapper = bootstrapperFactory.Create(clusterOptions.BootstrapPollInterval); }
public void When_Tracing_Enabled_Custom_To_CustomTraceListener_Not_Disposed() { using var listener = new CustomTraceListener(); var options = new ClusterOptions(); options.WithThresholdTracing(new ThresholdOptions { Enabled = true, ThresholdListener = listener }); using (var context = new ClusterContext(Mock.Of <ICluster>(), new CancellationTokenSource(), options)) { context.Start(); var tracer = context.ServiceProvider.GetRequiredService <IRequestTracer>(); var span = tracer.RequestSpan("works"); span.Dispose(); } Assert.False(listener.Disposed); }