Skip to content

Commit 45fea77

Browse files
bmermetEmanuele Palazzetti
authored andcommitted
Remove ServiceInfo (#34)
Removed because it's a legacy and deprecated API.
1 parent a03a1b3 commit 45fea77

File tree

17 files changed

+43
-184
lines changed

17 files changed

+43
-184
lines changed

src/Datadog.Trace.AspNetCore.Tests/MockWriter.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ public Task FlushAndCloseAsync()
1717
return Task.FromResult(true);
1818
}
1919

20-
public void WriteServiceInfo(ServiceInfo serviceInfo)
21-
{
22-
}
23-
2420
public void WriteTrace(List<Span> trace)
2521
{
2622
Traces.Add(trace);

src/Datadog.Trace.IntegrationTests.Net45/OpenTracingSendTracesToAgent.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class OpenTracingSendTracesToAgent
1414
public OpenTracingSendTracesToAgent()
1515
{
1616
_httpRecorder = new RecordHttpHandler();
17-
_tracer = OpenTracingTracerFactory.CreateTracer(new Uri("http://localhost:8126"), null, null, _httpRecorder);
17+
_tracer = OpenTracingTracerFactory.CreateTracer(new Uri("http://localhost:8126"), null, _httpRecorder);
1818
}
1919

2020
[Fact]
@@ -37,12 +37,9 @@ public async void MinimalSpan()
3737
[Fact]
3838
public async void CustomServiceName()
3939
{
40-
const string App = "MyApp";
41-
const string AppType = "db";
4240
const string ServiceName = "MyService";
43-
var serviceList = new List<ServiceInfo> { new ServiceInfo { App = App, AppType = AppType, ServiceName = ServiceName } };
4441
_httpRecorder = new RecordHttpHandler();
45-
_tracer = OpenTracingTracerFactory.CreateTracer(new Uri("http://localhost:8126"), serviceList, null, _httpRecorder);
42+
_tracer = OpenTracingTracerFactory.CreateTracer(new Uri("http://localhost:8126"), null, _httpRecorder);
4643

4744
var span = (OpenTracingSpan)_tracer.BuildSpan("Operation")
4845
.WithTag(DDTags.ResourceName, "This is a resource")
@@ -51,18 +48,13 @@ public async void CustomServiceName()
5148
span.Finish();
5249

5350
// Check that the HTTP calls went as expected
54-
await _httpRecorder.WaitForCompletion(2);
55-
Assert.Equal(2, _httpRecorder.Requests.Count);
56-
Assert.Equal(2, _httpRecorder.Responses.Count);
51+
await _httpRecorder.WaitForCompletion(1);
52+
Assert.Equal(1, _httpRecorder.Requests.Count);
53+
Assert.Equal(1, _httpRecorder.Responses.Count);
5754
Assert.All(_httpRecorder.Responses, (x) => Assert.Equal(HttpStatusCode.OK, x.StatusCode));
5855

5956
var trace = _httpRecorder.Traces.Single();
6057
MsgPackHelpers.AssertSpanEqual(span.DDSpan, trace.Single());
61-
62-
var serviceInfo = _httpRecorder.Services.Select(x => x.ServiceInfos().Single()).Single();
63-
Assert.Equal(ServiceName, serviceInfo.ServiceName);
64-
Assert.Equal(App, serviceInfo.App);
65-
Assert.Equal(AppType, serviceInfo.AppType);
6658
}
6759

6860
[Fact]

src/Datadog.Trace.IntegrationTests/MsgPackHelpers.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,6 @@ public static Dictionary<string, string> Tags(this MessagePackObject obj)
6868
return obj.AsList().First().AsDictionary()["meta"].AsDictionary().ToDictionary(kv => kv.Key.AsString(), kv => kv.Value.AsString());
6969
}
7070

