forked from ThreeMammals/Ocelot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removed fake service tracer (ThreeMammals#511)
* removed fake service tracer * removed comments
- Loading branch information
1 parent
a5bb74a
commit 049731b
Showing
8 changed files
with
318 additions
and
321 deletions.
There are no files selected for viewing
50 changes: 26 additions & 24 deletions
50
src/Ocelot/Configuration/Creator/HttpHandlerOptionsCreator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
using Butterfly.Client.Tracing; | ||
using Ocelot.Configuration.File; | ||
using Ocelot.Requester; | ||
|
||
namespace Ocelot.Configuration.Creator | ||
{ | ||
public class HttpHandlerOptionsCreator : IHttpHandlerOptionsCreator | ||
{ | ||
private readonly IServiceTracer _tracer; | ||
|
||
public HttpHandlerOptionsCreator(IServiceTracer tracer) | ||
{ | ||
_tracer = tracer; | ||
} | ||
|
||
public HttpHandlerOptions Create(FileHttpHandlerOptions options) | ||
{ | ||
var useTracing = _tracer.GetType() != typeof(FakeServiceTracer) && options.UseTracing; | ||
|
||
return new HttpHandlerOptions(options.AllowAutoRedirect, | ||
options.UseCookieContainer, useTracing, options.UseProxy); | ||
} | ||
} | ||
} | ||
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(IServiceProvider services) | ||
{ | ||
_tracer = services.GetService<IServiceTracer>(); | ||
} | ||
|
||
public HttpHandlerOptions Create(FileHttpHandlerOptions options) | ||
{ | ||
var useTracing = _tracer!= null && options.UseTracing; | ||
|
||
return new HttpHandlerOptions(options.AllowAutoRedirect, | ||
options.UseCookieContainer, useTracing, options.UseProxy); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,95 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.DiagnosticAdapter; | ||
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; | ||
|
||
public OcelotDiagnosticListener(IOcelotLoggerFactory factory, IServiceTracer tracer) | ||
{ | ||
_tracer = tracer; | ||
_logger = factory.CreateLogger<OcelotDiagnosticListener>(); | ||
} | ||
|
||
[DiagnosticName("Ocelot.MiddlewareException")] | ||
public virtual void OcelotMiddlewareException(Exception exception, DownstreamContext context, string name) | ||
{ | ||
_logger.LogTrace($"Ocelot.MiddlewareException: {name}; {exception.Message};"); | ||
Event(context.HttpContext, $"Ocelot.MiddlewareStarted: {name}; {context.HttpContext.Request.Path}"); | ||
} | ||
|
||
[DiagnosticName("Ocelot.MiddlewareStarted")] | ||
public virtual void OcelotMiddlewareStarted(DownstreamContext context, string name) | ||
{ | ||
_logger.LogTrace($"Ocelot.MiddlewareStarted: {name}; {context.HttpContext.Request.Path}"); | ||
Event(context.HttpContext, $"Ocelot.MiddlewareStarted: {name}; {context.HttpContext.Request.Path}"); | ||
} | ||
|
||
[DiagnosticName("Ocelot.MiddlewareFinished")] | ||
public virtual void OcelotMiddlewareFinished(DownstreamContext context, string name) | ||
{ | ||
_logger.LogTrace($"Ocelot.MiddlewareFinished: {name}; {context.HttpContext.Request.Path}"); | ||
Event(context.HttpContext, $"OcelotMiddlewareFinished: {name}; {context.HttpContext.Request.Path}"); | ||
} | ||
|
||
[DiagnosticName("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareStarting")] | ||
public virtual void OnMiddlewareStarting(HttpContext httpContext, string name) | ||
{ | ||
_logger.LogTrace($"MiddlewareStarting: {name}; {httpContext.Request.Path}"); | ||
Event(httpContext, $"MiddlewareStarting: {name}; {httpContext.Request.Path}"); | ||
} | ||
|
||
[DiagnosticName("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareException")] | ||
public virtual void OnMiddlewareException(Exception exception, string name) | ||
{ | ||
_logger.LogTrace($"MiddlewareException: {name}; {exception.Message};"); | ||
} | ||
|
||
[DiagnosticName("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareFinished")] | ||
public virtual void OnMiddlewareFinished(HttpContext httpContext, string name) | ||
{ | ||
_logger.LogTrace($"MiddlewareFinished: {name}; {httpContext.Response.StatusCode}"); | ||
Event(httpContext, $"MiddlewareFinished: {name}; {httpContext.Response.StatusCode}"); | ||
} | ||
|
||
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)) | ||
{ | ||
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)); | ||
} | ||
} | ||
} | ||
using System; | ||
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; | ||
|
||
public OcelotDiagnosticListener(IOcelotLoggerFactory factory, IServiceProvider services) | ||
{ | ||
_tracer = services.GetService<IServiceTracer>(); | ||
_logger = factory.CreateLogger<OcelotDiagnosticListener>(); | ||
} | ||
|
||
[DiagnosticName("Ocelot.MiddlewareException")] | ||
public virtual void OcelotMiddlewareException(Exception exception, DownstreamContext context, string name) | ||
{ | ||
_logger.LogTrace($"Ocelot.MiddlewareException: {name}; {exception.Message};"); | ||
Event(context.HttpContext, $"Ocelot.MiddlewareStarted: {name}; {context.HttpContext.Request.Path}"); | ||
} | ||
|
||
[DiagnosticName("Ocelot.MiddlewareStarted")] | ||
public virtual void OcelotMiddlewareStarted(DownstreamContext context, string name) | ||
{ | ||
_logger.LogTrace($"Ocelot.MiddlewareStarted: {name}; {context.HttpContext.Request.Path}"); | ||
Event(context.HttpContext, $"Ocelot.MiddlewareStarted: {name}; {context.HttpContext.Request.Path}"); | ||
} | ||
|
||
[DiagnosticName("Ocelot.MiddlewareFinished")] | ||
public virtual void OcelotMiddlewareFinished(DownstreamContext context, string name) | ||
{ | ||
_logger.LogTrace($"Ocelot.MiddlewareFinished: {name}; {context.HttpContext.Request.Path}"); | ||
Event(context.HttpContext, $"OcelotMiddlewareFinished: {name}; {context.HttpContext.Request.Path}"); | ||
} | ||
|
||
[DiagnosticName("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareStarting")] | ||
public virtual void OnMiddlewareStarting(HttpContext httpContext, string name) | ||
{ | ||
_logger.LogTrace($"MiddlewareStarting: {name}; {httpContext.Request.Path}"); | ||
Event(httpContext, $"MiddlewareStarting: {name}; {httpContext.Request.Path}"); | ||
} | ||
|
||
[DiagnosticName("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareException")] | ||
public virtual void OnMiddlewareException(Exception exception, string name) | ||
{ | ||
_logger.LogTrace($"MiddlewareException: {name}; {exception.Message};"); | ||
} | ||
|
||
[DiagnosticName("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareFinished")] | ||
public virtual void OnMiddlewareFinished(HttpContext httpContext, string name) | ||
{ | ||
_logger.LogTrace($"MiddlewareFinished: {name}; {httpContext.Response.StatusCode}"); | ||
Event(httpContext, $"MiddlewareFinished: {name}; {httpContext.Response.StatusCode}"); | ||
} | ||
|
||
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)); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.