SugaredTracer.d.ts 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { SugaredSpanOptions } from './SugaredOptions';
  2. import { Context, Span, Tracer } from '../../';
  3. /**
  4. * return a new SugaredTracer created from the supplied one
  5. * @param tracer
  6. */
  7. export declare function wrapTracer(tracer: Tracer): SugaredTracer;
  8. export declare class SugaredTracer implements Tracer {
  9. private readonly _tracer;
  10. constructor(tracer: Tracer);
  11. startActiveSpan: Tracer['startActiveSpan'];
  12. startSpan: Tracer['startSpan'];
  13. /**
  14. * Starts a new {@link Span} and calls the given function passing it the
  15. * created span as first argument.
  16. * Additionally, the new span gets set in context and this context is activated
  17. * for the duration of the function call.
  18. * The span will be closed after the function has executed.
  19. * If an exception occurs, it is recorded, the status is set to ERROR and the exception is rethrown.
  20. *
  21. * @param name The name of the span
  22. * @param [options] SugaredSpanOptions used for span creation
  23. * @param [context] Context to use to extract parent
  24. * @param fn function called in the context of the span and receives the newly created span as an argument
  25. * @returns return value of fn
  26. * @example
  27. * const something = tracer.withActiveSpan('op', span => {
  28. * // do some work
  29. * });
  30. * @example
  31. * const something = await tracer.withActiveSpan('op', span => {
  32. * // do some async work
  33. * });
  34. */
  35. withActiveSpan<F extends (span: Span) => ReturnType<F>>(name: string, fn: F): ReturnType<F>;
  36. withActiveSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, fn: F): ReturnType<F>;
  37. withActiveSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, context: Context, fn: F): ReturnType<F>;
  38. /**
  39. * Starts a new {@link Span} and ends it after execution of fn without setting it on context.
  40. * The span will be closed after the function has executed.
  41. * If an exception occurs, it is recorded, the status is et to ERROR and rethrown.
  42. *
  43. * This method does NOT modify the current Context.
  44. *
  45. * @param name The name of the span
  46. * @param [options] SugaredSpanOptions used for span creation
  47. * @param [context] Context to use to extract parent
  48. * @param fn function called in the context of the span and receives the newly created span as an argument
  49. * @returns Span The newly created span
  50. * @example
  51. * const something = tracer.withSpan('op', span => {
  52. * // do some work
  53. * });
  54. * @example
  55. * const something = await tracer.withSpan('op', span => {
  56. * // do some async work
  57. * });
  58. */
  59. withSpan<F extends (span: Span) => ReturnType<F>>(name: string, fn: F): ReturnType<F>;
  60. withSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, fn: F): ReturnType<F>;
  61. withSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, context: Context, fn: F): ReturnType<F>;
  62. withSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, context: Context, fn: F): ReturnType<F>;
  63. }
  64. //# sourceMappingURL=SugaredTracer.d.ts.map