@opentelemetry/api 1.6.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/build/esm/experimental/index.d.ts +3 -0
  2. package/build/esm/experimental/index.js +17 -0
  3. package/build/esm/experimental/index.js.map +1 -0
  4. package/build/esm/experimental/trace/SugaredOptions.d.ts +13 -0
  5. package/build/esm/experimental/trace/SugaredOptions.js +17 -0
  6. package/build/esm/experimental/trace/SugaredOptions.js.map +1 -0
  7. package/build/esm/experimental/trace/SugaredTracer.d.ts +64 -0
  8. package/build/esm/experimental/trace/SugaredTracer.js +92 -0
  9. package/build/esm/experimental/trace/SugaredTracer.js.map +1 -0
  10. package/build/esm/index.d.ts +1 -1
  11. package/build/esm/index.js.map +1 -1
  12. package/build/esm/metrics/Metric.d.ts +16 -0
  13. package/build/esm/metrics/Metric.js.map +1 -1
  14. package/build/esm/version.d.ts +1 -1
  15. package/build/esm/version.js +1 -1
  16. package/build/esm/version.js.map +1 -1
  17. package/build/esnext/api/context.d.ts +41 -0
  18. package/build/esnext/api/context.js +77 -0
  19. package/build/esnext/api/context.js.map +1 -0
  20. package/build/esnext/api/diag.d.ts +30 -0
  21. package/build/esnext/api/diag.js +89 -0
  22. package/build/esnext/api/diag.js.map +1 -0
  23. package/build/esnext/api/metrics.d.ts +28 -0
  24. package/build/esnext/api/metrics.js +57 -0
  25. package/build/esnext/api/metrics.js.map +1 -0
  26. package/build/esnext/api/propagation.d.ts +49 -0
  27. package/build/esnext/api/propagation.js +85 -0
  28. package/build/esnext/api/propagation.js.map +1 -0
  29. package/build/esnext/api/trace.d.ts +40 -0
  30. package/build/esnext/api/trace.js +75 -0
  31. package/build/esnext/api/trace.js.map +1 -0
  32. package/build/esnext/baggage/context-helpers.d.ts +29 -0
  33. package/build/esnext/baggage/context-helpers.js +56 -0
  34. package/build/esnext/baggage/context-helpers.js.map +1 -0
  35. package/build/esnext/baggage/internal/baggage-impl.d.ts +12 -0
  36. package/build/esnext/baggage/internal/baggage-impl.js +51 -0
  37. package/build/esnext/baggage/internal/baggage-impl.js.map +1 -0
  38. package/build/esnext/baggage/internal/symbol.d.ts +5 -0
  39. package/build/esnext/baggage/internal/symbol.js +20 -0
  40. package/build/esnext/baggage/internal/symbol.js.map +1 -0
  41. package/build/esnext/baggage/types.d.ts +60 -0
  42. package/build/esnext/baggage/types.js +17 -0
  43. package/build/esnext/baggage/types.js.map +1 -0
  44. package/build/esnext/baggage/utils.d.ts +15 -0
  45. package/build/esnext/baggage/utils.js +46 -0
  46. package/build/esnext/baggage/utils.js.map +1 -0
  47. package/build/esnext/common/Attributes.d.ts +15 -0
  48. package/build/esnext/common/Attributes.js +17 -0
  49. package/build/esnext/common/Attributes.js.map +1 -0
  50. package/build/esnext/common/Exception.d.ts +26 -0
  51. package/build/esnext/common/Exception.js +17 -0
  52. package/build/esnext/common/Exception.js.map +1 -0
  53. package/build/esnext/common/Time.d.ts +20 -0
  54. package/build/esnext/common/Time.js +2 -0
  55. package/build/esnext/common/Time.js.map +1 -0
  56. package/build/esnext/context/NoopContextManager.d.ts +9 -0
  57. package/build/esnext/context/NoopContextManager.js +34 -0
  58. package/build/esnext/context/NoopContextManager.js.map +1 -0
  59. package/build/esnext/context/context.d.ts +6 -0
  60. package/build/esnext/context/context.js +51 -0
  61. package/build/esnext/context/context.js.map +1 -0
  62. package/build/esnext/context/types.d.ts +52 -0
  63. package/build/esnext/context/types.js +17 -0
  64. package/build/esnext/context/types.js.map +1 -0
  65. package/build/esnext/context-api.d.ts +4 -0
  66. package/build/esnext/context-api.js +21 -0
  67. package/build/esnext/context-api.js.map +1 -0
  68. package/build/esnext/diag/ComponentLogger.d.ts +20 -0
  69. package/build/esnext/diag/ComponentLogger.js +55 -0
  70. package/build/esnext/diag/ComponentLogger.js.map +1 -0
  71. package/build/esnext/diag/consoleLogger.d.ts +38 -0
  72. package/build/esnext/diag/consoleLogger.js +53 -0
  73. package/build/esnext/diag/consoleLogger.js.map +1 -0
  74. package/build/esnext/diag/internal/logLevelLogger.d.ts +3 -0
  75. package/build/esnext/diag/internal/logLevelLogger.js +41 -0
  76. package/build/esnext/diag/internal/logLevelLogger.js.map +1 -0
  77. package/build/esnext/diag/internal/noopLogger.d.ts +8 -0
  78. package/build/esnext/diag/internal/noopLogger.js +31 -0
  79. package/build/esnext/diag/internal/noopLogger.js.map +1 -0
  80. package/build/esnext/diag/types.d.ts +100 -0
  81. package/build/esnext/diag/types.js +41 -0
  82. package/build/esnext/diag/types.js.map +1 -0
  83. package/build/esnext/diag-api.d.ts +9 -0
  84. package/build/esnext/diag-api.js +26 -0
  85. package/build/esnext/diag-api.js.map +1 -0
  86. package/build/esnext/experimental/index.d.ts +3 -0
  87. package/build/esnext/experimental/index.js +17 -0
  88. package/build/esnext/experimental/index.js.map +1 -0
  89. package/build/esnext/experimental/trace/SugaredOptions.d.ts +13 -0
  90. package/build/esnext/experimental/trace/SugaredOptions.js +17 -0
  91. package/build/esnext/experimental/trace/SugaredOptions.js.map +1 -0
  92. package/build/esnext/experimental/trace/SugaredTracer.d.ts +64 -0
  93. package/build/esnext/experimental/trace/SugaredTracer.js +88 -0
  94. package/build/esnext/experimental/trace/SugaredTracer.js.map +1 -0
  95. package/build/esnext/index.d.ts +54 -0
  96. package/build/esnext/index.js +53 -0
  97. package/build/esnext/index.js.map +1 -0
  98. package/build/esnext/internal/global-utils.d.ts +18 -0
  99. package/build/esnext/internal/global-utils.js +58 -0
  100. package/build/esnext/internal/global-utils.js.map +1 -0
  101. package/build/esnext/internal/semver.d.ts +34 -0
  102. package/build/esnext/internal/semver.js +118 -0
  103. package/build/esnext/internal/semver.js.map +1 -0
  104. package/build/esnext/metrics/Meter.d.ts +104 -0
  105. package/build/esnext/metrics/Meter.js +17 -0
  106. package/build/esnext/metrics/Meter.js.map +1 -0
  107. package/build/esnext/metrics/MeterProvider.d.ts +17 -0
  108. package/build/esnext/metrics/MeterProvider.js +17 -0
  109. package/build/esnext/metrics/MeterProvider.js.map +1 -0
  110. package/build/esnext/metrics/Metric.d.ts +109 -0
  111. package/build/esnext/metrics/Metric.js +22 -0
  112. package/build/esnext/metrics/Metric.js.map +1 -0
  113. package/build/esnext/metrics/NoopMeter.d.ts +74 -0
  114. package/build/esnext/metrics/NoopMeter.js +103 -0
  115. package/build/esnext/metrics/NoopMeter.js.map +1 -0
  116. package/build/esnext/metrics/NoopMeterProvider.d.ts +11 -0
  117. package/build/esnext/metrics/NoopMeterProvider.js +27 -0
  118. package/build/esnext/metrics/NoopMeterProvider.js.map +1 -0
  119. package/build/esnext/metrics/ObservableResult.d.ts +31 -0
  120. package/build/esnext/metrics/ObservableResult.js +17 -0
  121. package/build/esnext/metrics/ObservableResult.js.map +1 -0
  122. package/build/esnext/metrics-api.d.ts +4 -0
  123. package/build/esnext/metrics-api.js +21 -0
  124. package/build/esnext/metrics-api.js.map +1 -0
  125. package/build/esnext/platform/browser/globalThis.d.ts +10 -0
  126. package/build/esnext/platform/browser/globalThis.js +35 -0
  127. package/build/esnext/platform/browser/globalThis.js.map +1 -0
  128. package/build/esnext/platform/browser/index.d.ts +2 -0
  129. package/build/esnext/platform/browser/index.js +17 -0
  130. package/build/esnext/platform/browser/index.js.map +1 -0
  131. package/build/esnext/platform/index.d.ts +2 -0
  132. package/build/esnext/platform/index.js +17 -0
  133. package/build/esnext/platform/index.js.map +1 -0
  134. package/build/esnext/platform/node/globalThis.d.ts +3 -0
  135. package/build/esnext/platform/node/globalThis.js +19 -0
  136. package/build/esnext/platform/node/globalThis.js.map +1 -0
  137. package/build/esnext/platform/node/index.d.ts +2 -0
  138. package/build/esnext/platform/node/index.js +17 -0
  139. package/build/esnext/platform/node/index.js.map +1 -0
  140. package/build/esnext/propagation/NoopTextMapPropagator.d.ts +13 -0
  141. package/build/esnext/propagation/NoopTextMapPropagator.js +30 -0
  142. package/build/esnext/propagation/NoopTextMapPropagator.js.map +1 -0
  143. package/build/esnext/propagation/TextMapPropagator.d.ts +84 -0
  144. package/build/esnext/propagation/TextMapPropagator.js +38 -0
  145. package/build/esnext/propagation/TextMapPropagator.js.map +1 -0
  146. package/build/esnext/propagation-api.d.ts +4 -0
  147. package/build/esnext/propagation-api.js +21 -0
  148. package/build/esnext/propagation-api.js.map +1 -0
  149. package/build/esnext/trace/NonRecordingSpan.d.ts +25 -0
  150. package/build/esnext/trace/NonRecordingSpan.js +59 -0
  151. package/build/esnext/trace/NonRecordingSpan.js.map +1 -0
  152. package/build/esnext/trace/NoopTracer.d.ts +14 -0
  153. package/build/esnext/trace/NoopTracer.js +71 -0
  154. package/build/esnext/trace/NoopTracer.js.map +1 -0
  155. package/build/esnext/trace/NoopTracerProvider.d.ts +13 -0
  156. package/build/esnext/trace/NoopTracerProvider.js +28 -0
  157. package/build/esnext/trace/NoopTracerProvider.js.map +1 -0
  158. package/build/esnext/trace/ProxyTracer.d.ts +27 -0
  159. package/build/esnext/trace/ProxyTracer.js +51 -0
  160. package/build/esnext/trace/ProxyTracer.js.map +1 -0
  161. package/build/esnext/trace/ProxyTracerProvider.d.ts +25 -0
  162. package/build/esnext/trace/ProxyTracerProvider.js +50 -0
  163. package/build/esnext/trace/ProxyTracerProvider.js.map +1 -0
  164. package/build/esnext/trace/Sampler.d.ts +31 -0
  165. package/build/esnext/trace/Sampler.js +17 -0
  166. package/build/esnext/trace/Sampler.js.map +1 -0
  167. package/build/esnext/trace/SamplingResult.d.ts +49 -0
  168. package/build/esnext/trace/SamplingResult.js +39 -0
  169. package/build/esnext/trace/SamplingResult.js.map +1 -0
  170. package/build/esnext/trace/SpanOptions.d.ts +23 -0
  171. package/build/esnext/trace/SpanOptions.js +17 -0
  172. package/build/esnext/trace/SpanOptions.js.map +1 -0
  173. package/build/esnext/trace/attributes.d.ts +10 -0
  174. package/build/esnext/trace/attributes.js +17 -0
  175. package/build/esnext/trace/attributes.js.map +1 -0
  176. package/build/esnext/trace/context-utils.d.ts +41 -0
  177. package/build/esnext/trace/context-utils.js +73 -0
  178. package/build/esnext/trace/context-utils.js.map +1 -0
  179. package/build/esnext/trace/internal/tracestate-impl.d.ts +22 -0
  180. package/build/esnext/trace/internal/tracestate-impl.js +99 -0
  181. package/build/esnext/trace/internal/tracestate-impl.js.map +1 -0
  182. package/build/esnext/trace/internal/tracestate-validators.d.ts +15 -0
  183. package/build/esnext/trace/internal/tracestate-validators.js +41 -0
  184. package/build/esnext/trace/internal/tracestate-validators.js.map +1 -0
  185. package/build/esnext/trace/internal/utils.d.ts +3 -0
  186. package/build/esnext/trace/internal/utils.js +20 -0
  187. package/build/esnext/trace/internal/utils.js.map +1 -0
  188. package/build/esnext/trace/invalid-span-constants.d.ts +5 -0
  189. package/build/esnext/trace/invalid-span-constants.js +24 -0
  190. package/build/esnext/trace/invalid-span-constants.js.map +1 -0
  191. package/build/esnext/trace/link.d.ts +26 -0
  192. package/build/esnext/trace/link.js +17 -0
  193. package/build/esnext/trace/link.js.map +1 -0
  194. package/build/esnext/trace/span.d.ts +101 -0
  195. package/build/esnext/trace/span.js +17 -0
  196. package/build/esnext/trace/span.js.map +1 -0
  197. package/build/esnext/trace/span_context.d.ts +53 -0
  198. package/build/esnext/trace/span_context.js +17 -0
  199. package/build/esnext/trace/span_context.js.map +1 -0
  200. package/build/esnext/trace/span_kind.d.ts +27 -0
  201. package/build/esnext/trace/span_kind.js +43 -0
  202. package/build/esnext/trace/span_kind.js.map +1 -0
  203. package/build/esnext/trace/spancontext-utils.d.ts +17 -0
  204. package/build/esnext/trace/spancontext-utils.js +42 -0
  205. package/build/esnext/trace/spancontext-utils.js.map +1 -0
  206. package/build/esnext/trace/status.d.ts +25 -0
  207. package/build/esnext/trace/status.js +20 -0
  208. package/build/esnext/trace/status.js.map +1 -0
  209. package/build/esnext/trace/trace_flags.d.ts +7 -0
  210. package/build/esnext/trace/trace_flags.js +23 -0
  211. package/build/esnext/trace/trace_flags.js.map +1 -0
  212. package/build/esnext/trace/trace_state.d.ts +38 -0
  213. package/build/esnext/trace/trace_state.js +17 -0
  214. package/build/esnext/trace/trace_state.js.map +1 -0
  215. package/build/esnext/trace/tracer.d.ts +71 -0
  216. package/build/esnext/trace/tracer.js +17 -0
  217. package/build/esnext/trace/tracer.js.map +1 -0
  218. package/build/esnext/trace/tracer_options.d.ts +10 -0
  219. package/build/esnext/trace/tracer_options.js +17 -0
  220. package/build/esnext/trace/tracer_options.js.map +1 -0
  221. package/build/esnext/trace/tracer_provider.d.ts +21 -0
  222. package/build/esnext/trace/tracer_provider.js +17 -0
  223. package/build/esnext/trace/tracer_provider.js.map +1 -0
  224. package/build/esnext/trace-api.d.ts +4 -0
  225. package/build/esnext/trace-api.js +21 -0
  226. package/build/esnext/trace-api.js.map +1 -0
  227. package/build/esnext/version.d.ts +2 -0
  228. package/build/esnext/version.js +18 -0
  229. package/build/esnext/version.js.map +1 -0
  230. package/build/src/experimental/index.d.ts +3 -0
  231. package/build/src/experimental/index.js +22 -0
  232. package/build/src/experimental/index.js.map +1 -0
  233. package/build/src/experimental/trace/SugaredOptions.d.ts +13 -0
  234. package/build/src/experimental/trace/SugaredOptions.js +18 -0
  235. package/build/src/experimental/trace/SugaredOptions.js.map +1 -0
  236. package/build/src/experimental/trace/SugaredTracer.d.ts +64 -0
  237. package/build/src/experimental/trace/SugaredTracer.js +93 -0
  238. package/build/src/experimental/trace/SugaredTracer.js.map +1 -0
  239. package/build/src/index.d.ts +1 -1
  240. package/build/src/index.js.map +1 -1
  241. package/build/src/metrics/Metric.d.ts +16 -0
  242. package/build/src/metrics/Metric.js.map +1 -1
  243. package/build/src/version.d.ts +1 -1
  244. package/build/src/version.js +1 -1
  245. package/build/src/version.js.map +1 -1
  246. package/package.json +26 -7
