@usefarol/sdk 0.1.1 → 0.1.2

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
@@ -147,6 +147,18 @@ await pipeline("What is Farol?");
147
147
 
148
148
  Set `captureIo: true` in `trace` options to include `span.input` / `span.output` in the payload (only when you assign them). **Do not enable for sensitive data** without reviewing compliance needs.
149
149
 
150
+ ## Sampling
151
+
152
+ Set `sampleRate` to reduce the percentage of runs sent to Farol. Errors are always sent regardless of sample rate.
153
+
154
+ ```typescript
155
+ const myAgent = trace(fn, {
156
+ agentName: "my-agent",
157
+ farolKey: "frl_...",
158
+ sampleRate: 0.1, // send 10% of successful runs
159
+ });
160
+ ```
161
+
150
162
  ## Options
151
163
 
152
164
  | Option | Description |
@@ -157,6 +169,7 @@ Set `captureIo: true` in `trace` options to include `span.input` / `span.output`
157
169
  | `model` | Model label on the run |
158
170
  | `costPer1kInputTokens` / `costPer1kOutputTokens` | USD per 1k tokens for cost estimates |
159
171
  | `captureIo` | When `true`, include span `input`/`output` if set |
172
+ | `sampleRate` | Fraction of successful runs to send (`0.0`–`1.0`). Errors always sent. Default `1.0`. |
160
173
 
161
174
  ## Build (from source)
162
175
 
package/dist/index.d.mts CHANGED
@@ -6,6 +6,8 @@ interface TraceOptions {
6
6
  costPer1kInputTokens?: number;
7
7
  costPer1kOutputTokens?: number;
8
8
  captureIo?: boolean;
9
+ /** 0.0 to 1.0, default 1.0 */
10
+ sampleRate?: number;
9
11
  }
10
12
  interface SpanOptions {
11
13
  type?: "tool" | "llm";
package/dist/index.d.ts CHANGED
@@ -6,6 +6,8 @@ interface TraceOptions {
6
6
  costPer1kInputTokens?: number;
7
7
  costPer1kOutputTokens?: number;
8
8
  captureIo?: boolean;
9
+ /** 0.0 to 1.0, default 1.0 */
10
+ sampleRate?: number;
9
11
  }
10
12
  interface SpanOptions {
11
13
  type?: "tool" | "llm";
package/dist/index.js CHANGED
@@ -91,7 +91,8 @@ function trace(fn, options) {
91
91
  model = "unknown",
92
92
  costPer1kInputTokens = 25e-5,
93
93
  costPer1kOutputTokens = 125e-5,
94
- captureIo = false
94
+ captureIo = false,
95
+ sampleRate = 1
95
96
  } = options;
96
97
  if (captureIo) {
97
98
  console.warn(
@@ -117,7 +118,12 @@ function trace(fn, options) {
117
118
  for (const span of run.spans) {
118
119
  if (!span.endedAt) span.end();
119
120
  }
120
- await sendToFarol(run, farolKey, farolEndpoint, captureIo);
121
+ const shouldSend = run.status === "error" || Math.random() <= sampleRate;
122
+ if (shouldSend) {
123
+ await sendToFarol(run, farolKey, farolEndpoint, captureIo);
124
+ } else {
125
+ console.log(`[Farol] Run sampled out (sampleRate=${sampleRate})`);
126
+ }
121
127
  }
122
128
  };
123
129
  }
package/dist/index.mjs CHANGED
@@ -65,7 +65,8 @@ function trace(fn, options) {
65
65
  model = "unknown",
66
66
  costPer1kInputTokens = 25e-5,
67
67
  costPer1kOutputTokens = 125e-5,
68
- captureIo = false
68
+ captureIo = false,
69
+ sampleRate = 1
69
70
  } = options;
70
71
  if (captureIo) {
71
72
  console.warn(
@@ -91,7 +92,12 @@ function trace(fn, options) {
91
92
  for (const span of run.spans) {
92
93
  if (!span.endedAt) span.end();
93
94
  }
94
- await sendToFarol(run, farolKey, farolEndpoint, captureIo);
95
+ const shouldSend = run.status === "error" || Math.random() <= sampleRate;
96
+ if (shouldSend) {
97
+ await sendToFarol(run, farolKey, farolEndpoint, captureIo);
98
+ } else {
99
+ console.log(`[Farol] Run sampled out (sampleRate=${sampleRate})`);
100
+ }
95
101
  }
96
102
  };
97
103
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usefarol/sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "AI agent observability SDK for Node.js — plug-and-play monitoring for your agents",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/index.ts CHANGED
@@ -9,6 +9,8 @@ export interface TraceOptions {
9
9
  costPer1kInputTokens?: number;
10
10
  costPer1kOutputTokens?: number;
11
11
  captureIo?: boolean;
12
+ /** 0.0 to 1.0, default 1.0 */
13
+ sampleRate?: number;
12
14
  }
13
15
 
14
16
  export interface SpanOptions {
@@ -109,6 +111,7 @@ export function trace<T extends unknown[], R>(
109
111
  costPer1kInputTokens = 0.00025,
110
112
  costPer1kOutputTokens = 0.00125,
111
113
  captureIo = false,
114
+ sampleRate = 1.0,
112
115
  } = options;
113
116
 
114
117
  if (captureIo) {
@@ -142,7 +145,13 @@ export function trace<T extends unknown[], R>(
142
145
  if (!span.endedAt) span.end();
143
146
  }
144
147
 
145
- await sendToFarol(run, farolKey, farolEndpoint, captureIo);
148
+ const shouldSend =
149
+ run.status === "error" || Math.random() <= sampleRate;
150
+ if (shouldSend) {
151
+ await sendToFarol(run, farolKey, farolEndpoint, captureIo);
152
+ } else {
153
+ console.log(`[Farol] Run sampled out (sampleRate=${sampleRate})`);
154
+ }
146
155
  }
147
156
  };
148
157
  }