71-
public static IEnumerable<ServiceInfo> ServiceInfos(this MessagePackObjectDictionary obj)
72-
{
73-
foreach (var kv in obj)
74-
{
75-
var s = kv.Value.AsDictionary();
76-
yield return new ServiceInfo { App = s["app"].AsString(), AppType = s["app_type"].AsString(), ServiceName = kv.Key.AsString() };
77-
}
78-
}
79-
8071
public static void AssertSpanEqual(Span expected, MessagePackObject actual)
8172
{
8273
Assert.Equal(expected.Context.TraceId, actual.TraceId());

src/Datadog.Trace.IntegrationTests/OpenTracingSendTracesToAgent.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class OpenTracingSendTracesToAgent
1414
public OpenTracingSendTracesToAgent()
1515
{
1616
_httpRecorder = new RecordHttpHandler();
17-
_tracer = OpenTracingTracerFactory.CreateTracer(new Uri("http://localhost:8126"), null, null, _httpRecorder);
17+
_tracer = OpenTracingTracerFactory.CreateTracer(new Uri("http://localhost:8126"), null, _httpRecorder);
1818
}
1919

2020
[Fact]
@@ -37,12 +37,9 @@ public async void MinimalSpan()
3737
[Fact]
3838
public async void CustomServiceName()
3939
{
40-
const string App = "MyApp";
41-
const string AppType = "db";
4240
const string ServiceName = "MyService";
43-
var serviceList = new List<ServiceInfo> { new ServiceInfo { App = App, AppType = AppType, ServiceName = ServiceName } };
4441
_httpRecorder = new RecordHttpHandler();
45-
_tracer = OpenTracingTracerFactory.CreateTracer(new Uri("http://localhost:8126"), serviceList, null, _httpRecorder);
42+
_tracer = OpenTracingTracerFactory.CreateTracer(new Uri("http://localhost:8126"), null, _httpRecorder);
4643

4744
var span = (OpenTracingSpan)_tracer.BuildSpan("Operation")
4845
.WithTag(DDTags.ResourceName, "This is a resource")
@@ -51,18 +48,13 @@ public async void CustomServiceName()
5148
span.Finish();
5249

5350
// Check that the HTTP calls went as expected
54-
await _httpRecorder.WaitForCompletion(2);
55-
Assert.Equal(2, _httpRecorder.Requests.Count);
56-
Assert.Equal(2, _httpRecorder.Responses.Count);
51+
await _httpRecorder.WaitForCompletion(1);
52+
Assert.Equal(1, _httpRecorder.Requests.Count);
53+
Assert.Equal(1, _httpRecorder.Responses.Count);
5754
Assert.All(_httpRecorder.Responses, (x) => Assert.Equal(HttpStatusCode.OK, x.StatusCode));
5855

5956
var trace = _httpRecorder.Traces.Single();
6057
MsgPackHelpers.AssertSpanEqual(span.DDSpan, trace.Single());
61-
62-
var serviceInfo = _httpRecorder.Services.Select(x => x.ServiceInfos().Single()).Single();
63-
Assert.Equal(ServiceName, serviceInfo.ServiceName);
64-
Assert.Equal(App, serviceInfo.App);
65-
Assert.Equal(AppType, serviceInfo.AppType);
6658
}
6759

6860
[Fact]

src/Datadog.Trace.IntegrationTests/SendTracesToAgent.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class SendTracesToAgent
1414
public SendTracesToAgent()
1515
{
1616
_httpRecorder = new RecordHttpHandler();
17-
_tracer = Tracer.Create(new Uri("http://localhost:8126"), null, null, _httpRecorder);
17+
_tracer = Tracer.Create(new Uri("http://localhost:8126"), null, _httpRecorder);
1818
}
1919

2020
[Fact]
@@ -36,30 +36,22 @@ public async void MinimalSpan()
3636
[Fact]
3737
public async void CustomServiceName()
3838
{
39-
const string App = "MyApp";
40-
const string AppType = "db";
4139
const string ServiceName = "MyService";
42-
var serviceList = new List<ServiceInfo> { new ServiceInfo { App = App, AppType = AppType, ServiceName = ServiceName } };
4340
_httpRecorder = new RecordHttpHandler();
44-
_tracer = Tracer.Create(new Uri("http://localhost:8126"), serviceList, null, _httpRecorder);
41+
_tracer = Tracer.Create(new Uri("http://localhost:8126"), null, _httpRecorder);
4542

4643
var scope = _tracer.StartActive("Operation", serviceName: ServiceName);
4744
scope.Span.ResourceName = "This is a resource";
4845
scope.Dispose();
4946

5047
// Check that the HTTP calls went as expected
51-
await _httpRecorder.WaitForCompletion(2);
52-
Assert.Equal(2, _httpRecorder.Requests.Count);
53-
Assert.Equal(2, _httpRecorder.Responses.Count);
48+
await _httpRecorder.WaitForCompletion(1);
49+
Assert.Equal(1, _httpRecorder.Requests.Count);
50+
Assert.Equal(1, _httpRecorder.Responses.Count);
5451
Assert.All(_httpRecorder.Responses, (x) => Assert.Equal(HttpStatusCode.OK, x.StatusCode));
5552

5653
var trace = _httpRecorder.Traces.Single();
5754
MsgPackHelpers.AssertSpanEqual(scope.Span, trace.Single());
58-
59-
var serviceInfo = _httpRecorder.Services.Select(x => x.ServiceInfos().Single()).Single();
60-
Assert.Equal(ServiceName, serviceInfo.ServiceName);
61-
Assert.Equal(App, serviceInfo.App);
62-
Assert.Equal(AppType, serviceInfo.AppType);
6355
}
6456

6557
[Fact]

src/Datadog.Trace.Tests/AgentWriterTests.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,6 @@ public AgentWriterTests()
2222
_agentWriter = new AgentWriter(_api.Object);
2323
}
2424

