@opentelemetry/api 1.1.0 → 1.3.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 (187) hide show
  1. package/README.md +4 -4
  2. package/build/esm/api/context.js +25 -5
  3. package/build/esm/api/context.js.map +1 -1
  4. package/build/esm/api/diag.d.ts +3 -11
  5. package/build/esm/api/diag.js +38 -7
  6. package/build/esm/api/diag.js.map +1 -1
  7. package/build/esm/api/metrics.d.ts +28 -0
  8. package/build/esm/api/metrics.js +60 -0
  9. package/build/esm/api/metrics.js.map +1 -0
  10. package/build/esm/api/trace.d.ts +2 -1
  11. package/build/esm/api/trace.js +2 -1
  12. package/build/esm/api/trace.js.map +1 -1
  13. package/build/esm/baggage/internal/baggage-impl.js +41 -4
  14. package/build/esm/baggage/internal/baggage-impl.js.map +1 -1
  15. package/build/esm/context/NoopContextManager.js +25 -5
  16. package/build/esm/context/NoopContextManager.js.map +1 -1
  17. package/build/esm/context-api.d.ts +4 -0
  18. package/build/esm/context-api.js +21 -0
  19. package/build/esm/context-api.js.map +1 -0
  20. package/build/esm/diag/ComponentLogger.js +26 -1
  21. package/build/esm/diag/ComponentLogger.js.map +1 -1
  22. package/build/esm/diag/types.d.ts +30 -0
  23. package/build/esm/diag/types.js.map +1 -1
  24. package/build/esm/diag-api.d.ts +9 -0
  25. package/build/esm/diag-api.js +26 -0
  26. package/build/esm/diag-api.js.map +1 -0
  27. package/build/esm/index.d.ts +44 -48
  28. package/build/esm/index.js +29 -43
  29. package/build/esm/index.js.map +1 -1
  30. package/build/esm/internal/global-utils.d.ts +3 -1
  31. package/build/esm/internal/global-utils.js.map +1 -1
  32. package/build/esm/metrics/Meter.d.ts +104 -0
  33. package/build/esm/{diag/index.js → metrics/Meter.js} +2 -3
  34. package/build/esm/metrics/Meter.js.map +1 -0
  35. package/build/esm/metrics/MeterProvider.d.ts +17 -0
  36. package/build/esm/metrics/MeterProvider.js +17 -0
  37. package/build/esm/metrics/MeterProvider.js.map +1 -0
  38. package/build/esm/metrics/Metric.d.ts +97 -0
  39. package/build/esm/metrics/Metric.js +22 -0
  40. package/build/esm/metrics/Metric.js.map +1 -0
  41. package/build/esm/metrics/NoopMeter.d.ts +74 -0
  42. package/build/esm/metrics/NoopMeter.js +165 -0
  43. package/build/esm/metrics/NoopMeter.js.map +1 -0
  44. package/build/esm/metrics/NoopMeterProvider.d.ts +11 -0
  45. package/build/esm/metrics/NoopMeterProvider.js +31 -0
  46. package/build/esm/metrics/NoopMeterProvider.js.map +1 -0
  47. package/build/esm/metrics/ObservableResult.d.ts +31 -0
  48. package/build/esm/metrics/ObservableResult.js +17 -0
  49. package/build/esm/metrics/ObservableResult.js.map +1 -0
  50. package/build/esm/metrics-api.d.ts +4 -0
  51. package/build/esm/metrics-api.js +21 -0
  52. package/build/esm/metrics-api.js.map +1 -0
  53. package/build/esm/platform/browser/globalThis.js +1 -2
  54. package/build/esm/platform/browser/globalThis.js.map +1 -1
  55. package/build/esm/propagation-api.d.ts +4 -0
  56. package/build/esm/propagation-api.js +21 -0
  57. package/build/esm/propagation-api.js.map +1 -0
  58. package/build/esm/trace/NoopTracer.js +3 -3
  59. package/build/esm/trace/NoopTracer.js.map +1 -1
  60. package/build/esm/trace/Sampler.d.ts +1 -0
  61. package/build/esm/trace/Sampler.js.map +1 -1
  62. package/build/esm/trace/SamplingResult.d.ts +2 -0
  63. package/build/esm/trace/SamplingResult.js +1 -0
  64. package/build/esm/trace/SamplingResult.js.map +1 -1
  65. package/build/esm/trace/context-utils.d.ts +4 -0
  66. package/build/esm/trace/context-utils.js +7 -0
  67. package/build/esm/trace/context-utils.js.map +1 -1
  68. package/build/esm/trace-api.d.ts +4 -0
  69. package/build/esm/trace-api.js +21 -0
  70. package/build/esm/trace-api.js.map +1 -0
  71. package/build/esm/version.d.ts +1 -1
  72. package/build/esm/version.js +1 -1
  73. package/build/esm/version.js.map +1 -1
  74. package/build/src/api/context.js +26 -38
  75. package/build/src/api/context.js.map +1 -1
  76. package/build/src/api/diag.d.ts +3 -11
  77. package/build/src/api/diag.js +33 -33
  78. package/build/src/api/diag.js.map +1 -1
  79. package/build/src/api/metrics.d.ts +28 -0
  80. package/build/src/api/metrics.js +61 -0
  81. package/build/src/api/metrics.js.map +1 -0
  82. package/build/src/api/propagation.js +28 -31
  83. package/build/src/api/propagation.js.map +1 -1
  84. package/build/src/api/trace.d.ts +2 -1
  85. package/build/src/api/trace.js +23 -23
  86. package/build/src/api/trace.js.map +1 -1
  87. package/build/src/baggage/context-helpers.js +2 -2
  88. package/build/src/baggage/context-helpers.js.map +1 -1
  89. package/build/src/baggage/internal/baggage-impl.js +21 -30
  90. package/build/src/baggage/internal/baggage-impl.js.map +1 -1
  91. package/build/src/baggage/utils.js +7 -8
  92. package/build/src/baggage/utils.js.map +1 -1
  93. package/build/src/context/NoopContextManager.js +14 -26
  94. package/build/src/context/NoopContextManager.js.map +1 -1
  95. package/build/src/context/context.js +9 -10
  96. package/build/src/context/context.js.map +1 -1
  97. package/build/src/context-api.d.ts +4 -0
  98. package/build/src/{diag/index.js → context-api.js} +7 -13
  99. package/build/src/context-api.js.map +1 -0
  100. package/build/src/diag/ComponentLogger.js +16 -37
  101. package/build/src/diag/ComponentLogger.js.map +1 -1
  102. package/build/src/diag/consoleLogger.js +7 -12
  103. package/build/src/diag/consoleLogger.js.map +1 -1
  104. package/build/src/diag/internal/logLevelLogger.js +2 -2
  105. package/build/src/diag/internal/logLevelLogger.js.map +1 -1
  106. package/build/src/diag/types.d.ts +30 -0
  107. package/build/src/diag/types.js.map +1 -1
  108. package/build/src/diag-api.d.ts +9 -0
  109. package/build/src/diag-api.js +29 -0
  110. package/build/src/diag-api.js.map +1 -0
  111. package/build/src/index.d.ts +44 -48
  112. package/build/src/index.js +49 -56
  113. package/build/src/index.js.map +1 -1
  114. package/build/src/internal/global-utils.d.ts +3 -1
  115. package/build/src/internal/global-utils.js +15 -16
  116. package/build/src/internal/global-utils.js.map +1 -1
  117. package/build/src/internal/semver.js +9 -9
  118. package/build/src/internal/semver.js.map +1 -1
  119. package/build/src/metrics/Meter.d.ts +104 -0
  120. package/build/src/metrics/Meter.js +18 -0
  121. package/build/src/metrics/Meter.js.map +1 -0
  122. package/build/src/metrics/MeterProvider.d.ts +17 -0
  123. package/build/src/metrics/MeterProvider.js +18 -0
  124. package/build/src/metrics/MeterProvider.js.map +1 -0
  125. package/build/src/metrics/Metric.d.ts +97 -0
  126. package/build/src/metrics/Metric.js +25 -0
  127. package/build/src/metrics/Metric.js.map +1 -0
  128. package/build/src/metrics/NoopMeter.d.ts +74 -0
  129. package/build/src/metrics/NoopMeter.js +116 -0
  130. package/build/src/metrics/NoopMeter.js.map +1 -0
  131. package/build/src/metrics/NoopMeterProvider.d.ts +11 -0
  132. package/build/src/metrics/NoopMeterProvider.js +31 -0
  133. package/build/src/metrics/NoopMeterProvider.js.map +1 -0
  134. package/build/src/metrics/ObservableResult.d.ts +31 -0
  135. package/build/src/metrics/ObservableResult.js +18 -0
  136. package/build/src/metrics/ObservableResult.js.map +1 -0
  137. package/build/src/metrics-api.d.ts +4 -0
  138. package/build/src/metrics-api.js +24 -0
  139. package/build/src/metrics-api.js.map +1 -0
  140. package/build/src/platform/browser/globalThis.js +1 -2
  141. package/build/src/platform/browser/globalThis.js.map +1 -1
  142. package/build/src/propagation/NoopTextMapPropagator.js +7 -10
  143. package/build/src/propagation/NoopTextMapPropagator.js.map +1 -1
  144. package/build/src/propagation/TextMapPropagator.js +3 -3
  145. package/build/src/propagation/TextMapPropagator.js.map +1 -1
  146. package/build/src/propagation-api.d.ts +4 -0
  147. package/build/src/propagation-api.js +24 -0
  148. package/build/src/propagation-api.js.map +1 -0
  149. package/build/src/trace/NonRecordingSpan.js +20 -22
  150. package/build/src/trace/NonRecordingSpan.js.map +1 -1
  151. package/build/src/trace/NoopTracer.js +21 -24
  152. package/build/src/trace/NoopTracer.js.map +1 -1
  153. package/build/src/trace/NoopTracerProvider.js +5 -8
  154. package/build/src/trace/NoopTracerProvider.js.map +1 -1
  155. package/build/src/trace/ProxyTracer.js +13 -14
  156. package/build/src/trace/ProxyTracer.js.map +1 -1
  157. package/build/src/trace/ProxyTracerProvider.js +13 -16
  158. package/build/src/trace/ProxyTracerProvider.js.map +1 -1
  159. package/build/src/trace/Sampler.d.ts +1 -0
  160. package/build/src/trace/Sampler.js.map +1 -1
  161. package/build/src/trace/SamplingResult.d.ts +2 -0
  162. package/build/src/trace/SamplingResult.js +1 -0
  163. package/build/src/trace/SamplingResult.js.map +1 -1
  164. package/build/src/trace/context-utils.d.ts +4 -0
  165. package/build/src/trace/context-utils.js +12 -4
  166. package/build/src/trace/context-utils.js.map +1 -1
  167. package/build/src/trace/internal/tracestate-impl.js +33 -35
  168. package/build/src/trace/internal/tracestate-impl.js.map +1 -1
  169. package/build/src/trace/internal/tracestate-validators.js +6 -6
  170. package/build/src/trace/internal/tracestate-validators.js.map +1 -1
  171. package/build/src/trace/internal/utils.js +1 -1
  172. package/build/src/trace/internal/utils.js.map +1 -1
  173. package/build/src/trace/invalid-span-constants.js +1 -1
  174. package/build/src/trace/invalid-span-constants.js.map +1 -1
  175. package/build/src/trace/spancontext-utils.js +4 -4
  176. package/build/src/trace/spancontext-utils.js.map +1 -1
  177. package/build/src/trace-api.d.ts +4 -0
  178. package/build/src/trace-api.js +24 -0
  179. package/build/src/{diag/index.js.map → trace-api.js.map} +1 -1
  180. package/build/src/version.d.ts +1 -1
  181. package/build/src/version.js +1 -1
  182. package/build/src/version.js.map +1 -1
  183. package/package.json +34 -34
  184. package/CHANGELOG.md +0 -204
  185. package/build/esm/diag/index.d.ts +0 -3
  186. package/build/esm/diag/index.js.map +0 -1
  187. package/build/src/diag/index.d.ts +0 -3
