@zuplo/cli 7.7.7 → 7.7.9

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 (146) hide show
  1. package/node_modules/@posthog/core/dist/error-tracking/index.d.ts +1 -1
  2. package/node_modules/@posthog/core/dist/error-tracking/index.d.ts.map +1 -1
  3. package/node_modules/@posthog/core/dist/error-tracking/parsers/base.d.ts.map +1 -1
  4. package/node_modules/@posthog/core/dist/error-tracking/parsers/base.js +19 -2
  5. package/node_modules/@posthog/core/dist/error-tracking/parsers/base.mjs +19 -2
  6. package/node_modules/@posthog/core/dist/index.d.ts +7 -0
  7. package/node_modules/@posthog/core/dist/index.d.ts.map +1 -1
  8. package/node_modules/@posthog/core/dist/index.js +82 -21
  9. package/node_modules/@posthog/core/dist/index.mjs +4 -0
  10. package/node_modules/@posthog/core/dist/logs/index.d.ts +3 -2
  11. package/node_modules/@posthog/core/dist/logs/index.d.ts.map +1 -1
  12. package/node_modules/@posthog/core/dist/logs/index.js +28 -22
  13. package/node_modules/@posthog/core/dist/logs/index.mjs +29 -23
  14. package/node_modules/@posthog/core/dist/logs/logs-utils.js +1 -1
  15. package/node_modules/@posthog/core/dist/logs/logs-utils.mjs +2 -2
  16. package/node_modules/@posthog/core/dist/logs/types.d.ts +2 -2
  17. package/node_modules/@posthog/core/dist/metrics/index.d.ts +5 -2
  18. package/node_modules/@posthog/core/dist/metrics/index.d.ts.map +1 -1
  19. package/node_modules/@posthog/core/dist/metrics/index.js +28 -14
  20. package/node_modules/@posthog/core/dist/metrics/index.mjs +29 -15
  21. package/node_modules/@posthog/core/dist/metrics/metrics-utils.d.ts.map +1 -1
  22. package/node_modules/@posthog/core/dist/metrics/metrics-utils.js +1 -2
  23. package/node_modules/@posthog/core/dist/metrics/metrics-utils.mjs +2 -3
  24. package/node_modules/@posthog/core/dist/metrics/types.d.ts +7 -0
  25. package/node_modules/@posthog/core/dist/metrics/types.d.ts.map +1 -1
  26. package/node_modules/@posthog/core/dist/posthog-core-stateless.d.ts +32 -4
  27. package/node_modules/@posthog/core/dist/posthog-core-stateless.d.ts.map +1 -1
  28. package/node_modules/@posthog/core/dist/posthog-core-stateless.js +68 -20
  29. package/node_modules/@posthog/core/dist/posthog-core-stateless.mjs +68 -20
  30. package/node_modules/@posthog/core/dist/traces/config.d.ts +13 -0
  31. package/node_modules/@posthog/core/dist/traces/config.d.ts.map +1 -0
  32. package/node_modules/@posthog/core/dist/traces/config.js +101 -0
  33. package/node_modules/@posthog/core/dist/traces/config.mjs +63 -0
  34. package/node_modules/@posthog/core/dist/traces/context.d.ts +18 -0
  35. package/node_modules/@posthog/core/dist/traces/context.d.ts.map +1 -0
  36. package/node_modules/@posthog/core/dist/traces/context.js +53 -0
  37. package/node_modules/@posthog/core/dist/traces/context.mjs +15 -0
  38. package/node_modules/@posthog/core/dist/traces/ids.d.ts +12 -0
  39. package/node_modules/@posthog/core/dist/traces/ids.d.ts.map +1 -0
  40. package/node_modules/@posthog/core/dist/traces/ids.js +92 -0
  41. package/node_modules/@posthog/core/dist/traces/ids.mjs +42 -0
  42. package/node_modules/@posthog/core/dist/traces/index.d.ts +150 -0
  43. package/node_modules/@posthog/core/dist/traces/index.d.ts.map +1 -0
  44. package/node_modules/@posthog/core/dist/traces/index.js +551 -0
  45. package/node_modules/@posthog/core/dist/traces/index.mjs +513 -0
  46. package/node_modules/@posthog/core/dist/traces/otlp.d.ts +24 -0
  47. package/node_modules/@posthog/core/dist/traces/otlp.d.ts.map +1 -0
  48. package/node_modules/@posthog/core/dist/traces/otlp.js +158 -0
  49. package/node_modules/@posthog/core/dist/traces/otlp.mjs +108 -0
  50. package/node_modules/@posthog/core/dist/traces/sanitize.d.ts +32 -0
  51. package/node_modules/@posthog/core/dist/traces/sanitize.d.ts.map +1 -0
  52. package/node_modules/@posthog/core/dist/traces/sanitize.js +93 -0
  53. package/node_modules/@posthog/core/dist/traces/sanitize.mjs +43 -0
  54. package/node_modules/@posthog/core/dist/traces/span.d.ts +189 -0
  55. package/node_modules/@posthog/core/dist/traces/span.d.ts.map +1 -0
  56. package/node_modules/@posthog/core/dist/traces/span.js +533 -0
  57. package/node_modules/@posthog/core/dist/traces/span.mjs +462 -0
  58. package/node_modules/@posthog/core/dist/traces/traceparent.d.ts +51 -0
  59. package/node_modules/@posthog/core/dist/traces/traceparent.d.ts.map +1 -0
  60. package/node_modules/@posthog/core/dist/traces/traceparent.js +116 -0
  61. package/node_modules/@posthog/core/dist/traces/traceparent.mjs +63 -0
  62. package/node_modules/@posthog/core/dist/traces/types.d.ts +114 -0
  63. package/node_modules/@posthog/core/dist/traces/types.d.ts.map +1 -0
  64. package/node_modules/@posthog/core/dist/traces/types.js +18 -0
  65. package/node_modules/@posthog/core/dist/traces/types.mjs +1 -0
  66. package/node_modules/@posthog/core/dist/utils/backoff.d.ts +23 -0
  67. package/node_modules/@posthog/core/dist/utils/backoff.d.ts.map +1 -0
  68. package/node_modules/@posthog/core/dist/utils/backoff.js +65 -0
  69. package/node_modules/@posthog/core/dist/utils/backoff.mjs +14 -0
  70. package/node_modules/@posthog/core/dist/utils/flush-timer.d.ts +26 -0
  71. package/node_modules/@posthog/core/dist/utils/flush-timer.d.ts.map +1 -0
  72. package/node_modules/@posthog/core/dist/utils/flush-timer.js +67 -0
  73. package/node_modules/@posthog/core/dist/utils/flush-timer.mjs +29 -0
  74. package/node_modules/@posthog/core/dist/utils/json-utils.d.ts +7 -0
  75. package/node_modules/@posthog/core/dist/utils/json-utils.d.ts.map +1 -1
  76. package/node_modules/@posthog/core/dist/utils/json-utils.js +27 -0
  77. package/node_modules/@posthog/core/dist/utils/json-utils.mjs +25 -1
  78. package/node_modules/@posthog/core/dist/utils/otlp-resource.d.ts +13 -2
  79. package/node_modules/@posthog/core/dist/utils/otlp-resource.d.ts.map +1 -1
  80. package/node_modules/@posthog/core/dist/utils/otlp-resource.js +34 -7
  81. package/node_modules/@posthog/core/dist/utils/otlp-resource.mjs +26 -2
  82. package/node_modules/@posthog/core/dist/utils/retry-after.d.ts +55 -0
  83. package/node_modules/@posthog/core/dist/utils/retry-after.d.ts.map +1 -0
  84. package/node_modules/@posthog/core/dist/utils/retry-after.js +95 -0
  85. package/node_modules/@posthog/core/dist/utils/retry-after.mjs +50 -0
  86. package/node_modules/@posthog/core/package.json +3 -3
  87. package/node_modules/@posthog/core/src/error-tracking/index.ts +24 -1
  88. package/node_modules/@posthog/core/src/error-tracking/parsers/base.spec.ts +77 -7
  89. package/node_modules/@posthog/core/src/error-tracking/parsers/base.ts +42 -19
  90. package/node_modules/@posthog/core/src/index.ts +18 -0
  91. package/node_modules/@posthog/core/src/logs/index.spec.ts +490 -2
  92. package/node_modules/@posthog/core/src/logs/index.ts +63 -31
  93. package/node_modules/@posthog/core/src/logs/logs-utils.ts +2 -2
  94. package/node_modules/@posthog/core/src/logs/types.ts +2 -2
  95. package/node_modules/@posthog/core/src/metrics/index.spec.ts +304 -0
  96. package/node_modules/@posthog/core/src/metrics/index.ts +53 -16
  97. package/node_modules/@posthog/core/src/metrics/metrics-utils.ts +2 -3
  98. package/node_modules/@posthog/core/src/metrics/types.ts +10 -2
  99. package/node_modules/@posthog/core/src/posthog-core-stateless.ts +157 -38
  100. package/node_modules/@posthog/core/src/traces/config.spec.ts +271 -0
  101. package/node_modules/@posthog/core/src/traces/config.ts +142 -0
  102. package/node_modules/@posthog/core/src/traces/context.ts +30 -0
  103. package/node_modules/@posthog/core/src/traces/ids.spec.ts +115 -0
  104. package/node_modules/@posthog/core/src/traces/ids.ts +75 -0
  105. package/node_modules/@posthog/core/src/traces/index.spec.ts +3187 -0
  106. package/node_modules/@posthog/core/src/traces/index.ts +1060 -0
  107. package/node_modules/@posthog/core/src/traces/live-spans.spec.ts +69 -0
  108. package/node_modules/@posthog/core/src/traces/otlp.spec.ts +368 -0
  109. package/node_modules/@posthog/core/src/traces/otlp.ts +191 -0
  110. package/node_modules/@posthog/core/src/traces/sanitize.ts +116 -0
  111. package/node_modules/@posthog/core/src/traces/span.spec.ts +1122 -0
  112. package/node_modules/@posthog/core/src/traces/span.ts +822 -0
  113. package/node_modules/@posthog/core/src/traces/traceparent.spec.ts +184 -0
  114. package/node_modules/@posthog/core/src/traces/traceparent.ts +172 -0
  115. package/node_modules/@posthog/core/src/traces/types.ts +140 -0
  116. package/node_modules/@posthog/core/src/utils/backoff.ts +44 -0
  117. package/node_modules/@posthog/core/src/utils/flush-timer.ts +50 -0
  118. package/node_modules/@posthog/core/src/utils/json-utils.ts +33 -0
  119. package/node_modules/@posthog/core/src/utils/otlp-resource.spec.ts +55 -9
  120. package/node_modules/@posthog/core/src/utils/otlp-resource.ts +45 -4
  121. package/node_modules/@posthog/core/src/utils/retry-after.ts +135 -0
  122. package/node_modules/@posthog/types/dist/index.d.ts +1 -0
  123. package/node_modules/@posthog/types/dist/index.d.ts.map +1 -1
  124. package/node_modules/@posthog/types/dist/posthog-config.d.ts +10 -5
  125. package/node_modules/@posthog/types/dist/posthog-config.d.ts.map +1 -1
  126. package/node_modules/@posthog/types/dist/traces.d.ts +387 -0
  127. package/node_modules/@posthog/types/dist/traces.d.ts.map +1 -0
  128. package/node_modules/@posthog/types/dist/traces.js +18 -0
  129. package/node_modules/@posthog/types/dist/traces.mjs +1 -0
  130. package/node_modules/@posthog/types/package.json +1 -1
  131. package/node_modules/@posthog/types/src/index.ts +19 -0
  132. package/node_modules/@posthog/types/src/posthog-config.ts +10 -5
  133. package/node_modules/@posthog/types/src/traces.ts +429 -0
  134. package/node_modules/@zuplo/core/package.json +1 -1
  135. package/node_modules/@zuplo/graphql/package.json +1 -1
  136. package/node_modules/@zuplo/openapi-tools/package.json +1 -1
  137. package/node_modules/@zuplo/otel/package.json +1 -1
  138. package/node_modules/@zuplo/runtime/out/esm/{chunk-FEB2VFS7.js → chunk-KNAYKBEE.js} +96 -96
  139. package/node_modules/@zuplo/runtime/out/esm/chunk-KNAYKBEE.js.map +1 -0
  140. package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
  141. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +1 -1
  142. package/node_modules/@zuplo/runtime/out/esm/mocks/index.js +1 -1
  143. package/node_modules/@zuplo/runtime/package.json +1 -1
  144. package/package.json +11 -11
  145. package/node_modules/@zuplo/runtime/out/esm/chunk-FEB2VFS7.js.map +0 -1
  146. /package/node_modules/@zuplo/runtime/out/esm/{chunk-FEB2VFS7.js.LEGAL.txt → chunk-KNAYKBEE.js.LEGAL.txt} +0 -0
