Skip to content

Commit 94c4d3a

Browse files
authored
Update OpenTracing to 0.12.0 (#18)
1 parent 6a1731c commit 94c4d3a

11 files changed

Lines changed: 52 additions & 51 deletions

File tree

samples/Shared/JaegerServiceCollectionExtensions.cs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,30 @@ public static IServiceCollection AddJaeger(this IServiceCollection services)
2121
if (services == null)
2222
throw new ArgumentNullException(nameof(services));
2323

24-
services.AddSingleton<ITracer>(serviceProvider =>
25-
{
26-
string serviceName = Assembly.GetEntryAssembly().GetName().Name;
24+
// TODO !!!!
25+
// services.AddSingleton<ITracer>(serviceProvider =>
26+
// {
27+
// string serviceName = Assembly.GetEntryAssembly().GetName().Name;
2728

28-
ILoggerFactory loggerFactory = serviceProvider.GetRequiredService<ILoggerFactory>();
29+
// ILoggerFactory loggerFactory = serviceProvider.GetRequiredService<ILoggerFactory>();
2930

30-
ISampler sampler = new ConstSampler(sample: true);
31+
// ISampler sampler = new ConstSampler(sample: true);
3132

32-
IReporter reporter = new RemoteReporter.Builder(new JaegerHttpTransport(_jaegerUri, batchSize: 3))
33-
.WithMetricsFactory(NoopMetricsFactory.Instance)
34-
.WithLoggerFactory(loggerFactory)
35-
.Build();
33+
// IReporter reporter = new RemoteReporter.Builder(new JaegerHttpTransport(_jaegerUri, batchSize: 3))
34+
// .WithMetricsFactory(NoopMetricsFactory.Instance)
35+
// .WithLoggerFactory(loggerFactory)
36+
// .Build();
3637

37-
ITracer tracer = new Tracer.Builder(serviceName)
38-
.WithLoggerFactory(loggerFactory)
39-
.WithSampler(sampler)
40-
.WithReporter(reporter)
41-
.Build();
38+
// ITracer tracer = new Tracer.Builder(serviceName)
39+
// .WithLoggerFactory(loggerFactory)
40+
// .WithSampler(sampler)
41+
// .WithReporter(reporter)
42+
// .Build();
4243

43-
GlobalTracer.Register(tracer);
44+
// GlobalTracer.Register(tracer);
4445

45-
return tracer;
46-
});
46+
// return tracer;
47+
// });
4748

4849
// Prevent endless loops when OpenTracing is tracking HTTP requests to Jaeger.
4950
services.Configure<HttpHandlerDiagnosticOptions>(options =>

src/OpenTracing.Contrib.NetCore/AspNetCore/HostingEventProcessor.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ public bool ProcessEvent(string eventName, object arg)
5252

5353
IScope scope = _tracer.BuildSpan(operationName)
5454
.AsChildOf(extractedSpanContext)
55-
.WithTag(Tags.Component.Key, _options.ComponentName)
56-
.WithTag(Tags.SpanKind.Key, Tags.SpanKindServer)
57-
.WithTag(Tags.HttpMethod.Key, request.Method)
58-
.WithTag(Tags.HttpUrl.Key, request.GetDisplayUrl())
59-
.StartActive(finishSpanOnDispose: true);
55+
.WithTag(Tags.Component, _options.ComponentName)
56+
.WithTag(Tags.SpanKind, Tags.SpanKindServer)
57+
.WithTag(Tags.HttpMethod, request.Method)
58+
.WithTag(Tags.HttpUrl, request.GetDisplayUrl())
59+
.StartActive();
6060

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

85-
Tags.HttpStatus.Set(scope.Span, httpContext.Response.StatusCode);
85+
scope.Span.SetTag(Tags.HttpStatus, httpContext.Response.StatusCode);
8686
scope.Dispose();
8787
}
8888
}

