Closed EngRajabi closed 4 years ago
I don't really understand what you mean with "log level". The logs that are part of Span
don't have a log level. Span
itself also has no log level. A Span
can have an error
tag, which is for example set if an exception was thrown. Trace
s itself don't have a notation of log level neither.
There are multiple points where you can decide if a span get's sampled or not:
SpanContext
, when the Sampled
flag is not setISampler
, based on the operation name and trace idIReporter
, based on the whole span dataISender
, based on the whole span dataIt is not possible to only store traces that might contain an error, as spans are reported early. So spans that are part of the trace up until the error would already be stored.
You have the option to filter the traces that are stored for ones that contain at least one span with error
tagged.
As Trace
s are never explicitly finished (only Span
s are), you have no way to find out if there won't be another Span
added at any point containing an error. So there is AFAIK also no way how you could implement it in IReporter
or ISender
by using caches or anything as the Flushing
would have to be guessed.
If it's just to avoid storing data for "good" requests, I fear that's not possible by design. As it's possible to add new Span
s to a trace even after hours, there is no definitive end to a Trace
that could be used to check if the trace was good or not. If you only want to trace the erroneous Span
, writing an IReporter
that checks the tags before calling the real reporter would be your best option. But this would only log the span, not the whole trace.
Feel free to add more information about your use case and we might be able to help you more on how to fulfill this need.
@EngRajabi Were you able to solve your problem?
No I just want the http != 200 requests to be tracked
This should be hard to do apriori, since all Spans that are part of the trace are reported individually. Even before the HTTP Response is created. So you can only clean up after the complete trace is done. There is no notion about when the „complete trace“ is done as OpenTracing is not bound to HTTP or web itself. It would only be possible if you have just one single span for the whole handling without any children or follow-ups. Is this your use-case?
It seems that you are using OpenTracing.Contrib.Netcore. So maybe @cwe1ss knows more about if there are flags or specific ways to achieve this in that library (as this is a standalone project and not part of Jaeger).
Maybe also @yurishkuro has an idea on how to achieve this goal.
In a distributed system, this is only possible with Tail Based Sampling (see https://www.jaegertracing.io/roadmap/)
If you're tracing a single monolith service, than it's possible to sample on errors, Jaeger Go/Node clients partially support it (but not fully, spans that are already finished will still he lost).
how trace with log level like tracing only error. For example, if the level Error was set, only save the erroneous requests