tracer.d.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { Context } from '../context/types';
  2. import { Span } from './span';
  3. import { SpanOptions } from './SpanOptions';
  4. /**
  5. * Tracer provides an interface for creating {@link Span}s.
  6. */
  7. export interface Tracer {
  8. /**
  9. * Starts a new {@link Span}. Start the span without setting it on context.
  10. *
  11. * This method do NOT modify the current Context.
  12. *
  13. * @param name The name of the span
  14. * @param [options] SpanOptions used for span creation
  15. * @param [context] Context to use to extract parent
  16. * @returns Span The newly created span
  17. * @example
  18. * const span = tracer.startSpan('op');
  19. * span.setAttribute('key', 'value');
  20. * span.end();
  21. */
  22. startSpan(name: string, options?: SpanOptions, context?: Context): Span;
  23. /**
  24. * Starts a new {@link Span} and calls the given function passing it the
  25. * created span as first argument.
  26. * Additionally the new span gets set in context and this context is activated
  27. * for the duration of the function call.
  28. *
  29. * @param name The name of the span
  30. * @param [options] SpanOptions used for span creation
  31. * @param [context] Context to use to extract parent
  32. * @param fn function called in the context of the span and receives the newly created span as an argument
  33. * @returns return value of fn
  34. * @example
  35. * const something = tracer.startActiveSpan('op', span => {
  36. * try {
  37. * do some work
  38. * span.setStatus({code: SpanStatusCode.OK});
  39. * return something;
  40. * } catch (err) {
  41. * span.setStatus({
  42. * code: SpanStatusCode.ERROR,
  43. * message: err.message,
  44. * });
  45. * throw err;
  46. * } finally {
  47. * span.end();
  48. * }
  49. * });
  50. *
  51. * @example
  52. * const span = tracer.startActiveSpan('op', span => {
  53. * try {
  54. * do some work
  55. * return span;
  56. * } catch (err) {
  57. * span.setStatus({
  58. * code: SpanStatusCode.ERROR,
  59. * message: err.message,
  60. * });
  61. * throw err;
  62. * }
  63. * });
  64. * do some more work
  65. * span.end();
  66. */
  67. startActiveSpan<F extends (span: Span) => unknown>(name: string, fn: F): ReturnType<F>;
  68. startActiveSpan<F extends (span: Span) => unknown>(name: string, options: SpanOptions, fn: F): ReturnType<F>;
  69. startActiveSpan<F extends (span: Span) => unknown>(name: string, options: SpanOptions, context: Context, fn: F): ReturnType<F>;
  70. }
  71. //# sourceMappingURL=tracer.d.ts.map