mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-09-18 10:42:42 +08:00
tweaks
This commit is contained in:
@@ -10,8 +10,8 @@
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="OpenTracing" Version="0.12.1" />
|
||||
<ItemGroup>
|
||||
<PackageReference Include="OpenTracing" Version="0.12.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@@ -1,16 +1,14 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Ocelot.DependencyInjection;
|
||||
using Ocelot.Logging;
|
||||
using System;
|
||||
|
||||
namespace Ocelot.Tracing.OpenTracing
|
||||
namespace Ocelot.Tracing.OpenTracing
|
||||
{
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Ocelot.DependencyInjection;
|
||||
using Ocelot.Logging;
|
||||
|
||||
public static class OcelotBuilderExtensions
|
||||
{
|
||||
public static IOcelotBuilder AddOpenTracing(this IOcelotBuilder builder)
|
||||
{
|
||||
builder.Services.AddSingleton<ITracer, OpenTracingTracer>();
|
||||
|
||||
builder.Services.TryAddSingleton<ITracer, OpenTracingTracer>();
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
@@ -1,32 +1,36 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using OpenTracing;
|
||||
using OpenTracing.Propagation;
|
||||
using OpenTracing.Tag;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ocelot.Tracing.OpenTracing
|
||||
namespace Ocelot.Tracing.OpenTracing
|
||||
{
|
||||
using global::OpenTracing;
|
||||
using global::OpenTracing.Propagation;
|
||||
using global::OpenTracing.Tag;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
class OpenTracingTracer : Logging.ITracer
|
||||
{
|
||||
private readonly ITracer tracer;
|
||||
private readonly ITracer _tracer;
|
||||
|
||||
public OpenTracingTracer(ITracer tracer)
|
||||
{
|
||||
this.tracer = tracer ?? throw new ArgumentNullException(nameof(tracer));
|
||||
_tracer = tracer ?? throw new ArgumentNullException(nameof(tracer));
|
||||
}
|
||||
|
||||
public void Event(HttpContext httpContext, string @event)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken,
|
||||
Action<string> addTraceIdToRepo, Func<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>> baseSendAsync)
|
||||
public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
|
||||
CancellationToken cancellationToken,
|
||||
Action<string> addTraceIdToRepo,
|
||||
Func<HttpRequestMessage,
|
||||
CancellationToken,
|
||||
Task<HttpResponseMessage>> baseSendAsync)
|
||||
{
|
||||
using (IScope scope = this.tracer.BuildSpan(request.RequestUri.AbsoluteUri).StartActive(finishSpanOnDispose: true))
|
||||
using (IScope scope = _tracer.BuildSpan(request.RequestUri.AbsoluteUri).StartActive(finishSpanOnDispose: true))
|
||||
{
|
||||
var span = scope.Span;
|
||||
|
||||
@@ -38,7 +42,7 @@ namespace Ocelot.Tracing.OpenTracing
|
||||
|
||||
var headers = new Dictionary<string, string>();
|
||||
|
||||
this.tracer.Inject(span.Context, BuiltinFormats.HttpHeaders, new TextMapInjectAdapter(headers));
|
||||
_tracer.Inject(span.Context, BuiltinFormats.HttpHeaders, new TextMapInjectAdapter(headers));
|
||||
|
||||
foreach (var item in headers)
|
||||
{
|
||||
|
Reference in New Issue
Block a user