Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions src/Datadog.Tracer.IntegrationTests/SendTracesToAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,13 @@ public async void MinimalSpan()
span.Finish();

// Check that the HTTP calls went as expected
await _httpRecorder.WaitForCompletion(2);
Assert.Equal(2, _httpRecorder.Requests.Count);
Assert.Equal(2, _httpRecorder.Responses.Count);
await _httpRecorder.WaitForCompletion(1);
Assert.Equal(1, _httpRecorder.Requests.Count);
Assert.Equal(1, _httpRecorder.Responses.Count);
Assert.All(_httpRecorder.Responses, (x) => Assert.Equal(HttpStatusCode.OK, x.StatusCode));

var trace = _httpRecorder.Traces.Single();
AssertSpanEqual(span, trace.Single());

var serviceInfo = _httpRecorder.Services.Single().ServiceInfos().Single();
Assert.Equal(Constants.UnkownService, serviceInfo.ServiceName);
Assert.Equal(Constants.UnkownApp, serviceInfo.App);
Assert.Equal(Constants.WebAppType, serviceInfo.AppType);
}

[Fact]
Expand All @@ -81,17 +76,15 @@ public async void CustomServiceName()
span.Finish();

// Check that the HTTP calls went as expected
await _httpRecorder.WaitForCompletion(3);
Assert.Equal(3, _httpRecorder.Requests.Count);
Assert.Equal(3, _httpRecorder.Responses.Count);
await _httpRecorder.WaitForCompletion(2);
Assert.Equal(2, _httpRecorder.Requests.Count);
Assert.Equal(2, _httpRecorder.Responses.Count);
Assert.All(_httpRecorder.Responses, (x) => Assert.Equal(HttpStatusCode.OK, x.StatusCode));

var trace = _httpRecorder.Traces.Single();
AssertSpanEqual(span, trace.Single());

var serviceInfos = _httpRecorder.Services.Select(x => x.ServiceInfos().Single()).ToList();
Assert.Equal(2, serviceInfos.Count);
var serviceInfo = serviceInfos.Single(x => x.ServiceName == ServiceName);
var serviceInfo = _httpRecorder.Services.Select(x => x.ServiceInfos().Single()).Single();
Assert.Equal(ServiceName, serviceInfo.ServiceName);
Assert.Equal(App, serviceInfo.App);
Assert.Equal(AppType, serviceInfo.AppType);
Expand All @@ -108,9 +101,9 @@ public async void Utf8Everywhere()
span.Finish();

// Check that the HTTP calls went as expected
await _httpRecorder.WaitForCompletion(2);
Assert.Equal(2, _httpRecorder.Requests.Count);
Assert.Equal(2, _httpRecorder.Responses.Count);
await _httpRecorder.WaitForCompletion(1);
Assert.Equal(1, _httpRecorder.Requests.Count);
Assert.Equal(1, _httpRecorder.Responses.Count);
Assert.All(_httpRecorder.Responses, (x) => Assert.Equal(HttpStatusCode.OK, x.StatusCode));

var trace = _httpRecorder.Traces.Single();
Expand Down
9 changes: 1 addition & 8 deletions src/Datadog.Tracer.Tests/TracerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ public class TracerTests
{
private Mock<IAgentWriter> _agentWriter = new Mock<IAgentWriter>();

[Fact]
public void Ctor_DefaultValues_ShouldSendDefaultServiceInfo()
{
var tracer = new Tracer(_agentWriter.Object);
_agentWriter.Verify(x => x.WriteServiceInfo(It.Is<ServiceInfo>(y => y.ServiceName == Constants.UnkownService && y.AppType == Constants.WebAppType && y.App == Constants.UnkownApp)), Times.Once);
}

[Fact]
public void BuildSpan_NoParameter_DefaultParameters()
{
Expand All @@ -26,7 +19,7 @@ public void BuildSpan_NoParameter_DefaultParameters()
var builder = tracer.BuildSpan("Op1");
var span = (Span)builder.Start();

Assert.Equal(Constants.UnkownService, span.ServiceName);
Assert.Equal("Datadog.Tracer", span.ServiceName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Assert.Equal("Op1", span.OperationName);
}

Expand Down
26 changes: 15 additions & 11 deletions src/Datadog.Tracer/Tracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using OpenTracing.Propagation;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;

namespace Datadog.Tracer
Expand All @@ -18,17 +19,7 @@ internal class Tracer : ITracer, IDatadogTracer
public Tracer(IAgentWriter agentWriter, List<ServiceInfo> serviceInfo = null, string defaultServiceName = null)
{
_agentWriter = agentWriter;
// TODO:bertrand be smarter about the service name
_defaultServiceName = defaultServiceName ?? Constants.UnkownService;
if (_defaultServiceName == Constants.UnkownService)
{
_services[Constants.UnkownService] = new ServiceInfo
{
ServiceName = Constants.UnkownService,
App = Constants.UnkownApp,
AppType = Constants.WebAppType,
};
}
_defaultServiceName = GetExecutingAssemblyName() ?? Constants.UnkownService;
if (serviceInfo != null)
{
foreach(var service in serviceInfo)
Expand All @@ -42,6 +33,19 @@ public Tracer(IAgentWriter agentWriter, List<ServiceInfo> serviceInfo = null, st
}
}

private string GetExecutingAssemblyName()
{
try
{
var name = Assembly.GetExecutingAssembly().GetName();
return name.Name;
}
catch
{
return null;
}
}

public ISpanBuilder BuildSpan(string operationName)
{
return new SpanBuilder(this, operationName);
Expand Down