Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JaegerExporter GenerateServiceSpecificBatches option #1498

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.AgentHost.get -> string
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.AgentHost.set -> void
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.AgentPort.get -> int
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.AgentPort.set -> void
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.GenerateServiceSpecificBatches.get -> bool
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.GenerateServiceSpecificBatches.set -> void
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.JaegerExporterOptions() -> void
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.MaxPayloadSizeInBytes.get -> int?
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.MaxPayloadSizeInBytes.set -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.AgentHost.get -> string
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.AgentHost.set -> void
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.AgentPort.get -> int
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.AgentPort.set -> void
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.GenerateServiceSpecificBatches.get -> bool
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.GenerateServiceSpecificBatches.set -> void
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.JaegerExporterOptions() -> void
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.MaxPayloadSizeInBytes.get -> int?
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.MaxPayloadSizeInBytes.set -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.AgentHost.get -> string
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.AgentHost.set -> void
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.AgentPort.get -> int
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.AgentPort.set -> void
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.GenerateServiceSpecificBatches.get -> bool
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.GenerateServiceSpecificBatches.set -> void
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.JaegerExporterOptions() -> void
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.MaxPayloadSizeInBytes.get -> int?
OpenTelemetry.Exporter.Jaeger.JaegerExporterOptions.MaxPayloadSizeInBytes.set -> void
Expand Down
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Exporter.Jaeger/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Added `GenerateServiceSpecificBatches` option.
([#1498](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1498))

## 0.8.0-beta.1

Released 2020-Nov-5
Expand Down
6 changes: 5 additions & 1 deletion src/OpenTelemetry.Exporter.Jaeger/JaegerExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class JaegerExporter : BaseExporter<Activity>
private readonly JaegerThriftClient thriftClient;
private readonly InMemoryTransport memoryTransport;
private readonly TProtocol memoryProtocol;
private readonly bool generateServiceSpecificBatches;
private Dictionary<string, Process> processCache;
private int batchByteSize;
private bool disposedValue; // To detect redundant dispose calls
Expand All @@ -51,6 +52,7 @@ internal JaegerExporter(JaegerExporterOptions options, TTransport clientTranspor
this.thriftClient = new JaegerThriftClient(this.protocolFactory.GetProtocol(this.clientTransport));
this.memoryTransport = new InMemoryTransport(16000);
this.memoryProtocol = this.protocolFactory.GetProtocol(this.memoryTransport);
this.generateServiceSpecificBatches = options.GenerateServiceSpecificBatches;

this.Process = new Process(options.ServiceName, options.ProcessTags);
}
Expand Down Expand Up @@ -147,7 +149,9 @@ internal void SetResource(Resource resource)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void AppendSpan(JaegerSpan jaegerSpan)
{
var spanServiceName = jaegerSpan.PeerServiceName ?? this.Process.ServiceName;
var spanServiceName = !this.generateServiceSpecificBatches
? this.Process.ServiceName
: jaegerSpan.PeerServiceName ?? this.Process.ServiceName;

if (!this.processCache.TryGetValue(spanServiceName, out var spanProcess))
{
Expand Down
15 changes: 15 additions & 0 deletions src/OpenTelemetry.Exporter.Jaeger/JaegerExporterOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,20 @@ public class JaegerExporterOptions
/// Gets or sets the tags that should be sent with telemetry.
/// </summary>
public IEnumerable<KeyValuePair<string, object>> ProcessTags { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not a batch should be sent to the Jaeger agent for each service. Default value: true.
Copy link
Member

Choose a reason for hiding this comment

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

Given there is a concern that this causes exporter to send "incorrect" data, should we make this default to "false", so that SDK by default exports correct data. If a user want to send "incorrect" data to have better UI experience, let them explicitly opt-in to this behavior?

Copy link
Member

Choose a reason for hiding this comment

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

I think the incorrect behavior should be removed altogether, without options to enable it. The Jaeger UI enhancement is already being added in jaegertracing/jaeger-ui#659

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to verify everything works with the new Jaeger UI and then I'll open a PR to remove the hack. Question, is a note in CHANGELOG recommending users upgrade Jaeger UI to restore the functionality sufficient?

/// </summary>
/// <remarks>
/// Jaeger UI will only detect &amp; color dependency spans when both
/// the client &amp; server processes report data to the same Jaeger
/// instance. For processes that make calls to non-instrumented services
/// (third parties, SQL, legacy systems, etc.) the
/// GenerateServiceSpecificBatches flag is provided to trick Jaeger into
/// correctly detecting and displaying all dependent spans as if both
/// sides reported data. For more details, see <a
/// href="https://github.com/jaegertracing/jaeger-ui/issues/594">jaeger-ui/issues/594</a>.
/// </remarks>
public bool GenerateServiceSpecificBatches { get; set; } = true;
}
}
38 changes: 28 additions & 10 deletions test/OpenTelemetry.Exporter.Jaeger.Tests/JaegerExporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,17 @@ public void JaegerTraceExporter_BuildBatchesToTransmit_DefaultBatch()
Assert.Equal(3, batches.First().Count);
}

[Fact]
public void JaegerTraceExporter_BuildBatchesToTransmit_MultipleBatches()
[Theory]
[InlineData(true)]
[InlineData(false)]
public void JaegerTraceExporter_BuildBatchesToTransmit_MultipleBatches(bool generateServiceSpecificBatches)
{
// Arrange
using var jaegerExporter = new JaegerExporter(new JaegerExporterOptions { ServiceName = "TestService" });
using var jaegerExporter = new JaegerExporter(new JaegerExporterOptions
{
ServiceName = "TestService",
GenerateServiceSpecificBatches = generateServiceSpecificBatches,
});
jaegerExporter.SetResource(Resource.Empty);

// Act
Expand All @@ -156,15 +162,27 @@ public void JaegerTraceExporter_BuildBatchesToTransmit_MultipleBatches()
var batches = jaegerExporter.CurrentBatches.Values;

// Assert
Assert.Equal(2, batches.Count());

var primaryBatch = batches.Where(b => b.Process.ServiceName == "TestService");
Assert.Single(primaryBatch);
Assert.Equal(2, primaryBatch.First().Count);
if (generateServiceSpecificBatches)
{
Assert.Equal(2, batches.Count());

var primaryBatch = batches.Where(b => b.Process.ServiceName == "TestService");
Assert.Single(primaryBatch);
Assert.Equal(2, primaryBatch.First().Count);

var mySQLBatch = batches.Where(b => b.Process.ServiceName == "MySQL");
Assert.Single(mySQLBatch);
Assert.Equal(1, mySQLBatch.First().Count);
}
else
{
Assert.Single(batches);

var mySQLBatch = batches.Where(b => b.Process.ServiceName == "MySQL");
Assert.Single(mySQLBatch);
Assert.Equal(1, mySQLBatch.First().Count);
var primaryBatch = batches.Where(b => b.Process.ServiceName == "TestService");
Assert.Single(primaryBatch);
Assert.Equal(3, primaryBatch.First().Count);
}
}

[Fact]
Expand Down