/** * Returns a new child span if there's a {@link #currentSpan()} or a new trace if there isn't. The * result is the "current span" until {@link ScopedSpan#finish()} is called. * * Here's an example: * <pre>{@code * ScopedSpan span = tracer.startScopedSpan("encode"); * try { * // The span is in "scope" so that downstream code such as loggers can see trace IDs * return encoder.encode(); * } catch (RuntimeException | Error e) { * span.error(e); // Unless you handle exceptions, you might not know the operation failed! * throw e; * } finally { * span.finish(); * } * }</pre> */ public ScopedSpan startScopedSpan(String name) { return startScopedSpanWithParent(name, null); }
@Override public V call() throws Exception { ScopedSpan span = this.tracer.startScopedSpanWithParent(this.spanName, this.parent); try { return this.delegate.call(); } catch (Exception | Error ex) { span.error(ex); throw ex; } finally { span.finish(); } }
@Override public void run() { ScopedSpan span = this.tracer.startScopedSpanWithParent(this.spanName, this.parent); try { this.delegate.run(); } catch (Exception | Error e) { span.error(e); throw e; } finally { span.finish(); } }
void startScopedSpanWithParent(Tracer tracer, TraceContext context) { ScopedSpan span = tracer.startScopedSpanWithParent("encode", context); try { span.tag("foo", "bar"); span.tag("baz", "qux"); } finally { span.finish(); } }
/** * Returns a new child span if there's a {@link #currentSpan()} or a new trace if there isn't. The * result is the "current span" until {@link ScopedSpan#finish()} is called. * * Here's an example: * <pre>{@code * ScopedSpan span = tracer.startScopedSpan("encode"); * try { * // The span is in "scope" so that downstream code such as loggers can see trace IDs * return encoder.encode(); * } catch (RuntimeException | Error e) { * span.error(e); // Unless you handle exceptions, you might not know the operation failed! * throw e; * } finally { * span.finish(); * } * }</pre> */ public ScopedSpan startScopedSpan(String name) { return startScopedSpanWithParent(name, null); }
@Override public V call() throws Exception { ScopedSpan span = this.tracer.startScopedSpanWithParent(this.spanName, this.parent); try { return this.delegate.call(); } catch (Exception | Error ex) { span.error(ex); throw ex; } finally { span.finish(); } }
@Override public void run() { ScopedSpan span = this.tracer.startScopedSpanWithParent(this.spanName, this.parent); try { this.delegate.run(); } catch (Exception | Error e) { span.error(e); throw e; } finally { span.finish(); } }