@@ -0,0 +1,18 @@
1
+ import type { Span } from '@posthog/types';
2
+ import type { SpanContextManager } from './types';
3
+ /**
4
+ * Synchronous active-span tracking: restores the previous active span when the
5
+ * callback returns, which for an async callback means when it returns its
6
+ * promise — so spans started after an `await` won't see it as active.
7
+ *
8
+ * The fallback for runtimes with no ambient async context; Node injects an
9
+ * `AsyncLocalStorage`-backed manager instead. `parent` is the escape hatch.
10
+ *
11
+ * @internal Exposed for cross-package use within this SDK; not part of the stable public API.
12
+ */
13
+ export declare class SyncSpanContextManager implements SpanContextManager {
14
+ private _active;
15
+ active(): Span | undefined;
16
+ with<T>(span: Span, fn: () => T): T;
17
+ }
18
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/traces/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAEjD;;;;;;;;;GASG;AACH,qBAAa,sBAAuB,YAAW,kBAAkB;IAC/D,OAAO,CAAC,OAAO,CAAkB;IAEjC,MAAM,IAAI,IAAI,GAAG,SAAS;IAI1B,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;CASpC"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ class SyncSpanContextManager {
31
+ active() {
32
+ return this._active;
33
+ }
34
+ with(span, fn) {
35
+ const previous = this._active;
36
+ this._active = span;
37
+ try {
38
+ return fn();
39
+ } finally{
40
+ this._active = previous;
41
+ }
42
+ }
43
+ }
44
+ __webpack_require__.d(__webpack_exports__, {
45
+ SyncSpanContextManager: ()=>SyncSpanContextManager
46
+ });
47
+ exports.SyncSpanContextManager = __webpack_exports__.SyncSpanContextManager;
48
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
49
+ "SyncSpanContextManager"
50
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
51
+ Object.defineProperty(exports, '__esModule', {
52
+ value: true
53
+ });
@@ -0,0 +1,15 @@
1
+ class SyncSpanContextManager {
2
+ active() {
3
+ return this._active;
4
+ }
5
+ with(span, fn) {
6
+ const previous = this._active;
7
+ this._active = span;
8
+ try {
9
+ return fn();
10
+ } finally{
11
+ this._active = previous;
12
+ }
13
+ }
14
+ }
15
+ export { SyncSpanContextManager };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Random bytes from the platform's CSPRNG, falling back to `Math.random`.
3
+ *
4
+ * The fallback exists for React Native, which has no global `crypto` without a
5
+ * polyfill. Trace ids need collision resistance, not unpredictability.
6
+ */
7
+ export declare function getRandomBytes(byteLength: number): Uint8Array;
8
+ export declare function newTraceId(): string;
9
+ export declare function newSpanId(): string;
10
+ export declare function isValidTraceId(value: unknown): value is string;
11
+ export declare function isValidSpanId(value: unknown): value is string;
12
+ //# sourceMappingURL=ids.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../src/traces/ids.ts"],"names":[],"mappings":"AAkBA;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,CAe7D;AAiBD,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAMD,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE9D;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE7D"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ const TRACE_ID_BYTES = 16;
31
+ const SPAN_ID_BYTES = 8;
32
+ const TRACE_ID_HEX = 2 * TRACE_ID_BYTES;
33
+ const SPAN_ID_HEX = 2 * SPAN_ID_BYTES;
34
+ const INVALID_TRACE_ID = '0'.repeat(TRACE_ID_HEX);
35
+ const INVALID_SPAN_ID = '0'.repeat(SPAN_ID_HEX);
36
+ const HEX_RE = /^[0-9a-f]+$/;
37
+ function getRandomBytes(byteLength) {
38
+ const bytes = new Uint8Array(byteLength);
39
+ const cryptoLike = globalThis.crypto;
40
+ if (cryptoLike && 'function' == typeof cryptoLike.getRandomValues) try {
41
+ cryptoLike.getRandomValues(bytes);
42
+ return bytes;
43
+ } catch {}
44
+ for(let i = 0; i < byteLength; i++)bytes[i] = Math.floor(256 * Math.random());
45
+ return bytes;
46
+ }
47
+ function bytesToHex(bytes) {
48
+ let hex = '';
49
+ for(let i = 0; i < bytes.length; i++)hex += bytes[i].toString(16).padStart(2, '0');
50
+ return hex;
51
+ }
52
+ function randomHexId(byteLength) {
53
+ const hex = bytesToHex(getRandomBytes(byteLength));
54
+ return /[^0]/.test(hex) ? hex : hex.slice(0, -1) + '1';
55
+ }
56
+ function newTraceId() {
57
+ return randomHexId(TRACE_ID_BYTES);
58
+ }
59
+ function newSpanId() {
60
+ return randomHexId(SPAN_ID_BYTES);
61
+ }
62
+ function isValidHexId(value, length, invalid) {
63
+ return 'string' == typeof value && value.length === length && value !== invalid && HEX_RE.test(value);
64
+ }
65
+ function isValidTraceId(value) {
66
+ return isValidHexId(value, TRACE_ID_HEX, INVALID_TRACE_ID);
67
+ }
68
+ function isValidSpanId(value) {
69
+ return isValidHexId(value, SPAN_ID_HEX, INVALID_SPAN_ID);
70
+ }
71
+ __webpack_require__.d(__webpack_exports__, {
72
+ getRandomBytes: ()=>getRandomBytes,
73
+ isValidSpanId: ()=>isValidSpanId,
74
+ isValidTraceId: ()=>isValidTraceId,
75
+ newSpanId: ()=>newSpanId,
76
+ newTraceId: ()=>newTraceId
77
+ });
78
+ exports.getRandomBytes = __webpack_exports__.getRandomBytes;
79
+ exports.isValidSpanId = __webpack_exports__.isValidSpanId;
80
+ exports.isValidTraceId = __webpack_exports__.isValidTraceId;
81
+ exports.newSpanId = __webpack_exports__.newSpanId;
82
+ exports.newTraceId = __webpack_exports__.newTraceId;
83
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
84
+ "getRandomBytes",
85
+ "isValidSpanId",
86
+ "isValidTraceId",
87
+ "newSpanId",
88
+ "newTraceId"
89
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
90
+ Object.defineProperty(exports, '__esModule', {
91
+ value: true
92
+ });
@@ -0,0 +1,42 @@
1
+ const TRACE_ID_BYTES = 16;
2
+ const SPAN_ID_BYTES = 8;
3
+ const TRACE_ID_HEX = 2 * TRACE_ID_BYTES;
4
+ const SPAN_ID_HEX = 2 * SPAN_ID_BYTES;
5
+ const INVALID_TRACE_ID = '0'.repeat(TRACE_ID_HEX);
6
+ const INVALID_SPAN_ID = '0'.repeat(SPAN_ID_HEX);
7
+ const HEX_RE = /^[0-9a-f]+$/;
8
+ function getRandomBytes(byteLength) {
9
+ const bytes = new Uint8Array(byteLength);
10
+ const cryptoLike = globalThis.crypto;
11
+ if (cryptoLike && 'function' == typeof cryptoLike.getRandomValues) try {
12
+ cryptoLike.getRandomValues(bytes);
13
+ return bytes;
14
+ } catch {}
15
+ for(let i = 0; i < byteLength; i++)bytes[i] = Math.floor(256 * Math.random());
16
+ return bytes;
17
+ }
18
+ function bytesToHex(bytes) {
19
+ let hex = '';
20
+ for(let i = 0; i < bytes.length; i++)hex += bytes[i].toString(16).padStart(2, '0');
21
+ return hex;
22
+ }
23
+ function randomHexId(byteLength) {
24
+ const hex = bytesToHex(getRandomBytes(byteLength));
25
+ return /[^0]/.test(hex) ? hex : hex.slice(0, -1) + '1';
26
+ }
27
+ function newTraceId() {
28
+ return randomHexId(TRACE_ID_BYTES);
29
+ }
30
+ function newSpanId() {
31
+ return randomHexId(SPAN_ID_BYTES);
32
+ }
33
+ function isValidHexId(value, length, invalid) {
34
+ return 'string' == typeof value && value.length === length && value !== invalid && HEX_RE.test(value);
35
+ }
36
+ function isValidTraceId(value) {
37
+ return isValidHexId(value, TRACE_ID_HEX, INVALID_TRACE_ID);
38
+ }
39
+ function isValidSpanId(value) {
40
+ return isValidHexId(value, SPAN_ID_HEX, INVALID_SPAN_ID);
41
+ }
42
+ export { getRandomBytes, isValidSpanId, isValidTraceId, newSpanId, newTraceId };
@@ -0,0 +1,150 @@
1
+ import type { Span, StartSpanOptions } from '@posthog/types';
2
+ import type { Logger } from '../types';
3
+ import type { ResolvedTracesConfig, SpanContextManager, TraceSdkContext, TracesHost } from './types';
4
+ type SpanCallback<T> = (span: Span) => T;
5
+ /**
6
+ * The traces pipeline: span creation, active-span parenting, and OTLP export.
7
+ * Separate from the analytics-events pipeline — own queue, endpoint and flush
8
+ * cycle — mirroring logs and metrics.
9
+ *
10
+ * @internal Exposed for cross-package use within this SDK; not part of the stable public API.
11
+ */
12
+ export declare class PostHogTraces {
13
+ private readonly _instance;
14
+ private readonly _config;
15
+ private readonly _logger;
16
+ private readonly _getContext;
17
+ private readonly _contextManager;
18
+ /** Told when a span joins the queue, so a serverless host can keep the invocation alive. */
19
+ private readonly _onSpanQueued?;
20
+ private _queue;
21
+ private readonly _flushTimer;
22
+ private _flushPromise;
23
+ private _backgroundFlush?;
24
+ private _maxExportBatchSize;
25
+ private _droppedSinceWarning;
26
+ private _lastDropWarningAt;
27
+ private _dropReasons;
28
+ private _consecutiveFlushFailures;
29
+ private _flushJitter;
30
+ private _retryAfter;
31
+ private _headBatchFailures;
32
+ private _headBatchSize;
33
+ private _headBatchChargeableAt;
34
+ private _generation;
35
+ private _liveSpans;
36
+ constructor(_instance: TracesHost, _config: ResolvedTracesConfig, _logger: Logger, _getContext: () => TraceSdkContext, _contextManager: SpanContextManager,
37
+ /** Told when a span joins the queue, so a serverless host can keep the invocation alive. */
38
+ _onSpanQueued?: (() => void) | undefined);
39
+ /**
40
+ * Starts a span without making it active. Always returns a handle — an inert
41
+ * one when tracing cannot run — so calling code never branches.
42
+ */
43
+ startSpan(name: string, options?: StartSpanOptions): Span;
44
+ /**
45
+ * Runs a callback with a span active for its duration and guarantees the span
46
+ * ends — at return for a sync callback, at settle for an async one.
47
+ *
48
+ * A throw or rejection is recorded on the span and rethrown unmodified: the
49
+ * SDK never swallows application control flow.
50
+ */
51
+ withSpan<T>(name: string, fn: SpanCallback<T>): T;
52
+ withSpan<T>(name: string, options: StartSpanOptions, fn: SpanCallback<T>): T;
53
+ /** The active span, or `null` outside any `withSpan` callback. */
54
+ getActiveSpan(): Span | null;
55
+ /**
56
+ * Drains the span queue in repeated passes: joining a single in-flight pass
57
+ * would leave spans enqueued after its watermark behind.
58
+ *
59
+ * A pass reports spans removed — queue length can't stand in, since a send
60
+ * concurrent with an arrival leaves it unchanged.
61
+ *
62
+ * An open `Retry-After` window does not stop this: an explicit flush, or one a
63
+ * host runs to keep a request alive, sends whatever is queued — a serverless
64
+ * isolate may not be around for the armed timer to fire. The window is honoured
65
+ * by not charging such an attempt against the head batch's retry budget, so the
66
+ * wait costs a request rather than the spans. The periodic flush does wait it
67
+ * out.
68
+ */
69
+ /**
70
+ * Whether the endpoint has asked this queue to wait. An automatic flush skips
71
+ * it; the traces flush timer already drains once the window closes.
72
+ */
73
+ get throttled(): boolean;
74
+ flush(): Promise<void>;
75
+ private _startFlush;
76
+ /** Clears the queue and timer. Used on shutdown and between tests. */
77
+ reset(): void;
78
+ /** Called wherever the head batch leaves or changes shape, so its budget goes with it. */
79
+ private _resetHeadBatchBudget;
80
+ /**
81
+ * Resolves a span's parent: an explicit `parent`, then the active span, then a
82
+ * fresh root. A no-op explicit parent is rejected earlier, in `startSpan`.
83
+ */
84
+ private _resolveParent;
85
+ /**
86
+ * PostHog context snapshotted at span start. These are the product's join
87
+ * keys — they're what makes a span reachable from a person or a session.
88
+ */
89
+ private _autoContextAttributes;
90
+ /**
91
+ * Records a callback failure on the span: an `exception` event always, plus
92
+ * status `error` unless the callback explicitly marked the span `ok`.
93
+ */
94
+ private _recordCallbackError;
95
+ /**
96
+ * Drops live accounting for spans older than `maxSpanAgeMs`. An evicted span
97
+ * is never exported — its `end()` finds no entry — so one leak returns its
98
+ * slot instead of disabling tracing for the rest of the process.
99
+ */
100
+ private _evictAgedSpans;
101
+ private _onSpanEnd;
102
+ /**
103
+ * One diagnostic per span when its limits discarded anything, which is what
104
+ * OTel asks for. Counted after the post-hook pass, so drops a `beforeSpanSend`
105
+ * hook caused are included.
106
+ */
107
+ private _reportLimitDrops;
108
+ /**
109
+ * Runs the `beforeSpanSend` chain, returning the span to enqueue or `null` to
110
+ * drop it.
111
+ *
112
+ * A throwing hook drops the span: the hook is the documented scrubbing point,
113
+ * so a broken scrubber must not let the unscrubbed record through. Identity
114
+ * fields are restored afterwards, since rewriting them orphans shipped children.
115
+ */
116
+ private _runBeforeSpanSend;
117
+ /**
118
+ * Restores the fields a hook must not change. Runs per hook so a later hook in
119
+ * the chain cannot sample on an id an earlier one forged.
120
+ */
121
+ private _keepSpanIdentity;
122
+ private _recordDrop;
123
+ /** At most one warning per flush pass, naming the total and every reason behind it. */
124
+ private _warnAboutDrops;
125
+ /**
126
+ * Encodes a batch, dropping any span whose attributes can't be encoded.
127
+ * An unguarded throw here would leave the queue unspliced, so every later
128
+ * flush would die on the same span.
129
+ */
130
+ private _encodeBatch;
131
+ /**
132
+ * Discards the queue when consent has been withdrawn, returning how many spans
133
+ * it dropped. Spans carry `posthogDistinctId` and `sessionId`, so anything still
134
+ * queued when the user opts out must not be exported.
135
+ */
136
+ private _discardQueueIfConsentWithdrawn;
137
+ /** Returns how many spans it removed from the queue, sent or dropped. */
138
+ private _flushInner;
139
+ /**
140
+ * One background drain at a time. `flush()` is a multi-pass loop that keeps
141
+ * going while the queue stays above the batch size, so a trigger per span end
142
+ * would stack a loop per span on a busy service — each retaining its frames.
143
+ */
144
+ private _flushInBackground;
145
+ private _armFlushTimerIfQueued;
146
+ private _armFlushTimerIfQueuedNoEarlierThan;
147
+ private _nextFlushDelay;
148
+ }
149
+ export {};
150
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/traces/index.ts"],"names":[],"mappings":"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"}