@lmnr-ai/lmnr 0.7.13-alpha.1 → 0.8.0-alpha.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/dist/cli.cjs +1 -1
- package/dist/cli.d.cts +1 -1
- package/dist/cli.d.mts +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/{client-Cnj-Zfa4.mjs → client-BmOjmnjR.mjs} +2 -2
- package/dist/{client-Cnj-Zfa4.mjs.map → client-BmOjmnjR.mjs.map} +1 -1
- package/dist/{client-CPYdIP16.cjs → client-VmPk12gK.cjs} +2 -2
- package/dist/{client-CPYdIP16.cjs.map → client-VmPk12gK.cjs.map} +1 -1
- package/dist/{evaluations-C6jDSeZI.d.cts → evaluations-BE5hm0RG.d.cts} +7 -2
- package/dist/{evaluations-DQmES9uI.d.mts → evaluations-CL4yZPJK.d.mts} +7 -2
- package/dist/index.cjs +109 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +74 -6
- package/dist/index.d.mts +74 -6
- package/dist/index.mjs +109 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as TracingLevel, _ as MaskInputOptions, a as HumanEvaluator, b as SpanType, c as EvaluationDataset, d as StringUUID, f as Dataset, g as LaminarSpanContext, h as Event, i as EvaluatorFunctionReturn, l as LaminarDataset, m as EvaluationDatapointDatasetLink, o as evaluate, p as EvaluationDatapoint, r as EvaluatorFunction, s as InitializeOptions, t as Datapoint, u as LaminarClient, v as PushDatapointsResponse, x as TraceType, y as SessionRecordingOptions } from "./evaluations-
|
|
1
|
+
import { S as TracingLevel, _ as MaskInputOptions, a as HumanEvaluator, b as SpanType, c as EvaluationDataset, d as StringUUID, f as Dataset, g as LaminarSpanContext, h as Event, i as EvaluatorFunctionReturn, l as LaminarDataset, m as EvaluationDatapointDatasetLink, o as evaluate, p as EvaluationDatapoint, r as EvaluatorFunction, s as InitializeOptions, t as Datapoint, u as LaminarClient, v as PushDatapointsResponse, x as TraceType, y as SessionRecordingOptions } from "./evaluations-BE5hm0RG.cjs";
|
|
2
2
|
import { AttributeValue, Context, Span, Span as Span$1, TimeInput, Tracer, TracerProvider } from "@opentelemetry/api";
|
|
3
3
|
import { ReadableSpan, Span as Span$2, SpanExporter, SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
4
4
|
import * as AI from "ai";
|
|
@@ -60,7 +60,7 @@ declare function observe<A extends unknown[], F extends (...args: A) => ReturnTy
|
|
|
60
60
|
parentSpanContext,
|
|
61
61
|
metadata,
|
|
62
62
|
tags
|
|
63
|
-
}: ObserveOptions, fn: F, ...args: A):
|
|
63
|
+
}: ObserveOptions, fn: F, ...args: A): ReturnType<F>;
|
|
64
64
|
/**
|
|
65
65
|
* Sets the tracing level for any spans inside the function. This is useful for
|
|
66
66
|
* conditionally disabling the tracing for certain functions.
|
|
@@ -83,6 +83,12 @@ declare function observe<A extends unknown[], F extends (...args: A) => ReturnTy
|
|
|
83
83
|
declare function withTracingLevel<A extends unknown[], F extends (...args: A) => ReturnType<F>>(tracingLevel: TracingLevel, fn: F, ...args: A): ReturnType<F>;
|
|
84
84
|
/**
|
|
85
85
|
* Decorator that wraps a method to automatically observe it with Laminar tracing.
|
|
86
|
+
* This decorator uses the TypeScript 5.0+ standard decorator syntax.
|
|
87
|
+
*
|
|
88
|
+
* **Important**: Use this decorator only if your `tsconfig.json` does NOT have
|
|
89
|
+
* `experimentalDecorators: true`. If you're using experimental decorators, use
|
|
90
|
+
* {@link observeExperimentalDecorator} instead.
|
|
91
|
+
*
|
|
86
92
|
* This decorator can be used on class methods to automatically create spans.
|
|
87
93
|
*
|
|
88
94
|
* @param config - Configuration for the observe decorator, can be static or a function
|
|
@@ -90,6 +96,13 @@ declare function withTracingLevel<A extends unknown[], F extends (...args: A) =>
|
|
|
90
96
|
*
|
|
91
97
|
* @example
|
|
92
98
|
* ```typescript
|
|
99
|
+
* // In your tsconfig.json, ensure experimentalDecorators is NOT enabled:
|
|
100
|
+
* // {
|
|
101
|
+
* // "compilerOptions": {
|
|
102
|
+
* // "experimentalDecorators": false // or omit this line
|
|
103
|
+
* // }
|
|
104
|
+
* // }
|
|
105
|
+
*
|
|
93
106
|
* import { observeDecorator } from '@lmnr-ai/lmnr';
|
|
94
107
|
*
|
|
95
108
|
* class MyService {
|
|
@@ -109,7 +122,53 @@ declare function withTracingLevel<A extends unknown[], F extends (...args: A) =>
|
|
|
109
122
|
* }
|
|
110
123
|
* ```
|
|
111
124
|
*/
|
|
112
|
-
declare function observeDecorator(config: Partial<ObserveOptions> | ((thisArg:
|
|
125
|
+
declare function observeDecorator<This, Args extends unknown[], Return>(config: Partial<ObserveOptions> | ((thisArg: This, ...funcArgs: Args) => Partial<ObserveOptions>)): (originalMethod: (this: This, ...args: Args) => Return, context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
|
|
126
|
+
/**
|
|
127
|
+
* Decorator that wraps a method to automatically observe it with Laminar tracing.
|
|
128
|
+
* This decorator uses the legacy experimental decorator syntax
|
|
129
|
+
* (requires `--experimentalDecorators` flag).
|
|
130
|
+
*
|
|
131
|
+
* **Important**: Use this decorator only if your `tsconfig.json` has
|
|
132
|
+
* `experimentalDecorators: true` in the `compilerOptions` section
|
|
133
|
+
* (or if you compile with the `--experimentalDecorators` flag).
|
|
134
|
+
* For TypeScript 5.0+ projects without experimental decorators, use
|
|
135
|
+
* {@link observeDecorator} instead.
|
|
136
|
+
*
|
|
137
|
+
* This decorator can be used on class methods to automatically create spans.
|
|
138
|
+
*
|
|
139
|
+
* Use this only if you need the legacy experimental decorator syntax.
|
|
140
|
+
* @param config - Configuration for the observe decorator, can be static or a function
|
|
141
|
+
* @returns A method decorator
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* // In your tsconfig.json, ensure experimentalDecorators is enabled:
|
|
146
|
+
* // {
|
|
147
|
+
* // "compilerOptions": {
|
|
148
|
+
* // "experimentalDecorators": true
|
|
149
|
+
* // }
|
|
150
|
+
* // }
|
|
151
|
+
*
|
|
152
|
+
* import { observeExperimentalDecorator } from '@lmnr-ai/lmnr';
|
|
153
|
+
*
|
|
154
|
+
* class MyService {
|
|
155
|
+
* @observeExperimentalDecorator({ name: 'processData', spanType: 'DEFAULT' })
|
|
156
|
+
* async processData(input: string) {
|
|
157
|
+
* // Your code here
|
|
158
|
+
* return `processed: ${input}`;
|
|
159
|
+
* }
|
|
160
|
+
*
|
|
161
|
+
* @observeExperimentalDecorator((thisArg, ...args) => ({
|
|
162
|
+
* name: `dynamicMethod_${args[0]}`,
|
|
163
|
+
* sessionId: thisArg.sessionId
|
|
164
|
+
* }))
|
|
165
|
+
* async dynamicMethod(id: string) {
|
|
166
|
+
* // Your code here
|
|
167
|
+
* }
|
|
168
|
+
* }
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
declare function observeExperimentalDecorator(config: Partial<ObserveOptions> | ((thisArg: unknown, ...funcArgs: unknown[]) => Partial<ObserveOptions>)): (_target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
113
172
|
//#endregion
|
|
114
173
|
//#region src/opentelemetry-lib/tracing/processor.d.ts
|
|
115
174
|
interface LaminarSpanProcessorOptions {
|
|
@@ -155,6 +214,11 @@ interface LaminarSpanProcessorOptions {
|
|
|
155
214
|
* Defaults to a new LaminarSpanExporter.
|
|
156
215
|
*/
|
|
157
216
|
exporter?: SpanExporter;
|
|
217
|
+
/**
|
|
218
|
+
* The span processor to use. If passed, some of the other options will be ignored.
|
|
219
|
+
* If passed, wraps the underlying span processor.
|
|
220
|
+
*/
|
|
221
|
+
spanProcessor?: SpanProcessor;
|
|
158
222
|
}
|
|
159
223
|
declare class LaminarSpanProcessor implements SpanProcessor {
|
|
160
224
|
private instance;
|
|
@@ -221,6 +285,7 @@ interface LaminarInitializeProps {
|
|
|
221
285
|
sessionRecordingOptions?: SessionRecordingOptions;
|
|
222
286
|
metadata?: Record<string, any>;
|
|
223
287
|
inheritGlobalContext?: boolean;
|
|
288
|
+
spanProcessor?: SpanProcessor;
|
|
224
289
|
}
|
|
225
290
|
type LaminarAttributesProp = Record<typeof LaminarAttributes[keyof typeof LaminarAttributes], AttributeValue>;
|
|
226
291
|
declare class Laminar {
|
|
@@ -271,6 +336,8 @@ declare class Laminar {
|
|
|
271
336
|
* @param {boolean} props.inheritGlobalContext - Whether to inherit the global OpenTelemetry
|
|
272
337
|
* context. Defaults to false. This is useful if your library is instrumented with OpenTelemetry
|
|
273
338
|
* and you want Laminar spans to be children of the existing spans.
|
|
339
|
+
* @param {SpanProcessor} props.spanProcessor - The span processor to use. If passed, some of
|
|
340
|
+
* the other options will be ignored.
|
|
274
341
|
*
|
|
275
342
|
* @example
|
|
276
343
|
* import { Laminar } from '@lmnr-ai/lmnr';
|
|
@@ -304,7 +371,8 @@ declare class Laminar {
|
|
|
304
371
|
forceHttp,
|
|
305
372
|
sessionRecordingOptions,
|
|
306
373
|
metadata,
|
|
307
|
-
inheritGlobalContext
|
|
374
|
+
inheritGlobalContext,
|
|
375
|
+
spanProcessor
|
|
308
376
|
}?: LaminarInitializeProps): void;
|
|
309
377
|
/**
|
|
310
378
|
* Initialize Laminar context from the LMNR_SPAN_CONTEXT environment variable.
|
|
@@ -540,7 +608,7 @@ declare class Laminar {
|
|
|
540
608
|
*
|
|
541
609
|
* See {@link startSpan} docs for a usage example
|
|
542
610
|
*/
|
|
543
|
-
static withSpan<T>(span: Span$1, fn: () => T, endOnExit?: boolean): T
|
|
611
|
+
static withSpan<T>(span: Span$1, fn: () => T, endOnExit?: boolean): T;
|
|
544
612
|
static serializeLaminarSpanContext(span?: Span$1): string | null;
|
|
545
613
|
static getLaminarSpanContext(span?: Span$1): LaminarSpanContext | null;
|
|
546
614
|
/**
|
|
@@ -655,5 +723,5 @@ declare const initializeLaminarInstrumentations: (options?: {
|
|
|
655
723
|
sessionRecordingOptions?: SessionRecordingOptions;
|
|
656
724
|
}) => Instrumentation<_opentelemetry_instrumentation0.InstrumentationConfig>[];
|
|
657
725
|
//#endregion
|
|
658
|
-
export { type Datapoint, EvaluationDataset as Dataset, type Dataset as DatasetType, type EvaluationDatapoint, type EvaluationDatapointDatasetLink, type EvaluatorFunction, type EvaluatorFunctionReturn, type Event, HumanEvaluator, Laminar, LaminarAttributes, LaminarClient, LaminarDataset, type LaminarSpanContext, LaminarSpanProcessor, type MaskInputOptions, type PushDatapointsResponse, type SessionRecordingOptions, type Span, TracingLevel, evaluate, getTracer, getTracerProvider, initializeLaminarInstrumentations, instrumentClaudeAgentQuery, observe, observeDecorator, withTracingLevel, wrapAISDK };
|
|
726
|
+
export { type Datapoint, EvaluationDataset as Dataset, type Dataset as DatasetType, type EvaluationDatapoint, type EvaluationDatapointDatasetLink, type EvaluatorFunction, type EvaluatorFunctionReturn, type Event, HumanEvaluator, Laminar, LaminarAttributes, LaminarClient, LaminarDataset, type LaminarSpanContext, LaminarSpanProcessor, type MaskInputOptions, type PushDatapointsResponse, type SessionRecordingOptions, type Span, TracingLevel, evaluate, getTracer, getTracerProvider, initializeLaminarInstrumentations, instrumentClaudeAgentQuery, observe, observeDecorator, observeExperimentalDecorator, withTracingLevel, wrapAISDK };
|
|
659
727
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as TracingLevel, _ as MaskInputOptions, a as HumanEvaluator, b as SpanType, c as EvaluationDataset, d as StringUUID, f as Dataset, g as LaminarSpanContext, h as Event, i as EvaluatorFunctionReturn, l as LaminarDataset, m as EvaluationDatapointDatasetLink, o as evaluate, p as EvaluationDatapoint, r as EvaluatorFunction, s as InitializeOptions, t as Datapoint, u as LaminarClient, v as PushDatapointsResponse, x as TraceType, y as SessionRecordingOptions } from "./evaluations-
|
|
1
|
+
import { S as TracingLevel, _ as MaskInputOptions, a as HumanEvaluator, b as SpanType, c as EvaluationDataset, d as StringUUID, f as Dataset, g as LaminarSpanContext, h as Event, i as EvaluatorFunctionReturn, l as LaminarDataset, m as EvaluationDatapointDatasetLink, o as evaluate, p as EvaluationDatapoint, r as EvaluatorFunction, s as InitializeOptions, t as Datapoint, u as LaminarClient, v as PushDatapointsResponse, x as TraceType, y as SessionRecordingOptions } from "./evaluations-CL4yZPJK.mjs";
|
|
2
2
|
import { AttributeValue, Context, Span, Span as Span$1, TimeInput, Tracer, TracerProvider } from "@opentelemetry/api";
|
|
3
3
|
import * as _opentelemetry_instrumentation0 from "@opentelemetry/instrumentation";
|
|
4
4
|
import { Instrumentation, InstrumentationBase } from "@opentelemetry/instrumentation";
|
|
@@ -60,7 +60,7 @@ declare function observe<A extends unknown[], F extends (...args: A) => ReturnTy
|
|
|
60
60
|
parentSpanContext,
|
|
61
61
|
metadata,
|
|
62
62
|
tags
|
|
63
|
-
}: ObserveOptions, fn: F, ...args: A):
|
|
63
|
+
}: ObserveOptions, fn: F, ...args: A): ReturnType<F>;
|
|
64
64
|
/**
|
|
65
65
|
* Sets the tracing level for any spans inside the function. This is useful for
|
|
66
66
|
* conditionally disabling the tracing for certain functions.
|
|
@@ -83,6 +83,12 @@ declare function observe<A extends unknown[], F extends (...args: A) => ReturnTy
|
|
|
83
83
|
declare function withTracingLevel<A extends unknown[], F extends (...args: A) => ReturnType<F>>(tracingLevel: TracingLevel, fn: F, ...args: A): ReturnType<F>;
|
|
84
84
|
/**
|
|
85
85
|
* Decorator that wraps a method to automatically observe it with Laminar tracing.
|
|
86
|
+
* This decorator uses the TypeScript 5.0+ standard decorator syntax.
|
|
87
|
+
*
|
|
88
|
+
* **Important**: Use this decorator only if your `tsconfig.json` does NOT have
|
|
89
|
+
* `experimentalDecorators: true`. If you're using experimental decorators, use
|
|
90
|
+
* {@link observeExperimentalDecorator} instead.
|
|
91
|
+
*
|
|
86
92
|
* This decorator can be used on class methods to automatically create spans.
|
|
87
93
|
*
|
|
88
94
|
* @param config - Configuration for the observe decorator, can be static or a function
|
|
@@ -90,6 +96,13 @@ declare function withTracingLevel<A extends unknown[], F extends (...args: A) =>
|
|
|
90
96
|
*
|
|
91
97
|
* @example
|
|
92
98
|
* ```typescript
|
|
99
|
+
* // In your tsconfig.json, ensure experimentalDecorators is NOT enabled:
|
|
100
|
+
* // {
|
|
101
|
+
* // "compilerOptions": {
|
|
102
|
+
* // "experimentalDecorators": false // or omit this line
|
|
103
|
+
* // }
|
|
104
|
+
* // }
|
|
105
|
+
*
|
|
93
106
|
* import { observeDecorator } from '@lmnr-ai/lmnr';
|
|
94
107
|
*
|
|
95
108
|
* class MyService {
|
|
@@ -109,7 +122,53 @@ declare function withTracingLevel<A extends unknown[], F extends (...args: A) =>
|
|
|
109
122
|
* }
|
|
110
123
|
* ```
|
|
111
124
|
*/
|
|
112
|
-
declare function observeDecorator(config: Partial<ObserveOptions> | ((thisArg:
|
|
125
|
+
declare function observeDecorator<This, Args extends unknown[], Return>(config: Partial<ObserveOptions> | ((thisArg: This, ...funcArgs: Args) => Partial<ObserveOptions>)): (originalMethod: (this: This, ...args: Args) => Return, context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
|
|
126
|
+
/**
|
|
127
|
+
* Decorator that wraps a method to automatically observe it with Laminar tracing.
|
|
128
|
+
* This decorator uses the legacy experimental decorator syntax
|
|
129
|
+
* (requires `--experimentalDecorators` flag).
|
|
130
|
+
*
|
|
131
|
+
* **Important**: Use this decorator only if your `tsconfig.json` has
|
|
132
|
+
* `experimentalDecorators: true` in the `compilerOptions` section
|
|
133
|
+
* (or if you compile with the `--experimentalDecorators` flag).
|
|
134
|
+
* For TypeScript 5.0+ projects without experimental decorators, use
|
|
135
|
+
* {@link observeDecorator} instead.
|
|
136
|
+
*
|
|
137
|
+
* This decorator can be used on class methods to automatically create spans.
|
|
138
|
+
*
|
|
139
|
+
* Use this only if you need the legacy experimental decorator syntax.
|
|
140
|
+
* @param config - Configuration for the observe decorator, can be static or a function
|
|
141
|
+
* @returns A method decorator
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* // In your tsconfig.json, ensure experimentalDecorators is enabled:
|
|
146
|
+
* // {
|
|
147
|
+
* // "compilerOptions": {
|
|
148
|
+
* // "experimentalDecorators": true
|
|
149
|
+
* // }
|
|
150
|
+
* // }
|
|
151
|
+
*
|
|
152
|
+
* import { observeExperimentalDecorator } from '@lmnr-ai/lmnr';
|
|
153
|
+
*
|
|
154
|
+
* class MyService {
|
|
155
|
+
* @observeExperimentalDecorator({ name: 'processData', spanType: 'DEFAULT' })
|
|
156
|
+
* async processData(input: string) {
|
|
157
|
+
* // Your code here
|
|
158
|
+
* return `processed: ${input}`;
|
|
159
|
+
* }
|
|
160
|
+
*
|
|
161
|
+
* @observeExperimentalDecorator((thisArg, ...args) => ({
|
|
162
|
+
* name: `dynamicMethod_${args[0]}`,
|
|
163
|
+
* sessionId: thisArg.sessionId
|
|
164
|
+
* }))
|
|
165
|
+
* async dynamicMethod(id: string) {
|
|
166
|
+
* // Your code here
|
|
167
|
+
* }
|
|
168
|
+
* }
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
declare function observeExperimentalDecorator(config: Partial<ObserveOptions> | ((thisArg: unknown, ...funcArgs: unknown[]) => Partial<ObserveOptions>)): (_target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
113
172
|
//#endregion
|
|
114
173
|
//#region src/opentelemetry-lib/tracing/processor.d.ts
|
|
115
174
|
interface LaminarSpanProcessorOptions {
|
|
@@ -155,6 +214,11 @@ interface LaminarSpanProcessorOptions {
|
|
|
155
214
|
* Defaults to a new LaminarSpanExporter.
|
|
156
215
|
*/
|
|
157
216
|
exporter?: SpanExporter;
|
|
217
|
+
/**
|
|
218
|
+
* The span processor to use. If passed, some of the other options will be ignored.
|
|
219
|
+
* If passed, wraps the underlying span processor.
|
|
220
|
+
*/
|
|
221
|
+
spanProcessor?: SpanProcessor;
|
|
158
222
|
}
|
|
159
223
|
declare class LaminarSpanProcessor implements SpanProcessor {
|
|
160
224
|
private instance;
|
|
@@ -221,6 +285,7 @@ interface LaminarInitializeProps {
|
|
|
221
285
|
sessionRecordingOptions?: SessionRecordingOptions;
|
|
222
286
|
metadata?: Record<string, any>;
|
|
223
287
|
inheritGlobalContext?: boolean;
|
|
288
|
+
spanProcessor?: SpanProcessor;
|
|
224
289
|
}
|
|
225
290
|
type LaminarAttributesProp = Record<typeof LaminarAttributes[keyof typeof LaminarAttributes], AttributeValue>;
|
|
226
291
|
declare class Laminar {
|
|
@@ -271,6 +336,8 @@ declare class Laminar {
|
|
|
271
336
|
* @param {boolean} props.inheritGlobalContext - Whether to inherit the global OpenTelemetry
|
|
272
337
|
* context. Defaults to false. This is useful if your library is instrumented with OpenTelemetry
|
|
273
338
|
* and you want Laminar spans to be children of the existing spans.
|
|
339
|
+
* @param {SpanProcessor} props.spanProcessor - The span processor to use. If passed, some of
|
|
340
|
+
* the other options will be ignored.
|
|
274
341
|
*
|
|
275
342
|
* @example
|
|
276
343
|
* import { Laminar } from '@lmnr-ai/lmnr';
|
|
@@ -304,7 +371,8 @@ declare class Laminar {
|
|
|
304
371
|
forceHttp,
|
|
305
372
|
sessionRecordingOptions,
|
|
306
373
|
metadata,
|
|
307
|
-
inheritGlobalContext
|
|
374
|
+
inheritGlobalContext,
|
|
375
|
+
spanProcessor
|
|
308
376
|
}?: LaminarInitializeProps): void;
|
|
309
377
|
/**
|
|
310
378
|
* Initialize Laminar context from the LMNR_SPAN_CONTEXT environment variable.
|
|
@@ -540,7 +608,7 @@ declare class Laminar {
|
|
|
540
608
|
*
|
|
541
609
|
* See {@link startSpan} docs for a usage example
|
|
542
610
|
*/
|
|
543
|
-
static withSpan<T>(span: Span$1, fn: () => T, endOnExit?: boolean): T
|
|
611
|
+
static withSpan<T>(span: Span$1, fn: () => T, endOnExit?: boolean): T;
|
|
544
612
|
static serializeLaminarSpanContext(span?: Span$1): string | null;
|
|
545
613
|
static getLaminarSpanContext(span?: Span$1): LaminarSpanContext | null;
|
|
546
614
|
/**
|
|
@@ -655,5 +723,5 @@ declare const initializeLaminarInstrumentations: (options?: {
|
|
|
655
723
|
sessionRecordingOptions?: SessionRecordingOptions;
|
|
656
724
|
}) => Instrumentation<_opentelemetry_instrumentation0.InstrumentationConfig>[];
|
|
657
725
|
//#endregion
|
|
658
|
-
export { type Datapoint, EvaluationDataset as Dataset, type Dataset as DatasetType, type EvaluationDatapoint, type EvaluationDatapointDatasetLink, type EvaluatorFunction, type EvaluatorFunctionReturn, type Event, HumanEvaluator, Laminar, LaminarAttributes, LaminarClient, LaminarDataset, type LaminarSpanContext, LaminarSpanProcessor, type MaskInputOptions, type PushDatapointsResponse, type SessionRecordingOptions, type Span, TracingLevel, evaluate, getTracer, getTracerProvider, initializeLaminarInstrumentations, instrumentClaudeAgentQuery, observe, observeDecorator, withTracingLevel, wrapAISDK };
|
|
726
|
+
export { type Datapoint, EvaluationDataset as Dataset, type Dataset as DatasetType, type EvaluationDatapoint, type EvaluationDatapointDatasetLink, type EvaluatorFunction, type EvaluatorFunctionReturn, type Event, HumanEvaluator, Laminar, LaminarAttributes, LaminarClient, LaminarDataset, type LaminarSpanContext, LaminarSpanProcessor, type MaskInputOptions, type PushDatapointsResponse, type SessionRecordingOptions, type Span, TracingLevel, evaluate, getTracer, getTracerProvider, initializeLaminarInstrumentations, instrumentClaudeAgentQuery, observe, observeDecorator, observeExperimentalDecorator, withTracingLevel, wrapAISDK };
|
|
659
727
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as CONTEXT_SPAN_PATH_KEY, c as createResource, d as TracingLevel, f as __require, i as ASSOCIATION_PROPERTIES_KEY, l as getParentSpanId, n as getLangVersion, o as LaminarContextManager, r as version, s as LaminarSpan, t as LaminarClient, u as makeSpanOtelV2Compatible } from "./client-
|
|
1
|
+
import { a as CONTEXT_SPAN_PATH_KEY, c as createResource, d as TracingLevel, f as __require, i as ASSOCIATION_PROPERTIES_KEY, l as getParentSpanId, n as getLangVersion, o as LaminarContextManager, r as version, s as LaminarSpan, t as LaminarClient, u as makeSpanOtelV2Compatible } from "./client-BmOjmnjR.mjs";
|
|
2
2
|
import { A as SPAN_SDK_VERSION, C as SESSION_ID, D as SPAN_LANGUAGE_VERSION, E as SPAN_INSTRUMENTATION_SOURCE, M as TRACE_HAS_BROWSER_SESSION, N as TRACE_TYPE, O as SPAN_OUTPUT, P as USER_ID, S as PARENT_SPAN_PATH, T as SPAN_INPUT, _ as ASSOCIATION_PROPERTIES, a as getOtelEnvVar, b as LaminarAttributes, d as otelSpanIdToUUID, f as otelTraceIdToUUID, g as validateTracingConfig, h as tryToOtelSpanContext, j as SPAN_TYPE, k as SPAN_PATH, l as metadataToAttributes, n as Semaphore, o as initializeLogger, p as parseOtelHeaders, r as deserializeLaminarSpanContext, s as isOtelAttributeValueType, t as NIL_UUID, u as newUUID, v as ASSOCIATION_PROPERTIES_OVERRIDES, w as SPAN_IDS_PATH, x as PARENT_SPAN_IDS_PATH, y as HUMAN_EVALUATOR_OPTIONS } from "./utils-viuxL6V7.mjs";
|
|
3
3
|
import { config } from "dotenv";
|
|
4
4
|
import { DiagConsoleLogger, DiagLogLevel, ROOT_CONTEXT, context, createContextKey, diag, isSpanContextValid, trace } from "@opentelemetry/api";
|
|
@@ -341,7 +341,7 @@ function instrumentClaudeAgentQuery(originalQuery) {
|
|
|
341
341
|
const collected = [];
|
|
342
342
|
try {
|
|
343
343
|
await startProxy();
|
|
344
|
-
if (getProxyBaseUrl())
|
|
344
|
+
if (getProxyBaseUrl()) Laminar.withSpan(span, () => {
|
|
345
345
|
setTraceToProxy();
|
|
346
346
|
});
|
|
347
347
|
else logger$10.debug("No claude proxy server found. Skipping span context publication.");
|
|
@@ -351,7 +351,7 @@ function instrumentClaudeAgentQuery(originalQuery) {
|
|
|
351
351
|
yield message;
|
|
352
352
|
}
|
|
353
353
|
} catch (error) {
|
|
354
|
-
|
|
354
|
+
Laminar.withSpan(span, () => {
|
|
355
355
|
span.recordException(error);
|
|
356
356
|
});
|
|
357
357
|
throw error;
|
|
@@ -443,6 +443,8 @@ var Laminar = class Laminar {
|
|
|
443
443
|
* @param {boolean} props.inheritGlobalContext - Whether to inherit the global OpenTelemetry
|
|
444
444
|
* context. Defaults to false. This is useful if your library is instrumented with OpenTelemetry
|
|
445
445
|
* and you want Laminar spans to be children of the existing spans.
|
|
446
|
+
* @param {SpanProcessor} props.spanProcessor - The span processor to use. If passed, some of
|
|
447
|
+
* the other options will be ignored.
|
|
446
448
|
*
|
|
447
449
|
* @example
|
|
448
450
|
* import { Laminar } from '@lmnr-ai/lmnr';
|
|
@@ -462,7 +464,7 @@ var Laminar = class Laminar {
|
|
|
462
464
|
*
|
|
463
465
|
* @throws {Error} - If project API key is not set
|
|
464
466
|
*/
|
|
465
|
-
static initialize({ projectApiKey, baseUrl, baseHttpUrl, httpPort, grpcPort, instrumentModules, disableBatch, traceExportTimeoutMillis, logLevel, maxExportBatchSize, forceHttp, sessionRecordingOptions, metadata, inheritGlobalContext } = {}) {
|
|
467
|
+
static initialize({ projectApiKey, baseUrl, baseHttpUrl, httpPort, grpcPort, instrumentModules, disableBatch, traceExportTimeoutMillis, logLevel, maxExportBatchSize, forceHttp, sessionRecordingOptions, metadata, inheritGlobalContext, spanProcessor: spanProcessor$1 } = {}) {
|
|
466
468
|
if (this.isInitialized) {
|
|
467
469
|
logger$9.warn("Laminar has already been initialized. Skipping initialization.");
|
|
468
470
|
return;
|
|
@@ -484,6 +486,7 @@ var Laminar = class Laminar {
|
|
|
484
486
|
this.globalMetadata = metadata ?? {};
|
|
485
487
|
LaminarContextManager.setGlobalMetadata(this.globalMetadata);
|
|
486
488
|
if (inheritGlobalContext) LaminarContextManager.inheritGlobalContext = true;
|
|
489
|
+
if (spanProcessor$1 && !(spanProcessor$1 instanceof LaminarSpanProcessor)) logger$9.warn("Span processor is not a LaminarSpanProcessor. Some functionality may be impaired.");
|
|
487
490
|
this.isInitialized = true;
|
|
488
491
|
const urlWithoutSlash = url?.replace(/\/$/, "").replace(/:\d{1,5}$/g, "");
|
|
489
492
|
const httpUrlWithoutSlash = httpUrl?.replace(/\/$/, "").replace(/:\d{1,5}$/g, "");
|
|
@@ -500,7 +503,8 @@ var Laminar = class Laminar {
|
|
|
500
503
|
disableBatch,
|
|
501
504
|
maxExportBatchSize,
|
|
502
505
|
traceExportTimeoutMillis,
|
|
503
|
-
sessionRecordingOptions
|
|
506
|
+
sessionRecordingOptions,
|
|
507
|
+
spanProcessor: spanProcessor$1
|
|
504
508
|
});
|
|
505
509
|
this._initializeContextFromEnv();
|
|
506
510
|
}
|
|
@@ -849,7 +853,10 @@ var Laminar = class Laminar {
|
|
|
849
853
|
return context.with(context$1, () => LaminarContextManager.runWithIsolatedContext([context$1], () => {
|
|
850
854
|
try {
|
|
851
855
|
const result = fn();
|
|
852
|
-
if (result instanceof Promise) return result.
|
|
856
|
+
if (result instanceof Promise) return result.catch((err) => {
|
|
857
|
+
span.recordException(err);
|
|
858
|
+
throw err;
|
|
859
|
+
}).finally(() => {
|
|
853
860
|
if (endOnExit !== void 0 && endOnExit) span.end();
|
|
854
861
|
});
|
|
855
862
|
if (endOnExit !== void 0 && endOnExit) span.end();
|
|
@@ -3345,7 +3352,7 @@ var LaminarSpanExporter = class {
|
|
|
3345
3352
|
|
|
3346
3353
|
//#endregion
|
|
3347
3354
|
//#region src/opentelemetry-lib/tracing/processor.ts
|
|
3348
|
-
var LaminarSpanProcessor = class {
|
|
3355
|
+
var LaminarSpanProcessor = class LaminarSpanProcessor {
|
|
3349
3356
|
/**
|
|
3350
3357
|
* @param {object} options - The options for the Laminar span processor.
|
|
3351
3358
|
* @param {string} options.baseUrl - The base URL of the Laminar API.
|
|
@@ -3364,11 +3371,18 @@ var LaminarSpanProcessor = class {
|
|
|
3364
3371
|
constructor(options = {}) {
|
|
3365
3372
|
this._spanIdToPath = /* @__PURE__ */ new Map();
|
|
3366
3373
|
this._spanIdLists = /* @__PURE__ */ new Map();
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
});
|
|
3374
|
+
if (options.spanProcessor && options.spanProcessor instanceof LaminarSpanProcessor) {
|
|
3375
|
+
this.instance = options.spanProcessor.instance;
|
|
3376
|
+
this._spanIdToPath = options.spanProcessor._spanIdToPath;
|
|
3377
|
+
this._spanIdLists = options.spanProcessor._spanIdLists;
|
|
3378
|
+
} else if (options.spanProcessor) this.instance = options.spanProcessor;
|
|
3379
|
+
else {
|
|
3380
|
+
const exporter = options.exporter ?? new LaminarSpanExporter(options);
|
|
3381
|
+
this.instance = options.disableBatch ? new SimpleSpanProcessor(exporter) : new BatchSpanProcessor(exporter, {
|
|
3382
|
+
maxExportBatchSize: options.maxExportBatchSize ?? 512,
|
|
3383
|
+
exportTimeoutMillis: options.traceExportTimeoutMillis ?? 3e4
|
|
3384
|
+
});
|
|
3385
|
+
}
|
|
3372
3386
|
}
|
|
3373
3387
|
forceFlush() {
|
|
3374
3388
|
return this.instance.forceFlush();
|
|
@@ -3488,6 +3502,7 @@ const startTracing = (options) => {
|
|
|
3488
3502
|
});
|
|
3489
3503
|
const port = options.forceHttp ? options.httpPort : options.port;
|
|
3490
3504
|
spanProcessor = new LaminarSpanProcessor({
|
|
3505
|
+
spanProcessor: options.spanProcessor,
|
|
3491
3506
|
baseUrl: options.baseUrl,
|
|
3492
3507
|
port,
|
|
3493
3508
|
apiKey: options.apiKey,
|
|
@@ -3635,7 +3650,7 @@ function observeBase({ name, associationProperties, input, ignoreInput, ignoreOu
|
|
|
3635
3650
|
} catch (e) {
|
|
3636
3651
|
logger$2.warn("Failed to parse parent span context: " + (e instanceof Error ? e.message : String(e)));
|
|
3637
3652
|
}
|
|
3638
|
-
return context.with(entityContext, () => getTracer().startActiveSpan(name, { attributes: associationProperties }, entityContext,
|
|
3653
|
+
return context.with(entityContext, () => getTracer().startActiveSpan(name, { attributes: associationProperties }, entityContext, (span) => {
|
|
3639
3654
|
if (shouldSendTraces() && !ignoreInput) try {
|
|
3640
3655
|
const spanInput = inputParameters ?? args;
|
|
3641
3656
|
if (input !== void 0) span.setAttribute(SPAN_INPUT, typeof input === "string" ? input : serialize(input));
|
|
@@ -3729,7 +3744,7 @@ const logger$1 = initializeLogger();
|
|
|
3729
3744
|
* // Your code here
|
|
3730
3745
|
* });
|
|
3731
3746
|
*/
|
|
3732
|
-
|
|
3747
|
+
function observe({ name, sessionId, userId, traceType, spanType, input, ignoreInput, ignoreOutput, parentSpanContext, metadata, tags }, fn, ...args) {
|
|
3733
3748
|
if (fn === void 0 || typeof fn !== "function") throw new Error("Invalid `observe` usage. Second argument `fn` must be a function.");
|
|
3734
3749
|
const associationProperties = buildAssociationProperties({
|
|
3735
3750
|
sessionId,
|
|
@@ -3740,7 +3755,7 @@ async function observe({ name, sessionId, userId, traceType, spanType, input, ig
|
|
|
3740
3755
|
metadata,
|
|
3741
3756
|
parentSpanContext
|
|
3742
3757
|
});
|
|
3743
|
-
return
|
|
3758
|
+
return observeBase({
|
|
3744
3759
|
name: name ?? fn.name,
|
|
3745
3760
|
associationProperties,
|
|
3746
3761
|
input,
|
|
@@ -3834,6 +3849,12 @@ const buildAssociationProperties = (options) => {
|
|
|
3834
3849
|
};
|
|
3835
3850
|
/**
|
|
3836
3851
|
* Decorator that wraps a method to automatically observe it with Laminar tracing.
|
|
3852
|
+
* This decorator uses the TypeScript 5.0+ standard decorator syntax.
|
|
3853
|
+
*
|
|
3854
|
+
* **Important**: Use this decorator only if your `tsconfig.json` does NOT have
|
|
3855
|
+
* `experimentalDecorators: true`. If you're using experimental decorators, use
|
|
3856
|
+
* {@link observeExperimentalDecorator} instead.
|
|
3857
|
+
*
|
|
3837
3858
|
* This decorator can be used on class methods to automatically create spans.
|
|
3838
3859
|
*
|
|
3839
3860
|
* @param config - Configuration for the observe decorator, can be static or a function
|
|
@@ -3841,6 +3862,13 @@ const buildAssociationProperties = (options) => {
|
|
|
3841
3862
|
*
|
|
3842
3863
|
* @example
|
|
3843
3864
|
* ```typescript
|
|
3865
|
+
* // In your tsconfig.json, ensure experimentalDecorators is NOT enabled:
|
|
3866
|
+
* // {
|
|
3867
|
+
* // "compilerOptions": {
|
|
3868
|
+
* // "experimentalDecorators": false // or omit this line
|
|
3869
|
+
* // }
|
|
3870
|
+
* // }
|
|
3871
|
+
*
|
|
3844
3872
|
* import { observeDecorator } from '@lmnr-ai/lmnr';
|
|
3845
3873
|
*
|
|
3846
3874
|
* class MyService {
|
|
@@ -3861,8 +3889,72 @@ const buildAssociationProperties = (options) => {
|
|
|
3861
3889
|
* ```
|
|
3862
3890
|
*/
|
|
3863
3891
|
function observeDecorator(config$1) {
|
|
3892
|
+
return function(originalMethod, context$1) {
|
|
3893
|
+
if (context$1.kind !== "method") throw new Error(`observeDecorator can only be applied to methods. Applied to: ${String(context$1.name)}`);
|
|
3894
|
+
const methodName = String(context$1.name);
|
|
3895
|
+
return function(...args) {
|
|
3896
|
+
let actualConfig;
|
|
3897
|
+
if (typeof config$1 === "function") actualConfig = config$1(this, ...args);
|
|
3898
|
+
else actualConfig = config$1;
|
|
3899
|
+
return observeBase({
|
|
3900
|
+
name: actualConfig.name ?? methodName,
|
|
3901
|
+
associationProperties: buildAssociationProperties(actualConfig),
|
|
3902
|
+
input: actualConfig.input,
|
|
3903
|
+
ignoreInput: actualConfig.ignoreInput,
|
|
3904
|
+
ignoreOutput: actualConfig.ignoreOutput,
|
|
3905
|
+
parentSpanContext: actualConfig.parentSpanContext
|
|
3906
|
+
}, originalMethod, this, ...args);
|
|
3907
|
+
};
|
|
3908
|
+
};
|
|
3909
|
+
}
|
|
3910
|
+
/**
|
|
3911
|
+
* Decorator that wraps a method to automatically observe it with Laminar tracing.
|
|
3912
|
+
* This decorator uses the legacy experimental decorator syntax
|
|
3913
|
+
* (requires `--experimentalDecorators` flag).
|
|
3914
|
+
*
|
|
3915
|
+
* **Important**: Use this decorator only if your `tsconfig.json` has
|
|
3916
|
+
* `experimentalDecorators: true` in the `compilerOptions` section
|
|
3917
|
+
* (or if you compile with the `--experimentalDecorators` flag).
|
|
3918
|
+
* For TypeScript 5.0+ projects without experimental decorators, use
|
|
3919
|
+
* {@link observeDecorator} instead.
|
|
3920
|
+
*
|
|
3921
|
+
* This decorator can be used on class methods to automatically create spans.
|
|
3922
|
+
*
|
|
3923
|
+
* Use this only if you need the legacy experimental decorator syntax.
|
|
3924
|
+
* @param config - Configuration for the observe decorator, can be static or a function
|
|
3925
|
+
* @returns A method decorator
|
|
3926
|
+
*
|
|
3927
|
+
* @example
|
|
3928
|
+
* ```typescript
|
|
3929
|
+
* // In your tsconfig.json, ensure experimentalDecorators is enabled:
|
|
3930
|
+
* // {
|
|
3931
|
+
* // "compilerOptions": {
|
|
3932
|
+
* // "experimentalDecorators": true
|
|
3933
|
+
* // }
|
|
3934
|
+
* // }
|
|
3935
|
+
*
|
|
3936
|
+
* import { observeExperimentalDecorator } from '@lmnr-ai/lmnr';
|
|
3937
|
+
*
|
|
3938
|
+
* class MyService {
|
|
3939
|
+
* @observeExperimentalDecorator({ name: 'processData', spanType: 'DEFAULT' })
|
|
3940
|
+
* async processData(input: string) {
|
|
3941
|
+
* // Your code here
|
|
3942
|
+
* return `processed: ${input}`;
|
|
3943
|
+
* }
|
|
3944
|
+
*
|
|
3945
|
+
* @observeExperimentalDecorator((thisArg, ...args) => ({
|
|
3946
|
+
* name: `dynamicMethod_${args[0]}`,
|
|
3947
|
+
* sessionId: thisArg.sessionId
|
|
3948
|
+
* }))
|
|
3949
|
+
* async dynamicMethod(id: string) {
|
|
3950
|
+
* // Your code here
|
|
3951
|
+
* }
|
|
3952
|
+
* }
|
|
3953
|
+
* ```
|
|
3954
|
+
*/
|
|
3955
|
+
function observeExperimentalDecorator(config$1) {
|
|
3864
3956
|
return function(_target, propertyKey, descriptor) {
|
|
3865
|
-
if (!descriptor || typeof descriptor.value !== "function") throw new Error(`
|
|
3957
|
+
if (!descriptor || typeof descriptor.value !== "function") throw new Error(`observeExperimentalDecorator can only be applied to methods. Applied to: ${String(propertyKey)}`);
|
|
3866
3958
|
const originalMethod = descriptor.value;
|
|
3867
3959
|
descriptor.value = function(...args) {
|
|
3868
3960
|
let actualConfig;
|
|
@@ -4228,5 +4320,5 @@ const wrapAISDK = (ai) => {
|
|
|
4228
4320
|
};
|
|
4229
4321
|
|
|
4230
4322
|
//#endregion
|
|
4231
|
-
export { EvaluationDataset as Dataset, HumanEvaluator, Laminar, LaminarAttributes, LaminarClient, LaminarDataset, LaminarSpanProcessor, TracingLevel, evaluate, getTracer, getTracerProvider, initializeLaminarInstrumentations, instrumentClaudeAgentQuery, observe, observeDecorator, withTracingLevel, wrapAISDK };
|
|
4323
|
+
export { EvaluationDataset as Dataset, HumanEvaluator, Laminar, LaminarAttributes, LaminarClient, LaminarDataset, LaminarSpanProcessor, TracingLevel, evaluate, getTracer, getTracerProvider, initializeLaminarInstrumentations, instrumentClaudeAgentQuery, observe, observeDecorator, observeExperimentalDecorator, withTracingLevel, wrapAISDK };
|
|
4232
4324
|
//# sourceMappingURL=index.mjs.map
|