Updating reference from SpanExporter to ActivityExporter for Jaeger (#793)

* Remove SpanExporter from Jaeger

renaming files and updating references

merging JaegerExporter and JaegerTraceExporter

merging tests

update

* removing comment
This commit is contained in:
Eddy Nakamura 2020-07-09 21:40:18 -03:00 committed by GitHub
parent db781d2dfd
commit 4d9d4a014a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 65 additions and 260 deletions

View File

@ -18,7 +18,7 @@ namespace OpenTelemetry.Exporter.AspNet
this.openTelemetry = OpenTelemetrySdk.EnableOpenTelemetry(
(builder) => builder.AddDependencyInstrumentation()
.AddRequestInstrumentation()
.UseJaegerActivityExporter(c =>
.UseJaegerExporter(c =>
{
c.AgentHost = "localhost";
c.AgentPort = 6831;

View File

@ -40,7 +40,7 @@ namespace Samples
{
Parser.Default.ParseArguments<JaegerOptions, ZipkinOptions, PrometheusOptions, HttpClientOptions, ZPagesOptions, ConsoleOptions, OtlpOptions>(args)
.MapResult(
(JaegerOptions options) => TestJaeger.Run(options.Host, options.Port),
(JaegerOptions options) => TestJaegerExporter.Run(options.Host, options.Port),
(ZipkinOptions options) => TestZipkin.Run(options.Uri),
(PrometheusOptions options) => TestPrometheus.RunAsync(options.Port, options.PushIntervalInSecs, options.DurationInMins),
(HttpClientOptions options) => TestHttpClient.Run(),

View File

@ -1,4 +1,4 @@
// <copyright file="TestJaeger.cs" company="OpenTelemetry Authors">
// <copyright file="TestJaegerExporter.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
@ -14,14 +14,12 @@
// limitations under the License.
// </copyright>
using System;
using System.Collections.Generic;
using System.Threading;
using OpenTelemetry.Trace;
using OpenTelemetry.Trace.Configuration;
namespace Samples
{
internal class TestJaeger
internal class TestJaegerExporter
{
internal static object Run(string host, int port)
{
@ -36,7 +34,7 @@ namespace Samples
builder => builder
.AddActivitySource("Samples.SampleServer")
.AddActivitySource("Samples.SampleClient")
.UseJaegerActivityExporter(o =>
.UseJaegerExporter(o =>
{
o.ServiceName = "jaeger-test";
o.AgentHost = host;
@ -50,9 +48,7 @@ namespace Samples
{
sample.Start();
Console.WriteLine("Traces are being created and exported" +
"to Jaeger in the background. Use Jaeger to view them." +
"Press ENTER to stop.");
Console.WriteLine("Sample is running on the background, press ENTER to stop");
Console.ReadLine();
}

View File

@ -1,85 +0,0 @@
// <copyright file="JaegerActivityExporter.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using OpenTelemetry.Exporter.Jaeger.Implementation;
using OpenTelemetry.Trace.Export;
namespace OpenTelemetry.Exporter.Jaeger
{
public class JaegerActivityExporter : ActivityExporter, IDisposable
{
private readonly SemaphoreSlim exportLock = new SemaphoreSlim(1);
private bool disposedValue = false; // To detect redundant dispose calls
public JaegerActivityExporter(JaegerExporterOptions options)
{
this.JaegerAgentUdpBatcher = new JaegerUdpBatcher(options);
}
internal IJaegerUdpBatcher JaegerAgentUdpBatcher { get; }
public override async Task<ExportResult> ExportAsync(IEnumerable<Activity> activityBatch, CancellationToken cancellationToken)
{
await this.exportLock.WaitAsync().ConfigureAwait(false);
try
{
foreach (var activity in activityBatch)
{
// TODO: group by activity source
// avoid cancelling here: this is no return point: if we reached this point
// and cancellation is requested, it's better if we try to finish sending spans rather than drop it
await this.JaegerAgentUdpBatcher.AppendAsync(activity.ToJaegerSpan(), CancellationToken.None).ConfigureAwait(false);
}
// TODO jaeger status to ExportResult
return ExportResult.Success;
}
finally
{
this.exportLock.Release();
}
}
public override async Task ShutdownAsync(CancellationToken cancellationToken)
{
await this.JaegerAgentUdpBatcher.FlushAsync(cancellationToken).ConfigureAwait(false);
}
public void Dispose()
{
// Do not change this code. Put cleanup code in Dispose(bool disposing).
this.Dispose(true);
}
protected virtual void Dispose(bool disposing)
{
if (!this.disposedValue)
{
if (disposing)
{
this.JaegerAgentUdpBatcher.Dispose();
}
this.disposedValue = true;
}
}
}
}

View File

@ -1,4 +1,4 @@
// <copyright file="JaegerTraceExporter.cs" company="OpenTelemetry Authors">
// <copyright file="JaegerExporter.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
@ -15,47 +15,49 @@
// </copyright>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using OpenTelemetry.Exporter.Jaeger.Implementation;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using OpenTelemetry.Trace.Export;
namespace OpenTelemetry.Exporter.Jaeger
{
public class JaegerTraceExporter : SpanExporter, IDisposable
public class JaegerExporter : ActivityExporter, IDisposable
{
private readonly SemaphoreSlim exportLock = new SemaphoreSlim(1);
private bool libraryResourceApplied = false;
private bool disposedValue = false; // To detect redundant dispose calls
public JaegerTraceExporter(JaegerExporterOptions options)
public JaegerExporter(JaegerExporterOptions options)
{
this.JaegerAgentUdpBatcher = new JaegerUdpBatcher(options);
}
internal IJaegerUdpBatcher JaegerAgentUdpBatcher { get; }
public override async Task<ExportResult> ExportAsync(IEnumerable<SpanData> otelSpanList, CancellationToken cancellationToken)
public override async Task<ExportResult> ExportAsync(IEnumerable<Activity> activityBatch, CancellationToken cancellationToken)
{
await this.exportLock.WaitAsync().ConfigureAwait(false);
try
{
if (!this.libraryResourceApplied && otelSpanList.Count() > 0)
if (!this.libraryResourceApplied && activityBatch.Count() > 0)
{
var libraryResource = otelSpanList.First().LibraryResource;
var libraryResource = activityBatch.First().GetResource();
this.ApplyLibraryResource(libraryResource ?? Resource.Empty);
this.libraryResourceApplied = true;
}
foreach (var s in otelSpanList)
foreach (var activity in activityBatch)
{
// avoid cancelling here: this is no return point: if we reached this point
// and cancellation is requested, it's better if we try to finish sending spans rather than drop it
await this.JaegerAgentUdpBatcher.AppendAsync(s.ToJaegerSpan(), CancellationToken.None).ConfigureAwait(false);
await this.JaegerAgentUdpBatcher.AppendAsync(activity.ToJaegerSpan(), CancellationToken.None).ConfigureAwait(false);
}
// TODO jaeger status to ExportResult
@ -137,7 +139,6 @@ namespace OpenTelemetry.Exporter.Jaeger
if (disposing)
{
this.JaegerAgentUdpBatcher.Dispose();
this.exportLock.Dispose();
}
this.disposedValue = true;

View File

@ -31,7 +31,7 @@ namespace OpenTelemetry.Trace.Configuration
/// <param name="configure">Exporter configuration options.</param>
/// <param name="processorConfigure">Activity processor configuration.</param>
/// <returns>The instance of <see cref="OpenTelemetryBuilder"/> to chain the calls.</returns>
public static OpenTelemetryBuilder UseJaegerActivityExporter(this OpenTelemetryBuilder builder, Action<JaegerExporterOptions> configure = null, Action<ActivityProcessorPipelineBuilder> processorConfigure = null)
public static OpenTelemetryBuilder UseJaegerExporter(this OpenTelemetryBuilder builder, Action<JaegerExporterOptions> configure = null, Action<ActivityProcessorPipelineBuilder> processorConfigure = null)
{
if (builder == null)
{
@ -43,7 +43,7 @@ namespace OpenTelemetry.Trace.Configuration
var exporterOptions = new JaegerExporterOptions();
configure?.Invoke(exporterOptions);
var activityExporter = new JaegerActivityExporter(exporterOptions);
var activityExporter = new JaegerExporter(exporterOptions);
processorConfigure?.Invoke(pipeline);
pipeline.SetExporter(activityExporter);
});

View File

@ -1,86 +0,0 @@
// <copyright file="TracerBuilderExtensions.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
using System;
using OpenTelemetry.Exporter.Jaeger;
using OpenTelemetry.Trace.Export;
namespace OpenTelemetry.Trace.Configuration
{
/// <summary>
/// Extension methods to simplify registering a Jaeger exporter.
/// </summary>
public static class TracerBuilderExtensions
{
/// <summary>
/// Registers a Jaeger exporter.
/// </summary>
/// <param name="builder">Trace builder to use.</param>
/// <param name="configure">Exporter configuration options.</param>
/// <returns>The instance of <see cref="TracerBuilder"/> to chain the calls.</returns>
public static TracerBuilder UseJaeger(this TracerBuilder builder, Action<JaegerExporterOptions> configure)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (configure == null)
{
throw new ArgumentNullException(nameof(configure));
}
var options = new JaegerExporterOptions();
configure(options);
return builder.AddProcessorPipeline(b => b
.SetExporter(new JaegerTraceExporter(options))
.SetExportingProcessor(e => new BatchingSpanProcessor(e)));
}
/// <summary>
/// Registers Jaeger exporter.
/// </summary>
/// <param name="builder">Trace builder to use.</param>
/// <param name="configure">Exporter configuration options.</param>
/// <param name="processorConfigure">Span processor configuration.</param>
/// <returns>The instance of <see cref="TracerBuilder"/> to chain the calls.</returns>
public static TracerBuilder UseJaeger(this TracerBuilder builder, Action<JaegerExporterOptions> configure, Action<SpanProcessorPipelineBuilder> processorConfigure)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (configure == null)
{
throw new ArgumentNullException(nameof(configure));
}
if (processorConfigure == null)
{
throw new ArgumentNullException(nameof(processorConfigure));
}
var options = new JaegerExporterOptions();
configure(options);
return builder.AddProcessorPipeline(b =>
{
b.SetExporter(new JaegerTraceExporter(options));
processorConfigure.Invoke(b);
});
}
}
}

View File

@ -1,59 +0,0 @@
// <copyright file="JaegerActivityExporterTests.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
using System.Diagnostics;
using OpenTelemetry.Trace.Configuration;
using Xunit;
namespace OpenTelemetry.Exporter.Jaeger.Tests
{
public class JaegerActivityExporterTests
{
[Fact]
public void UseJaegerActivityExporterWithCustomActivityProcessor()
{
const string ActivitySourceName = "jaeger.test";
TestActivityProcessor testActivityProcessor = new TestActivityProcessor();
bool startCalled = false;
bool endCalled = false;
testActivityProcessor.StartAction =
(a) =>
{
startCalled = true;
};
testActivityProcessor.EndAction =
(a) =>
{
endCalled = true;
};
var openTelemetrySdk = OpenTelemetrySdk.EnableOpenTelemetry(b => b
.AddActivitySource(ActivitySourceName)
.UseJaegerActivityExporter(
null, p => p.AddProcessor((next) => testActivityProcessor)));
var source = new ActivitySource(ActivitySourceName);
var activity = source.StartActivity("Test Jaeger Activity");
activity?.Stop();
Assert.True(startCalled);
Assert.True(endCalled);
}
}
}

View File

@ -1,4 +1,4 @@
// <copyright file="JaegerTraceExporterTests.cs" company="OpenTelemetry Authors">
// <copyright file="JaegerExporterTests.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
@ -13,19 +13,57 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
using System.Collections.Generic;
using System.Diagnostics;
using OpenTelemetry.Exporter.Jaeger.Implementation;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace.Configuration;
using Xunit;
namespace OpenTelemetry.Exporter.Jaeger.Tests.Implementation
namespace OpenTelemetry.Exporter.Jaeger.Tests
{
public class JaegerTraceExporterTests
public class JaegerExporterTests
{
[Fact]
public void UseJaegerExporterWithCustomActivityProcessor()
{
const string ActivitySourceName = "jaeger.test";
TestActivityProcessor testActivityProcessor = new TestActivityProcessor();
bool startCalled = false;
bool endCalled = false;
testActivityProcessor.StartAction =
(a) =>
{
startCalled = true;
};
testActivityProcessor.EndAction =
(a) =>
{
endCalled = true;
};
var openTelemetrySdk = OpenTelemetrySdk.EnableOpenTelemetry(b => b
.AddActivitySource(ActivitySourceName)
.UseJaegerExporter(
null, p => p.AddProcessor((next) => testActivityProcessor)));
var source = new ActivitySource(ActivitySourceName);
var activity = source.StartActivity("Test Jaeger Activity");
activity?.Stop();
Assert.True(startCalled);
Assert.True(endCalled);
}
[Fact]
public void JaegerTraceExporter_ctor_NullServiceNameAllowed()
{
using var jaegerTraceExporter = new JaegerTraceExporter(new JaegerExporterOptions
using var jaegerTraceExporter = new JaegerExporter(new JaegerExporterOptions
{
ServiceName = null,
});
@ -35,7 +73,7 @@ namespace OpenTelemetry.Exporter.Jaeger.Tests.Implementation
[Fact]
public void JaegerTraceExporter_ApplyLibraryResource_UpdatesServiceName()
{
using var jaegerTraceExporter = new JaegerTraceExporter(new JaegerExporterOptions());
using var jaegerTraceExporter = new JaegerExporter(new JaegerExporterOptions());
var process = jaegerTraceExporter.JaegerAgentUdpBatcher.Process;
process.ServiceName = "TestService";
@ -56,7 +94,7 @@ namespace OpenTelemetry.Exporter.Jaeger.Tests.Implementation
[Fact]
public void JaegerTraceExporter_ApplyLibraryResource_CreatesTags()
{
using var jaegerTraceExporter = new JaegerTraceExporter(new JaegerExporterOptions());
using var jaegerTraceExporter = new JaegerExporter(new JaegerExporterOptions());
var process = jaegerTraceExporter.JaegerAgentUdpBatcher.Process;
jaegerTraceExporter.ApplyLibraryResource(new Resource(new Dictionary<string, object>
@ -72,7 +110,7 @@ namespace OpenTelemetry.Exporter.Jaeger.Tests.Implementation
[Fact]
public void JaegerTraceExporter_ApplyLibraryResource_CombinesTags()
{
using var jaegerTraceExporter = new JaegerTraceExporter(new JaegerExporterOptions());
using var jaegerTraceExporter = new JaegerExporter(new JaegerExporterOptions());
var process = jaegerTraceExporter.JaegerAgentUdpBatcher.Process;
process.Tags = new Dictionary<string, JaegerTag> { ["Tag1"] = new KeyValuePair<string, object>("Tag1", "value1").ToJaegerTag() };
@ -91,7 +129,7 @@ namespace OpenTelemetry.Exporter.Jaeger.Tests.Implementation
[Fact]
public void JaegerTraceExporter_ApplyLibraryResource_IgnoreLibraryResources()
{
using var jaegerTraceExporter = new JaegerTraceExporter(new JaegerExporterOptions());
using var jaegerTraceExporter = new JaegerExporter(new JaegerExporterOptions());
var process = jaegerTraceExporter.JaegerAgentUdpBatcher.Process;
jaegerTraceExporter.ApplyLibraryResource(new Resource(new Dictionary<string, object>