span.d.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { Exception } from '../common/Exception';
  2. import { TimeInput } from '../common/Time';
  3. import { SpanAttributes, SpanAttributeValue } from './attributes';
  4. import { SpanContext } from './span_context';
  5. import { SpanStatus } from './status';
  6. import { Link } from './link';
  7. /**
  8. * An interface that represents a span. A span represents a single operation
  9. * within a trace. Examples of span might include remote procedure calls or a
  10. * in-process function calls to sub-components. A Trace has a single, top-level
  11. * "root" Span that in turn may have zero or more child Spans, which in turn
  12. * may have children.
  13. *
  14. * Spans are created by the {@link Tracer.startSpan} method.
  15. */
  16. export interface Span {
  17. /**
  18. * Returns the {@link SpanContext} object associated with this Span.
  19. *
  20. * Get an immutable, serializable identifier for this span that can be used
  21. * to create new child spans. Returned SpanContext is usable even after the
  22. * span ends.
  23. *
  24. * @returns the SpanContext object associated with this Span.
  25. */
  26. spanContext(): SpanContext;
  27. /**
  28. * Sets an attribute to the span.
  29. *
  30. * Sets a single Attribute with the key and value passed as arguments.
  31. *
  32. * @param key the key for this attribute.
  33. * @param value the value for this attribute. Setting a value null or
  34. * undefined is invalid and will result in undefined behavior.
  35. */
  36. setAttribute(key: string, value: SpanAttributeValue): this;
  37. /**
  38. * Sets attributes to the span.
  39. *
  40. * @param attributes the attributes that will be added.
  41. * null or undefined attribute values
  42. * are invalid and will result in undefined behavior.
  43. */
  44. setAttributes(attributes: SpanAttributes): this;
  45. /**
  46. * Adds an event to the Span.
  47. *
  48. * @param name the name of the event.
  49. * @param [attributesOrStartTime] the attributes that will be added; these are
  50. * associated with this event. Can be also a start time
  51. * if type is {@type TimeInput} and 3rd param is undefined
  52. * @param [startTime] start time of the event.
  53. */
  54. addEvent(name: string, attributesOrStartTime?: SpanAttributes | TimeInput, startTime?: TimeInput): this;
  55. /**
  56. * Adds a single link to the span.
  57. *
  58. * Links added after the creation will not affect the sampling decision.
  59. * It is preferred span links be added at span creation.
  60. *
  61. * @param link the link to add.
  62. */
  63. addLink(link: Link): this;
  64. /**
  65. * Adds multiple links to the span.
  66. *
  67. * Links added after the creation will not affect the sampling decision.
  68. * It is preferred span links be added at span creation.
  69. *
  70. * @param links the links to add.
  71. */
  72. addLinks(links: Link[]): this;
  73. /**
  74. * Sets a status to the span. If used, this will override the default Span
  75. * status. Default is {@link SpanStatusCode.UNSET}. SetStatus overrides the value
  76. * of previous calls to SetStatus on the Span.
  77. *
  78. * @param status the SpanStatus to set.
  79. */
  80. setStatus(status: SpanStatus): this;
  81. /**
  82. * Updates the Span name.
  83. *
  84. * This will override the name provided via {@link Tracer.startSpan}.
  85. *
  86. * Upon this update, any sampling behavior based on Span name will depend on
  87. * the implementation.
  88. *
  89. * @param name the Span name.
  90. */
  91. updateName(name: string): this;
  92. /**
  93. * Marks the end of Span execution.
  94. *
  95. * Call to End of a Span MUST not have any effects on child spans. Those may
  96. * still be running and can be ended later.
  97. *
  98. * Do not return `this`. The Span generally should not be used after it
  99. * is ended so chaining is not desired in this context.
  100. *
  101. * @param [endTime] the time to set as Span's end time. If not provided,
  102. * use the current time as the span's end time.
  103. */
  104. end(endTime?: TimeInput): void;
  105. /**
  106. * Returns the flag whether this span will be recorded.
  107. *
  108. * @returns true if this Span is active and recording information like events
  109. * with the `AddEvent` operation and attributes using `setAttributes`.
  110. */
  111. isRecording(): boolean;
  112. /**
  113. * Sets exception as a span event
  114. * @param exception the exception the only accepted values are string or Error
  115. * @param [time] the time to set as Span's event time. If not provided,
  116. * use the current time.
  117. */
  118. recordException(exception: Exception, time?: TimeInput): void;
  119. }
  120. //# sourceMappingURL=span.d.ts.map