@@ -4,6 +4,7 @@ import { Link } from './link';
4
4
  import { SamplingResult } from './SamplingResult';
5
5
  import { SpanKind } from './span_kind';
6
6
  /**
7
+ * @deprecated use the one declared in @opentelemetry/sdk-trace-base instead.
7
8
  * This interface represent a sampler. Sampling is a mechanism to control the
8
9
  * noise and overhead introduced by OpenTelemetry by reducing the number of
9
10
  * samples of traces collected and sent to the backend.
@@ -1 +1 @@
1
- {"version":3,"file":"Sampler.js","sourceRoot":"","sources":["../../../src/trace/Sampler.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 { Context } from '../context/types';\nimport { SpanAttributes } from './attributes';\nimport { Link } from './link';\nimport { SamplingResult } from './SamplingResult';\nimport { SpanKind } from './span_kind';\n\n/**\n * This interface represent a sampler. Sampling is a mechanism to control the\n * noise and overhead introduced by OpenTelemetry by reducing the number of\n * samples of traces collected and sent to the backend.\n */\nexport interface Sampler {\n /**\n * Checks whether span needs to be created and tracked.\n *\n * @param context Parent Context which may contain a span.\n * @param traceId of the span to be created. It can be different from the\n * traceId in the {@link SpanContext}. Typically in situations when the\n * span to be created starts a new trace.\n * @param spanName of the span to be created.\n * @param spanKind of the span to be created.\n * @param attributes Initial set of SpanAttributes for the Span being constructed.\n * @param links Collection of links that will be associated with the Span to\n * be created. Typically useful for batch operations.\n * @returns a {@link SamplingResult}.\n */\n shouldSample(\n context: Context,\n traceId: string,\n spanName: string,\n spanKind: SpanKind,\n attributes: SpanAttributes,\n links: Link[]\n ): SamplingResult;\n\n /** Returns the sampler name or short description with the configuration. */\n toString(): string;\n}\n"]}
1
+ {"version":3,"file":"Sampler.js","sourceRoot":"","sources":["../../../src/trace/Sampler.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 { Context } from '../context/types';\nimport { SpanAttributes } from './attributes';\nimport { Link } from './link';\nimport { SamplingResult } from './SamplingResult';\nimport { SpanKind } from './span_kind';\n\n/**\n * @deprecated use the one declared in @opentelemetry/sdk-trace-base instead.\n * This interface represent a sampler. Sampling is a mechanism to control the\n * noise and overhead introduced by OpenTelemetry by reducing the number of\n * samples of traces collected and sent to the backend.\n */\nexport interface Sampler {\n /**\n * Checks whether span needs to be created and tracked.\n *\n * @param context Parent Context which may contain a span.\n * @param traceId of the span to be created. It can be different from the\n * traceId in the {@link SpanContext}. Typically in situations when the\n * span to be created starts a new trace.\n * @param spanName of the span to be created.\n * @param spanKind of the span to be created.\n * @param attributes Initial set of SpanAttributes for the Span being constructed.\n * @param links Collection of links that will be associated with the Span to\n * be created. Typically useful for batch operations.\n * @returns a {@link SamplingResult}.\n */\n shouldSample(\n context: Context,\n traceId: string,\n spanName: string,\n spanKind: SpanKind,\n attributes: SpanAttributes,\n links: Link[]\n ): SamplingResult;\n\n /** Returns the sampler name or short description with the configuration. */\n toString(): string;\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import { SpanAttributes } from './attributes';
2
2
  /**
3
+ * @deprecated use the one declared in @opentelemetry/sdk-trace-base instead.
3
4
  * A sampling decision that determines how a {@link Span} will be recorded
4
5
  * and collected.
5
6
  */
@@ -21,6 +22,7 @@ export declare enum SamplingDecision {
21
22
  RECORD_AND_SAMPLED = 2
22
23
  }
23
24
  /**
25
+ * @deprecated use the one declared in @opentelemetry/sdk-trace-base instead.
24
26
  * A sampling result contains a decision for a {@link Span} and additional
25
27
  * attributes the sampler would like to added to the Span.
26
28
  */
@@ -14,6 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  /**
17
+ * @deprecated use the one declared in @opentelemetry/sdk-trace-base instead.
17
18
  * A sampling decision that determines how a {@link Span} will be recorded
18
19
  * and collected.
19
20
  */
@@ -1 +1 @@
1
- {"version":3,"file":"SamplingResult.js","sourceRoot":"","sources":["../../../src/trace/SamplingResult.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH;;;GAGG;AACH,MAAM,CAAN,IAAY,gBAgBX;AAhBD,WAAY,gBAAgB;IAC1B;;;OAGG;IACH,mEAAU,CAAA;IACV;;;OAGG;IACH,2DAAM,CAAA;IACN;;;OAGG;IACH,mFAAkB,CAAA;AACpB,CAAC,EAhBW,gBAAgB,KAAhB,gBAAgB,QAgB3B","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 { SpanAttributes } from './attributes';\n\n/**\n * A sampling decision that determines how a {@link Span} will be recorded\n * and collected.\n */\nexport enum SamplingDecision {\n /**\n * `Span.isRecording() === false`, span will not be recorded and all events\n * and attributes will be dropped.\n */\n NOT_RECORD,\n /**\n * `Span.isRecording() === true`, but `Sampled` flag in {@link TraceFlags}\n * MUST NOT be set.\n */\n RECORD,\n /**\n * `Span.isRecording() === true` AND `Sampled` flag in {@link TraceFlags}\n * MUST be set.\n */\n RECORD_AND_SAMPLED,\n}\n\n/**\n * A sampling result contains a decision for a {@link Span} and additional\n * attributes the sampler would like to added to the Span.\n */\nexport interface SamplingResult {\n /**\n * A sampling decision, refer to {@link SamplingDecision} for details.\n */\n decision: SamplingDecision;\n /**\n * The list of attributes returned by SamplingResult MUST be immutable.\n * Caller may call {@link Sampler}.shouldSample any number of times and\n * can safely cache the returned value.\n */\n attributes?: Readonly<SpanAttributes>;\n}\n"]}
1
+ {"version":3,"file":"SamplingResult.js","sourceRoot":"","sources":["../../../src/trace/SamplingResult.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH;;;;GAIG;AACH,MAAM,CAAN,IAAY,gBAgBX;AAhBD,WAAY,gBAAgB;IAC1B;;;OAGG;IACH,mEAAU,CAAA;IACV;;;OAGG;IACH,2DAAM,CAAA;IACN;;;OAGG;IACH,mFAAkB,CAAA;AACpB,CAAC,EAhBW,gBAAgB,KAAhB,gBAAgB,QAgB3B","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 { SpanAttributes } from './attributes';\n\n/**\n * @deprecated use the one declared in @opentelemetry/sdk-trace-base instead.\n * A sampling decision that determines how a {@link Span} will be recorded\n * and collected.\n */\nexport enum SamplingDecision {\n /**\n * `Span.isRecording() === false`, span will not be recorded and all events\n * and attributes will be dropped.\n */\n NOT_RECORD,\n /**\n * `Span.isRecording() === true`, but `Sampled` flag in {@link TraceFlags}\n * MUST NOT be set.\n */\n RECORD,\n /**\n * `Span.isRecording() === true` AND `Sampled` flag in {@link TraceFlags}\n * MUST be set.\n */\n RECORD_AND_SAMPLED,\n}\n\n/**\n * @deprecated use the one declared in @opentelemetry/sdk-trace-base instead.\n * A sampling result contains a decision for a {@link Span} and additional\n * attributes the sampler would like to added to the Span.\n */\nexport interface SamplingResult {\n /**\n * A sampling decision, refer to {@link SamplingDecision} for details.\n */\n decision: SamplingDecision;\n /**\n * The list of attributes returned by SamplingResult MUST be immutable.\n * Caller may call {@link Sampler}.shouldSample any number of times and\n * can safely cache the returned value.\n */\n attributes?: Readonly<SpanAttributes>;\n}\n"]}
@@ -7,6 +7,10 @@ import { SpanContext } from './span_context';
7
7
  * @param context context to get span from
8
8
  */
9
9
  export declare function getSpan(context: Context): Span | undefined;
10
+ /**
11
+ * Gets the span from the current context, if one exists.
12
+ */
13
+ export declare function getActiveSpan(): Span | undefined;
10
14
  /**
11
15
  * Set the span on a context
12
16
  *
@@ -15,6 +15,7 @@
15
15
  */
16
16
  import { createContextKey } from '../context/context';
17
17
  import { NonRecordingSpan } from './NonRecordingSpan';
18
+ import { ContextAPI } from '../api/context';
18
19
  /**
19
20
  * span key
20
21
  */
@@ -27,6 +28,12 @@ var SPAN_KEY = createContextKey('OpenTelemetry Context Key SPAN');
27
28
  export function getSpan(context) {
28
29
  return context.getValue(SPAN_KEY) || undefined;
29
30
  }
31
+ /**
32
+ * Gets the span from the current context, if one exists.
33
+ */
34
+ export function getActiveSpan() {
35
+ return getSpan(ContextAPI.getInstance().active());
36
+ }
30
37
  /**
31
38
  * Set the span on a context
32
39
  *
@@ -1 +1 @@
1
- {"version":3,"file":"context-utils.js","sourceRoot":"","sources":["../../../src/trace/context-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAItD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD;;GAEG;AACH,IAAM,QAAQ,GAAG,gBAAgB,CAAC,gCAAgC,CAAC,CAAC;AAEpE;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,OAAgB;IACtC,OAAQ,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU,IAAI,SAAS,CAAC;AAC3D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,OAAgB,EAAE,IAAU;IAClD,OAAO,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAC1C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,OAAgB;IACzC,OAAO,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAC5B,OAAgB,EAChB,WAAwB;IAExB,OAAO,OAAO,CAAC,OAAO,EAAE,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,OAAgB;;IAC7C,OAAO,MAAA,OAAO,CAAC,OAAO,CAAC,0CAAE,WAAW,EAAE,CAAC;AACzC,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\nimport { createContextKey } from '../context/context';\nimport { Context } from '../context/types';\nimport { Span } from './span';\nimport { SpanContext } from './span_context';\nimport { NonRecordingSpan } from './NonRecordingSpan';\n\n/**\n * span key\n */\nconst SPAN_KEY = createContextKey('OpenTelemetry Context Key SPAN');\n\n/**\n * Return the span if one exists\n *\n * @param context context to get span from\n */\nexport function getSpan(context: Context): Span | undefined {\n return (context.getValue(SPAN_KEY) as Span) || undefined;\n}\n\n/**\n * Set the span on a context\n *\n * @param context context to use as parent\n * @param span span to set active\n */\nexport function setSpan(context: Context, span: Span): Context {\n return context.setValue(SPAN_KEY, span);\n}\n\n/**\n * Remove current span stored in the context\n *\n * @param context context to delete span from\n */\nexport function deleteSpan(context: Context): Context {\n return context.deleteValue(SPAN_KEY);\n}\n\n/**\n * Wrap span context in a NoopSpan and set as span in a new\n * context\n *\n * @param context context to set active span on\n * @param spanContext span context to be wrapped\n */\nexport function setSpanContext(\n context: Context,\n spanContext: SpanContext\n): Context {\n return setSpan(context, new NonRecordingSpan(spanContext));\n}\n\n/**\n * Get the span context of the span if it exists.\n *\n * @param context context to get values from\n */\nexport function getSpanContext(context: Context): SpanContext | undefined {\n return getSpan(context)?.spanContext();\n}\n"]}
1
+ {"version":3,"file":"context-utils.js","sourceRoot":"","sources":["../../../src/trace/context-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAItD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;GAEG;AACH,IAAM,QAAQ,GAAG,gBAAgB,CAAC,gCAAgC,CAAC,CAAC;AAEpE;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,OAAgB;IACtC,OAAQ,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU,IAAI,SAAS,CAAC;AAC3D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,OAAO,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;AACpD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,OAAgB,EAAE,IAAU;IAClD,OAAO,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAC1C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,OAAgB;IACzC,OAAO,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAC5B,OAAgB,EAChB,WAAwB;IAExB,OAAO,OAAO,CAAC,OAAO,EAAE,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,OAAgB;;IAC7C,OAAO,MAAA,OAAO,CAAC,OAAO,CAAC,0CAAE,WAAW,EAAE,CAAC;AACzC,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\nimport { createContextKey } from '../context/context';\nimport { Context } from '../context/types';\nimport { Span } from './span';\nimport { SpanContext } from './span_context';\nimport { NonRecordingSpan } from './NonRecordingSpan';\nimport { ContextAPI } from '../api/context';\n\n/**\n * span key\n */\nconst SPAN_KEY = createContextKey('OpenTelemetry Context Key SPAN');\n\n/**\n * Return the span if one exists\n *\n * @param context context to get span from\n */\nexport function getSpan(context: Context): Span | undefined {\n return (context.getValue(SPAN_KEY) as Span) || undefined;\n}\n\n/**\n * Gets the span from the current context, if one exists.\n */\nexport function getActiveSpan(): Span | undefined {\n return getSpan(ContextAPI.getInstance().active());\n}\n\n/**\n * Set the span on a context\n *\n * @param context context to use as parent\n * @param span span to set active\n */\nexport function setSpan(context: Context, span: Span): Context {\n return context.setValue(SPAN_KEY, span);\n}\n\n/**\n * Remove current span stored in the context\n *\n * @param context context to delete span from\n */\nexport function deleteSpan(context: Context): Context {\n return context.deleteValue(SPAN_KEY);\n}\n\n/**\n * Wrap span context in a NoopSpan and set as span in a new\n * context\n *\n * @param context context to set active span on\n * @param spanContext span context to be wrapped\n */\nexport function setSpanContext(\n context: Context,\n spanContext: SpanContext\n): Context {\n return setSpan(context, new NonRecordingSpan(spanContext));\n}\n\n/**\n * Get the span context of the span if it exists.\n *\n * @param context context to get values from\n */\nexport function getSpanContext(context: Context): SpanContext | undefined {\n return getSpan(context)?.spanContext();\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import { TraceAPI } from './api/trace';
2
+ /** Entrypoint for trace API */
3
+ export declare const trace: TraceAPI;
4
+ //# sourceMappingURL=trace-api.d.ts.map
@@ -0,0 +1,21 @@
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
+ // Split module-level variable definition into separate files to allow
17
+ // tree-shaking on each api instance.
18
+ import { TraceAPI } from './api/trace';
19
+ /** Entrypoint for trace API */
20
+ export var trace = TraceAPI.getInstance();
21
+ //# sourceMappingURL=trace-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace-api.js","sourceRoot":"","sources":["../../src/trace-api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,sEAAsE;AACtE,qCAAqC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,+BAA+B;AAC/B,MAAM,CAAC,IAAM,KAAK,GAAG,QAAQ,CAAC,WAAW,EAAE,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// Split module-level variable definition into separate files to allow\n// tree-shaking on each api instance.\nimport { TraceAPI } from './api/trace';\n/** Entrypoint for trace API */\nexport const trace = TraceAPI.getInstance();\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "1.1.0";
1
+ export declare const VERSION = "1.3.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.1.0';
17
+ export var VERSION = '1.3.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.1.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.3.0';\n"]}
@@ -14,46 +14,40 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
18
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
19
- to[j] = from[i];
20
- return to;
21
- };
22
17
  Object.defineProperty(exports, "__esModule", { value: true });
23
18
  exports.ContextAPI = void 0;
24
- var NoopContextManager_1 = require("../context/NoopContextManager");
25
- var global_utils_1 = require("../internal/global-utils");
26
- var diag_1 = require("./diag");
27
- var API_NAME = 'context';
28
- var NOOP_CONTEXT_MANAGER = new NoopContextManager_1.NoopContextManager();
19
+ const NoopContextManager_1 = require("../context/NoopContextManager");
20
+ const global_utils_1 = require("../internal/global-utils");
21
+ const diag_1 = require("./diag");
22
+ const API_NAME = 'context';
23
+ const NOOP_CONTEXT_MANAGER = new NoopContextManager_1.NoopContextManager();
29
24
  /**
30
25
  * Singleton object which represents the entry point to the OpenTelemetry Context API
31
26
  */
32
- var ContextAPI = /** @class */ (function () {
27
+ class ContextAPI {
33
28
  /** Empty private constructor prevents end users from constructing a new instance of the API */
34
- function ContextAPI() {
35
- }
29
+ constructor() { }
36
30
  /** Get the singleton instance of the Context API */
37
- ContextAPI.getInstance = function () {
31
+ static getInstance() {
38
32
  if (!this._instance) {
39
33
  this._instance = new ContextAPI();
40
34
  }
41
35
  return this._instance;
42
- };
36
+ }
43
37
  /**
44
38
  * Set the current context manager.
45
39
  *
46
40
  * @returns true if the context manager was successfully registered, else false
47
41
  */
48
- ContextAPI.prototype.setGlobalContextManager = function (contextManager) {
49
- return global_utils_1.registerGlobal(API_NAME, contextManager, diag_1.DiagAPI.instance());
50
- };
42
+ setGlobalContextManager(contextManager) {
43
+ return (0, global_utils_1.registerGlobal)(API_NAME, contextManager, diag_1.DiagAPI.instance());
44
+ }
51
45
  /**
52
46
  * Get the currently active context
53
47
  */
54
- ContextAPI.prototype.active = function () {
48
+ active() {
55
49
  return this._getContextManager().active();
56
- };
50
+ }
57
51
  /**
58
52
  * Execute a function with an active context
59
53
  *
@@ -62,32 +56,26 @@ var ContextAPI = /** @class */ (function () {
62
56
  * @param thisArg optional receiver to be used for calling fn
63
57
  * @param args optional arguments forwarded to fn
64
58
  */
65
- ContextAPI.prototype.with = function (context, fn, thisArg) {
66
- var _a;
67
- var args = [];
68
- for (var _i = 3; _i < arguments.length; _i++) {
69
- args[_i - 3] = arguments[_i];
70
- }
71
- return (_a = this._getContextManager()).with.apply(_a, __spreadArray([context, fn, thisArg], args));
72
- };
59
+ with(context, fn, thisArg, ...args) {
60
+ return this._getContextManager().with(context, fn, thisArg, ...args);
61
+ }
73
62
  /**
74
63
  * Bind a context to a target function or event emitter
75
64
  *
76
65
  * @param context context to bind to the event emitter or function. Defaults to the currently active context
77
66
  * @param target function or event emitter to bind
78
67
  */
79
- ContextAPI.prototype.bind = function (context, target) {
68
+ bind(context, target) {
80
69
  return this._getContextManager().bind(context, target);
81
- };
82
- ContextAPI.prototype._getContextManager = function () {
83
- return global_utils_1.getGlobal(API_NAME) || NOOP_CONTEXT_MANAGER;
84
- };
70
+ }
71
+ _getContextManager() {
72
+ return (0, global_utils_1.getGlobal)(API_NAME) || NOOP_CONTEXT_MANAGER;
73
+ }
85
74
  /** Disable and remove the global context manager */
86
- ContextAPI.prototype.disable = function () {
75
+ disable() {
87
76
  this._getContextManager().disable();
88
- global_utils_1.unregisterGlobal(API_NAME, diag_1.DiagAPI.instance());
89
- };
90
- return ContextAPI;
91
- }());
77
+ (0, global_utils_1.unregisterGlobal)(API_NAME, diag_1.DiagAPI.instance());
78
+ }
79
+ }
92
80
  exports.ContextAPI = ContextAPI;
93
81
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/api/context.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;AAEH,oEAAmE;AAEnE,yDAIkC;AAClC,+BAAiC;AAEjC,IAAM,QAAQ,GAAG,SAAS,CAAC;AAC3B,IAAM,oBAAoB,GAAG,IAAI,uCAAkB,EAAE,CAAC;AAEtD;;GAEG;AACH;IAGE,+FAA+F;IAC/F;IAAuB,CAAC;IAExB,oDAAoD;IACtC,sBAAW,GAAzB;QACE,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,4CAAuB,GAA9B,UAA+B,cAA8B;QAC3D,OAAO,6BAAc,CAAC,QAAQ,EAAE,cAAc,EAAE,cAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IACtE,CAAC;IAED;;OAEG;IACI,2BAAM,GAAb;QACE,OAAO,IAAI,CAAC,kBAAkB,EAAE,CAAC,MAAM,EAAE,CAAC;IAC5C,CAAC;IAED;;;;;;;OAOG;IACI,yBAAI,GAAX,UACE,OAAgB,EAChB,EAAK,EACL,OAA8B;;QAC9B,cAAU;aAAV,UAAU,EAAV,qBAAU,EAAV,IAAU;YAAV,6BAAU;;QAEV,OAAO,CAAA,KAAA,IAAI,CAAC,kBAAkB,EAAE,CAAA,CAAC,IAAI,0BAAC,OAAO,EAAE,EAAE,EAAE,OAAO,GAAK,IAAI,GAAE;IACvE,CAAC;IAED;;;;;OAKG;IACI,yBAAI,GAAX,UAAe,OAAgB,EAAE,MAAS;QACxC,OAAO,IAAI,CAAC,kBAAkB,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC;IAEO,uCAAkB,GAA1B;QACE,OAAO,wBAAS,CAAC,QAAQ,CAAC,IAAI,oBAAoB,CAAC;IACrD,CAAC;IAED,oDAAoD;IAC7C,4BAAO,GAAd;QACE,IAAI,CAAC,kBAAkB,EAAE,CAAC,OAAO,EAAE,CAAC;QACpC,+BAAgB,CAAC,QAAQ,EAAE,cAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IACjD,CAAC;IACH,iBAAC;AAAD,CAAC,AAnED,IAmEC;AAnEY,gCAAU","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"]}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/api/context.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,sEAAmE;AAEnE,2DAIkC;AAClC,iCAAiC;AAEjC,MAAM,QAAQ,GAAG,SAAS,CAAC;AAC3B,MAAM,oBAAoB,GAAG,IAAI,uCAAkB,EAAE,CAAC;AAEtD;;GAEG;AACH,MAAa,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,IAAA,6BAAc,EAAC,QAAQ,EAAE,cAAc,EAAE,cAAO,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,IAAA,wBAAS,EAAC,QAAQ,CAAC,IAAI,oBAAoB,CAAC;IACrD,CAAC;IAED,oDAAoD;IAC7C,OAAO;QACZ,IAAI,CAAC,kBAAkB,EAAE,CAAC,OAAO,EAAE,CAAC;QACpC,IAAA,+BAAgB,EAAC,QAAQ,EAAE,cAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IACjD,CAAC;CACF;AAnED,gCAmEC","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"]}
@@ -1,9 +1,9 @@
1
- import { ComponentLoggerOptions, DiagLogFunction, DiagLogger, DiagLogLevel } from '../diag/types';
1
+ import { ComponentLoggerOptions, DiagLogFunction, DiagLogger, DiagLoggerApi } from '../diag/types';
2
2
  /**
3
3
  * Singleton object which represents the entry point to the OpenTelemetry internal
4
4
  * diagnostic API
5
5
  */
6
- export declare class DiagAPI implements DiagLogger {
6
+ export declare class DiagAPI implements DiagLogger, DiagLoggerApi {
7
7
  private static _instance?;
8
8
  /** Get the singleton instance of the DiagAPI API */
9
9
  static instance(): DiagAPI;
@@ -12,15 +12,7 @@ export declare class DiagAPI implements DiagLogger {
12
12
  * @private
13
13
  */
14
14
  private constructor();
15
- /**
16
- * Set the global DiagLogger and DiagLogLevel.
17
- * If a global diag logger is already set, this will override it.
18
- *
19
- * @param logger - [Optional] The DiagLogger instance to set as the default logger.
20
- * @param logLevel - [Optional] The DiagLogLevel used to filter logs sent to the logger. If not provided it will default to INFO.
21
- * @returns true if the logger was successfully registered, else false
22
- */
23
- setLogger: (logger: DiagLogger, logLevel?: DiagLogLevel) => boolean;
15
+ setLogger: DiagLoggerApi['setLogger'];
24
16
  /**
25
17
  *
26
18
  */
@@ -16,62 +16,63 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.DiagAPI = void 0;
19
- var ComponentLogger_1 = require("../diag/ComponentLogger");
20
- var logLevelLogger_1 = require("../diag/internal/logLevelLogger");
21
- var types_1 = require("../diag/types");
22
- var global_utils_1 = require("../internal/global-utils");
23
- var API_NAME = 'diag';
19
+ const ComponentLogger_1 = require("../diag/ComponentLogger");
20
+ const logLevelLogger_1 = require("../diag/internal/logLevelLogger");
21
+ const types_1 = require("../diag/types");
22
+ const global_utils_1 = require("../internal/global-utils");
23
+ const API_NAME = 'diag';
24
24
  /**
25
25
  * Singleton object which represents the entry point to the OpenTelemetry internal
26
26
  * diagnostic API
27
27
  */
28
- var DiagAPI = /** @class */ (function () {
28
+ class DiagAPI {
29
29
  /**
30
30
  * Private internal constructor
31
31
  * @private
32
32
  */
33
- function DiagAPI() {
33
+ constructor() {
34
34
  function _logProxy(funcName) {
35
- return function () {
36
- var args = [];
37
- for (var _i = 0; _i < arguments.length; _i++) {
38
- args[_i] = arguments[_i];
39
- }
40
- var logger = global_utils_1.getGlobal('diag');
35
+ return function (...args) {
36
+ const logger = (0, global_utils_1.getGlobal)('diag');
41
37
  // shortcut if logger not set
42
38
  if (!logger)
43
39
  return;
44
- return logger[funcName].apply(logger, args);
40
+ return logger[funcName](...args);
45
41
  };
46
42
  }
47
43
  // Using self local variable for minification purposes as 'this' cannot be minified
48
- var self = this;
44
+ const self = this;
49
45
  // DiagAPI specific functions
50
- self.setLogger = function (logger, logLevel) {
51
- var _a, _b;
52
- if (logLevel === void 0) { logLevel = types_1.DiagLogLevel.INFO; }
46
+ const setLogger = (logger, optionsOrLogLevel = { logLevel: types_1.DiagLogLevel.INFO }) => {
47
+ var _a, _b, _c;
53
48
  if (logger === self) {
54
49
  // There isn't much we can do here.
55
50
  // Logging to the console might break the user application.
56
51
  // Try to log to self. If a logger was previously registered it will receive the log.
57
- var err = new Error('Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation');
52
+ const err = new Error('Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation');
58
53
  self.error((_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
59
54
  return false;
60
55
  }
61
- var oldLogger = global_utils_1.getGlobal('diag');
62
- var newLogger = logLevelLogger_1.createLogLevelDiagLogger(logLevel, logger);
56
+ if (typeof optionsOrLogLevel === 'number') {
57
+ optionsOrLogLevel = {
58
+ logLevel: optionsOrLogLevel,
59
+ };
60
+ }
61
+ const oldLogger = (0, global_utils_1.getGlobal)('diag');
62
+ const newLogger = (0, logLevelLogger_1.createLogLevelDiagLogger)((_b = optionsOrLogLevel.logLevel) !== null && _b !== void 0 ? _b : types_1.DiagLogLevel.INFO, logger);
63
63
  // There already is an logger registered. We'll let it know before overwriting it.
64
- if (oldLogger) {
65
- var stack = (_b = new Error().stack) !== null && _b !== void 0 ? _b : '<failed to generate stacktrace>';
66
- oldLogger.warn("Current logger will be overwritten from " + stack);
67
- newLogger.warn("Current logger will overwrite one already registered from " + stack);
64
+ if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) {
65
+ const stack = (_c = new Error().stack) !== null && _c !== void 0 ? _c : '<failed to generate stacktrace>';
66
+ oldLogger.warn(`Current logger will be overwritten from ${stack}`);
67
+ newLogger.warn(`Current logger will overwrite one already registered from ${stack}`);
68
68
  }
69
- return global_utils_1.registerGlobal('diag', newLogger, self, true);
69
+ return (0, global_utils_1.registerGlobal)('diag', newLogger, self, true);
70
70
  };
71
- self.disable = function () {
72
- global_utils_1.unregisterGlobal(API_NAME, self);
71
+ self.setLogger = setLogger;
72
+ self.disable = () => {
73
+ (0, global_utils_1.unregisterGlobal)(API_NAME, self);
73
74
  };
74
- self.createComponentLogger = function (options) {
75
+ self.createComponentLogger = (options) => {
75
76
  return new ComponentLogger_1.DiagComponentLogger(options);
76
77
  };
77
78
  self.verbose = _logProxy('verbose');
@@ -81,13 +82,12 @@ var DiagAPI = /** @class */ (function () {
81
82
  self.error = _logProxy('error');
82
83
  }
83
84
  /** Get the singleton instance of the DiagAPI API */
84
- DiagAPI.instance = function () {
85
+ static instance() {
85
86
  if (!this._instance) {
86
87
  this._instance = new DiagAPI();
87
88
  }
88
89
  return this._instance;
89
- };
90
- return DiagAPI;
91
- }());
90
+ }
91
+ }
92
92
  exports.DiagAPI = DiagAPI;
93
93
  //# sourceMappingURL=diag.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"diag.js","sourceRoot":"","sources":["../../../src/api/diag.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,2DAA8D;AAC9D,kEAA2E;AAC3E,uCAKuB;AACvB,yDAIkC;AAElC,IAAM,QAAQ,GAAG,MAAM,CAAC;AAExB;;;GAGG;AACH;IAYE;;;OAGG;IACH;QACE,SAAS,SAAS,CAAC,QAA0B;YAC3C,OAAO;gBAAU,cAAO;qBAAP,UAAO,EAAP,qBAAO,EAAP,IAAO;oBAAP,yBAAO;;gBACtB,IAAM,MAAM,GAAG,wBAAS,CAAC,MAAM,CAAC,CAAC;gBACjC,6BAA6B;gBAC7B,IAAI,CAAC,MAAM;oBAAE,OAAO;gBACpB,OAAO,MAAM,CAAC,QAAQ,CAAC,OAAhB,MAAM,EAAc,IAAI,EAAE;YACnC,CAAC,CAAC;QACJ,CAAC;QAED,mFAAmF;QACnF,IAAM,IAAI,GAAG,IAAI,CAAC;QAElB,6BAA6B;QAE7B,IAAI,CAAC,SAAS,GAAG,UACf,MAAkB,EAClB,QAA0C;;YAA1C,yBAAA,EAAA,WAAyB,oBAAY,CAAC,IAAI;YAE1C,IAAI,MAAM,KAAK,IAAI,EAAE;gBACnB,mCAAmC;gBACnC,2DAA2D;gBAC3D,qFAAqF;gBACrF,IAAM,GAAG,GAAG,IAAI,KAAK,CACnB,oIAAoI,CACrI,CAAC;gBACF,IAAI,CAAC,KAAK,CAAC,MAAA,GAAG,CAAC,KAAK,mCAAI,GAAG,CAAC,OAAO,CAAC,CAAC;gBACrC,OAAO,KAAK,CAAC;aACd;YAED,IAAM,SAAS,GAAG,wBAAS,CAAC,MAAM,CAAC,CAAC;YACpC,IAAM,SAAS,GAAG,yCAAwB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YAC7D,kFAAkF;YAClF,IAAI,SAAS,EAAE;gBACb,IAAM,KAAK,GAAG,MAAA,IAAI,KAAK,EAAE,CAAC,KAAK,mCAAI,iCAAiC,CAAC;gBACrE,SAAS,CAAC,IAAI,CAAC,6CAA2C,KAAO,CAAC,CAAC;gBACnE,SAAS,CAAC,IAAI,CACZ,+DAA6D,KAAO,CACrE,CAAC;aACH;YAED,OAAO,6BAAc,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QACvD,CAAC,CAAC;QAEF,IAAI,CAAC,OAAO,GAAG;YACb,+BAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACnC,CAAC,CAAC;QAEF,IAAI,CAAC,qBAAqB,GAAG,UAAC,OAA+B;YAC3D,OAAO,IAAI,qCAAmB,CAAC,OAAO,CAAC,CAAC;QAC1C,CAAC,CAAC;QAEF,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;QAC9B,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IAtED,oDAAoD;IACtC,gBAAQ,GAAtB;QACE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACnB,IAAI,CAAC,SAAS,GAAG,IAAI,OAAO,EAAE,CAAC;SAChC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IA4FH,cAAC;AAAD,CAAC,AAtGD,IAsGC;AAtGY,0BAAO","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 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 {\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 self.setLogger = (\n logger: DiagLogger,\n logLevel: DiagLogLevel = 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 const oldLogger = getGlobal('diag');\n const newLogger = createLogLevelDiagLogger(logLevel, logger);\n // There already is an logger registered. We'll let it know before overwriting it.\n if (oldLogger) {\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.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 /**\n * Set the global DiagLogger and DiagLogLevel.\n * If a global diag logger is already set, this will override it.\n *\n * @param logger - [Optional] The DiagLogger instance to set as the default logger.\n * @param logLevel - [Optional] The DiagLogLevel used to filter logs sent to the logger. If not provided it will default to INFO.\n * @returns true if the logger was successfully registered, else false\n */\n public setLogger!: (logger: DiagLogger, logLevel?: DiagLogLevel) => boolean;\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"]}
1
+ {"version":3,"file":"diag.js","sourceRoot":"","sources":["../../../src/api/diag.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,6DAA8D;AAC9D,oEAA2E;AAC3E,yCAMuB;AACvB,2DAIkC;AAElC,MAAM,QAAQ,GAAG,MAAM,CAAC;AAExB;;;GAGG;AACH,MAAa,OAAO;IAYlB;;;OAGG;IACH;QACE,SAAS,SAAS,CAAC,QAA0B;YAC3C,OAAO,UAAU,GAAG,IAAI;gBACtB,MAAM,MAAM,GAAG,IAAA,wBAAS,EAAC,MAAM,CAAC,CAAC;gBACjC,6BAA6B;gBAC7B,IAAI,CAAC,MAAM;oBAAE,OAAO;gBACpB,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;YACnC,CAAC,CAAC;QACJ,CAAC;QAED,mFAAmF;QACnF,MAAM,IAAI,GAAG,IAAI,CAAC;QAElB,6BAA6B;QAE7B,MAAM,SAAS,GAA+B,CAC5C,MAAM,EACN,iBAAiB,GAAG,EAAE,QAAQ,EAAE,oBAAY,CAAC,IAAI,EAAE,EACnD,EAAE;;YACF,IAAI,MAAM,KAAK,IAAI,EAAE;gBACnB,mCAAmC;gBACnC,2DAA2D;gBAC3D,qFAAqF;gBACrF,MAAM,GAAG,GAAG,IAAI,KAAK,CACnB,oIAAoI,CACrI,CAAC;gBACF,IAAI,CAAC,KAAK,CAAC,MAAA,GAAG,CAAC,KAAK,mCAAI,GAAG,CAAC,OAAO,CAAC,CAAC;gBACrC,OAAO,KAAK,CAAC;aACd;YAED,IAAI,OAAO,iBAAiB,KAAK,QAAQ,EAAE;gBACzC,iBAAiB,GAAG;oBAClB,QAAQ,EAAE,iBAAiB;iBAC5B,CAAC;aACH;YAED,MAAM,SAAS,GAAG,IAAA,wBAAS,EAAC,MAAM,CAAC,CAAC;YACpC,MAAM,SAAS,GAAG,IAAA,yCAAwB,EAAC,MAAA,iBAAiB,CAAC,QAAQ,mCAAI,oBAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YACpG,kFAAkF;YAClF,IAAI,SAAS,IAAI,CAAC,iBAAiB,CAAC,uBAAuB,EAAE;gBAC3D,MAAM,KAAK,GAAG,MAAA,IAAI,KAAK,EAAE,CAAC,KAAK,mCAAI,iCAAiC,CAAC;gBACrE,SAAS,CAAC,IAAI,CAAC,2CAA2C,KAAK,EAAE,CAAC,CAAC;gBACnE,SAAS,CAAC,IAAI,CACZ,6DAA6D,KAAK,EAAE,CACrE,CAAC;aACH;YAED,OAAO,IAAA,6BAAc,EAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QACvD,CAAC,CAAC;QAEF,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAE3B,IAAI,CAAC,OAAO,GAAG,GAAG,EAAE;YAClB,IAAA,+BAAgB,EAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACnC,CAAC,CAAC;QAEF,IAAI,CAAC,qBAAqB,GAAG,CAAC,OAA+B,EAAE,EAAE;YAC/D,OAAO,IAAI,qCAAmB,CAAC,OAAO,CAAC,CAAC;QAC1C,CAAC,CAAC;QAEF,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;QAC9B,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IA9ED,oDAAoD;IAC7C,MAAM,CAAC,QAAQ;QACpB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACnB,IAAI,CAAC,SAAS,GAAG,IAAI,OAAO,EAAE,CAAC;SAChC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CA4FF;AAtGD,0BAsGC","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(optionsOrLogLevel.logLevel ?? DiagLogLevel.INFO, logger);\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"]}
@@ -0,0 +1,28 @@
1
+ import { Meter, MeterOptions } from '../metrics/Meter';
2
+ import { MeterProvider } from '../metrics/MeterProvider';
3
+ /**
4
+ * Singleton object which represents the entry point to the OpenTelemetry Metrics API
5
+ */
6
+ export declare class MetricsAPI {
7
+ private static _instance?;
8
+ /** Empty private constructor prevents end users from constructing a new instance of the API */
9
+ private constructor();
10
+ /** Get the singleton instance of the Metrics API */
11
+ static getInstance(): MetricsAPI;
12
+ /**
13
+ * Set the current global meter provider.
14
+ * Returns true if the meter provider was successfully registered, else false.
15
+ */
16
+ setGlobalMeterProvider(provider: MeterProvider): boolean;
17
+ /**
18
+ * Returns the global meter provider.
19
+ */
20
+ getMeterProvider(): MeterProvider;
21
+ /**
22
+ * Returns a meter from the global meter provider.
23
+ */
24
+ getMeter(name: string, version?: string, options?: MeterOptions): Meter;
25
+ /** Remove the global meter provider */
26
+ disable(): void;
27
+ }
28
+ //# sourceMappingURL=metrics.d.ts.map
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright The OpenTelemetry Authors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.MetricsAPI = void 0;
19
+ const NoopMeterProvider_1 = require("../metrics/NoopMeterProvider");
20
+ const global_utils_1 = require("../internal/global-utils");
21
+ const diag_1 = require("./diag");
22
+ const API_NAME = 'metrics';
23
+ /**
24
+ * Singleton object which represents the entry point to the OpenTelemetry Metrics API
25
+ */
26
+ class MetricsAPI {
27
+ /** Empty private constructor prevents end users from constructing a new instance of the API */
28
+ constructor() { }
29
+ /** Get the singleton instance of the Metrics API */
30
+ static getInstance() {
31
+ if (!this._instance) {
32
+ this._instance = new MetricsAPI();
33
+ }
34
+ return this._instance;
35
+ }
36
+ /**
37
+ * Set the current global meter provider.
38
+ * Returns true if the meter provider was successfully registered, else false.
39
+ */
40
+ setGlobalMeterProvider(provider) {
41
+ return (0, global_utils_1.registerGlobal)(API_NAME, provider, diag_1.DiagAPI.instance());
42
+ }
43
+ /**
44
+ * Returns the global meter provider.
45
+ */
46
+ getMeterProvider() {
47
+ return (0, global_utils_1.getGlobal)(API_NAME) || NoopMeterProvider_1.NOOP_METER_PROVIDER;
48
+ }
49
+ /**
50
+ * Returns a meter from the global meter provider.
51
+ */
52
+ getMeter(name, version, options) {
53
+ return this.getMeterProvider().getMeter(name, version, options);
54
+ }
55
+ /** Remove the global meter provider */
56
+ disable() {
57
+ (0, global_utils_1.unregisterGlobal)(API_NAME, diag_1.DiagAPI.instance());
58
+ }
59
+ }
60
+ exports.MetricsAPI = MetricsAPI;
61
+ //# sourceMappingURL=metrics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/api/metrics.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAIH,oEAAmE;AACnE,2DAAuF;AACvF,iCAAiC;AAEjC,MAAM,QAAQ,GAAG,SAAS,CAAC;AAE3B;;GAEG;AACH,MAAa,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;;;OAGG;IACI,sBAAsB,CAAC,QAAuB;QACnD,OAAO,IAAA,6BAAc,EAAC,QAAQ,EAAE,QAAQ,EAAE,cAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAChE,CAAC;IAED;;OAEG;IACI,gBAAgB;QACrB,OAAO,IAAA,wBAAS,EAAC,QAAQ,CAAC,IAAI,uCAAmB,CAAC;IACpD,CAAC;IAED;;OAEG;IACI,QAAQ,CAAC,IAAY,EAAE,OAAgB,EAAE,OAAsB;QACpE,OAAO,IAAI,CAAC,gBAAgB,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAClE,CAAC;IAED,uCAAuC;IAChC,OAAO;QACZ,IAAA,+BAAgB,EAAC,QAAQ,EAAE,cAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IACjD,CAAC;CACF;AAzCD,gCAyCC","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 { Meter, MeterOptions } from '../metrics/Meter';\nimport { MeterProvider } from '../metrics/MeterProvider';\nimport { NOOP_METER_PROVIDER } from '../metrics/NoopMeterProvider';\nimport { getGlobal, registerGlobal, unregisterGlobal } from '../internal/global-utils';\nimport { DiagAPI } from './diag';\n\nconst API_NAME = 'metrics';\n\n/**\n * Singleton object which represents the entry point to the OpenTelemetry Metrics API\n */\nexport class MetricsAPI {\n private static _instance?: MetricsAPI;\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 Metrics API */\n public static getInstance(): MetricsAPI {\n if (!this._instance) {\n this._instance = new MetricsAPI();\n }\n\n return this._instance;\n }\n\n /**\n * Set the current global meter provider.\n * Returns true if the meter provider was successfully registered, else false.\n */\n public setGlobalMeterProvider(provider: MeterProvider): boolean {\n return registerGlobal(API_NAME, provider, DiagAPI.instance());\n }\n\n /**\n * Returns the global meter provider.\n */\n public getMeterProvider(): MeterProvider {\n return getGlobal(API_NAME) || NOOP_METER_PROVIDER;\n }\n\n /**\n * Returns a meter from the global meter provider.\n */\n public getMeter(name: string, version?: string, options?: MeterOptions): Meter {\n return this.getMeterProvider().getMeter(name, version, options);\n }\n\n /** Remove the global meter provider */\n public disable(): void {\n unregisterGlobal(API_NAME, DiagAPI.instance());\n }\n}\n"]}