src/OpenTracing.Contrib.NetCore/AspNetCore/MvcEventProcessor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public bool ProcessEvent(string eventName, object arg)
4545
: $"Action {actionDescriptor.DisplayName}";
4646

4747
_tracer.BuildSpan(operationName)
48-
.WithTag(Tags.Component.Key, ActionComponent)
48+
.WithTag(Tags.Component, ActionComponent)
4949
.WithTag(ActionTagControllerName, controllerActionDescriptor?.ControllerTypeInfo.FullName)
5050
.WithTag(ActionTagActionName, controllerActionDescriptor?.ActionName)
51-
.StartActive(finishSpanOnDispose: true);
51+
.StartActive();
5252
}
5353
return true;
5454

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

7171
_tracer.BuildSpan(operationName)
72-
.WithTag(Tags.Component.Key, ResultComponent)
72+
.WithTag(Tags.Component, ResultComponent)
7373
.WithTag(ResultTagType, resultType)
74-
.StartActive(finishSpanOnDispose: true);
74+
.StartActive();
7575
}
7676
return true;
7777

src/OpenTracing.Contrib.NetCore/CoreFx/HttpHandlerDiagnostics.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ protected override void OnNext(string eventName, object arg)
5454
string operationName = _options.OperationNameResolver(request);
5555

5656
ISpan span = Tracer.BuildSpan(operationName)
57-
.WithTag(Tags.SpanKind.Key, Tags.SpanKindClient)
58-
.WithTag(Tags.Component.Key, _options.ComponentName)
59-
.WithTag(Tags.HttpMethod.Key, request.Method.ToString())
60-
.WithTag(Tags.HttpUrl.Key, request.RequestUri.ToString())
61-
.WithTag(Tags.PeerHostname.Key, request.RequestUri.Host)
62-
.WithTag(Tags.PeerPort.Key, request.RequestUri.Port)
57+
.WithTag(Tags.SpanKind, Tags.SpanKindClient)
58+
.WithTag(Tags.Component, _options.ComponentName)
59+
.WithTag(Tags.HttpMethod, request.Method.ToString())
60+
.WithTag(Tags.HttpUrl, request.RequestUri.ToString())
61+
.WithTag(Tags.PeerHostname, request.RequestUri.Host)
62+
.WithTag(Tags.PeerPort, request.RequestUri.Port)
6363
.Start();
6464

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

9999
if (response != null)
100100
{
101-
span.SetTag(Tags.HttpStatus.Key, (int)response.StatusCode);
101+
span.SetTag(Tags.HttpStatus, (int)response.StatusCode);
102102
}
103103

104104
if (requestTaskStatus == TaskStatus.Canceled || requestTaskStatus == TaskStatus.Faulted)
105105
{
106-
span.SetTag(Tags.Error.Key, true);
106+
span.SetTag(Tags.Error, true);
107107
}
108108

109109
span.Finish();

src/OpenTracing.Contrib.NetCore/EntityFrameworkCore/EntityFrameworkCoreDiagnostics.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ protected override void OnNext(string eventName, object untypedArg)
3636
string operationName = _options.OperationNameResolver(args);
3737

3838
Tracer.BuildSpan(operationName)
39-
.WithTag(Tags.SpanKind.Key, Tags.SpanKindClient)
40-
.WithTag(Tags.Component.Key, _options.ComponentName)
41-
.WithTag(Tags.DbInstance.Key, args.Command.Connection.Database)
42-
.WithTag(Tags.DbStatement.Key, args.Command.CommandText)
39+
.WithTag(Tags.SpanKind, Tags.SpanKindClient)
40+
.WithTag(Tags.Component, _options.ComponentName)
41+
.WithTag(Tags.DbInstance, args.Command.Connection.Database)
42+
.WithTag(Tags.DbStatement, args.Command.CommandText)
4343
.WithTag(TagMethod, args.ExecuteMethod.ToString())
4444
.WithTag(TagIsAsync, args.IsAsync)
45-
.StartActive(finishSpanOnDispose: true);
45+
.StartActive();
4646
}
4747
break;
4848

