Skip to content

Commit

Permalink
Allow the jaeger exporter path to be configured
Browse files Browse the repository at this point in the history
  • Loading branch information
Abraham Heidebrecht committed Feb 2, 2022
1 parent d421cf0 commit 6e0ce44
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public JaegerHttpClient(Uri endpoint, HttpClient httpClient)

this.endpoint = endpoint;
this.httpClient = httpClient;

this.httpClient.BaseAddress = this.endpoint;
}

public bool Connected => true;
Expand Down Expand Up @@ -67,7 +65,7 @@ public int Send(byte[] buffer, int offset, int count)
// Prevent Jaeger's HTTP operations from being instrumented.
using var scope = SuppressInstrumentationScope.Begin();

using HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "/api/traces");
using HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, this.endpoint);

request.Content = new ByteArrayContent(buffer, offset, count)
{
Expand Down
6 changes: 4 additions & 2 deletions src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class JaegerExporterOptions
internal const string OTelAgentHostEnvVarKey = "OTEL_EXPORTER_JAEGER_AGENT_HOST";
internal const string OTelAgentPortEnvVarKey = "OTEL_EXPORTER_JAEGER_AGENT_PORT";
internal const string OTelEndpointEnvVarKey = "OTEL_EXPORTER_JAEGER_ENDPOINT";
internal const string DefaultJaegerEndpoint = "http://localhost:14268/api/traces";

internal static readonly Func<HttpClient> DefaultHttpClientFactory = () => new HttpClient();

Expand Down Expand Up @@ -80,9 +81,10 @@ public JaegerExporterOptions()
public int AgentPort { get; set; } = 6831;

/// <summary>
/// Gets or sets the Jaeger HTTP endpoint. Default value: "http://localhost:14268".
/// Gets or sets the Jaeger HTTP endpoint. Default value: "http://localhost:14268/api/traces".
/// Typically https://jaeger-server-name:14268/api/traces.
/// </summary>
public Uri Endpoint { get; set; } = new Uri("http://localhost:14268");
public Uri Endpoint { get; set; } = new Uri(DefaultJaegerEndpoint);

/// <summary>
/// Gets or sets the maximum payload size in bytes. Default value: 4096.
Expand Down
34 changes: 34 additions & 0 deletions test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry.Exporter.Jaeger.Implementation;
using OpenTelemetry.Exporter.Jaeger.Implementation.Tests;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using RichardSzalay.MockHttp;
using Thrift.Protocol;
using Xunit;

Expand Down Expand Up @@ -109,6 +112,37 @@ public void ServiceProviderHttpClientFactoryInvoked()
Assert.Equal(1, invocations);
}

[Theory]
[InlineData(JaegerExporterOptions.DefaultJaegerEndpoint)]
[InlineData("http://localhost:1234")]
[InlineData("http://localhost:1234/foo/bar")]
public void HttpClient_Posts_To_Configured_Endpoint(string uri)
{
// Arrange
var mockHandler = new MockHttpMessageHandler();
mockHandler.Expect(HttpMethod.Post, uri)
.Respond(HttpStatusCode.OK);

var options = new JaegerExporterOptions
{
Endpoint = new Uri(uri),
HttpClientFactory = () => mockHandler.ToHttpClient(),
Protocol = JaegerExportProtocol.HttpBinaryThrift,
ExportProcessorType = ExportProcessorType.Simple,
};

using var jaegerExporter = new JaegerExporter(options);

// Act
jaegerExporter.SetResourceAndInitializeBatch(Resource.Empty);
jaegerExporter.AppendSpan(CreateTestJaegerSpan());
jaegerExporter.SendCurrentBatch();

// Assert
mockHandler.VerifyNoOutstandingExpectation();
mockHandler.VerifyNoOutstandingRequest();
}

[Fact]
public void JaegerTraceExporter_SetResource_UpdatesServiceName()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Unit test project for Jaeger Exporter for OpenTelemetry</Description>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
Expand All @@ -18,6 +18,7 @@
<DotNetCliToolReference Include="dotnet-xunit" Version="$(DotNetXUnitCliVer)" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="$(MicrosoftExtensionsHostingPkgVer)" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.20" />
<PackageReference Include="RichardSzalay.MockHttp" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 6e0ce44

Please sign in to comment.