@@ -0,0 +1,3 @@
1
+ export { wrapTracer, SugaredTracer } from './trace/SugaredTracer';
2
+ export { SugaredSpanOptions } from './trace/SugaredOptions';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export { wrapTracer, SugaredTracer } from './trace/SugaredTracer';
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/experimental/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nexport { wrapTracer, SugaredTracer } from './trace/SugaredTracer';\nexport { SugaredSpanOptions } from './trace/SugaredOptions';\n"]}
@@ -0,0 +1,13 @@
1
+ import { Span, SpanOptions } from '../../';
2
+ /**
3
+ * Options needed for span creation
4
+ */
5
+ export interface SugaredSpanOptions extends SpanOptions {
6
+ /**
7
+ * function to overwrite default exception behavior to record the exception. No exceptions should be thrown in the function.
8
+ * @param e Error which triggered this exception
9
+ * @param span current span from context
10
+ */
11
+ onException?: (e: Error, span: Span) => void;
12
+ }
13
+ //# sourceMappingURL=SugaredOptions.d.ts.map
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};
17
+ //# sourceMappingURL=SugaredOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SugaredOptions.js","sourceRoot":"","sources":["../../../../src/experimental/trace/SugaredOptions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Span, SpanOptions } from '../../';\n\n/**\n * Options needed for span creation\n */\nexport interface SugaredSpanOptions extends SpanOptions {\n /**\n * function to overwrite default exception behavior to record the exception. No exceptions should be thrown in the function.\n * @param e Error which triggered this exception\n * @param span current span from context\n */\n onException?: (e: Error, span: Span) => void;\n}\n"]}
@@ -0,0 +1,64 @@
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
@@ -0,0 +1,92 @@
1
+ import { context, SpanStatusCode } from '../../';
2
+ var defaultOnException = function (e, span) {
3
+ span.recordException(e);
4
+ span.setStatus({
5
+ code: SpanStatusCode.ERROR,
6
+ });
7
+ };
8
+ /**
9
+ * return a new SugaredTracer created from the supplied one
10
+ * @param tracer
11
+ */
12
+ export function wrapTracer(tracer) {
13
+ return new SugaredTracer(tracer);
14
+ }
15
+ var SugaredTracer = /** @class */ (function () {
16
+ function SugaredTracer(tracer) {
17
+ this._tracer = tracer;
18
+ this.startSpan = tracer.startSpan.bind(this._tracer);
19
+ this.startActiveSpan = tracer.startActiveSpan.bind(this._tracer);
20
+ }
21
+ SugaredTracer.prototype.withActiveSpan = function (name, arg2, arg3, arg4) {
22
+ var _a = massageParams(arg2, arg3, arg4), opts = _a.opts, ctx = _a.ctx, fn = _a.fn;
23
+ return this._tracer.startActiveSpan(name, opts, ctx, function (span) {
24
+ return handleFn(span, opts, fn);
25
+ });
26
+ };
27
+ SugaredTracer.prototype.withSpan = function (name, arg2, arg3, arg4) {
28
+ var _a = massageParams(arg2, arg3, arg4), opts = _a.opts, ctx = _a.ctx, fn = _a.fn;
29
+ var span = this._tracer.startSpan(name, opts, ctx);
30
+ return handleFn(span, opts, fn);
31
+ };
32
+ return SugaredTracer;
33
+ }());
34
+ export { SugaredTracer };
35
+ /**
36
+ * Massages parameters of withSpan and withActiveSpan to allow signature overwrites
37
+ * @param arg
38
+ * @param arg2
39
+ * @param arg3
40
+ */
41
+ function massageParams(arg, arg2, arg3) {
42
+ var opts;
43
+ var ctx;
44
+ var fn;
45
+ if (!arg2 && !arg3) {
46
+ fn = arg;
47
+ }
48
+ else if (!arg3) {
49
+ opts = arg;
50
+ fn = arg2;
51
+ }
52
+ else {
53
+ opts = arg;
54
+ ctx = arg2;
55
+ fn = arg3;
56
+ }
57
+ opts = opts !== null && opts !== void 0 ? opts : {};
58
+ ctx = ctx !== null && ctx !== void 0 ? ctx : context.active();
59
+ return { opts: opts, ctx: ctx, fn: fn };
60
+ }
61
+ /**
62
+ * Executes fn, returns results and runs onException in the case of exception to allow overwriting of error handling
63
+ * @param span
64
+ * @param opts
65
+ * @param fn
66
+ */
67
+ function handleFn(span, opts, fn) {
68
+ var _a;
69
+ var onException = (_a = opts.onException) !== null && _a !== void 0 ? _a : defaultOnException;
70
+ var errorHandler = function (e) {
71
+ onException(e, span);
72
+ span.end();
73
+ throw e;
74
+ };
75
+ try {
76
+ var ret = fn(span);
77
+ // if fn is an async function, attach a recordException and spanEnd callback to the promise
78
+ if (typeof (ret === null || ret === void 0 ? void 0 : ret.then) === 'function') {
79
+ return ret.then(function (val) {
80
+ span.end();
81
+ return val;
82
+ }, errorHandler);
83
+ }
84
+ span.end();
85
+ return ret;
86
+ }
87
+ catch (e) {
88
+ // add throw to signal the compiler that this will throw in the inner scope
89
+ throw errorHandler(e);
90
+ }
91
+ }
92
+ //# sourceMappingURL=SugaredTracer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SugaredTracer.js","sourceRoot":"","sources":["../../../../src/experimental/trace/SugaredTracer.ts"],"names":[],"mappings":"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","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { SugaredSpanOptions } from './SugaredOptions';\nimport { context, Context, Span, SpanStatusCode, Tracer } from '../../';\n\nconst defaultOnException = (e: Error, span: Span) => {\n span.recordException(e);\n span.setStatus({\n code: SpanStatusCode.ERROR,\n });\n};\n\n/**\n * return a new SugaredTracer created from the supplied one\n * @param tracer\n */\nexport function wrapTracer(tracer: Tracer): SugaredTracer {\n return new SugaredTracer(tracer);\n}\n\nexport class SugaredTracer implements Tracer {\n private readonly _tracer: Tracer;\n\n constructor(tracer: Tracer) {\n this._tracer = tracer;\n this.startSpan = tracer.startSpan.bind(this._tracer);\n this.startActiveSpan = tracer.startActiveSpan.bind(this._tracer);\n }\n\n startActiveSpan: Tracer['startActiveSpan'];\n startSpan: Tracer['startSpan'];\n\n /**\n * Starts a new {@link Span} and calls the given function passing it the\n * created span as first argument.\n * Additionally, the new span gets set in context and this context is activated\n * for the duration of the function call.\n * The span will be closed after the function has executed.\n * If an exception occurs, it is recorded, the status is set to ERROR and the exception is rethrown.\n *\n * @param name The name of the span\n * @param [options] SugaredSpanOptions used for span creation\n * @param [context] Context to use to extract parent\n * @param fn function called in the context of the span and receives the newly created span as an argument\n * @returns return value of fn\n * @example\n * const something = tracer.withActiveSpan('op', span => {\n * // do some work\n * });\n * @example\n * const something = await tracer.withActiveSpan('op', span => {\n * // do some async work\n * });\n */\n withActiveSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n fn: F\n ): ReturnType<F>;\n withActiveSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n options: SugaredSpanOptions,\n fn: F\n ): ReturnType<F>;\n withActiveSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n options: SugaredSpanOptions,\n context: Context,\n fn: F\n ): ReturnType<F>;\n withActiveSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n arg2: F | SugaredSpanOptions,\n arg3?: F | Context,\n arg4?: F\n ): ReturnType<F> {\n const { opts, ctx, fn } = massageParams(arg2, arg3, arg4);\n\n return this._tracer.startActiveSpan(name, opts, ctx, (span: Span) =>\n handleFn(span, opts, fn)\n ) as ReturnType<F>;\n }\n\n /**\n * Starts a new {@link Span} and ends it after execution of fn without setting it on context.\n * The span will be closed after the function has executed.\n * If an exception occurs, it is recorded, the status is et to ERROR and rethrown.\n *\n * This method does NOT modify the current Context.\n *\n * @param name The name of the span\n * @param [options] SugaredSpanOptions used for span creation\n * @param [context] Context to use to extract parent\n * @param fn function called in the context of the span and receives the newly created span as an argument\n * @returns Span The newly created span\n * @example\n * const something = tracer.withSpan('op', span => {\n * // do some work\n * });\n * @example\n * const something = await tracer.withSpan('op', span => {\n * // do some async work\n * });\n */\n withSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n fn: F\n ): ReturnType<F>;\n withSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n options: SugaredSpanOptions,\n fn: F\n ): ReturnType<F>;\n withSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n options: SugaredSpanOptions,\n context: Context,\n fn: F\n ): ReturnType<F>;\n withSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n options: SugaredSpanOptions,\n context: Context,\n fn: F\n ): ReturnType<F>;\n withSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n arg2: SugaredSpanOptions | F,\n arg3?: Context | F,\n arg4?: F\n ): ReturnType<F> {\n const { opts, ctx, fn } = massageParams(arg2, arg3, arg4);\n\n const span = this._tracer.startSpan(name, opts, ctx);\n return handleFn(span, opts, fn) as ReturnType<F>;\n }\n}\n\n/**\n * Massages parameters of withSpan and withActiveSpan to allow signature overwrites\n * @param arg\n * @param arg2\n * @param arg3\n */\nfunction massageParams<F extends (span: Span) => ReturnType<F>>(\n arg: F | SugaredSpanOptions,\n arg2?: F | Context,\n arg3?: F\n) {\n let opts: SugaredSpanOptions | undefined;\n let ctx: Context | undefined;\n let fn: F;\n\n if (!arg2 && !arg3) {\n fn = arg as F;\n } else if (!arg3) {\n opts = arg as SugaredSpanOptions;\n fn = arg2 as F;\n } else {\n opts = arg as SugaredSpanOptions;\n ctx = arg2 as Context;\n fn = arg3 as F;\n }\n opts = opts ?? {};\n ctx = ctx ?? context.active();\n\n return { opts, ctx, fn };\n}\n\n/**\n * Executes fn, returns results and runs onException in the case of exception to allow overwriting of error handling\n * @param span\n * @param opts\n * @param fn\n */\nfunction handleFn<F extends (span: Span) => ReturnType<F>>(\n span: Span,\n opts: SugaredSpanOptions,\n fn: F\n): ReturnType<F> {\n const onException = opts.onException ?? defaultOnException;\n const errorHandler = (e: Error) => {\n onException(e, span);\n span.end();\n throw e;\n };\n\n try {\n const ret = fn(span) as Promise<ReturnType<F>>;\n // if fn is an async function, attach a recordException and spanEnd callback to the promise\n if (typeof ret?.then === 'function') {\n return ret.then(val => {\n span.end();\n return val;\n }, errorHandler) as ReturnType<F>;\n }\n span.end();\n return ret as ReturnType<F>;\n } catch (e) {\n // add throw to signal the compiler that this will throw in the inner scope\n throw errorHandler(e);\n }\n}\n"]}
@@ -12,7 +12,7 @@ export type { DiagAPI } from './api/diag';
12
12
  export { createNoopMeter } from './metrics/NoopMeter';