25-
[Fact]
26-
public async Task WriteServiceInfo_2Services_SendToApi()
27-
{
28-
var serviceInfo = new ServiceInfo { App = "AA", AppType = "BB", ServiceName = "CC" };
29-
_agentWriter.WriteServiceInfo(serviceInfo);
30-
await Task.Delay(TimeSpan.FromSeconds(1.5));
31-
_api.Verify(x => x.SendServiceAsync(It.Is<ServiceInfo>(y => y.Equals(serviceInfo))), Times.Once);
32-
33-
serviceInfo = new ServiceInfo { App = "DD", AppType = "EE", ServiceName = "FF" };
34-
_agentWriter.WriteServiceInfo(serviceInfo);
35-
await Task.Delay(TimeSpan.FromSeconds(1.5));
36-
_api.Verify(x => x.SendServiceAsync(It.Is<ServiceInfo>(y => y.Equals(serviceInfo))), Times.Once);
37-
}
38-
3925
[Fact]
4026
public async Task WriteTrace_2Traces_SendToApi()
4127
{

src/Datadog.Trace.Tests/ApiTests.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Net;
34
using System.Net.Http;
45
using System.Threading;
56
using System.Threading.Tasks;
7+
using Moq;
68
using Xunit;
79

810
namespace Datadog.Trace.Tests
@@ -31,8 +33,17 @@ protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage reques
3133

3234
public class ApiTests
3335
{
36+
private Mock<IAgentWriter> _writerMock;
37+
private Tracer _tracer;
38+
39+
public ApiTests()
40+
{
41+
_writerMock = new Mock<IAgentWriter>();
42+
_tracer = new Tracer(_writerMock.Object);
43+
}
44+
3445
[Fact]
35-
public async Task SendServiceAsync_200OK_AllGood()
46+
public async Task SendTraceAsync_200OK_AllGood()
3647
{
3748
var response = new HttpResponseMessage
3849
{
@@ -41,13 +52,13 @@ public async Task SendServiceAsync_200OK_AllGood()
4152
var handler = new SetResponseHandler(response);
4253
var api = new Api(new Uri("http://localhost:1234"), handler);
4354

44-
await api.SendServiceAsync(new ServiceInfo());
55+
await api.SendTracesAsync(new List<List<Span>> { new List<Span> { _tracer.StartSpan("Operation") } });
4556

4657
Assert.Equal(1, handler.RequestsCount);
4758
}
4859

4960
[Fact]
50-
public async Task SendServiceAsync_500_ErrorIsCaught()
61+
public async Task SendTracesAsync_500_ErrorIsCaught()
5162
{
5263
var response = new HttpResponseMessage
5364
{
@@ -56,7 +67,7 @@ public async Task SendServiceAsync_500_ErrorIsCaught()
5667
var handler = new SetResponseHandler(response);
5768
var api = new Api(new Uri("http://localhost:1234"), handler);
5869

59-
await api.SendServiceAsync(new ServiceInfo());
70+
await api.SendTracesAsync(new List<List<Span>> { new List<Span> { _tracer.StartSpan("Operation") } });
6071

6172
Assert.Equal(1, handler.RequestsCount);
6273

src/Datadog.Trace.Tests/TracerTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public void StartActive_FinishOnClose_SpanIsFinishedWhenScopeIsClosed()
7676
public void StartActive_FinishOnClose_SpanIsFinishedWhenScopeIsDisposed()
7777
{
7878
Scope scope;
79-
using(scope = _tracer.StartActive("Operation")){
79+
using (scope = _tracer.StartActive("Operation"))
80+
{
8081
Assert.False(scope.Span.IsFinished);
8182
}
8283

src/Datadog.Trace/Implementations/ServiceInfo.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/Datadog.Trace/Implementations/Tracer.cs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class Tracer : IDatadogTracer
1515

1616
private AsyncLocalScopeManager _scopeManager;
1717
private string _defaultServiceName;
18-
private Dictionary<string, ServiceInfo> _services = new Dictionary<string, ServiceInfo>();
1918
private IAgentWriter _agentWriter;
2019
private bool _isDebugEnabled;
2120

@@ -24,23 +23,11 @@ static Tracer()
2423
Instance = Create();
2524
}
2625

27-
internal Tracer(IAgentWriter agentWriter, List<ServiceInfo> serviceInfo = null, string defaultServiceName = null, bool isDebugEnabled = false)
26+
internal Tracer(IAgentWriter agentWriter, string defaultServiceName = null, bool isDebugEnabled = false)
2827
{
2928
_isDebugEnabled = isDebugEnabled;
3029
_agentWriter = agentWriter;
3130
_defaultServiceName = defaultServiceName ?? GetAppDomainFriendlyName() ?? Constants.UnkownService;
32-
if (serviceInfo != null)
33-
{
34-
foreach (var service in serviceInfo)
35-
{
36-
_services[service.ServiceName] = service;
37-
}
38-
}
39-
40-
foreach (var service in _services.Values)
41-
{
42-
_agentWriter.WriteServiceInfo(service);
43-
}
4431

4532
// Register callbacks to make sure we flush the traces before exiting
4633
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
@@ -69,14 +56,13 @@ internal Tracer(IAgentWriter agentWriter, List<ServiceInfo> serviceInfo = null,
6956
/// Create a new Tracer with the given parameters
7057
/// </summary>
7158
/// <param name="agentEndpoint">The agent endpoint where the traces will be sent (default is http://localhost:8126).</param>
72-
/// <param name="serviceInfoList">The service information list.</param>
7359
/// <param name="defaultServiceName">Default name of the service (default is the name of the executing assembly).</param>
7460
/// <param name="isDebugEnabled">Turns on all debug logging (this may have an impact on application performance).</param>
7561
/// <returns>The newly created tracer</returns>
76-
public static Tracer Create(Uri agentEndpoint = null, List<ServiceInfo> serviceInfoList = null, string defaultServiceName = null, bool isDebugEnabled = false)
62+
public static Tracer Create(Uri agentEndpoint = null, string defaultServiceName = null, bool isDebugEnabled = false)
7763
{
7864
agentEndpoint = agentEndpoint ?? _defaultUri;
79-
return Create(agentEndpoint, serviceInfoList, defaultServiceName, null, isDebugEnabled);
65+
return Create(agentEndpoint, defaultServiceName, null, isDebugEnabled);
8066
}
8167

8268
/// <summary>
@@ -132,11 +118,11 @@ void IDatadogTracer.Write(List<Span> trace)
132118
_agentWriter.WriteTrace(trace);
133119
}
134120

135-
internal static Tracer Create(Uri agentEndpoint, List<ServiceInfo> serviceInfoList = null, string defaultServiceName = null, DelegatingHandler delegatingHandler = null, bool isDebugEnabled = false)
121+
internal static Tracer Create(Uri agentEndpoint, string serviceName, DelegatingHandler delegatingHandler = null, bool isDebugEnabled = false)
136122
{
137123
var api = new Api(agentEndpoint, delegatingHandler);
138124
var agentWriter = new AgentWriter(api);
139-
var tracer = new Tracer(agentWriter, serviceInfoList, defaultServiceName, isDebugEnabled);
125+
var tracer = new Tracer(agentWriter, serviceName, isDebugEnabled);
140126
return tracer;
141127
}
142128

0 commit comments

Comments
 (0)