@traccia2/sdk 0.0.1

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 (130) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +503 -0
  3. package/dist/auto.d.ts +27 -0
  4. package/dist/auto.d.ts.map +1 -0
  5. package/dist/auto.js +171 -0
  6. package/dist/auto.js.map +1 -0
  7. package/dist/config/env-config.d.ts +21 -0
  8. package/dist/config/env-config.d.ts.map +1 -0
  9. package/dist/config/env-config.js +111 -0
  10. package/dist/config/env-config.js.map +1 -0
  11. package/dist/config/pricing-config.d.ts +27 -0
  12. package/dist/config/pricing-config.d.ts.map +1 -0
  13. package/dist/config/pricing-config.js +74 -0
  14. package/dist/config/pricing-config.js.map +1 -0
  15. package/dist/config/runtime-config.d.ts +65 -0
  16. package/dist/config/runtime-config.d.ts.map +1 -0
  17. package/dist/config/runtime-config.js +97 -0
  18. package/dist/config/runtime-config.js.map +1 -0
  19. package/dist/context/context.d.ts +29 -0
  20. package/dist/context/context.d.ts.map +1 -0
  21. package/dist/context/context.js +48 -0
  22. package/dist/context/context.js.map +1 -0
  23. package/dist/exporter/console-exporter.d.ts +18 -0
  24. package/dist/exporter/console-exporter.d.ts.map +1 -0
  25. package/dist/exporter/console-exporter.js +39 -0
  26. package/dist/exporter/console-exporter.js.map +1 -0
  27. package/dist/exporter/http-exporter.d.ts +57 -0
  28. package/dist/exporter/http-exporter.d.ts.map +1 -0
  29. package/dist/exporter/http-exporter.js +181 -0
  30. package/dist/exporter/http-exporter.js.map +1 -0
  31. package/dist/exporter/index.d.ts +7 -0
  32. package/dist/exporter/index.d.ts.map +1 -0
  33. package/dist/exporter/index.js +12 -0
  34. package/dist/exporter/index.js.map +1 -0
  35. package/dist/index.d.ts +10 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +32 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/integrations/index.d.ts +9 -0
  40. package/dist/integrations/index.d.ts.map +1 -0
  41. package/dist/integrations/index.js +16 -0
  42. package/dist/integrations/index.js.map +1 -0
  43. package/dist/integrations/langchain-callback.d.ts +72 -0
  44. package/dist/integrations/langchain-callback.d.ts.map +1 -0
  45. package/dist/integrations/langchain-callback.js +201 -0
  46. package/dist/integrations/langchain-callback.js.map +1 -0
  47. package/dist/integrations/langgraph-instrumentation.d.ts +57 -0
  48. package/dist/integrations/langgraph-instrumentation.d.ts.map +1 -0
  49. package/dist/integrations/langgraph-instrumentation.js +162 -0
  50. package/dist/integrations/langgraph-instrumentation.js.map +1 -0
  51. package/dist/processor/batch-processor.d.ts +68 -0
  52. package/dist/processor/batch-processor.d.ts.map +1 -0
  53. package/dist/processor/batch-processor.js +150 -0
  54. package/dist/processor/batch-processor.js.map +1 -0
  55. package/dist/processor/cost-processor.d.ts +16 -0
  56. package/dist/processor/cost-processor.d.ts.map +1 -0
  57. package/dist/processor/cost-processor.js +50 -0
  58. package/dist/processor/cost-processor.js.map +1 -0
  59. package/dist/processor/index.d.ts +9 -0
  60. package/dist/processor/index.d.ts.map +1 -0
  61. package/dist/processor/index.js +18 -0
  62. package/dist/processor/index.js.map +1 -0
  63. package/dist/processor/logging-processor.d.ts +13 -0
  64. package/dist/processor/logging-processor.d.ts.map +1 -0
  65. package/dist/processor/logging-processor.js +26 -0
  66. package/dist/processor/logging-processor.js.map +1 -0
  67. package/dist/processor/sampler.d.ts +20 -0
  68. package/dist/processor/sampler.d.ts.map +1 -0
  69. package/dist/processor/sampler.js +33 -0
  70. package/dist/processor/sampler.js.map +1 -0
  71. package/dist/processor/token-counter.d.ts +13 -0
  72. package/dist/processor/token-counter.d.ts.map +1 -0
  73. package/dist/processor/token-counter.js +40 -0
  74. package/dist/processor/token-counter.js.map +1 -0
  75. package/dist/tracer/index.d.ts +8 -0
  76. package/dist/tracer/index.d.ts.map +1 -0
  77. package/dist/tracer/index.js +15 -0
  78. package/dist/tracer/index.js.map +1 -0
  79. package/dist/tracer/provider.d.ts +59 -0
  80. package/dist/tracer/provider.d.ts.map +1 -0
  81. package/dist/tracer/provider.js +114 -0
  82. package/dist/tracer/provider.js.map +1 -0
  83. package/dist/tracer/span-context.d.ts +23 -0
  84. package/dist/tracer/span-context.d.ts.map +1 -0
  85. package/dist/tracer/span-context.js +34 -0
  86. package/dist/tracer/span-context.js.map +1 -0
  87. package/dist/tracer/span.d.ts +49 -0
  88. package/dist/tracer/span.d.ts.map +1 -0
  89. package/dist/tracer/span.js +118 -0
  90. package/dist/tracer/span.js.map +1 -0
  91. package/dist/tracer/tracer.d.ts +28 -0
  92. package/dist/tracer/tracer.d.ts.map +1 -0
  93. package/dist/tracer/tracer.js +75 -0
  94. package/dist/tracer/tracer.js.map +1 -0
  95. package/dist/types.d.ts +135 -0
  96. package/dist/types.d.ts.map +1 -0
  97. package/dist/types.js +16 -0
  98. package/dist/types.js.map +1 -0
  99. package/package.json +79 -0
  100. package/src/__tests__/exporter.test.ts +62 -0
  101. package/src/__tests__/integrations-langchain.test.ts +384 -0
  102. package/src/__tests__/integrations-langgraph.test.ts +479 -0
  103. package/src/__tests__/processor.test.ts +89 -0
  104. package/src/__tests__/span.test.ts +103 -0
  105. package/src/__tests__/tracer.test.ts +89 -0
  106. package/src/auto.ts +198 -0
  107. package/src/config/env-config.ts +93 -0
  108. package/src/config/pricing-config.ts +84 -0
  109. package/src/config/runtime-config.ts +108 -0
  110. package/src/context/context.ts +52 -0
  111. package/src/exporter/console-exporter.ts +38 -0
  112. package/src/exporter/http-exporter.ts +188 -0
  113. package/src/exporter/index.ts +7 -0
  114. package/src/index.ts +51 -0
  115. package/src/integrations/README.md +287 -0
  116. package/src/integrations/index.ts +13 -0
  117. package/src/integrations/langchain-callback.ts +229 -0
  118. package/src/integrations/langgraph-instrumentation.ts +174 -0
  119. package/src/processor/batch-processor.ts +180 -0
  120. package/src/processor/cost-processor.ts +57 -0
  121. package/src/processor/index.ts +9 -0
  122. package/src/processor/logging-processor.ts +26 -0
  123. package/src/processor/sampler.ts +35 -0
  124. package/src/processor/token-counter.ts +42 -0
  125. package/src/tracer/index.ts +8 -0
  126. package/src/tracer/provider.ts +130 -0
  127. package/src/tracer/span-context.ts +46 -0
  128. package/src/tracer/span.ts +145 -0
  129. package/src/tracer/tracer.ts +100 -0
  130. package/src/types.ts +155 -0
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /**
3
+ * Context management for spans using async local storage.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getCurrentSpan = getCurrentSpan;
7
+ exports.setCurrentSpan = setCurrentSpan;
8
+ exports.runWithSpan = runWithSpan;
9
+ exports.runWithSpanAsync = runWithSpanAsync;
10
+ exports.getContext = getContext;
11
+ const async_hooks_1 = require("async_hooks");
12
+ const spanContext = new async_hooks_1.AsyncLocalStorage();
13
+ /**
14
+ * Get the current span from context.
15
+ */
16
+ function getCurrentSpan() {
17
+ const ctx = spanContext.getStore();
18
+ return ctx?.span;
19
+ }
20
+ /**
21
+ * Set the current span in context.
22
+ */
23
+ function setCurrentSpan(span) {
24
+ const ctx = spanContext.getStore() || {};
25
+ ctx.span = span;
26
+ if (ctx) {
27
+ spanContext.enterWith(ctx);
28
+ }
29
+ }
30
+ /**
31
+ * Run a function with a specific span as the current span.
32
+ */
33
+ function runWithSpan(span, fn) {
34
+ return spanContext.run({ span }, fn);
35
+ }
36
+ /**
37
+ * Run a function with a specific span as the current span (async).
38
+ */
39
+ function runWithSpanAsync(span, fn) {
40
+ return spanContext.run({ span }, fn);
41
+ }
42
+ /**
43
+ * Get the current context store.
44
+ */
45
+ function getContext() {
46
+ return spanContext.getStore() || {};
47
+ }
48
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/context/context.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAcH,wCAGC;AAKD,wCAMC;AAKD,kCAEC;AAKD,4CAEC;AAKD,gCAEC;AA/CD,6CAAgD;AAOhD,MAAM,WAAW,GAAG,IAAI,+BAAiB,EAAe,CAAC;AAEzD;;GAEG;AACH,SAAgB,cAAc;IAC5B,MAAM,GAAG,GAAG,WAAW,CAAC,QAAQ,EAAE,CAAC;IACnC,OAAO,GAAG,EAAE,IAAI,CAAC;AACnB,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,IAAuB;IACpD,MAAM,GAAG,GAAG,WAAW,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC;IACzC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;IAChB,IAAI,GAAG,EAAE,CAAC;QACR,WAAW,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,WAAW,CAAI,IAAW,EAAE,EAAW;IACrD,OAAO,WAAW,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;AACvC,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAI,IAAW,EAAE,EAAoB;IACnE,OAAO,WAAW,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;AACvC,CAAC;AAED;;GAEG;AACH,SAAgB,UAAU;IACxB,OAAO,WAAW,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC;AACtC,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Console Exporter for debugging purposes.
3
+ */
4
+ import { ISpan, ISpanExporter } from '../types';
5
+ /**
6
+ * Console Exporter for printing spans to console.
7
+ */
8
+ export declare class ConsoleExporter implements ISpanExporter {
9
+ /**
10
+ * Export spans to console.
11
+ */
12
+ export(spans: ISpan[]): Promise<boolean>;
13
+ /**
14
+ * Shutdown the exporter.
15
+ */
16
+ shutdown(): Promise<void>;
17
+ }
18
+ //# sourceMappingURL=console-exporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console-exporter.d.ts","sourceRoot":"","sources":["../../src/exporter/console-exporter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEhD;;GAEG;AACH,qBAAa,eAAgB,YAAW,aAAa;IACnD;;OAEG;IACI,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAkB/C;;OAEG;IACU,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAGvC"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ /**
3
+ * Console Exporter for debugging purposes.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ConsoleExporter = void 0;
7
+ /**
8
+ * Console Exporter for printing spans to console.
9
+ */
10
+ class ConsoleExporter {
11
+ /**
12
+ * Export spans to console.
13
+ */
14
+ export(spans) {
15
+ for (const span of spans) {
16
+ console.log('=== Span ===');
17
+ console.log(`Name: ${span.name}`);
18
+ console.log(`TraceId: ${span.context.traceId}`);
19
+ console.log(`SpanId: ${span.context.spanId}`);
20
+ console.log(`ParentSpanId: ${span.parentSpanId || 'none'}`);
21
+ console.log(`Duration: ${span.durationNs}ns`);
22
+ console.log(`Status: ${span.status}`);
23
+ if (span.statusDescription) {
24
+ console.log(`Status Description: ${span.statusDescription}`);
25
+ }
26
+ console.log('Attributes:', span.attributes);
27
+ console.log('Events:', span.events);
28
+ }
29
+ return Promise.resolve(true);
30
+ }
31
+ /**
32
+ * Shutdown the exporter.
33
+ */
34
+ async shutdown() {
35
+ // No-op
36
+ }
37
+ }
38
+ exports.ConsoleExporter = ConsoleExporter;
39
+ //# sourceMappingURL=console-exporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console-exporter.js","sourceRoot":"","sources":["../../src/exporter/console-exporter.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAIH;;GAEG;AACH,MAAa,eAAe;IAC1B;;OAEG;IACI,MAAM,CAAC,KAAc;QAC1B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;YAC5B,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;YAClC,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;YAChD,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;YAC9C,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,CAAC,YAAY,IAAI,MAAM,EAAE,CAAC,CAAC;YAC5D,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC;YAC9C,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;YACtC,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;gBAC3B,OAAO,CAAC,GAAG,CAAC,uBAAuB,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;YAC/D,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YAC5C,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACtC,CAAC;QACD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ;QACnB,QAAQ;IACV,CAAC;CACF;AA5BD,0CA4BC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * HTTP Exporter for sending spans to a backend service.
3
+ */
4
+ import { ISpan, ISpanExporter } from '../types';
5
+ export declare const DEFAULT_ENDPOINT = "https://api.dashboard.com/api/v1/traces";
6
+ /**
7
+ * HTTP Exporter configuration.
8
+ */
9
+ export interface HttpExporterOptions {
10
+ endpoint?: string;
11
+ apiKey?: string;
12
+ timeout?: number;
13
+ maxRetries?: number;
14
+ backoffBase?: number;
15
+ backoffJitter?: number;
16
+ }
17
+ /**
18
+ * HTTP Exporter for sending spans to a backend.
19
+ */
20
+ export declare class HttpExporter implements ISpanExporter {
21
+ private endpoint;
22
+ private apiKey?;
23
+ private timeout;
24
+ private maxRetries;
25
+ private backoffBase;
26
+ private backoffJitter;
27
+ constructor(options?: HttpExporterOptions);
28
+ /**
29
+ * Export spans to the backend.
30
+ */
31
+ export(spans: ISpan[]): Promise<boolean>;
32
+ /**
33
+ * Shutdown the exporter.
34
+ */
35
+ shutdown(): Promise<void>;
36
+ /**
37
+ * Serialize spans to JSON bytes.
38
+ */
39
+ private serializeSpans;
40
+ /**
41
+ * Get request headers.
42
+ */
43
+ private getHeaders;
44
+ /**
45
+ * Send HTTP request.
46
+ */
47
+ private sendRequest;
48
+ /**
49
+ * Compute exponential backoff with jitter.
50
+ */
51
+ private computeBackoff;
52
+ /**
53
+ * Sleep for a given number of milliseconds.
54
+ */
55
+ private sleep;
56
+ }
57
+ //# sourceMappingURL=http-exporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-exporter.d.ts","sourceRoot":"","sources":["../../src/exporter/http-exporter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEhD,eAAO,MAAM,gBAAgB,4CAA4C,CAAC;AAI1E;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,qBAAa,YAAa,YAAW,aAAa;IAChD,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,aAAa,CAAS;gBAElB,OAAO,GAAE,mBAAwB;IAS7C;;OAEG;IACG,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAkC9C;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAI/B;;OAEG;IACH,OAAO,CAAC,cAAc;IAoBtB;;OAEG;IACH,OAAO,CAAC,UAAU;IAalB;;OAEG;IACH,OAAO,CAAC,WAAW;IA0CnB;;OAEG;IACH,OAAO,CAAC,cAAc;IAMtB;;OAEG;IACH,OAAO,CAAC,KAAK;CAGd"}
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ /**
3
+ * HTTP Exporter for sending spans to a backend service.
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.HttpExporter = exports.DEFAULT_ENDPOINT = void 0;
40
+ const https = __importStar(require("https"));
41
+ const http = __importStar(require("http"));
42
+ exports.DEFAULT_ENDPOINT = 'https://api.dashboard.com/api/v1/traces';
43
+ const TRANSIENT_STATUS_CODES = new Set([429, 503, 504]);
44
+ /**
45
+ * HTTP Exporter for sending spans to a backend.
46
+ */
47
+ class HttpExporter {
48
+ constructor(options = {}) {
49
+ this.endpoint = options.endpoint || exports.DEFAULT_ENDPOINT;
50
+ this.apiKey = options.apiKey;
51
+ this.timeout = options.timeout || 10000;
52
+ this.maxRetries = options.maxRetries || 5;
53
+ this.backoffBase = options.backoffBase || 1;
54
+ this.backoffJitter = options.backoffJitter || 0.5;
55
+ }
56
+ /**
57
+ * Export spans to the backend.
58
+ */
59
+ async export(spans) {
60
+ if (spans.length === 0) {
61
+ return true;
62
+ }
63
+ const payload = this.serializeSpans(spans);
64
+ const headers = this.getHeaders();
65
+ for (let attempt = 0; attempt < this.maxRetries; attempt++) {
66
+ try {
67
+ const status = await this.sendRequest(payload, headers);
68
+ if (status >= 200 && status < 300) {
69
+ return true;
70
+ }
71
+ if (!TRANSIENT_STATUS_CODES.has(status)) {
72
+ return false;
73
+ }
74
+ const backoff = this.computeBackoff(attempt);
75
+ await this.sleep(backoff);
76
+ }
77
+ catch {
78
+ // Treat transport errors as transient
79
+ if (attempt < this.maxRetries - 1) {
80
+ const backoff = this.computeBackoff(attempt);
81
+ await this.sleep(backoff);
82
+ }
83
+ }
84
+ }
85
+ return false;
86
+ }
87
+ /**
88
+ * Shutdown the exporter.
89
+ */
90
+ async shutdown() {
91
+ // No-op for HTTP exporter
92
+ }
93
+ /**
94
+ * Serialize spans to JSON bytes.
95
+ */
96
+ serializeSpans(spans) {
97
+ const serialized = spans.map((span) => ({
98
+ traceId: span.context.traceId,
99
+ spanId: span.context.spanId,
100
+ parentSpanId: span.parentSpanId,
101
+ name: span.name,
102
+ startTimeNs: span.startTimeNs,
103
+ endTimeNs: span.endTimeNs,
104
+ durationNs: span.durationNs,
105
+ attributes: span.attributes,
106
+ events: span.events,
107
+ status: span.status,
108
+ statusDescription: span.statusDescription,
109
+ traceFlags: span.context.traceFlags,
110
+ traceState: span.context.traceState,
111
+ }));
112
+ return JSON.stringify(serialized);
113
+ }
114
+ /**
115
+ * Get request headers.
116
+ */
117
+ getHeaders() {
118
+ const headers = {
119
+ 'Content-Type': 'application/json',
120
+ 'User-Agent': 'traccia-sdk-ts/1.0.0',
121
+ };
122
+ if (this.apiKey) {
123
+ headers['Authorization'] = `Bearer ${this.apiKey}`;
124
+ }
125
+ return headers;
126
+ }
127
+ /**
128
+ * Send HTTP request.
129
+ */
130
+ sendRequest(payload, headers) {
131
+ return new Promise((resolve, reject) => {
132
+ const url = new URL(this.endpoint);
133
+ const isHttps = url.protocol === 'https:';
134
+ const client = isHttps ? https : http;
135
+ const options = {
136
+ hostname: url.hostname,
137
+ port: url.port,
138
+ path: url.pathname + url.search,
139
+ method: 'POST',
140
+ headers: {
141
+ ...headers,
142
+ 'Content-Length': Buffer.byteLength(payload),
143
+ },
144
+ timeout: this.timeout,
145
+ };
146
+ const request = client.request(options, (response) => {
147
+ response.on('data', () => {
148
+ // Consume data but don't store
149
+ });
150
+ response.on('end', () => {
151
+ resolve(response.statusCode || 500);
152
+ });
153
+ });
154
+ request.on('error', (error) => {
155
+ reject(error);
156
+ });
157
+ request.on('timeout', () => {
158
+ request.destroy();
159
+ reject(new Error('Request timeout'));
160
+ });
161
+ request.write(payload);
162
+ request.end();
163
+ });
164
+ }
165
+ /**
166
+ * Compute exponential backoff with jitter.
167
+ */
168
+ computeBackoff(attempt) {
169
+ const exponential = this.backoffBase * Math.pow(2, attempt);
170
+ const jitter = Math.random() * this.backoffJitter;
171
+ return (exponential + jitter) * 1000;
172
+ }
173
+ /**
174
+ * Sleep for a given number of milliseconds.
175
+ */
176
+ sleep(ms) {
177
+ return new Promise((resolve) => setTimeout(resolve, ms));
178
+ }
179
+ }
180
+ exports.HttpExporter = HttpExporter;
181
+ //# sourceMappingURL=http-exporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-exporter.js","sourceRoot":"","sources":["../../src/exporter/http-exporter.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAA+B;AAC/B,2CAA6B;AAGhB,QAAA,gBAAgB,GAAG,yCAAyC,CAAC;AAE1E,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAcxD;;GAEG;AACH,MAAa,YAAY;IAQvB,YAAY,UAA+B,EAAE;QAC3C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,wBAAgB,CAAC;QACrD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC;QACxC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC;QAC1C,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,CAAC,CAAC;QAC5C,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,GAAG,CAAC;IACpD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CAAC,KAAc;QACzB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QA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,CAAC;IACvC,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,EAAU;QACtB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;CACF;AAhKD,oCAgKC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Exporter module exports.
3
+ */
4
+ export { HttpExporter, DEFAULT_ENDPOINT } from './http-exporter';
5
+ export type { HttpExporterOptions } from './http-exporter';
6
+ export { ConsoleExporter } from './console-exporter';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/exporter/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACjE,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ /**
3
+ * Exporter module exports.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ConsoleExporter = exports.DEFAULT_ENDPOINT = exports.HttpExporter = void 0;
7
+ var http_exporter_1 = require("./http-exporter");
8
+ Object.defineProperty(exports, "HttpExporter", { enumerable: true, get: function () { return http_exporter_1.HttpExporter; } });
9
+ Object.defineProperty(exports, "DEFAULT_ENDPOINT", { enumerable: true, get: function () { return http_exporter_1.DEFAULT_ENDPOINT; } });
10
+ var console_exporter_1 = require("./console-exporter");
11
+ Object.defineProperty(exports, "ConsoleExporter", { enumerable: true, get: function () { return console_exporter_1.ConsoleExporter; } });
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/exporter/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iDAAiE;AAAxD,6GAAA,YAAY,OAAA;AAAE,iHAAA,gBAAgB,OAAA;AAEvC,uDAAqD;AAA5C,mHAAA,eAAe,OAAA"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Main SDK entry point.
3
+ */
4
+ export { getTracer, getTracerProvider, setTracerProvider, startTracing, stopTracing, } from './auto';
5
+ export { TracerProvider, Tracer, Span, SpanContext, } from './tracer';
6
+ export { HttpExporter, ConsoleExporter, } from './exporter';
7
+ export { Sampler, BatchSpanProcessor, TokenCountingProcessor, CostAnnotatingProcessor, LoggingSpanProcessor, } from './processor';
8
+ export type { ISpan, ITracer, ITracerProvider, ISpanContext, ISpanProcessor, ISpanExporter, ISampler, SDKConfig, Resource, SpanEvent, SamplingResult, } from './types';
9
+ export { SpanStatus } from './types';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,WAAW,GACZ,MAAM,QAAQ,CAAC;AAEhB,OAAO,EACL,cAAc,EACd,MAAM,EACN,IAAI,EACJ,WAAW,GACZ,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,YAAY,EACZ,eAAe,GAChB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,OAAO,EACP,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,KAAK,EACL,OAAO,EACP,eAAe,EACf,YAAY,EACZ,cAAc,EACd,aAAa,EACb,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,SAAS,EACT,cAAc,GACf,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /**
3
+ * Main SDK entry point.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SpanStatus = exports.LoggingSpanProcessor = exports.CostAnnotatingProcessor = exports.TokenCountingProcessor = exports.BatchSpanProcessor = exports.Sampler = exports.ConsoleExporter = exports.HttpExporter = exports.SpanContext = exports.Span = exports.Tracer = exports.TracerProvider = exports.stopTracing = exports.startTracing = exports.setTracerProvider = exports.getTracerProvider = exports.getTracer = void 0;
7
+ var auto_1 = require("./auto");
8
+ Object.defineProperty(exports, "getTracer", { enumerable: true, get: function () { return auto_1.getTracer; } });
9
+ Object.defineProperty(exports, "getTracerProvider", { enumerable: true, get: function () { return auto_1.getTracerProvider; } });
10
+ Object.defineProperty(exports, "setTracerProvider", { enumerable: true, get: function () { return auto_1.setTracerProvider; } });
11
+ Object.defineProperty(exports, "startTracing", { enumerable: true, get: function () { return auto_1.startTracing; } });
12
+ Object.defineProperty(exports, "stopTracing", { enumerable: true, get: function () { return auto_1.stopTracing; } });
13
+ var tracer_1 = require("./tracer");
14
+ Object.defineProperty(exports, "TracerProvider", { enumerable: true, get: function () { return tracer_1.TracerProvider; } });
15
+ Object.defineProperty(exports, "Tracer", { enumerable: true, get: function () { return tracer_1.Tracer; } });
16
+ Object.defineProperty(exports, "Span", { enumerable: true, get: function () { return tracer_1.Span; } });
17
+ Object.defineProperty(exports, "SpanContext", { enumerable: true, get: function () { return tracer_1.SpanContext; } });
18
+ var exporter_1 = require("./exporter");
19
+ Object.defineProperty(exports, "HttpExporter", { enumerable: true, get: function () { return exporter_1.HttpExporter; } });
20
+ Object.defineProperty(exports, "ConsoleExporter", { enumerable: true, get: function () { return exporter_1.ConsoleExporter; } });
21
+ var processor_1 = require("./processor");
22
+ Object.defineProperty(exports, "Sampler", { enumerable: true, get: function () { return processor_1.Sampler; } });
23
+ Object.defineProperty(exports, "BatchSpanProcessor", { enumerable: true, get: function () { return processor_1.BatchSpanProcessor; } });
24
+ Object.defineProperty(exports, "TokenCountingProcessor", { enumerable: true, get: function () { return processor_1.TokenCountingProcessor; } });
25
+ Object.defineProperty(exports, "CostAnnotatingProcessor", { enumerable: true, get: function () { return processor_1.CostAnnotatingProcessor; } });
26
+ Object.defineProperty(exports, "LoggingSpanProcessor", { enumerable: true, get: function () { return processor_1.LoggingSpanProcessor; } });
27
+ var types_1 = require("./types");
28
+ Object.defineProperty(exports, "SpanStatus", { enumerable: true, get: function () { return types_1.SpanStatus; } });
29
+ // Integrations (optional)
30
+ // Import from '@traccia/sdk/integrations' for framework-specific integrations
31
+ // See src/integrations/README.md for documentation
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,+BAMgB;AALd,iGAAA,SAAS,OAAA;AACT,yGAAA,iBAAiB,OAAA;AACjB,yGAAA,iBAAiB,OAAA;AACjB,oGAAA,YAAY,OAAA;AACZ,mGAAA,WAAW,OAAA;AAGb,mCAKkB;AAJhB,wGAAA,cAAc,OAAA;AACd,gGAAA,MAAM,OAAA;AACN,8FAAA,IAAI,OAAA;AACJ,qGAAA,WAAW,OAAA;AAGb,uCAGoB;AAFlB,wGAAA,YAAY,OAAA;AACZ,2GAAA,eAAe,OAAA;AAGjB,yCAMqB;AALnB,oGAAA,OAAO,OAAA;AACP,+GAAA,kBAAkB,OAAA;AAClB,mHAAA,sBAAsB,OAAA;AACtB,oHAAA,uBAAuB,OAAA;AACvB,iHAAA,oBAAoB,OAAA;AAiBtB,iCAAqC;AAA5B,mGAAA,UAAU,OAAA;AAEnB,0BAA0B;AAC1B,8EAA8E;AAC9E,mDAAmD"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Traccia SDK Integrations
3
+ * Provides automatic instrumentation for popular frameworks and libraries.
4
+ *
5
+ * @module integrations
6
+ */
7
+ export { TraciaCallbackHandler } from './langchain-callback';
8
+ export { instrumentLangGraph, createTracedNode, createTracedConditional, } from './langgraph-instrumentation';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/integrations/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ /**
3
+ * Traccia SDK Integrations
4
+ * Provides automatic instrumentation for popular frameworks and libraries.
5
+ *
6
+ * @module integrations
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createTracedConditional = exports.createTracedNode = exports.instrumentLangGraph = exports.TraciaCallbackHandler = void 0;
10
+ var langchain_callback_1 = require("./langchain-callback");
11
+ Object.defineProperty(exports, "TraciaCallbackHandler", { enumerable: true, get: function () { return langchain_callback_1.TraciaCallbackHandler; } });
12
+ var langgraph_instrumentation_1 = require("./langgraph-instrumentation");
13
+ Object.defineProperty(exports, "instrumentLangGraph", { enumerable: true, get: function () { return langgraph_instrumentation_1.instrumentLangGraph; } });
14
+ Object.defineProperty(exports, "createTracedNode", { enumerable: true, get: function () { return langgraph_instrumentation_1.createTracedNode; } });
15
+ Object.defineProperty(exports, "createTracedConditional", { enumerable: true, get: function () { return langgraph_instrumentation_1.createTracedConditional; } });
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/integrations/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,2DAA6D;AAApD,2HAAA,qBAAqB,OAAA;AAC9B,yEAIqC;AAHnC,gIAAA,mBAAmB,OAAA;AACnB,6HAAA,gBAAgB,OAAA;AAChB,oIAAA,uBAAuB,OAAA"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * LangChain callback handler for automatic tracing.
3
+ * Integrates with LangChain's callback system to automatically instrument
4
+ * LLM calls, chains, agents, and tools.
5
+ */
6
+ /**
7
+ * LangChain Callback Handler for Traccia SDK.
8
+ * Automatically traces LLM calls, chains, agents, and tools.
9
+ *
10
+ * @example
11
+ * import { ChatOpenAI } from 'langchain/chat_models/openai';
12
+ * import { LLMChain } from 'langchain/chains';
13
+ * import { TraciaCallbackHandler } from '@traccia/sdk/integrations/langchain';
14
+ *
15
+ * const handler = new TraciaCallbackHandler();
16
+ * const chain = new LLMChain({
17
+ * llm: new ChatOpenAI(),
18
+ * callbacks: [handler],
19
+ * });
20
+ *
21
+ * await chain.run({ input: 'What is 2+2?' });
22
+ * // Automatically traced with spans for LLM, chain execution, tokens, etc.
23
+ */
24
+ export declare class TraciaCallbackHandler {
25
+ private tracer;
26
+ private spanStack;
27
+ /**
28
+ * Handle LLM start - called when an LLM begins execution.
29
+ */
30
+ handleLLMStart(llm: any, prompts: string[], runId: string, _parentRunId?: string): Promise<void>;
31
+ /**
32
+ * Handle LLM end - called when an LLM finishes execution.
33
+ */
34
+ handleLLMEnd(output: any, runId: string): Promise<void>;
35
+ /**
36
+ * Handle LLM error.
37
+ */
38
+ handleLLMError(error: Error, runId: string): Promise<void>;
39
+ /**
40
+ * Handle chain start - called when a chain begins execution.
41
+ */
42
+ handleChainStart(chain: any, inputs: any, runId: string, _parentRunId?: string): Promise<void>;
43
+ /**
44
+ * Handle chain end - called when a chain finishes execution.
45
+ */
46
+ handleChainEnd(output: any, runId: string): Promise<void>;
47
+ /**
48
+ * Handle chain error.
49
+ */
50
+ handleChainError(error: Error, runId: string): Promise<void>;
51
+ /**
52
+ * Handle tool start - called when a tool is invoked.
53
+ */
54
+ handleToolStart(tool: any, input: string, runId: string, _parentRunId?: string): Promise<void>;
55
+ /**
56
+ * Handle tool end - called when a tool finishes execution.
57
+ */
58
+ handleToolEnd(output: string, runId: string): Promise<void>;
59
+ /**
60
+ * Handle tool error.
61
+ */
62
+ handleToolError(error: Error, runId: string): Promise<void>;
63
+ /**
64
+ * Handle agent action.
65
+ */
66
+ handleAgentAction(action: any, runId: string): Promise<void>;
67
+ /**
68
+ * Handle agent finish.
69
+ */
70
+ handleAgentFinish(finish: any, runId: string): Promise<void>;
71
+ }
72
+ //# sourceMappingURL=langchain-callback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"langchain-callback.d.ts","sourceRoot":"","sources":["../../src/integrations/langchain-callback.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,SAAS,CAAiC;IAElD;;OAEG;IACU,cAAc,CACzB,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,MAAM,EAAE,EACjB,KAAK,EAAE,MAAM,EACb,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,IAAI,CAAC;IAahB;;OAEG;IACU,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BpE;;OAEG;IACU,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASvE;;OAEG;IACU,gBAAgB,CAC3B,KAAK,EAAE,GAAG,EACV,MAAM,EAAE,GAAG,EACX,KAAK,EAAE,MAAM,EACb,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,IAAI,CAAC;IAchB;;OAEG;IACU,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBtE;;OAEG;IACU,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASzE;;OAEG;IACU,eAAe,CAC1B,IAAI,EAAE,GAAG,EACT,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,YA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