broke out butterfly into seperate project (#521)

* broke out butterfly into seperate project

* nearly did it...

* updated docs as I have broken the butterfly code off into a seperate dll
This commit is contained in:
Tom Pallister
2018-08-03 08:11:47 +01:00
committed by GitHub
parent 24f8a18579
commit 37fb32b7f5
14 changed files with 66 additions and 485 deletions

View File

@ -1,18 +1,17 @@
namespace Ocelot.Configuration.Creator
{
using System;
using Butterfly.Client.Tracing;
using Logging;
using Microsoft.Extensions.DependencyInjection;
using Ocelot.Configuration.File;
using Ocelot.Requester;
public class HttpHandlerOptionsCreator : IHttpHandlerOptionsCreator
{
private readonly IServiceTracer _tracer;
private readonly ITracer _tracer;
public HttpHandlerOptionsCreator(IServiceProvider services)
{
_tracer = services.GetService<IServiceTracer>();
_tracer = services.GetService<ITracer>();
}
public HttpHandlerOptions Create(FileHttpHandlerOptions options)

View File

@ -1,4 +1,3 @@
using Butterfly.Client.AspNetCore;
using CacheManager.Core;
using System;
using System.Net.Http;
@ -17,8 +16,6 @@ namespace Ocelot.DependencyInjection
IOcelotBuilder AddCacheManager(Action<ConfigurationBuilderCachePart> settings);
IOcelotBuilder AddOpenTracing(Action<ButterflyOptions> settings);
IOcelotAdministrationBuilder AddAdministration(string path, string secret);
IOcelotAdministrationBuilder AddAdministration(string path, Action<IdentityServerAuthenticationOptions> configOptions);

View File

@ -40,10 +40,8 @@ namespace Ocelot.DependencyInjection
using Ocelot.Configuration;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System.Net.Http;
using Butterfly.Client.AspNetCore;
using Ocelot.Infrastructure;
using Ocelot.Infrastructure.Consul;
using Butterfly.Client.Tracing;
using Ocelot.Middleware.Multiplexer;
using ServiceDiscovery.Providers;
using Steeltoe.Common.Discovery;
@ -228,12 +226,6 @@ namespace Ocelot.DependencyInjection
return this;
}
public IOcelotBuilder AddOpenTracing(Action<ButterflyOptions> settings)
{
_services.AddButterfly(settings);
return this;
}
public IOcelotBuilder AddStoreOcelotConfigurationInConsul()
{
_services.AddHostedService<FileConfigurationPoller>();

View File

@ -2,26 +2,20 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DiagnosticAdapter;
using Microsoft.Extensions.DependencyInjection;
using Butterfly.Client.AspNetCore;
using Butterfly.OpenTracing;
using Ocelot.Middleware;
using Butterfly.Client.Tracing;
using System.Linq;
using System.Collections.Generic;
using Ocelot.Infrastructure.Extensions;
using Ocelot.Requester;
namespace Ocelot.Logging
{
public class OcelotDiagnosticListener
{
private readonly IServiceTracer _tracer;
private readonly IOcelotLogger _logger;
private readonly ITracer _tracer;
public OcelotDiagnosticListener(IOcelotLoggerFactory factory, IServiceProvider services)
public OcelotDiagnosticListener(IOcelotLoggerFactory factory, IServiceProvider serviceProvider)
{
_tracer = services.GetService<IServiceTracer>();
_logger = factory.CreateLogger<OcelotDiagnosticListener>();
_tracer = serviceProvider.GetService<ITracer>();
}
[DiagnosticName("Ocelot.MiddlewareException")]
@ -67,29 +61,7 @@ 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..
if(_tracer == null)
{
return;
}
var span = httpContext.GetSpan();
if(span == null)
{
var spanBuilder = new SpanBuilder($"server {httpContext.Request.Method} {httpContext.Request.Path}");
if (_tracer.Tracer.TryExtract(out var spanContext, httpContext.Request.Headers, (c, k) => c[k].GetValue(),
c => c.Select(x => new KeyValuePair<string, string>(x.Key, x.Value.GetValue())).GetEnumerator()))
{
spanBuilder.AsChildOf(spanContext);
}
span = _tracer.Start(spanBuilder);
httpContext.SetSpan(span);
}
span?.Log(LogField.CreateNew().Event(@event));
_tracer?.Event(httpContext, @event);
}
}
}

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
@ -25,10 +25,6 @@
<DebugSymbols>True</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Butterfly.Client" Version="0.0.8" />
<PackageReference Include="Butterfly.Client.AspNetCore" Version="0.0.8">
<NoWarn>NU1701</NoWarn>
</PackageReference>
<PackageReference Include="FluentValidation" Version="7.6.104" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="2.6.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.1" />

View File

@ -2,7 +2,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using Butterfly.Client.Tracing;
using Microsoft.Extensions.DependencyInjection;
using Ocelot.Configuration;
using Ocelot.Logging;

View File

@ -1,21 +1,19 @@
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Butterfly.Client.Tracing;
using Butterfly.OpenTracing;
using Ocelot.Infrastructure.RequestData;
namespace Ocelot.Requester
namespace Ocelot.Requester
{
using Logging;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Ocelot.Infrastructure.RequestData;
public class OcelotHttpTracingHandler : DelegatingHandler, ITracingHandler
{
private readonly IServiceTracer _tracer;
private readonly ITracer _tracer;
private readonly IRequestScopedDataRepository _repo;
private const string PrefixSpanId = "ot-spanId";
public OcelotHttpTracingHandler(
IServiceTracer tracer,
ITracer tracer,
IRequestScopedDataRepository repo,
HttpMessageHandler httpMessageHandler = null)
{
@ -28,46 +26,8 @@ namespace Ocelot.Requester
HttpRequestMessage request,
CancellationToken cancellationToken)
{
return _tracer.ChildTraceAsync($"httpclient {request.Method}", DateTimeOffset.UtcNow, span => TracingSendAsync(span, request, cancellationToken));
}
protected virtual async Task<HttpResponseMessage> TracingSendAsync(
ISpan span,
HttpRequestMessage request,
CancellationToken cancellationToken)
{
if (request.Headers.Contains(PrefixSpanId))
{
request.Headers.Remove(PrefixSpanId);
request.Headers.TryAddWithoutValidation(PrefixSpanId, span.SpanContext.SpanId);
}
_repo.Add("TraceId", span.SpanContext.TraceId);
span.Tags.Client().Component("HttpClient")
.HttpMethod(request.Method.Method)
.HttpUrl(request.RequestUri.OriginalString)
.HttpHost(request.RequestUri.Host)
.HttpPath(request.RequestUri.PathAndQuery)
.PeerAddress(request.RequestUri.OriginalString)
.PeerHostName(request.RequestUri.Host)
.PeerPort(request.RequestUri.Port);
_tracer.Tracer.Inject(span.SpanContext, request.Headers, (c, k, v) =>
{
if (!c.Contains(k))
{
c.Add(k, v);
}
});
span.Log(LogField.CreateNew().ClientSend());
var responseMessage = await base.SendAsync(request, cancellationToken);
span.Log(LogField.CreateNew().ClientReceive());
return responseMessage;
return _tracer.SendAsync(request, cancellationToken, x => _repo.Add("TraceId", x), (r,c) => base.SendAsync(r, c));
}
}
}

View File

@ -1,13 +1,13 @@
namespace Ocelot.Requester
{
using System;
using Butterfly.Client.Tracing;
using Logging;
using Ocelot.Infrastructure.RequestData;
using Microsoft.Extensions.DependencyInjection;
public class TracingHandlerFactory : ITracingHandlerFactory
{
private readonly IServiceTracer _tracer;
private readonly ITracer _tracer;
private readonly IRequestScopedDataRepository _repo;
public TracingHandlerFactory(
@ -15,7 +15,7 @@ namespace Ocelot.Requester
IRequestScopedDataRepository repo)
{
_repo = repo;
_tracer = services.GetService<IServiceTracer>();
_tracer = services.GetService<ITracer>();
}
public ITracingHandler Get()