我正试图使用Jaeger包从C#应用程序向Jaeger发送跟踪。
在jaeger客户端csharp文档中没有最小的例子,但从我所读到的内容来看,我认为这应该是可行的。
using Jaeger;
using Jaeger.Samplers;
namespace jaegertest
{
class Program
{
static void Main(string[] args)
{
var tracer = new Tracer.Builder("my-service")
.WithSampler(new ConstSampler(true))
.Build();
using (var scope = tracer.BuildSpan("foo").StartActive(true))
{
System.Threading.Thread.Sleep(1000);
}
}
}
}
我运行了jaeger-all-in-one.exe,但当我运行此代码时,没有任何新痕迹的迹象。我尝试过手动配置采样器、发送器、报告器等,但都没有成功。我需要添加什么才能使我的痕迹出现在Jaeger中?
这是我能找到的最简单的工作示例。
using Jaeger;
using Jaeger.Reporters;
using Jaeger.Samplers;
using Jaeger.Senders.Thrift;
namespace jaegertest
{
class Program
{
static void Main(string[] args)
{
var tracer = new Tracer.Builder("my-service")
.WithSampler(new ConstSampler(true))
.WithReporter(new RemoteReporter.Builder()
.WithSender(new UdpSender())
.Build())
.Build();
using (var scope = tracer.BuildSpan("foo").StartActive(true))
{
System.Threading.Thread.Sleep(1000);
}
tracer.Dispose();
}
}
}
下面是一个从配置构建跟踪器的更现实的示例。
using Jaeger;
using Jaeger.Samplers;
using Jaeger.Senders;
using Jaeger.Senders.Thrift;
using Microsoft.Extensions.Logging;
namespace jaegertest
{
class Program
{
static void Main(string[] args)
{
var loggerFactory = new LoggerFactory();
var samplerConfiguration = new Configuration.SamplerConfiguration(loggerFactory)
.WithType(ConstSampler.Type)
.WithParam(1);
var senderResolver = new SenderResolver(loggerFactory)
.RegisterSenderFactory<ThriftSenderFactory>();
var senderConfiguration = new Configuration.SenderConfiguration(loggerFactory)
.WithSenderResolver(senderResolver);
var reporterConfiguration = new Configuration.ReporterConfiguration(loggerFactory)
.WithSender(senderConfiguration)
.WithLogSpans(true);
var tracer = (Tracer)new Configuration("my-service", loggerFactory)
.WithSampler(samplerConfiguration)
.WithReporter(reporterConfiguration)
.GetTracer();
using (var scope = tracer.BuildSpan("foo").StartActive(true))
{
System.Threading.Thread.Sleep(1000);
}
tracer.Dispose();
}
}
}