Skip to content

Commit

Permalink
Update OpenTracing to 0.12.0 (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwe1ss authored May 24, 2018
1 parent 6a1731c commit 94c4d3a
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 51 deletions.
35 changes: 18 additions & 17 deletions samples/Shared/JaegerServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,30 @@ public static IServiceCollection AddJaeger(this IServiceCollection services)
if (services == null)
throw new ArgumentNullException(nameof(services));

services.AddSingleton<ITracer>(serviceProvider =>
{
string serviceName = Assembly.GetEntryAssembly().GetName().Name;
// TODO !!!!
// services.AddSingleton<ITracer>(serviceProvider =>
// {
// string serviceName = Assembly.GetEntryAssembly().GetName().Name;

ILoggerFactory loggerFactory = serviceProvider.GetRequiredService<ILoggerFactory>();
// ILoggerFactory loggerFactory = serviceProvider.GetRequiredService<ILoggerFactory>();

ISampler sampler = new ConstSampler(sample: true);
// ISampler sampler = new ConstSampler(sample: true);

IReporter reporter = new RemoteReporter.Builder(new JaegerHttpTransport(_jaegerUri, batchSize: 3))
.WithMetricsFactory(NoopMetricsFactory.Instance)
.WithLoggerFactory(loggerFactory)
.Build();
// IReporter reporter = new RemoteReporter.Builder(new JaegerHttpTransport(_jaegerUri, batchSize: 3))
// .WithMetricsFactory(NoopMetricsFactory.Instance)
// .WithLoggerFactory(loggerFactory)
// .Build();

ITracer tracer = new Tracer.Builder(serviceName)
.WithLoggerFactory(loggerFactory)
.WithSampler(sampler)
.WithReporter(reporter)
.Build();
// ITracer tracer = new Tracer.Builder(serviceName)
// .WithLoggerFactory(loggerFactory)
// .WithSampler(sampler)
// .WithReporter(reporter)
// .Build();

GlobalTracer.Register(tracer);
// GlobalTracer.Register(tracer);

return tracer;
});
// return tracer;
// });

// Prevent endless loops when OpenTracing is tracking HTTP requests to Jaeger.
services.Configure<HttpHandlerDiagnosticOptions>(options =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public bool ProcessEvent(string eventName, object arg)

IScope scope = _tracer.BuildSpan(operationName)
.AsChildOf(extractedSpanContext)
.WithTag(Tags.Component.Key, _options.ComponentName)
.WithTag(Tags.SpanKind.Key, Tags.SpanKindServer)
.WithTag(Tags.HttpMethod.Key, request.Method)
.WithTag(Tags.HttpUrl.Key, request.GetDisplayUrl())
.StartActive(finishSpanOnDispose: true);
.WithTag(Tags.Component, _options.ComponentName)
.WithTag(Tags.SpanKind, Tags.SpanKindServer)
.WithTag(Tags.HttpMethod, request.Method)
.WithTag(Tags.HttpUrl, request.GetDisplayUrl())
.StartActive();

_options.OnRequest?.Invoke(scope.Span, httpContext);
}
Expand All @@ -82,7 +82,7 @@ public bool ProcessEvent(string eventName, object arg)
{
var httpContext = (HttpContext)_httpRequestIn_stop_HttpContextFetcher.Fetch(arg);

Tags.HttpStatus.Set(scope.Span, httpContext.Response.StatusCode);
scope.Span.SetTag(Tags.HttpStatus, httpContext.Response.StatusCode);
scope.Dispose();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public bool ProcessEvent(string eventName, object arg)
: $"Action {actionDescriptor.DisplayName}";

_tracer.BuildSpan(operationName)
.WithTag(Tags.Component.Key, ActionComponent)
.WithTag(Tags.Component, ActionComponent)
.WithTag(ActionTagControllerName, controllerActionDescriptor?.ControllerTypeInfo.FullName)
.WithTag(ActionTagActionName, controllerActionDescriptor?.ActionName)
.StartActive(finishSpanOnDispose: true);
.StartActive();
}
return true;

Expand All @@ -69,9 +69,9 @@ public bool ProcessEvent(string eventName, object arg)
string operationName = $"Result {resultType}";

_tracer.BuildSpan(operationName)
.WithTag(Tags.Component.Key, ResultComponent)
.WithTag(Tags.Component, ResultComponent)
.WithTag(ResultTagType, resultType)
.StartActive(finishSpanOnDispose: true);
.StartActive();
}
return true;

Expand Down
16 changes: 8 additions & 8 deletions src/OpenTracing.Contrib.NetCore/CoreFx/HttpHandlerDiagnostics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ protected override void OnNext(string eventName, object arg)
string operationName = _options.OperationNameResolver(request);

