question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handle exceptions from Tracer.Extract

See original GitHub issue

The Tracer.Extract method today returns an ISpanContext object. This can be null if no TracerId or SpanId were found. There is a possibility that the extract method throws an exception if something goes wrong. If the user forgets to catch this exception the user program will crash.

Compare with the Go version, extract returns a Tuple<context, error>. Here context is always nil if extract was unsuccessful, with a reason in the error property. Error types are ErrSpanContextNotFound, ErrUnsupportedFormat, ErrSpanContextCorrupted, ErrInvalidCarrier or implementation-specific errors.

A suggestion is to mimic the same behavior for C#. If we have

public interface ITracer
{
   ...
   public ExtractResult Extract(format, carrier)
   ...
}

public class ExtractResult
{
   public ISpanContext SpanContext { get; }
   public bool Success { get; }
   public Exception Exception { get;}
}

In this way the user always get a SpanContext back that could be used in Tracer.StartSpan (since null is a valid startSpan parameter). The user also has the possibility to check the error and react on but it is not mandatory. And most important, it will not throw exceptions that the user needs to handle.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dawallincommented, Aug 30, 2016

The TryExtract patter with an out parameter was the original behavior. It has 2 disadvantages. If extract fails, the user can’t extract why. And the out parameter does not work with async/await. I don’t know if we ever need async in extract, but if it is a stream as a carrier then maybe.

I see tracing just as logging. From the Serilog documentation, and I know log4net does the same thing.

Serilog takes the view that, all things considered, logging is a lower priority than other application code and should never avoidably impact the operation of a running application.

Think I’ve seen something about this somewhere around opentracing as well. I prefer that the implementation can do internal logging if something goes wrong but swallows all exceptions. With the result pattern the user can, but are not forced to determine if there was an error. It is then possible for the user to rethrow if he/she likes to.

0reactions
cwe1sscommented, Feb 13, 2018

I’ll close this as the discussion for this has to happen either in opentracing/specification or in opentracing-java.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get exception description and stack trace which caused an ...
traceback.format_exc() uses sys.exc_info() . In Python 2 it would return whatever exception was currently being handled and was buggy, sometimes ...
Read more >
io.opentracing.Tracer.extract java code examples
Best Java code snippets using io.opentracing.Tracer.extract (Showing top 20 results out of 333) · Javadoc. Show more · Popular methods of Tracer ·...
Read more >
Handling Exceptions and Error responses in Java Rest Services
Such a method handles exceptions that occur in all GET/POST/PUT (or any ... Tracing back client errors to the correct Exception and Stack...
Read more >
Errors and Exceptions
To manually record exceptions, we need to get the span from the tracer and then call a function called recordException() or recordError() which...
Read more >
OpenTelemetry exceptions and error handling
Manage exceptions and errors of your OpenTelemetry instrumentation. ... span&.status = OpenTelemetry::Trace::Status.error("Unhandled exception of type: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found