@fallom/trace 0.1.0 → 0.1.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.
package/README.md CHANGED
@@ -14,12 +14,14 @@ npm install @fallom/trace @traceloop/node-server-sdk
14
14
  ## Quick Start
15
15
 
16
16
  ```typescript
17
+ // ⚠️ IMPORTANT: Import and initialize Fallom BEFORE importing OpenAI!
17
18
  import fallom from '@fallom/trace';
18
- import OpenAI from 'openai';
19
19
 
20
- // Initialize FIRST - before importing your LLM libraries
21
20
  fallom.init({ apiKey: 'your-api-key' });
22
21
 
22
+ // NOW import OpenAI (after instrumentation is set up)
23
+ const { default: OpenAI } = await import('openai');
24
+
23
25
  // Set default session context for tracing
24
26
  fallom.trace.setSession('my-agent', sessionId);
25
27
 
@@ -31,6 +33,8 @@ const response = await openai.chat.completions.create({
31
33
  });
32
34
  ```
33
35
 
36
+ > ⚠️ **Import Order Matters!** Auto-instrumentation hooks into libraries when they're imported. You must call `fallom.init()` BEFORE importing `openai`, `@anthropic-ai/sdk`, etc. Use dynamic imports (`await import('openai')`) to ensure correct order.
37
+
34
38
  ## Model A/B Testing
35
39
 
36
40
  Run A/B tests on models with zero latency. Same session always gets same model (sticky assignment).
@@ -99,15 +103,18 @@ Auto-capture all LLM calls with OpenTelemetry instrumentation.
99
103
  ### Automatic Tracing
100
104
 
101
105
  ```typescript
106
+ // Step 1: Import and init Fallom FIRST
102
107
  import fallom from '@fallom/trace';
103
-
104
- // Initialize before making LLM calls
105
108
  fallom.init();
106
109
 
107
- // Set session context
110
+ // Step 2: Dynamic import OpenAI AFTER init
111
+ const { default: OpenAI } = await import('openai');
112
+ const openai = new OpenAI();
113
+
114
+ // Step 3: Set session context
108
115
  fallom.trace.setSession('my-agent', sessionId);
109
116
 
110
- // All LLM calls automatically traced with:
117
+ // Step 4: Make LLM calls - automatically traced with:
111
118
  // - Model, tokens, latency
112
119
  // - Prompts and completions
113
120
  // - Your config_key and session_id
@@ -117,6 +124,11 @@ const response = await openai.chat.completions.create({
117
124
  });
118
125
  ```
119
126
 
127
+ > **Required dependency:** Install `@traceloop/node-server-sdk` for auto-instrumentation:
128
+ > ```bash
129
+ > npm install @traceloop/node-server-sdk
130
+ > ```
131
+
120
132
  ### Async Context Propagation
121
133
 
122
134
  For proper session context across async boundaries, use `runWithSession`:
@@ -269,6 +281,8 @@ See the `../examples/` folder for complete examples:
269
281
 
270
282
  - Node.js >= 18.0.0
271
283
 
284
+ > ⚠️ **Bun Compatibility:** Auto-tracing uses OpenTelemetry instrumentation which relies on Node.js module hooks. **Bun has limited support** for this. For full tracing functionality, use Node.js. A/B testing (`models.get()`) works fine in Bun.
285
+
272
286
  ## License
273
287
 
274
288
  MIT
package/dist/index.js CHANGED
@@ -727,12 +727,15 @@ function init(options = {}) {
727
727
  }
728
728
  function autoInstrument() {
729
729
  try {
730
- const { Traceloop } = require("@traceloop/node-server-sdk");
730
+ const traceloopModule = require("@traceloop/node-server-sdk");
731
+ const Traceloop = traceloopModule.Traceloop || traceloopModule.default?.Traceloop || traceloopModule;
732
+ if (!Traceloop?.initialize) {
733
+ return;
734
+ }
731
735
  Traceloop.initialize({
732
- baseUrl: `${baseUrl}/v1/traces`,
736
+ baseUrl,
733
737
  apiKey,
734
- disableBatch: false,
735
- // Respect capture content setting
738
+ disableBatch: true,
736
739
  traceContent: captureContent
737
740
  });
738
741
  } catch {
package/dist/index.mjs CHANGED
@@ -710,12 +710,15 @@ function init(options = {}) {
710
710
  }
711
711
  function autoInstrument() {
712
712
  try {
713
- const { Traceloop } = __require("@traceloop/node-server-sdk");
713
+ const traceloopModule = __require("@traceloop/node-server-sdk");
714
+ const Traceloop = traceloopModule.Traceloop || traceloopModule.default?.Traceloop || traceloopModule;
715
+ if (!Traceloop?.initialize) {
716
+ return;
717
+ }
714
718
  Traceloop.initialize({
715
- baseUrl: `${baseUrl}/v1/traces`,
719
+ baseUrl,
716
720
  apiKey,
717
- disableBatch: false,
718
- // Respect capture content setting
721
+ disableBatch: true,
719
722
  traceContent: captureContent
720
723
  });
721
724
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fallom/trace",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Model A/B testing and tracing for LLM applications. Zero latency, production-ready.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -44,7 +44,8 @@
44
44
  "@opentelemetry/sdk-node": "^0.46.0",
45
45
  "@opentelemetry/sdk-trace-node": "^1.19.0",
46
46
  "@opentelemetry/exporter-trace-otlp-http": "^0.46.0",
47
- "@traceloop/node-server-sdk": "^0.5.0"
47
+ "@traceloop/node-server-sdk": "^0.5.0",
48
+ "tslib": "^2.6.0"
48
49
  },
49
50
  "devDependencies": {
50
51
  "@types/node": "^20.10.0",
@@ -56,4 +57,3 @@
56
57
  "node": ">=18.0.0"
57
58
  }
58
59
  }
59
-