Fix jaeger exporter by assigning jaegerAgentUdpBatcher in constructor (#242)

* fix jaeger exporter by assigning udpbatcher in constructor

* JaegerTraceExporter keep existing constructor and default to JaegerUdpBatcher when none specified.

* monior refactor
This commit is contained in:
Cijo Thomas 2019-10-01 07:27:34 -07:00 committed by Austin Parker
parent bae63f8c34
commit 6cad307c01
4 changed files with 25 additions and 19 deletions

View File

@ -156,13 +156,14 @@ the Compact Thrift API port. You can configure the Jaeger exporter by following
3. See the [sample][jaeger-sample] for an example of how to use the exporter.
```csharp
var exporter = new JaegerExporter(
new JaegerExporterOptions
{
ServiceName = "tracing-to-jaeger-service",
AgentHost = host,
AgentPort = port,
});
var jaegerOptions = new JaegerExporterOptions()
{
ServiceName = "tracing-to-jaeger-service",
AgentHost = host,
AgentPort = port,
};
var exporter = new JaegerTraceExporter(jaegerOptions);
var tracer = new Tracer(new BatchingSpanProcessor(exporter), TraceConfig.Default);

View File

@ -20,6 +20,7 @@ namespace Samples
using System.Collections.Generic;
using System.Threading;
using OpenTelemetry.Exporter.Jaeger;
using OpenTelemetry.Exporter.Jaeger.Implementation;
using OpenTelemetry.Trace;
using OpenTelemetry.Trace.Config;
using OpenTelemetry.Trace.Export;
@ -29,13 +30,15 @@ namespace Samples
internal static object Run(string host, int port)
{
// Configure exporter to export traces to Jaeger
var jaegerOptions = new JaegerExporterOptions()
{
ServiceName = "tracing-to-jaeger-service",
AgentHost = host,
AgentPort = port,
};
var exporter = new JaegerTraceExporter(
new JaegerExporterOptions
{
ServiceName = "tracing-to-jaeger-service",
AgentHost = host,
AgentPort = port,
});
jaegerOptions);
// Create a tracer. You may also need to register it as a global instance to make auto-collectors work..
var tracer = new Tracer(new BatchingSpanProcessor(exporter), TraceConfig.Default);
@ -80,6 +83,7 @@ namespace Samples
// Annotate our span to capture metadata about our operation
var attributes = new Dictionary<string, object>();
attributes.Add("use", "demo");
attributes.Add("iteration", i);
span.AddEvent("Invoking DoWork", attributes);
}
}

View File

@ -1,4 +1,4 @@
// <copyright file="JaegerUdpBatcher.cs" company="OpenTelemetry Authors">
// <copyright file="JaegerUdpBatcher.cs" company="OpenTelemetry Authors">
// Copyright 2018, OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
@ -39,7 +39,7 @@ namespace OpenTelemetry.Exporter.Jaeger.Implementation
public JaegerUdpBatcher(JaegerExporterOptions options)
{
this.maxPacketSize = options.MaxPacketSize == 0 ? DefaultMaxPacketSize : options.MaxPacketSize;
this.maxPacketSize = (!options.MaxPacketSize.HasValue || options.MaxPacketSize == 0) ? DefaultMaxPacketSize : options.MaxPacketSize;
this.protocolFactory = new TCompactProtocol.Factory();
this.clientTransport = new JaegerThriftClientTransport(options.AgentHost, options.AgentPort.Value);
this.thriftClient = new JaegerThriftClient(this.protocolFactory.GetProtocol(this.clientTransport));

View File

@ -35,13 +35,14 @@ namespace OpenTelemetry.Exporter.Jaeger
private bool disposedValue = false; // To detect redundant dispose calls
public JaegerTraceExporter(JaegerExporterOptions options)
: this(options, new JaegerUdpBatcher(options))
{
}
public JaegerTraceExporter(JaegerExporterOptions options, IJaegerUdpBatcher jaegerAgentUdpBatcher)
{
this.ValidateOptions(options);
this.InitializeOptions(options);
}
public JaegerTraceExporter(IJaegerUdpBatcher jaegerAgentUdpBatcher)
{
this.jaegerAgentUdpBatcher = jaegerAgentUdpBatcher;
}