mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-23 00:32:50 +08:00
removed fake service tracer (#511)
* removed fake service tracer * removed comments
This commit is contained in:
parent
a5bb74a2ea
commit
049731b43b
@ -1,21 +1,23 @@
|
||||
using Butterfly.Client.Tracing;
|
||||
using Ocelot.Configuration.File;
|
||||
using Ocelot.Requester;
|
||||
|
||||
namespace Ocelot.Configuration.Creator
|
||||
namespace Ocelot.Configuration.Creator
|
||||
{
|
||||
using System;
|
||||
using Butterfly.Client.Tracing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Ocelot.Configuration.File;
|
||||
using Ocelot.Requester;
|
||||
|
||||
public class HttpHandlerOptionsCreator : IHttpHandlerOptionsCreator
|
||||
{
|
||||
private readonly IServiceTracer _tracer;
|
||||
|
||||
public HttpHandlerOptionsCreator(IServiceTracer tracer)
|
||||
public HttpHandlerOptionsCreator(IServiceProvider services)
|
||||
{
|
||||
_tracer = tracer;
|
||||
_tracer = services.GetService<IServiceTracer>();
|
||||
}
|
||||
|
||||
public HttpHandlerOptions Create(FileHttpHandlerOptions options)
|
||||
{
|
||||
var useTracing = _tracer.GetType() != typeof(FakeServiceTracer) && options.UseTracing;
|
||||
var useTracing = _tracer!= null && options.UseTracing;
|
||||
|
||||
return new HttpHandlerOptions(options.AllowAutoRedirect,
|
||||
options.UseCookieContainer, useTracing, options.UseProxy);
|
||||
|
@ -158,8 +158,6 @@ namespace Ocelot.DependencyInjection
|
||||
_services.TryAddSingleton<IResponseAggregator, SimpleJsonResponseAggregator>();
|
||||
_services.AddSingleton<ITracingHandlerFactory, TracingHandlerFactory>();
|
||||
|
||||
// We add this here so that we can always inject something into the factory for IoC..
|
||||
_services.AddSingleton<IServiceTracer, FakeServiceTracer>();
|
||||
_services.TryAddSingleton<IFileConfigurationPollerOptions, InMemoryFileConfigurationPollerOptions>();
|
||||
_services.TryAddSingleton<IAddHeadersToResponse, AddHeadersToResponse>();
|
||||
_services.TryAddSingleton<IPlaceholders, Placeholders>();
|
||||
@ -237,8 +235,6 @@ namespace Ocelot.DependencyInjection
|
||||
|
||||
public IOcelotBuilder AddOpenTracing(Action<ButterflyOptions> settings)
|
||||
{
|
||||
// Earlier we add FakeServiceTracer and need to remove it here before we add butterfly
|
||||
_services.RemoveAll<IServiceTracer>();
|
||||
_services.AddButterfly(settings);
|
||||
return this;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DiagnosticAdapter;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Butterfly.Client.AspNetCore;
|
||||
using Butterfly.OpenTracing;
|
||||
using Ocelot.Middleware;
|
||||
@ -17,9 +18,9 @@ namespace Ocelot.Logging
|
||||
private readonly IServiceTracer _tracer;
|
||||
private readonly IOcelotLogger _logger;
|
||||
|
||||
public OcelotDiagnosticListener(IOcelotLoggerFactory factory, IServiceTracer tracer)
|
||||
public OcelotDiagnosticListener(IOcelotLoggerFactory factory, IServiceProvider services)
|
||||
{
|
||||
_tracer = tracer;
|
||||
_tracer = services.GetService<IServiceTracer>();
|
||||
_logger = factory.CreateLogger<OcelotDiagnosticListener>();
|
||||
}
|
||||
|
||||
@ -67,10 +68,8 @@ namespace Ocelot.Logging
|
||||
private void Event(HttpContext httpContext, string @event)
|
||||
{
|
||||
// todo - if the user isnt using tracing the code gets here and will blow up on
|
||||
// _tracer.Tracer.TryExtract. We already use the fake tracer for another scenario
|
||||
// so sticking it here as well..I guess we need a factory for this but cba to do it at
|
||||
// the moment
|
||||
if(_tracer.GetType() == typeof(FakeServiceTracer))
|
||||
// _tracer.Tracer.TryExtract..
|
||||
if(_tracer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
using Butterfly.Client.Tracing;
|
||||
using Butterfly.OpenTracing;
|
||||
|
||||
namespace Ocelot.Requester
|
||||
{
|
||||
public class FakeServiceTracer : IServiceTracer
|
||||
{
|
||||
public ITracer Tracer { get; }
|
||||
public string ServiceName { get; }
|
||||
public string Environment { get; }
|
||||
public string Identity { get; }
|
||||
public ISpan Start(ISpanBuilder spanBuilder)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,19 +1,21 @@
|
||||
using Butterfly.Client.Tracing;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
|
||||
namespace Ocelot.Requester
|
||||
{
|
||||
using System;
|
||||
using Butterfly.Client.Tracing;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
public class TracingHandlerFactory : ITracingHandlerFactory
|
||||
{
|
||||
private readonly IServiceTracer _tracer;
|
||||
private readonly IRequestScopedDataRepository _repo;
|
||||
|
||||
public TracingHandlerFactory(
|
||||
IServiceTracer tracer,
|
||||
IServiceProvider services,
|
||||
IRequestScopedDataRepository repo)
|
||||
{
|
||||
_repo = repo;
|
||||
_tracer = tracer;
|
||||
_tracer = services.GetService<IServiceTracer>();
|
||||
}
|
||||
|
||||
public ITracingHandler Get()
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using Butterfly.Client.Tracing;
|
||||
using Butterfly.OpenTracing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Creator;
|
||||
using Ocelot.Configuration.File;
|
||||
@ -16,12 +17,14 @@ namespace Ocelot.UnitTests.Configuration
|
||||
private IHttpHandlerOptionsCreator _httpHandlerOptionsCreator;
|
||||
private FileReRoute _fileReRoute;
|
||||
private HttpHandlerOptions _httpHandlerOptions;
|
||||
private IServiceTracer _serviceTracer;
|
||||
private IServiceProvider _serviceProvider;
|
||||
private IServiceCollection _serviceCollection;
|
||||
|
||||
public HttpHandlerOptionsCreatorTests()
|
||||
{
|
||||
_serviceTracer = new FakeServiceTracer();
|
||||
_httpHandlerOptionsCreator = new HttpHandlerOptionsCreator(_serviceTracer);
|
||||
_serviceCollection = new ServiceCollection();
|
||||
_serviceProvider = _serviceCollection.BuildServiceProvider();
|
||||
_httpHandlerOptionsCreator = new HttpHandlerOptionsCreator(_serviceProvider);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -153,7 +156,9 @@ namespace Ocelot.UnitTests.Configuration
|
||||
private void GivenARealTracer()
|
||||
{
|
||||
var tracer = new RealTracer();
|
||||
_httpHandlerOptionsCreator = new HttpHandlerOptionsCreator(tracer);
|
||||
_serviceCollection.AddSingleton<IServiceTracer, RealTracer>();
|
||||
_serviceProvider = _serviceCollection.BuildServiceProvider();
|
||||
_httpHandlerOptionsCreator = new HttpHandlerOptionsCreator(_serviceProvider);
|
||||
}
|
||||
|
||||
class RealTracer : IServiceTracer
|
||||
|
@ -7,6 +7,7 @@ using Xunit;
|
||||
using Ocelot.Middleware;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Ocelot.UnitTests.Logging
|
||||
{
|
||||
@ -15,7 +16,8 @@ namespace Ocelot.UnitTests.Logging
|
||||
private readonly OcelotDiagnosticListener _listener;
|
||||
private Mock<IOcelotLoggerFactory> _factory;
|
||||
private readonly Mock<IOcelotLogger> _logger;
|
||||
private IServiceTracer _tracer;
|
||||
private IServiceCollection _serviceCollection;
|
||||
private IServiceProvider _serviceProvider;
|
||||
private DownstreamContext _downstreamContext;
|
||||
private string _name;
|
||||
private Exception _exception;
|
||||
@ -24,9 +26,10 @@ namespace Ocelot.UnitTests.Logging
|
||||
{
|
||||
_factory = new Mock<IOcelotLoggerFactory>();
|
||||
_logger = new Mock<IOcelotLogger>();
|
||||
_tracer = new FakeServiceTracer();
|
||||
_serviceCollection = new ServiceCollection();
|
||||
_serviceProvider = _serviceCollection.BuildServiceProvider();
|
||||
_factory.Setup(x => x.CreateLogger<OcelotDiagnosticListener>()).Returns(_logger.Object);
|
||||
_listener = new OcelotDiagnosticListener(_factory.Object, _tracer);
|
||||
_listener = new OcelotDiagnosticListener(_factory.Object, _serviceProvider);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using Butterfly.Client.Tracing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Requester;
|
||||
@ -11,13 +13,18 @@ namespace Ocelot.UnitTests.Requester
|
||||
{
|
||||
private TracingHandlerFactory _factory;
|
||||
private Mock<IServiceTracer> _tracer;
|
||||
private IServiceCollection _serviceCollection;
|
||||
private IServiceProvider _serviceProvider;
|
||||
private Mock<IRequestScopedDataRepository> _repo;
|
||||
|
||||
public TracingHandlerFactoryTests()
|
||||
{
|
||||
_tracer = new Mock<IServiceTracer>();
|
||||
_serviceCollection = new ServiceCollection();
|
||||
_serviceCollection.AddSingleton<IServiceTracer>(_tracer.Object);
|
||||
_serviceProvider = _serviceCollection.BuildServiceProvider();
|
||||
_repo = new Mock<IRequestScopedDataRepository>();
|
||||
_factory = new TracingHandlerFactory(_tracer.Object, _repo.Object);
|
||||
_factory = new TracingHandlerFactory(_serviceProvider, _repo.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
Loading…
x
Reference in New Issue
Block a user