src/OpenTracing.Contrib.NetCore/Internal/GenericEventProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ public void ProcessEvent(string eventName, object untypedArg)
4343
private void HandleActivityStart(string eventName, Activity activity, object untypedArg)
4444
{
4545
ISpanBuilder spanBuilder = _tracer.BuildSpan(activity.OperationName)
46-
.WithTag(Tags.Component.Key, _listenerName);
46+
.WithTag(Tags.Component, _listenerName);
4747

4848
foreach (var tag in activity.Tags)
4949
{
5050
spanBuilder.WithTag(tag.Key, tag.Value);
5151
}
5252

53-
spanBuilder.StartActive(finishSpanOnDispose: true);
53+
spanBuilder.StartActive();
5454
}
5555

5656
private void HandleActivityStop(string eventName, Activity activity)

src/OpenTracing.Contrib.NetCore/Internal/SpanExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static void SetException(this ISpan span, Exception exception)
1515
if (span == null || exception == null)
1616
return;
1717

18-
Tags.Error.Set(span, true);
18+
span.SetTag(Tags.Error, true);
1919

2020
span.Log(new Dictionary<string, object>(3)
2121
{

src/OpenTracing.Contrib.NetCore/OpenTracing.Contrib.NetCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Instrumented components: HttpClient calls, ASP.NET Core, Entity Framework Core a
1414
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="2.0.0" />
1515
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
1616
<PackageReference Include="Microsoft.Extensions.Options" Version="2.0.0" />
17-
<PackageReference Include="OpenTracing" Version="0.11.0" />
17+
<PackageReference Include="OpenTracing" Version="0.12.0" />
1818
</ItemGroup>
1919

2020
<ItemGroup>

test/OpenTracing.Contrib.NetCore.Tests/AspNetCore/HostingTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public async Task Span_has_correct_properties()
131131
Assert.Empty(span.GeneratedErrors);
132132
Assert.Empty(span.LogEntries);
133133
Assert.Equal("HTTP GET", span.OperationName);
134-
Assert.Equal(0, span.ParentId);
134+
Assert.Null(span.ParentId);
135135
Assert.Empty(span.References);
136136

137137
Assert.Equal(5, span.Tags.Count);
@@ -168,13 +168,13 @@ public async Task Extracts_trace_headers()
168168
Assert.Single(finishedSpans);
169169

170170
var span = finishedSpans[0];
171-
Assert.Equal(100, span.Context.TraceId);
171+
Assert.Equal("100", span.Context.TraceId);
172172
Assert.Single(span.References);
173173

174174
var reference = span.References[0];
175175
Assert.Equal(References.ChildOf, reference.ReferenceType);
176-
Assert.Equal(100, reference.Context.TraceId);
177-
Assert.Equal(101, reference.Context.SpanId);
176+
Assert.Equal("100", reference.Context.TraceId);
177+
Assert.Equal("101", reference.Context.SpanId);
178178
}
179179

180180
[Fact]

test/OpenTracing.Contrib.NetCore.Tests/CoreFx/HttpHandlerDiagnosticTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public async Task Creates_span()
9595
public async Task Span_is_child_of_parent()
9696
{
9797
// Create parent span
98-
using (var scope = _tracer.BuildSpan("parent").StartActive(finishSpanOnDispose: true))
98+
using (var scope = _tracer.BuildSpan("parent").StartActive())
9999
{
100100
await _httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, new Uri("http://www.example.com/api/values")));
101101
}
@@ -125,7 +125,7 @@ public async Task Span_has_correct_properties()
125125
Assert.Empty(span.GeneratedErrors);
126126
Assert.Empty(span.LogEntries);
127127
Assert.Equal("HTTP GET", span.OperationName);
128-
Assert.Equal(0, span.ParentId);
128+
Assert.Null(span.ParentId);
129129
Assert.Empty(span.References);
130130

131131
Assert.Equal(7, span.Tags.Count);

0 commit comments

Comments
 (0)