ISpan span = Tracer.BuildSpan(operationName)
.WithTag(Tags.SpanKind.Key, Tags.SpanKindClient)
.WithTag(Tags.Component.Key, _options.ComponentName)
.WithTag(Tags.HttpMethod.Key, request.Method.ToString())
.WithTag(Tags.HttpUrl.Key, request.RequestUri.ToString())
.WithTag(Tags.PeerHostname.Key, request.RequestUri.Host)
.WithTag(Tags.PeerPort.Key, request.RequestUri.Port)
.WithTag(Tags.SpanKind, Tags.SpanKindClient)
.WithTag(Tags.Component, _options.ComponentName)
.WithTag(Tags.HttpMethod, request.Method.ToString())
.WithTag(Tags.HttpUrl, request.RequestUri.ToString())
.WithTag(Tags.PeerHostname, request.RequestUri.Host)
.WithTag(Tags.PeerPort, request.RequestUri.Port)
.Start();

_options.OnRequest?.Invoke(span, request);
Expand Down Expand Up @@ -98,12 +98,12 @@ protected override void OnNext(string eventName, object arg)

if (response != null)
{
span.SetTag(Tags.HttpStatus.Key, (int)response.StatusCode);
span.SetTag(Tags.HttpStatus, (int)response.StatusCode);
}

if (requestTaskStatus == TaskStatus.Canceled || requestTaskStatus == TaskStatus.Faulted)
{
span.SetTag(Tags.Error.Key, true);
span.SetTag(Tags.Error, true);
}

span.Finish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ protected override void OnNext(string eventName, object untypedArg)
string operationName = _options.OperationNameResolver(args);

Tracer.BuildSpan(operationName)
.WithTag(Tags.SpanKind.Key, Tags.SpanKindClient)
.WithTag(Tags.Component.Key, _options.ComponentName)
.WithTag(Tags.DbInstance.Key, args.Command.Connection.Database)
.WithTag(Tags.DbStatement.Key, args.Command.CommandText)
.WithTag(Tags.SpanKind, Tags.SpanKindClient)
.WithTag(Tags.Component, _options.ComponentName)
.WithTag(Tags.DbInstance, args.Command.Connection.Database)
.WithTag(Tags.DbStatement, args.Command.CommandText)
.WithTag(TagMethod, args.ExecuteMethod.ToString())
.WithTag(TagIsAsync, args.IsAsync)
.StartActive(finishSpanOnDispose: true);
.StartActive();
}
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ public void ProcessEvent(string eventName, object untypedArg)
private void HandleActivityStart(string eventName, Activity activity, object untypedArg)
{
ISpanBuilder spanBuilder = _tracer.BuildSpan(activity.OperationName)
.WithTag(Tags.Component.Key, _listenerName);
.WithTag(Tags.Component, _listenerName);

foreach (var tag in activity.Tags)
{
spanBuilder.WithTag(tag.Key, tag.Value);
}

spanBuilder.StartActive(finishSpanOnDispose: true);
spanBuilder.StartActive();
}

private void HandleActivityStop(string eventName, Activity activity)
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTracing.Contrib.NetCore/Internal/SpanExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void SetException(this ISpan span, Exception exception)
if (span == null || exception == null)
return;

Tags.Error.Set(span, true);
span.SetTag(Tags.Error, true);

span.Log(new Dictionary<string, object>(3)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Instrumented components: HttpClient calls, ASP.NET Core, Entity Framework Core a
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.0.0" />
<PackageReference Include="OpenTracing" Version="0.11.0" />
<PackageReference Include="OpenTracing" Version="0.12.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public async Task Span_has_correct_properties()
Assert.Empty(span.GeneratedErrors);
Assert.Empty(span.LogEntries);
Assert.Equal("HTTP GET", span.OperationName);
Assert.Equal(0, span.ParentId);
Assert.Null(span.ParentId);
Assert.Empty(span.References);

Assert.Equal(5, span.Tags.Count);
Expand Down Expand Up @@ -168,13 +168,13 @@ public async Task Extracts_trace_headers()
Assert.Single(finishedSpans);

var span = finishedSpans[0];
Assert.Equal(100, span.Context.TraceId);
Assert.Equal("100", span.Context.TraceId);
Assert.Single(span.References);

var reference = span.References[0];
Assert.Equal(References.ChildOf, reference.ReferenceType);
Assert.Equal(100, reference.Context.TraceId);
Assert.Equal(101, reference.Context.SpanId);
Assert.Equal("100", reference.Context.TraceId);
Assert.Equal("101", reference.Context.SpanId);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public async Task Creates_span()
public async Task Span_is_child_of_parent()
{
// Create parent span
using (var scope = _tracer.BuildSpan("parent").StartActive(finishSpanOnDispose: true))
using (var scope = _tracer.BuildSpan("parent").StartActive())
{
await _httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, new Uri("http://www.example.com/api/values")));
}
Expand Down Expand Up @@ -125,7 +125,7 @@ public async Task Span_has_correct_properties()
Assert.Empty(span.GeneratedErrors);
Assert.Empty(span.LogEntries);
Assert.Equal("HTTP GET", span.OperationName);
Assert.Equal(0, span.ParentId);
Assert.Null(span.ParentId);
Assert.Empty(span.References);

Assert.Equal(7, span.Tags.Count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public LoggingTest()
private IScope StartScope(string operationName = "FooOperation")
{
return _tracer.BuildSpan(operationName)
.StartActive(finishSpanOnDispose: true);
.StartActive();
}

private MockSpan.LogEntry Log(Action actionUnderScope)
Expand Down

0 comments on commit 94c4d3a

Please sign in to comment.