13
13
  export { MeterOptions, Meter } from './metrics/Meter';
14
14
  export { MeterProvider } from './metrics/MeterProvider';
15
- export { ValueType, Counter, Histogram, MetricOptions, Observable, ObservableCounter, ObservableGauge, ObservableUpDownCounter, UpDownCounter, BatchObservableCallback, MetricAttributes, MetricAttributeValue, ObservableCallback, } from './metrics/Metric';
15
+ export { ValueType, Counter, Histogram, MetricOptions, Observable, ObservableCounter, ObservableGauge, ObservableUpDownCounter, UpDownCounter, BatchObservableCallback, MetricAdvice, MetricAttributes, MetricAttributeValue, ObservableCallback, } from './metrics/Metric';
16
16
  export { BatchObservableResult, ObservableResult, } from './metrics/ObservableResult';
17
17
  export type { MetricsAPI } from './api/metrics';
18
18
  export { TextMapPropagator, TextMapSetter, TextMapGetter, defaultTextMapGetter, defaultTextMapSetter, } from './propagation/TextMapPropagator';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,8BAA8B,EAAE,MAAM,iBAAiB,CAAC;AAKjE,eAAe;AACf,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAInE,YAAY;AACZ,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAGL,YAAY,GAGb,MAAM,cAAc,CAAC;AAGtB,eAAe;AACf,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD,OAAO,EACL,SAAS,GAaV,MAAM,kBAAkB,CAAC;AAO1B,mBAAmB;AACnB,OAAO,EAIL,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,iCAAiC,CAAC;AAMzC,OAAO,EAAE,WAAW,EAAmB,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,OAAO,EAAE,gBAAgB,EAAkB,MAAM,wBAAwB,CAAC;AAE1E,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAG7C,OAAO,EAAc,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAI1D,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,aAAa,GACd,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,cAAc,EACd,eAAe,EACf,oBAAoB,GACrB,MAAM,gCAAgC,CAAC;AAGxC,sEAAsE;AACtE,qCAAqC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,gBAAgB;AAChB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;AACtD,kBAAkB;AAClB,eAAe;IACb,OAAO,SAAA;IACP,IAAI,MAAA;IACJ,OAAO,SAAA;IACP,WAAW,aAAA;IACX,KAAK,OAAA;CACN,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { BaggageEntry, BaggageEntryMetadata, Baggage } from './baggage/types';\nexport { baggageEntryMetadataFromString } from './baggage/utils';\nexport { Exception } from './common/Exception';\nexport { HrTime, TimeInput } from './common/Time';\nexport { Attributes, AttributeValue } from './common/Attributes';\n\n// Context APIs\nexport { createContextKey, ROOT_CONTEXT } from './context/context';\nexport { Context, ContextManager } from './context/types';\nexport type { ContextAPI } from './api/context';\n\n// Diag APIs\nexport { DiagConsoleLogger } from './diag/consoleLogger';\nexport {\n DiagLogFunction,\n DiagLogger,\n DiagLogLevel,\n ComponentLoggerOptions,\n DiagLoggerOptions,\n} from './diag/types';\nexport type { DiagAPI } from './api/diag';\n\n// Metrics APIs\nexport { createNoopMeter } from './metrics/NoopMeter';\nexport { MeterOptions, Meter } from './metrics/Meter';\nexport { MeterProvider } from './metrics/MeterProvider';\nexport {\n ValueType,\n Counter,\n Histogram,\n MetricOptions,\n Observable,\n ObservableCounter,\n ObservableGauge,\n ObservableUpDownCounter,\n UpDownCounter,\n BatchObservableCallback,\n MetricAttributes,\n MetricAttributeValue,\n ObservableCallback,\n} from './metrics/Metric';\nexport {\n BatchObservableResult,\n ObservableResult,\n} from './metrics/ObservableResult';\nexport type { MetricsAPI } from './api/metrics';\n\n// Propagation APIs\nexport {\n TextMapPropagator,\n TextMapSetter,\n TextMapGetter,\n defaultTextMapGetter,\n defaultTextMapSetter,\n} from './propagation/TextMapPropagator';\nexport type { PropagationAPI } from './api/propagation';\n\n// Trace APIs\nexport { SpanAttributes, SpanAttributeValue } from './trace/attributes';\nexport { Link } from './trace/link';\nexport { ProxyTracer, TracerDelegator } from './trace/ProxyTracer';\nexport { ProxyTracerProvider } from './trace/ProxyTracerProvider';\nexport { Sampler } from './trace/Sampler';\nexport { SamplingDecision, SamplingResult } from './trace/SamplingResult';\nexport { SpanContext } from './trace/span_context';\nexport { SpanKind } from './trace/span_kind';\nexport { Span } from './trace/span';\nexport { SpanOptions } from './trace/SpanOptions';\nexport { SpanStatus, SpanStatusCode } from './trace/status';\nexport { TraceFlags } from './trace/trace_flags';\nexport { TraceState } from './trace/trace_state';\nexport { createTraceState } from './trace/internal/utils';\nexport { TracerProvider } from './trace/tracer_provider';\nexport { Tracer } from './trace/tracer';\nexport { TracerOptions } from './trace/tracer_options';\nexport {\n isSpanContextValid,\n isValidTraceId,\n isValidSpanId,\n} from './trace/spancontext-utils';\nexport {\n INVALID_SPANID,\n INVALID_TRACEID,\n INVALID_SPAN_CONTEXT,\n} from './trace/invalid-span-constants';\nexport type { TraceAPI } from './api/trace';\n\n// Split module-level variable definition into separate files to allow\n// tree-shaking on each api instance.\nimport { context } from './context-api';\nimport { diag } from './diag-api';\nimport { metrics } from './metrics-api';\nimport { propagation } from './propagation-api';\nimport { trace } from './trace-api';\n\n// Named export.\nexport { context, diag, metrics, propagation, trace };\n// Default export.\nexport default {\n context,\n diag,\n metrics,\n propagation,\n trace,\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,8BAA8B,EAAE,MAAM,iBAAiB,CAAC;AAKjE,eAAe;AACf,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAInE,YAAY;AACZ,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAGL,YAAY,GAGb,MAAM,cAAc,CAAC;AAGtB,eAAe;AACf,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD,OAAO,EACL,SAAS,GAcV,MAAM,kBAAkB,CAAC;AAO1B,mBAAmB;AACnB,OAAO,EAIL,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,iCAAiC,CAAC;AAMzC,OAAO,EAAE,WAAW,EAAmB,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,OAAO,EAAE,gBAAgB,EAAkB,MAAM,wBAAwB,CAAC;AAE1E,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAG7C,OAAO,EAAc,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAI1D,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,aAAa,GACd,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,cAAc,EACd,eAAe,EACf,oBAAoB,GACrB,MAAM,gCAAgC,CAAC;AAGxC,sEAAsE;AACtE,qCAAqC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,gBAAgB;AAChB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;AACtD,kBAAkB;AAClB,eAAe;IACb,OAAO,SAAA;IACP,IAAI,MAAA;IACJ,OAAO,SAAA;IACP,WAAW,aAAA;IACX,KAAK,OAAA;CACN,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { BaggageEntry, BaggageEntryMetadata, Baggage } from './baggage/types';\nexport { baggageEntryMetadataFromString } from './baggage/utils';\nexport { Exception } from './common/Exception';\nexport { HrTime, TimeInput } from './common/Time';\nexport { Attributes, AttributeValue } from './common/Attributes';\n\n// Context APIs\nexport { createContextKey, ROOT_CONTEXT } from './context/context';\nexport { Context, ContextManager } from './context/types';\nexport type { ContextAPI } from './api/context';\n\n// Diag APIs\nexport { DiagConsoleLogger } from './diag/consoleLogger';\nexport {\n DiagLogFunction,\n DiagLogger,\n DiagLogLevel,\n ComponentLoggerOptions,\n DiagLoggerOptions,\n} from './diag/types';\nexport type { DiagAPI } from './api/diag';\n\n// Metrics APIs\nexport { createNoopMeter } from './metrics/NoopMeter';\nexport { MeterOptions, Meter } from './metrics/Meter';\nexport { MeterProvider } from './metrics/MeterProvider';\nexport {\n ValueType,\n Counter,\n Histogram,\n MetricOptions,\n Observable,\n ObservableCounter,\n ObservableGauge,\n ObservableUpDownCounter,\n UpDownCounter,\n BatchObservableCallback,\n MetricAdvice,\n MetricAttributes,\n MetricAttributeValue,\n ObservableCallback,\n} from './metrics/Metric';\nexport {\n BatchObservableResult,\n ObservableResult,\n} from './metrics/ObservableResult';\nexport type { MetricsAPI } from './api/metrics';\n\n// Propagation APIs\nexport {\n TextMapPropagator,\n TextMapSetter,\n TextMapGetter,\n defaultTextMapGetter,\n defaultTextMapSetter,\n} from './propagation/TextMapPropagator';\nexport type { PropagationAPI } from './api/propagation';\n\n// Trace APIs\nexport { SpanAttributes, SpanAttributeValue } from './trace/attributes';\nexport { Link } from './trace/link';\nexport { ProxyTracer, TracerDelegator } from './trace/ProxyTracer';\nexport { ProxyTracerProvider } from './trace/ProxyTracerProvider';\nexport { Sampler } from './trace/Sampler';\nexport { SamplingDecision, SamplingResult } from './trace/SamplingResult';\nexport { SpanContext } from './trace/span_context';\nexport { SpanKind } from './trace/span_kind';\nexport { Span } from './trace/span';\nexport { SpanOptions } from './trace/SpanOptions';\nexport { SpanStatus, SpanStatusCode } from './trace/status';\nexport { TraceFlags } from './trace/trace_flags';\nexport { TraceState } from './trace/trace_state';\nexport { createTraceState } from './trace/internal/utils';\nexport { TracerProvider } from './trace/tracer_provider';\nexport { Tracer } from './trace/tracer';\nexport { TracerOptions } from './trace/tracer_options';\nexport {\n isSpanContextValid,\n isValidTraceId,\n isValidSpanId,\n} from './trace/spancontext-utils';\nexport {\n INVALID_SPANID,\n INVALID_TRACEID,\n INVALID_SPAN_CONTEXT,\n} from './trace/invalid-span-constants';\nexport type { TraceAPI } from './api/trace';\n\n// Split module-level variable definition into separate files to allow\n// tree-shaking on each api instance.\nimport { context } from './context-api';\nimport { diag } from './diag-api';\nimport { metrics } from './metrics-api';\nimport { propagation } from './propagation-api';\nimport { trace } from './trace-api';\n\n// Named export.\nexport { context, diag, metrics, propagation, trace };\n// Default export.\nexport default {\n context,\n diag,\n metrics,\n propagation,\n trace,\n};\n"]}
