Skip to content

Commit

Permalink
Allow the jaeger exporter path to be configured (#2847)
Browse files Browse the repository at this point in the history
  • Loading branch information
abe545 authored Feb 24, 2022
1 parent f2fcb53 commit 13e721d
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 7 deletions.
9 changes: 9 additions & 0 deletions src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
Supported values: `udp/thrift.compact` and `http/thrift.binary` defined
in the [specification](https://github.com/open-telemetry/opentelemetry-specification/blob/9a0a3300c6269c2837a1d7c9c5232ec816f63222/specification/sdk-environment-variables.md?plain=1#L129).
([#2914](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2914))
* Change handling of `OTEL_EXPORTER_JAEGER_ENDPOINT` to require the path to
post. Previous versions of this library would append `/api/traces` to the
value specified in this variable, but now the application author must do so.
This change must also be made if you manually configure the
`JaegerExporterOptions` class - the `Endpoint` must now include the path.
For most environments, this will be `/api/traces`. The effective default
is still `http://localhost:14268/api/traces`. This was done to match
the clarified [specification](https://github.com/open-telemetry/opentelemetry-specification/pull/2333))
([#2847](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2847))

## 1.2.0-rc2

Expand Down
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 @@ -88,9 +89,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
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void JaegerExporterOptions_Defaults()
Assert.Equal(4096, options.MaxPayloadSizeInBytes);
Assert.Equal(ExportProcessorType.Batch, options.ExportProcessorType);
Assert.Equal(JaegerExportProtocol.UdpCompactThrift, options.Protocol);
Assert.Equal(new Uri("http://localhost:14268"), options.Endpoint);
Assert.Equal(JaegerExporterOptions.DefaultJaegerEndpoint, options.Endpoint.ToString());
}

[Fact]
Expand Down
49 changes: 49 additions & 0 deletions test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
// </copyright>

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry.Exporter.Jaeger.Implementation;
using OpenTelemetry.Exporter.Jaeger.Implementation.Tests;
using OpenTelemetry.Resources;
using OpenTelemetry.Tests;
using OpenTelemetry.Trace;
using Thrift.Protocol;
using Xunit;
Expand Down Expand Up @@ -109,6 +112,52 @@ public void ServiceProviderHttpClientFactoryInvoked()
Assert.Equal(1, invocations);
}

[Theory]
[InlineData("/api/traces")]
[InlineData("/foo/bar")]
[InlineData("/")]
public void HttpClient_Posts_To_Configured_Endpoint(string uriPath)
{
// Arrange
ConcurrentDictionary<Guid, string> responses = new ConcurrentDictionary<Guid, string>();
using var testServer = TestHttpServer.RunServer(
context =>
{
context.Response.StatusCode = 200;

using StreamReader readStream = new StreamReader(context.Request.InputStream);

string requestContent = readStream.ReadToEnd();

responses.TryAdd(
Guid.Parse(context.Request.QueryString["requestId"]),
context.Request.Url.LocalPath);

context.Response.OutputStream.Close();
},
out var testServerHost,
out var testServerPort);

var requestId = Guid.NewGuid();
var options = new JaegerExporterOptions
{
Endpoint = new Uri($"http://{testServerHost}:{testServerPort}{uriPath}?requestId={requestId}"),
Protocol = JaegerExportProtocol.HttpBinaryThrift,
ExportProcessorType = ExportProcessorType.Simple,
};

using var jaegerExporter = new JaegerExporter(options);

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

// Assert
Assert.True(responses.ContainsKey(requestId));
Assert.Equal(uriPath, responses[requestId]);
}

[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 Down Expand Up @@ -27,6 +27,7 @@
<Compile Include="$(RepoRoot)\test\OpenTelemetry.Tests\Shared\EventSourceTestHelper.cs" Link="Includes\EventSourceTestHelper.cs" />
<Compile Include="$(RepoRoot)\test\OpenTelemetry.Tests\Shared\TestActivityProcessor.cs" Link="Includes\TestActivityProcessor.cs" />
<Compile Include="$(RepoRoot)\test\OpenTelemetry.Tests\Shared\TestEventListener.cs" Link="Includes\TestEventListener.cs" />
<Compile Include="$(RepoRoot)\test\OpenTelemetry.Tests\Shared\TestHttpServer.cs" Link="Includes\TestHttpServer.cs" />
</ItemGroup>

</Project>

0 comments on commit 13e721d

Please sign in to comment.