Answer the question
In order to leave comments, you need to log in
Where to look for TraceId from OpenTelemetry in Jaeger and how to bind microservices?
Hello.
A few questions came up when using OpenTelemetry in .net core applications.
To get traces, I use Jaeger deployed in docker.
Based on the documentation:
https://opentelemetry.io/docs/instrumentation/net/...
https://docs.microsoft.com/en-us/dotnet/core/diagn...
Question one, how to see in Jaeger UI identifier of traces?
Here is an example of my code:
ActivitySource source = new ActivitySource(ServiceName);
Activity span = source.StartActivity(name);
string traceid = span.TraceId.ToHexString();
Activity span = source.CreateActivity(name);
span?.SetParentId(parentTraceId);
span?.Start();
Answer the question
In order to leave comments, you need to log in
In general, not everything is as simple as it seemed.
I had to download the opentelemetry sources https://github.com/open-telemetry/opentelemetry-dotnet and see how the distribution of trace information in the AspNetCore toolkit works.
Saving, transferring and restoring TraceID (and additional information) is called Propogation.
There is a special class in the OpenTelemetry package:
OpenTelemetry.Context.Propagation.Propagators
Which returns these propagators with which to implement and retrieve context information (tracing information).
To embed trace data somewhere, you can use something like this:
//достаем текстового распространителя
var textMapPropagator = Propagators.DefaultTextMapPropagator;
//формируем контекст распространения
var propContext = new OpenTelemetry.Context.Propagation.PropagationContext(Activity.Current.Context, Baggage.Current);
//этот метод вызывает для каждого необходимого значения их контекста распространения ваш же метод, который сохраняет пару ключ-значения для последующего восстановления
textMapPropagator.Inject(propContext,context, (ctx, name, val) =>
{
ctx.Headers.Set(name,val);
});
//извлекаем из среды распространяемую трейс-информацию
var propagator = Propagators.DefaultTextMapPropagator;
PropagationContext propagationContext = propagator.Extract(default, context,
(ctx, name) => { return new string[] { ctx.Headers.Get<string>(name) }; });
if (propagationContext.ActivityContext.IsValid())
{
//формируем новый спан.
newOne = new Activity("Consumer");
newOne.SetParentId(propagationContext.ActivityContext.TraceId,
propagationContext.ActivityContext.SpanId,
propagationContext.ActivityContext.TraceFlags);
newOne.TraceStateString = propagationContext.ActivityContext.TraceState;
newOne.Start();
newOne.IsAllDataRequested = false;
Baggage.Current = propagationContext.Baggage;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question