@@ -1,6 +1,17 @@
1
1
  import { Attributes, AttributeValue } from '../common/Attributes';
2
2
  import { Context } from '../context/types';
3
3
  import { BatchObservableResult, ObservableResult } from './ObservableResult';
4
+ /**
5
+ * Advisory options influencing aggregation configuration parameters.
6
+ * @experimental
7
+ */
8
+ export interface MetricAdvice {
9
+ /**
10
+ * Hint the explicit bucket boundaries for SDK if the metric is been
11
+ * aggregated with a HistogramAggregator.
12
+ */
13
+ explicitBucketBoundaries?: number[];
14
+ }
4
15
  /**
5
16
  * Options needed for metric creation
6
17
  */
@@ -20,6 +31,11 @@ export interface MetricOptions {
20
31
  * @default {@link ValueType.DOUBLE}
21
32
  */
22
33
  valueType?: ValueType;
34
+ /**
35
+ * The advice influencing aggregation configuration parameters.
36
+ * @experimental
37
+ */
38
+ advice?: MetricAdvice;
23
39
  }
24
40
  /** The Type of value. It describes how the data is reported. */
25
41
  export declare enum ValueType {
@@ -1 +1 @@
1
- {"version":3,"file":"Metric.js","sourceRoot":"","sources":["../../../src/metrics/Metric.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA6BH,gEAAgE;AAChE,MAAM,CAAN,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,uCAAG,CAAA;IACH,6CAAM,CAAA;AACR,CAAC,EAHW,SAAS,KAAT,SAAS,QAGpB","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Attributes, AttributeValue } from '../common/Attributes';\nimport { Context } from '../context/types';\nimport { BatchObservableResult, ObservableResult } from './ObservableResult';\n\n/**\n * Options needed for metric creation\n */\nexport interface MetricOptions {\n /**\n * The description of the Metric.\n * @default ''\n */\n description?: string;\n\n /**\n * The unit of the Metric values.\n * @default ''\n */\n unit?: string;\n\n /**\n * Indicates the type of the recorded value.\n * @default {@link ValueType.DOUBLE}\n */\n valueType?: ValueType;\n}\n\n/** The Type of value. It describes how the data is reported. */\nexport enum ValueType {\n INT,\n DOUBLE,\n}\n\n/**\n * Counter is the most common synchronous instrument. This instrument supports\n * an `Add(increment)` function for reporting a sum, and is restricted to\n * non-negative increments. The default aggregation is Sum, as for any additive\n * instrument.\n *\n * Example uses for Counter:\n * <ol>\n * <li> count the number of bytes received. </li>\n * <li> count the number of requests completed. </li>\n * <li> count the number of accounts created. </li>\n * <li> count the number of checkpoints run. </li>\n * <li> count the number of 5xx errors. </li>\n * <ol>\n */\nexport interface Counter<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> {\n /**\n * Increment value of counter by the input. Inputs must not be negative.\n */\n add(value: number, attributes?: AttributesTypes, context?: Context): void;\n}\n\nexport interface UpDownCounter<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> {\n /**\n * Increment value of counter by the input. Inputs may be negative.\n */\n add(value: number, attributes?: AttributesTypes, context?: Context): void;\n}\n\nexport interface Histogram<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> {\n /**\n * Records a measurement. Value of the measurement must not be negative.\n */\n record(value: number, attributes?: AttributesTypes, context?: Context): void;\n}\n\n/**\n * @deprecated please use {@link Attributes}\n */\nexport type MetricAttributes = Attributes;\n\n/**\n * @deprecated please use {@link AttributeValue}\n */\nexport type MetricAttributeValue = AttributeValue;\n\n/**\n * The observable callback for Observable instruments.\n */\nexport type ObservableCallback<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> = (\n observableResult: ObservableResult<AttributesTypes>\n) => void | Promise<void>;\n\n/**\n * The observable callback for a batch of Observable instruments.\n */\nexport type BatchObservableCallback<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> = (\n observableResult: BatchObservableResult<AttributesTypes>\n) => void | Promise<void>;\n\nexport interface Observable<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> {\n /**\n * Sets up a function that will be called whenever a metric collection is initiated.\n *\n * If the function is already in the list of callbacks for this Observable, the function is not added a second time.\n */\n addCallback(callback: ObservableCallback<AttributesTypes>): void;\n\n /**\n * Removes a callback previously registered with {@link Observable.addCallback}.\n */\n removeCallback(callback: ObservableCallback<AttributesTypes>): void;\n}\n\nexport type ObservableCounter<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> = Observable<AttributesTypes>;\nexport type ObservableUpDownCounter<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> = Observable<AttributesTypes>;\nexport type ObservableGauge<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> = Observable<AttributesTypes>;\n"]}
1
+ {"version":3,"file":"Metric.js","sourceRoot":"","sources":["../../../src/metrics/Metric.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA+CH,gEAAgE;AAChE,MAAM,CAAN,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,uCAAG,CAAA;IACH,6CAAM,CAAA;AACR,CAAC,EAHW,SAAS,KAAT,SAAS,QAGpB","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Attributes, AttributeValue } from '../common/Attributes';\nimport { Context } from '../context/types';\nimport { BatchObservableResult, ObservableResult } from './ObservableResult';\n\n/**\n * Advisory options influencing aggregation configuration parameters.\n * @experimental\n */\nexport interface MetricAdvice {\n /**\n * Hint the explicit bucket boundaries for SDK if the metric is been\n * aggregated with a HistogramAggregator.\n */\n explicitBucketBoundaries?: number[];\n}\n\n/**\n * Options needed for metric creation\n */\nexport interface MetricOptions {\n /**\n * The description of the Metric.\n * @default ''\n */\n description?: string;\n\n /**\n * The unit of the Metric values.\n * @default ''\n */\n unit?: string;\n\n /**\n * Indicates the type of the recorded value.\n * @default {@link ValueType.DOUBLE}\n */\n valueType?: ValueType;\n\n /**\n * The advice influencing aggregation configuration parameters.\n * @experimental\n */\n advice?: MetricAdvice;\n}\n\n/** The Type of value. It describes how the data is reported. */\nexport enum ValueType {\n INT,\n DOUBLE,\n}\n\n/**\n * Counter is the most common synchronous instrument. This instrument supports\n * an `Add(increment)` function for reporting a sum, and is restricted to\n * non-negative increments. The default aggregation is Sum, as for any additive\n * instrument.\n *\n * Example uses for Counter:\n * <ol>\n * <li> count the number of bytes received. </li>\n * <li> count the number of requests completed. </li>\n * <li> count the number of accounts created. </li>\n * <li> count the number of checkpoints run. </li>\n * <li> count the number of 5xx errors. </li>\n * <ol>\n */\nexport interface Counter<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> {\n /**\n * Increment value of counter by the input. Inputs must not be negative.\n */\n add(value: number, attributes?: AttributesTypes, context?: Context): void;\n}\n\nexport interface UpDownCounter<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> {\n /**\n * Increment value of counter by the input. Inputs may be negative.\n */\n add(value: number, attributes?: AttributesTypes, context?: Context): void;\n}\n\nexport interface Histogram<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> {\n /**\n * Records a measurement. Value of the measurement must not be negative.\n */\n record(value: number, attributes?: AttributesTypes, context?: Context): void;\n}\n\n/**\n * @deprecated please use {@link Attributes}\n */\nexport type MetricAttributes = Attributes;\n\n/**\n * @deprecated please use {@link AttributeValue}\n */\nexport type MetricAttributeValue = AttributeValue;\n\n/**\n * The observable callback for Observable instruments.\n */\nexport type ObservableCallback<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> = (\n observableResult: ObservableResult<AttributesTypes>\n) => void | Promise<void>;\n\n/**\n * The observable callback for a batch of Observable instruments.\n */\nexport type BatchObservableCallback<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> = (\n observableResult: BatchObservableResult<AttributesTypes>\n) => void | Promise<void>;\n\nexport interface Observable<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> {\n /**\n * Sets up a function that will be called whenever a metric collection is initiated.\n *\n * If the function is already in the list of callbacks for this Observable, the function is not added a second time.\n */\n addCallback(callback: ObservableCallback<AttributesTypes>): void;\n\n /**\n * Removes a callback previously registered with {@link Observable.addCallback}.\n */\n removeCallback(callback: ObservableCallback<AttributesTypes>): void;\n}\n\nexport type ObservableCounter<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> = Observable<AttributesTypes>;\nexport type ObservableUpDownCounter<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> = Observable<AttributesTypes>;\nexport type ObservableGauge<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> = Observable<AttributesTypes>;\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "1.6.0";
1
+ export declare const VERSION = "1.8.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -14,5 +14,5 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  // this is autogenerated file, see scripts/version-update.js
17
- export var VERSION = '1.6.0';
17
+ export var VERSION = '1.8.0';
18
18
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,IAAM,OAAO,GAAG,OAAO,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '1.6.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,IAAM,OAAO,GAAG,OAAO,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '1.8.0';\n"]}
@@ -0,0 +1,41 @@
1
+ import { Context, ContextManager } from '../context/types';
2
+ /**
3
+ * Singleton object which represents the entry point to the OpenTelemetry Context API
4
+ */
5
+ export declare class ContextAPI {
6
+ private static _instance?;
7
+ /** Empty private constructor prevents end users from constructing a new instance of the API */
8
+ private constructor();
9
+ /** Get the singleton instance of the Context API */
10
+ static getInstance(): ContextAPI;
11
+ /**
12
+ * Set the current context manager.
13
+ *
14
+ * @returns true if the context manager was successfully registered, else false
15
+ */
16
+ setGlobalContextManager(contextManager: ContextManager): boolean;
17
+ /**
18
+ * Get the currently active context
19
+ */
20
+ active(): Context;
21
+ /**
22
+ * Execute a function with an active context
23
+ *
24
+ * @param context context to be active during function execution
25
+ * @param fn function to execute in a context
26
+ * @param thisArg optional receiver to be used for calling fn
27
+ * @param args optional arguments forwarded to fn
28
+ */
29
+ with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(context: Context, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
30
+ /**
31
+ * Bind a context to a target function or event emitter
32
+ *
33
+ * @param context context to bind to the event emitter or function. Defaults to the currently active context
34
+ * @param target function or event emitter to bind
35
+ */
36
+ bind<T>(context: Context, target: T): T;
37
+ private _getContextManager;
38
+ /** Disable and remove the global context manager */
39
+ disable(): void;
40
+ }
41
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1,77 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { NoopContextManager } from '../context/NoopContextManager';
17
+ import { getGlobal, registerGlobal, unregisterGlobal, } from '../internal/global-utils';
18
+ import { DiagAPI } from './diag';
19
+ const API_NAME = 'context';
20
+ const NOOP_CONTEXT_MANAGER = new NoopContextManager();
21
+ /**
22
+ * Singleton object which represents the entry point to the OpenTelemetry Context API
23
+ */
24
+ export class ContextAPI {
25
+ /** Empty private constructor prevents end users from constructing a new instance of the API */
26
+ constructor() { }
27
+ /** Get the singleton instance of the Context API */
28
+ static getInstance() {
29
+ if (!this._instance) {
30
+ this._instance = new ContextAPI();
31
+ }
32
+ return this._instance;
33
+ }
34
+ /**
35
+ * Set the current context manager.
36
+ *
37
+ * @returns true if the context manager was successfully registered, else false
38
+ */
39
+ setGlobalContextManager(contextManager) {
40
+ return registerGlobal(API_NAME, contextManager, DiagAPI.instance());
41
+ }
42
+ /**
43
+ * Get the currently active context
44
+ */
45
+ active() {
46
+ return this._getContextManager().active();
47
+ }
48
+ /**
49
+ * Execute a function with an active context
50
+ *
51
+ * @param context context to be active during function execution
52
+ * @param fn function to execute in a context
53
+ * @param thisArg optional receiver to be used for calling fn
54
+ * @param args optional arguments forwarded to fn
55
+ */
56
+ with(context, fn, thisArg, ...args) {
57
+ return this._getContextManager().with(context, fn, thisArg, ...args);
58
+ }
59
+ /**
60
+ * Bind a context to a target function or event emitter
61
+ *
62
+ * @param context context to bind to the event emitter or function. Defaults to the currently active context
63
+ * @param target function or event emitter to bind
64
+ */
65
+ bind(context, target) {
66
+ return this._getContextManager().bind(context, target);
67
+ }
68
+ _getContextManager() {
69
+ return getGlobal(API_NAME) || NOOP_CONTEXT_MANAGER;
70
+ }
71
+ /** Disable and remove the global context manager */
72
+ disable() {
73
+ this._getContextManager().disable();
74
+ unregisterGlobal(API_NAME, DiagAPI.instance());
75
+ }
76
+ }
77
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/api/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,EACL,SAAS,EACT,cAAc,EACd,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,MAAM,QAAQ,GAAG,SAAS,CAAC;AAC3B,MAAM,oBAAoB,GAAG,IAAI,kBAAkB,EAAE,CAAC;AAEtD;;GAEG;AACH,MAAM,OAAO,UAAU;IAGrB,+FAA+F;IAC/F,gBAAuB,CAAC;IAExB,oDAAoD;IAC7C,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACnB,IAAI,CAAC,SAAS,GAAG,IAAI,UAAU,EAAE,CAAC;SACnC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACI,uBAAuB,CAAC,cAA8B;QAC3D,OAAO,cAAc,CAAC,QAAQ,EAAE,cAAc,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IACtE,CAAC;IAED;;OAEG;IACI,MAAM;QACX,OAAO,IAAI,CAAC,kBAAkB,EAAE,CAAC,MAAM,EAAE,CAAC;IAC5C,CAAC;IAED;;;;;;;OAOG;IACI,IAAI,CACT,OAAgB,EAChB,EAAK,EACL,OAA8B,EAC9B,GAAG,IAAO;QAEV,OAAO,IAAI,CAAC,kBAAkB,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IACvE,CAAC;IAED;;;;;OAKG;IACI,IAAI,CAAI,OAAgB,EAAE,MAAS;QACxC,OAAO,IAAI,CAAC,kBAAkB,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC;IAEO,kBAAkB;QACxB,OAAO,SAAS,CAAC,QAAQ,CAAC,IAAI,oBAAoB,CAAC;IACrD,CAAC;IAED,oDAAoD;IAC7C,OAAO;QACZ,IAAI,CAAC,kBAAkB,EAAE,CAAC,OAAO,EAAE,CAAC;QACpC,gBAAgB,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IACjD,CAAC;CACF","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { NoopContextManager } from '../context/NoopContextManager';\nimport { Context, ContextManager } from '../context/types';\nimport {\n getGlobal,\n registerGlobal,\n unregisterGlobal,\n} from '../internal/global-utils';\nimport { DiagAPI } from './diag';\n\nconst API_NAME = 'context';\nconst NOOP_CONTEXT_MANAGER = new NoopContextManager();\n\n/**\n * Singleton object which represents the entry point to the OpenTelemetry Context API\n */\nexport class ContextAPI {\n private static _instance?: ContextAPI;\n\n /** Empty private constructor prevents end users from constructing a new instance of the API */\n private constructor() {}\n\n /** Get the singleton instance of the Context API */\n public static getInstance(): ContextAPI {\n if (!this._instance) {\n this._instance = new ContextAPI();\n }\n\n return this._instance;\n }\n\n /**\n * Set the current context manager.\n *\n * @returns true if the context manager was successfully registered, else false\n */\n public setGlobalContextManager(contextManager: ContextManager): boolean {\n return registerGlobal(API_NAME, contextManager, DiagAPI.instance());\n }\n\n /**\n * Get the currently active context\n */\n public active(): Context {\n return this._getContextManager().active();\n }\n\n /**\n * Execute a function with an active context\n *\n * @param context context to be active during function execution\n * @param fn function to execute in a context\n * @param thisArg optional receiver to be used for calling fn\n * @param args optional arguments forwarded to fn\n */\n public with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(\n context: Context,\n fn: F,\n thisArg?: ThisParameterType<F>,\n ...args: A\n ): ReturnType<F> {\n return this._getContextManager().with(context, fn, thisArg, ...args);\n }\n\n /**\n * Bind a context to a target function or event emitter\n *\n * @param context context to bind to the event emitter or function. Defaults to the currently active context\n * @param target function or event emitter to bind\n */\n public bind<T>(context: Context, target: T): T {\n return this._getContextManager().bind(context, target);\n }\n\n private _getContextManager(): ContextManager {\n return getGlobal(API_NAME) || NOOP_CONTEXT_MANAGER;\n }\n\n /** Disable and remove the global context manager */\n public disable() {\n this._getContextManager().disable();\n unregisterGlobal(API_NAME, DiagAPI.instance());\n }\n}\n"]}
@@ -0,0 +1,30 @@
1
+ import { ComponentLoggerOptions, DiagLogFunction, DiagLogger, DiagLoggerApi } from '../diag/types';
2
+ /**
3
+ * Singleton object which represents the entry point to the OpenTelemetry internal
4
+ * diagnostic API
5
+ */
6
+ export declare class DiagAPI implements DiagLogger, DiagLoggerApi {
7
+ private static _instance?;
8
+ /** Get the singleton instance of the DiagAPI API */
9
+ static instance(): DiagAPI;
10
+ /**
11
+ * Private internal constructor
12
+ * @private
13
+ */
14
+ private constructor();
15
+ setLogger: DiagLoggerApi['setLogger'];
16
+ /**
17
+ *
18
+ */
19
+ createComponentLogger: (options: ComponentLoggerOptions) => DiagLogger;
20
+ verbose: DiagLogFunction;
21
+ debug: DiagLogFunction;
22
+ info: DiagLogFunction;
23
+ warn: DiagLogFunction;
24
+ error: DiagLogFunction;
25
+ /**
26
+ * Unregister the global logger and return to Noop
27
+ */
28
+ disable: () => void;
29
+ }
30
+ //# sourceMappingURL=diag.d.ts.map
@@ -0,0 +1,89 @@
1
+ /*
2
+ * Copyright The OpenTelemetry Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { DiagComponentLogger } from '../diag/ComponentLogger';
17
+ import { createLogLevelDiagLogger } from '../diag/internal/logLevelLogger';
18
+ import { DiagLogLevel, } from '../diag/types';
19
+ import { getGlobal, registerGlobal, unregisterGlobal, } from '../internal/global-utils';
20
+ const API_NAME = 'diag';
21
+ /**
22
+ * Singleton object which represents the entry point to the OpenTelemetry internal
23
+ * diagnostic API
24
+ */
25
+ export class DiagAPI {
26
+ /**
27
+ * Private internal constructor
28
+ * @private
29
+ */
30
+ constructor() {
31
+ function _logProxy(funcName) {
32
+ return function (...args) {
33
+ const logger = getGlobal('diag');
34
+ // shortcut if logger not set
35
+ if (!logger)
36
+ return;
37
+ return logger[funcName](...args);
38
+ };
39
+ }
40
+ // Using self local variable for minification purposes as 'this' cannot be minified
41
+ const self = this;
42
+ // DiagAPI specific functions
43
+ const setLogger = (logger, optionsOrLogLevel = { logLevel: DiagLogLevel.INFO }) => {
44
+ var _a, _b, _c;
45
+ if (logger === self) {
46
+ // There isn't much we can do here.
47
+ // Logging to the console might break the user application.
48
+ // Try to log to self. If a logger was previously registered it will receive the log.
49
+ const err = new Error('Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation');
50
+ self.error((_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
51
+ return false;
52
+ }
53
+ if (typeof optionsOrLogLevel === 'number') {
54
+ optionsOrLogLevel = {
55
+ logLevel: optionsOrLogLevel,
56
+ };
57
+ }
58
+ const oldLogger = getGlobal('diag');
59
+ const newLogger = createLogLevelDiagLogger((_b = optionsOrLogLevel.logLevel) !== null && _b !== void 0 ? _b : DiagLogLevel.INFO, logger);
60
+ // There already is an logger registered. We'll let it know before overwriting it.
61
+ if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) {
62
+ const stack = (_c = new Error().stack) !== null && _c !== void 0 ? _c : '<failed to generate stacktrace>';
63
+ oldLogger.warn(`Current logger will be overwritten from ${stack}`);
64
+ newLogger.warn(`Current logger will overwrite one already registered from ${stack}`);
65
+ }
66
+ return registerGlobal('diag', newLogger, self, true);
67
+ };
68
+ self.setLogger = setLogger;
69
+ self.disable = () => {
70
+ unregisterGlobal(API_NAME, self);
71
+ };
72
+ self.createComponentLogger = (options) => {
73
+ return new DiagComponentLogger(options);
74
+ };
75
+ self.verbose = _logProxy('verbose');
76
+ self.debug = _logProxy('debug');
77
+ self.info = _logProxy('info');
78
+ self.warn = _logProxy('warn');
79
+ self.error = _logProxy('error');
80
+ }
81
+ /** Get the singleton instance of the DiagAPI API */
82
+ static instance() {
83
+ if (!this._instance) {
84
+ this._instance = new DiagAPI();
85
+ }
86
+ return this._instance;
87
+ }
88
+ }
89
+ //# sourceMappingURL=diag.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diag.js","sourceRoot":"","sources":["../../../src/api/diag.ts"],"names":[],"mappings":"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","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { DiagComponentLogger } from '../diag/ComponentLogger';\nimport { createLogLevelDiagLogger } from '../diag/internal/logLevelLogger';\nimport {\n ComponentLoggerOptions,\n DiagLogFunction,\n DiagLogger,\n DiagLoggerApi,\n DiagLogLevel,\n} from '../diag/types';\nimport {\n getGlobal,\n registerGlobal,\n unregisterGlobal,\n} from '../internal/global-utils';\n\nconst API_NAME = 'diag';\n\n/**\n * Singleton object which represents the entry point to the OpenTelemetry internal\n * diagnostic API\n */\nexport class DiagAPI implements DiagLogger, DiagLoggerApi {\n private static _instance?: DiagAPI;\n\n /** Get the singleton instance of the DiagAPI API */\n public static instance(): DiagAPI {\n if (!this._instance) {\n this._instance = new DiagAPI();\n }\n\n return this._instance;\n }\n\n /**\n * Private internal constructor\n * @private\n */\n private constructor() {\n function _logProxy(funcName: keyof DiagLogger): DiagLogFunction {\n return function (...args) {\n const logger = getGlobal('diag');\n // shortcut if logger not set\n if (!logger) return;\n return logger[funcName](...args);\n };\n }\n\n // Using self local variable for minification purposes as 'this' cannot be minified\n const self = this;\n\n // DiagAPI specific functions\n\n const setLogger: DiagLoggerApi['setLogger'] = (\n logger,\n optionsOrLogLevel = { logLevel: DiagLogLevel.INFO }\n ) => {\n if (logger === self) {\n // There isn't much we can do here.\n // Logging to the console might break the user application.\n // Try to log to self. If a logger was previously registered it will receive the log.\n const err = new Error(\n 'Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation'\n );\n self.error(err.stack ?? err.message);\n return false;\n }\n\n if (typeof optionsOrLogLevel === 'number') {\n optionsOrLogLevel = {\n logLevel: optionsOrLogLevel,\n };\n }\n\n const oldLogger = getGlobal('diag');\n const newLogger = createLogLevelDiagLogger(\n optionsOrLogLevel.logLevel ?? DiagLogLevel.INFO,\n logger\n );\n // There already is an logger registered. We'll let it know before overwriting it.\n if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) {\n const stack = new Error().stack ?? '<failed to generate stacktrace>';\n oldLogger.warn(`Current logger will be overwritten from ${stack}`);\n newLogger.warn(\n `Current logger will overwrite one already registered from ${stack}`\n );\n }\n\n return registerGlobal('diag', newLogger, self, true);\n };\n\n self.setLogger = setLogger;\n\n self.disable = () => {\n unregisterGlobal(API_NAME, self);\n };\n\n self.createComponentLogger = (options: ComponentLoggerOptions) => {\n return new DiagComponentLogger(options);\n };\n\n self.verbose = _logProxy('verbose');\n self.debug = _logProxy('debug');\n self.info = _logProxy('info');\n self.warn = _logProxy('warn');\n self.error = _logProxy('error');\n }\n\n public setLogger!: DiagLoggerApi['setLogger'];\n /**\n *\n */\n public createComponentLogger!: (\n options: ComponentLoggerOptions\n ) => DiagLogger;\n\n // DiagLogger implementation\n public verbose!: DiagLogFunction;\n public debug!: DiagLogFunction;\n public info!: DiagLogFunction;\n public warn!: DiagLogFunction;\n public error!: DiagLogFunction;\n\n /**\n * Unregister the global logger and return to Noop\n */\n public disable!: () => void;\n}\n"]}