@lmnr-ai/lmnr 0.7.13-alpha.2 → 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.mjs +1 -1
- package/dist/{client-BugRObJS.mjs → client-BmOjmnjR.mjs} +2 -2
- package/dist/{client-BugRObJS.mjs.map → client-BmOjmnjR.mjs.map} +1 -1
- package/dist/{client-Bu3Bn7n9.cjs → client-VmPk12gK.cjs} +2 -2
- package/dist/{client-Bu3Bn7n9.cjs.map → client-VmPk12gK.cjs.map} +1 -1
- package/dist/index.cjs +89 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +63 -4
- package/dist/index.d.mts +63 -4
- package/dist/index.mjs +89 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -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 {
|
|
@@ -549,7 +608,7 @@ declare class Laminar {
|
|
|
549
608
|
*
|
|
550
609
|
* See {@link startSpan} docs for a usage example
|
|
551
610
|
*/
|
|
552
|
-
static withSpan<T>(span: Span$1, fn: () => T, endOnExit?: boolean): T
|
|
611
|
+
static withSpan<T>(span: Span$1, fn: () => T, endOnExit?: boolean): T;
|
|
553
612
|
static serializeLaminarSpanContext(span?: Span$1): string | null;
|
|
554
613
|
static getLaminarSpanContext(span?: Span$1): LaminarSpanContext | null;
|
|
555
614
|
/**
|
|
@@ -664,5 +723,5 @@ declare const initializeLaminarInstrumentations: (options?: {
|
|
|
664
723
|
sessionRecordingOptions?: SessionRecordingOptions;
|
|
665
724
|
}) => Instrumentation<_opentelemetry_instrumentation0.InstrumentationConfig>[];
|
|
666
725
|
//#endregion
|
|
667
|
-
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 };
|
|
668
727
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -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 {
|
|
@@ -549,7 +608,7 @@ declare class Laminar {
|
|
|
549
608
|
*
|
|
550
609
|
* See {@link startSpan} docs for a usage example
|
|
551
610
|
*/
|
|
552
|
-
static withSpan<T>(span: Span$1, fn: () => T, endOnExit?: boolean): T
|
|
611
|
+
static withSpan<T>(span: Span$1, fn: () => T, endOnExit?: boolean): T;
|
|
553
612
|
static serializeLaminarSpanContext(span?: Span$1): string | null;
|
|
554
613
|
static getLaminarSpanContext(span?: Span$1): LaminarSpanContext | null;
|
|
555
614
|
/**
|
|
@@ -664,5 +723,5 @@ declare const initializeLaminarInstrumentations: (options?: {
|
|
|
664
723
|
sessionRecordingOptions?: SessionRecordingOptions;
|
|
665
724
|
}) => Instrumentation<_opentelemetry_instrumentation0.InstrumentationConfig>[];
|
|
666
725
|
//#endregion
|
|
667
|
-
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 };
|
|
668
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;
|
|
@@ -853,7 +853,10 @@ var Laminar = class Laminar {
|
|
|
853
853
|
return context.with(context$1, () => LaminarContextManager.runWithIsolatedContext([context$1], () => {
|
|
854
854
|
try {
|
|
855
855
|
const result = fn();
|
|
856
|
-
if (result instanceof Promise) return result.
|
|
856
|
+
if (result instanceof Promise) return result.catch((err) => {
|
|
857
|
+
span.recordException(err);
|
|
858
|
+
throw err;
|
|
859
|
+
}).finally(() => {
|
|
857
860
|
if (endOnExit !== void 0 && endOnExit) span.end();
|
|
858
861
|
});
|
|
859
862
|
if (endOnExit !== void 0 && endOnExit) span.end();
|
|
@@ -3647,7 +3650,7 @@ function observeBase({ name, associationProperties, input, ignoreInput, ignoreOu
|
|
|
3647
3650
|
} catch (e) {
|
|
3648
3651
|
logger$2.warn("Failed to parse parent span context: " + (e instanceof Error ? e.message : String(e)));
|
|
3649
3652
|
}
|
|
3650
|
-
return context.with(entityContext, () => getTracer().startActiveSpan(name, { attributes: associationProperties }, entityContext,
|
|
3653
|
+
return context.with(entityContext, () => getTracer().startActiveSpan(name, { attributes: associationProperties }, entityContext, (span) => {
|
|
3651
3654
|
if (shouldSendTraces() && !ignoreInput) try {
|
|
3652
3655
|
const spanInput = inputParameters ?? args;
|
|
3653
3656
|
if (input !== void 0) span.setAttribute(SPAN_INPUT, typeof input === "string" ? input : serialize(input));
|
|
@@ -3741,7 +3744,7 @@ const logger$1 = initializeLogger();
|
|
|
3741
3744
|
* // Your code here
|
|
3742
3745
|
* });
|
|
3743
3746
|
*/
|
|
3744
|
-
|
|
3747
|
+
function observe({ name, sessionId, userId, traceType, spanType, input, ignoreInput, ignoreOutput, parentSpanContext, metadata, tags }, fn, ...args) {
|
|
3745
3748
|
if (fn === void 0 || typeof fn !== "function") throw new Error("Invalid `observe` usage. Second argument `fn` must be a function.");
|
|
3746
3749
|
const associationProperties = buildAssociationProperties({
|
|
3747
3750
|
sessionId,
|
|
@@ -3752,7 +3755,7 @@ async function observe({ name, sessionId, userId, traceType, spanType, input, ig
|
|
|
3752
3755
|
metadata,
|
|
3753
3756
|
parentSpanContext
|
|
3754
3757
|
});
|
|
3755
|
-
return
|
|
3758
|
+
return observeBase({
|
|
3756
3759
|
name: name ?? fn.name,
|
|
3757
3760
|
associationProperties,
|
|
3758
3761
|
input,
|
|
@@ -3846,6 +3849,12 @@ const buildAssociationProperties = (options) => {
|
|
|
3846
3849
|
};
|
|
3847
3850
|
/**
|
|
3848
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
|
+
*
|
|
3849
3858
|
* This decorator can be used on class methods to automatically create spans.
|
|
3850
3859
|
*
|
|
3851
3860
|
* @param config - Configuration for the observe decorator, can be static or a function
|
|
@@ -3853,6 +3862,13 @@ const buildAssociationProperties = (options) => {
|
|
|
3853
3862
|
*
|
|
3854
3863
|
* @example
|
|
3855
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
|
+
*
|
|
3856
3872
|
* import { observeDecorator } from '@lmnr-ai/lmnr';
|
|
3857
3873
|
*
|
|
3858
3874
|
* class MyService {
|
|
@@ -3873,8 +3889,72 @@ const buildAssociationProperties = (options) => {
|
|
|
3873
3889
|
* ```
|
|
3874
3890
|
*/
|
|
3875
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) {
|
|
3876
3956
|
return function(_target, propertyKey, descriptor) {
|
|
3877
|
-
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)}`);
|
|
3878
3958
|
const originalMethod = descriptor.value;
|
|
3879
3959
|
descriptor.value = function(...args) {
|
|
3880
3960
|
let actualConfig;
|
|
@@ -4240,5 +4320,5 @@ const wrapAISDK = (ai) => {
|
|
|
4240
4320
|
};
|
|
4241
4321
|
|
|
4242
4322
|
//#endregion
|
|
4243
|
-
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 };
|
|
4244
4324
|
//# sourceMappingURL=index.mjs.map
|