@langfuse/core 4.3.0 → 4.4.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/index.cjs +514 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +424 -8
- package/dist/index.d.ts +424 -8
- package/dist/index.mjs +512 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Context } from '@opentelemetry/api';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Enumeration of log levels in order of severity (lowest to highest).
|
|
3
5
|
*/
|
|
@@ -179,6 +181,7 @@ declare const resetGlobalLogger: () => void;
|
|
|
179
181
|
declare const LANGFUSE_TRACER_NAME = "langfuse-sdk";
|
|
180
182
|
declare const LANGFUSE_SDK_VERSION: string;
|
|
181
183
|
declare const LANGFUSE_SDK_NAME = "javascript";
|
|
184
|
+
declare const LANGFUSE_SDK_EXPERIMENT_ENVIRONMENT = "sdk-experiment";
|
|
182
185
|
declare enum LangfuseOtelSpanAttributes {
|
|
183
186
|
TRACE_NAME = "langfuse.trace.name",
|
|
184
187
|
TRACE_USER_ID = "user.id",
|
|
@@ -205,6 +208,15 @@ declare enum LangfuseOtelSpanAttributes {
|
|
|
205
208
|
RELEASE = "langfuse.release",
|
|
206
209
|
VERSION = "langfuse.version",
|
|
207
210
|
AS_ROOT = "langfuse.internal.as_root",
|
|
211
|
+
EXPERIMENT_ID = "langfuse.experiment.id",
|
|
212
|
+
EXPERIMENT_NAME = "langfuse.experiment.name",
|
|
213
|
+
EXPERIMENT_DESCRIPTION = "langfuse.experiment.description",
|
|
214
|
+
EXPERIMENT_METADATA = "langfuse.experiment.metadata",
|
|
215
|
+
EXPERIMENT_DATASET_ID = "langfuse.experiment.dataset.id",
|
|
216
|
+
EXPERIMENT_ITEM_ID = "langfuse.experiment.item.id",
|
|
217
|
+
EXPERIMENT_ITEM_EXPECTED_OUTPUT = "langfuse.experiment.item.expected_output",
|
|
218
|
+
EXPERIMENT_ITEM_METADATA = "langfuse.experiment.item.metadata",
|
|
219
|
+
EXPERIMENT_ITEM_ROOT_OBSERVATION_ID = "langfuse.experiment.item.root_observation_id",
|
|
208
220
|
TRACE_COMPAT_USER_ID = "langfuse.user.id",
|
|
209
221
|
TRACE_COMPAT_SESSION_ID = "langfuse.session.id"
|
|
210
222
|
}
|
|
@@ -980,6 +992,10 @@ interface Dataset {
|
|
|
980
992
|
name: string;
|
|
981
993
|
description?: string;
|
|
982
994
|
metadata?: unknown;
|
|
995
|
+
/** JSON Schema for validating dataset item inputs */
|
|
996
|
+
inputSchema?: unknown;
|
|
997
|
+
/** JSON Schema for validating dataset item expected outputs */
|
|
998
|
+
expectedOutputSchema?: unknown;
|
|
983
999
|
projectId: string;
|
|
984
1000
|
createdAt: string;
|
|
985
1001
|
updatedAt: string;
|
|
@@ -1469,6 +1485,10 @@ interface CreateDatasetRequest {
|
|
|
1469
1485
|
name: string;
|
|
1470
1486
|
description?: string;
|
|
1471
1487
|
metadata?: unknown;
|
|
1488
|
+
/** JSON Schema for validating dataset item inputs. When set, all new and existing dataset items will be validated against this schema. */
|
|
1489
|
+
inputSchema?: unknown;
|
|
1490
|
+
/** JSON Schema for validating dataset item expected outputs. When set, all new and existing dataset items will be validated against this schema. */
|
|
1491
|
+
expectedOutputSchema?: unknown;
|
|
1472
1492
|
}
|
|
1473
1493
|
|
|
1474
1494
|
/**
|
|
@@ -2523,13 +2543,15 @@ interface GetObservationsRequest {
|
|
|
2523
2543
|
/** Optional filter to only include observations with a certain version. */
|
|
2524
2544
|
version?: string;
|
|
2525
2545
|
/**
|
|
2526
|
-
* JSON string containing an array of filter conditions. When provided, this takes precedence over
|
|
2546
|
+
* JSON string containing an array of filter conditions. When provided, this takes precedence over query parameter filters (userId, name, type, level, environment, fromStartTime, ...).
|
|
2547
|
+
*
|
|
2548
|
+
* ## Filter Structure
|
|
2527
2549
|
* Each filter condition has the following structure:
|
|
2528
2550
|
* ```json
|
|
2529
2551
|
* [
|
|
2530
2552
|
* {
|
|
2531
2553
|
* "type": string, // Required. One of: "datetime", "string", "number", "stringOptions", "categoryOptions", "arrayOptions", "stringObject", "numberObject", "boolean", "null"
|
|
2532
|
-
* "column": string, // Required. Column to filter on
|
|
2554
|
+
* "column": string, // Required. Column to filter on (see available columns below)
|
|
2533
2555
|
* "operator": string, // Required. Operator based on type:
|
|
2534
2556
|
* // - datetime: ">", "<", ">=", "<="
|
|
2535
2557
|
* // - string: "=", "contains", "does not contain", "starts with", "ends with"
|
|
@@ -2546,6 +2568,78 @@ interface GetObservationsRequest {
|
|
|
2546
2568
|
* }
|
|
2547
2569
|
* ]
|
|
2548
2570
|
* ```
|
|
2571
|
+
*
|
|
2572
|
+
* ## Available Columns
|
|
2573
|
+
*
|
|
2574
|
+
* ### Core Observation Fields
|
|
2575
|
+
* - `id` (string) - Observation ID
|
|
2576
|
+
* - `type` (string) - Observation type (SPAN, GENERATION, EVENT)
|
|
2577
|
+
* - `name` (string) - Observation name
|
|
2578
|
+
* - `traceId` (string) - Associated trace ID
|
|
2579
|
+
* - `startTime` (datetime) - Observation start time
|
|
2580
|
+
* - `endTime` (datetime) - Observation end time
|
|
2581
|
+
* - `environment` (string) - Environment tag
|
|
2582
|
+
* - `level` (string) - Log level (DEBUG, DEFAULT, WARNING, ERROR)
|
|
2583
|
+
* - `statusMessage` (string) - Status message
|
|
2584
|
+
* - `version` (string) - Version tag
|
|
2585
|
+
*
|
|
2586
|
+
* ### Performance Metrics
|
|
2587
|
+
* - `latency` (number) - Latency in seconds (calculated: end_time - start_time)
|
|
2588
|
+
* - `timeToFirstToken` (number) - Time to first token in seconds
|
|
2589
|
+
* - `tokensPerSecond` (number) - Output tokens per second
|
|
2590
|
+
*
|
|
2591
|
+
* ### Token Usage
|
|
2592
|
+
* - `inputTokens` (number) - Number of input tokens
|
|
2593
|
+
* - `outputTokens` (number) - Number of output tokens
|
|
2594
|
+
* - `totalTokens` (number) - Total tokens (alias: `tokens`)
|
|
2595
|
+
*
|
|
2596
|
+
* ### Cost Metrics
|
|
2597
|
+
* - `inputCost` (number) - Input cost in USD
|
|
2598
|
+
* - `outputCost` (number) - Output cost in USD
|
|
2599
|
+
* - `totalCost` (number) - Total cost in USD
|
|
2600
|
+
*
|
|
2601
|
+
* ### Model Information
|
|
2602
|
+
* - `model` (string) - Provided model name
|
|
2603
|
+
* - `promptName` (string) - Associated prompt name
|
|
2604
|
+
* - `promptVersion` (number) - Associated prompt version
|
|
2605
|
+
*
|
|
2606
|
+
* ### Structured Data
|
|
2607
|
+
* - `metadata` (stringObject/numberObject/categoryOptions) - Metadata key-value pairs. Use `key` parameter to filter on specific metadata keys.
|
|
2608
|
+
*
|
|
2609
|
+
* ### Scores (requires join with scores table)
|
|
2610
|
+
* - `scores_avg` (number) - Average of numeric scores (alias: `scores`)
|
|
2611
|
+
* - `score_categories` (categoryOptions) - Categorical score values
|
|
2612
|
+
*
|
|
2613
|
+
* ### Associated Trace Fields (requires join with traces table)
|
|
2614
|
+
* - `userId` (string) - User ID from associated trace
|
|
2615
|
+
* - `traceName` (string) - Name from associated trace
|
|
2616
|
+
* - `traceEnvironment` (string) - Environment from associated trace
|
|
2617
|
+
* - `traceTags` (arrayOptions) - Tags from associated trace
|
|
2618
|
+
*
|
|
2619
|
+
* ## Filter Examples
|
|
2620
|
+
* ```json
|
|
2621
|
+
* [
|
|
2622
|
+
* {
|
|
2623
|
+
* "type": "string",
|
|
2624
|
+
* "column": "type",
|
|
2625
|
+
* "operator": "=",
|
|
2626
|
+
* "value": "GENERATION"
|
|
2627
|
+
* },
|
|
2628
|
+
* {
|
|
2629
|
+
* "type": "number",
|
|
2630
|
+
* "column": "latency",
|
|
2631
|
+
* "operator": ">=",
|
|
2632
|
+
* "value": 2.5
|
|
2633
|
+
* },
|
|
2634
|
+
* {
|
|
2635
|
+
* "type": "stringObject",
|
|
2636
|
+
* "column": "metadata",
|
|
2637
|
+
* "key": "environment",
|
|
2638
|
+
* "operator": "=",
|
|
2639
|
+
* "value": "production"
|
|
2640
|
+
* }
|
|
2641
|
+
* ]
|
|
2642
|
+
* ```
|
|
2549
2643
|
*/
|
|
2550
2644
|
filter?: string;
|
|
2551
2645
|
}
|
|
@@ -2816,16 +2910,39 @@ interface OrganizationProjectsResponse {
|
|
|
2816
2910
|
projects: OrganizationProject[];
|
|
2817
2911
|
}
|
|
2818
2912
|
|
|
2913
|
+
/**
|
|
2914
|
+
* This file was auto-generated by Fern from our API Definition.
|
|
2915
|
+
*/
|
|
2916
|
+
interface OrganizationApiKey {
|
|
2917
|
+
id: string;
|
|
2918
|
+
createdAt: string;
|
|
2919
|
+
expiresAt?: string;
|
|
2920
|
+
lastUsedAt?: string;
|
|
2921
|
+
note?: string;
|
|
2922
|
+
publicKey: string;
|
|
2923
|
+
displaySecretKey: string;
|
|
2924
|
+
}
|
|
2925
|
+
|
|
2926
|
+
/**
|
|
2927
|
+
* This file was auto-generated by Fern from our API Definition.
|
|
2928
|
+
*/
|
|
2929
|
+
|
|
2930
|
+
interface OrganizationApiKeysResponse {
|
|
2931
|
+
apiKeys: OrganizationApiKey[];
|
|
2932
|
+
}
|
|
2933
|
+
|
|
2819
2934
|
type index$b_DeleteMembershipRequest = DeleteMembershipRequest;
|
|
2820
2935
|
type index$b_MembershipDeletionResponse = MembershipDeletionResponse;
|
|
2821
2936
|
type index$b_MembershipRequest = MembershipRequest;
|
|
2822
2937
|
type index$b_MembershipResponse = MembershipResponse;
|
|
2823
2938
|
declare const index$b_MembershipRole: typeof MembershipRole;
|
|
2824
2939
|
type index$b_MembershipsResponse = MembershipsResponse;
|
|
2940
|
+
type index$b_OrganizationApiKey = OrganizationApiKey;
|
|
2941
|
+
type index$b_OrganizationApiKeysResponse = OrganizationApiKeysResponse;
|
|
2825
2942
|
type index$b_OrganizationProject = OrganizationProject;
|
|
2826
2943
|
type index$b_OrganizationProjectsResponse = OrganizationProjectsResponse;
|
|
2827
2944
|
declare namespace index$b {
|
|
2828
|
-
export { type index$b_DeleteMembershipRequest as DeleteMembershipRequest, type index$b_MembershipDeletionResponse as MembershipDeletionResponse, type index$b_MembershipRequest as MembershipRequest, type index$b_MembershipResponse as MembershipResponse, index$b_MembershipRole as MembershipRole, type index$b_MembershipsResponse as MembershipsResponse, type index$b_OrganizationProject as OrganizationProject, type index$b_OrganizationProjectsResponse as OrganizationProjectsResponse };
|
|
2945
|
+
export { type index$b_DeleteMembershipRequest as DeleteMembershipRequest, type index$b_MembershipDeletionResponse as MembershipDeletionResponse, type index$b_MembershipRequest as MembershipRequest, type index$b_MembershipResponse as MembershipResponse, index$b_MembershipRole as MembershipRole, type index$b_MembershipsResponse as MembershipsResponse, type index$b_OrganizationApiKey as OrganizationApiKey, type index$b_OrganizationApiKeysResponse as OrganizationApiKeysResponse, type index$b_OrganizationProject as OrganizationProject, type index$b_OrganizationProjectsResponse as OrganizationProjectsResponse };
|
|
2829
2946
|
}
|
|
2830
2947
|
|
|
2831
2948
|
/**
|
|
@@ -3686,7 +3803,7 @@ interface CreateScoreRequest {
|
|
|
3686
3803
|
/** The value of the score. Must be passed as string for categorical scores, and numeric for boolean and numeric scores. Boolean score values must equal either 1 or 0 (true or false) */
|
|
3687
3804
|
value: CreateScoreValue;
|
|
3688
3805
|
comment?: string;
|
|
3689
|
-
metadata?: unknown
|
|
3806
|
+
metadata?: Record<string, unknown>;
|
|
3690
3807
|
/** The environment of the score. Can be any lowercase alphanumeric string with hyphens and underscores that does not start with 'langfuse'. */
|
|
3691
3808
|
environment?: string;
|
|
3692
3809
|
/** The annotation queue referenced by the score. Indicates if score was initially created while processing annotation queue. */
|
|
@@ -3801,13 +3918,15 @@ interface GetTracesRequest {
|
|
|
3801
3918
|
/** Comma-separated list of fields to include in the response. Available field groups: 'core' (always included), 'io' (input, output, metadata), 'scores', 'observations', 'metrics'. If not specified, all fields are returned. Example: 'core,scores,metrics'. Note: Excluded 'observations' or 'scores' fields return empty arrays; excluded 'metrics' returns -1 for 'totalCost' and 'latency'. */
|
|
3802
3919
|
fields?: string;
|
|
3803
3920
|
/**
|
|
3804
|
-
* JSON string containing an array of filter conditions. When provided, this takes precedence over
|
|
3921
|
+
* JSON string containing an array of filter conditions. When provided, this takes precedence over query parameter filters (userId, name, sessionId, tags, version, release, environment, fromTimestamp, toTimestamp).
|
|
3922
|
+
*
|
|
3923
|
+
* ## Filter Structure
|
|
3805
3924
|
* Each filter condition has the following structure:
|
|
3806
3925
|
* ```json
|
|
3807
3926
|
* [
|
|
3808
3927
|
* {
|
|
3809
3928
|
* "type": string, // Required. One of: "datetime", "string", "number", "stringOptions", "categoryOptions", "arrayOptions", "stringObject", "numberObject", "boolean", "null"
|
|
3810
|
-
* "column": string, // Required. Column to filter on
|
|
3929
|
+
* "column": string, // Required. Column to filter on (see available columns below)
|
|
3811
3930
|
* "operator": string, // Required. Operator based on type:
|
|
3812
3931
|
* // - datetime: ">", "<", ">=", "<="
|
|
3813
3932
|
* // - string: "=", "contains", "does not contain", "starts with", "ends with"
|
|
@@ -3824,6 +3943,86 @@ interface GetTracesRequest {
|
|
|
3824
3943
|
* }
|
|
3825
3944
|
* ]
|
|
3826
3945
|
* ```
|
|
3946
|
+
*
|
|
3947
|
+
* ## Available Columns
|
|
3948
|
+
*
|
|
3949
|
+
* ### Core Trace Fields
|
|
3950
|
+
* - `id` (string) - Trace ID
|
|
3951
|
+
* - `name` (string) - Trace name
|
|
3952
|
+
* - `timestamp` (datetime) - Trace timestamp
|
|
3953
|
+
* - `userId` (string) - User ID
|
|
3954
|
+
* - `sessionId` (string) - Session ID
|
|
3955
|
+
* - `environment` (string) - Environment tag
|
|
3956
|
+
* - `version` (string) - Version tag
|
|
3957
|
+
* - `release` (string) - Release tag
|
|
3958
|
+
* - `tags` (arrayOptions) - Array of tags
|
|
3959
|
+
* - `bookmarked` (boolean) - Bookmark status
|
|
3960
|
+
*
|
|
3961
|
+
* ### Structured Data
|
|
3962
|
+
* - `metadata` (stringObject/numberObject/categoryOptions) - Metadata key-value pairs. Use `key` parameter to filter on specific metadata keys.
|
|
3963
|
+
*
|
|
3964
|
+
* ### Aggregated Metrics (from observations)
|
|
3965
|
+
* These metrics are aggregated from all observations within the trace:
|
|
3966
|
+
* - `latency` (number) - Latency in seconds (time from first observation start to last observation end)
|
|
3967
|
+
* - `inputTokens` (number) - Total input tokens across all observations
|
|
3968
|
+
* - `outputTokens` (number) - Total output tokens across all observations
|
|
3969
|
+
* - `totalTokens` (number) - Total tokens (alias: `tokens`)
|
|
3970
|
+
* - `inputCost` (number) - Total input cost in USD
|
|
3971
|
+
* - `outputCost` (number) - Total output cost in USD
|
|
3972
|
+
* - `totalCost` (number) - Total cost in USD
|
|
3973
|
+
*
|
|
3974
|
+
* ### Observation Level Aggregations
|
|
3975
|
+
* These fields aggregate observation levels within the trace:
|
|
3976
|
+
* - `level` (string) - Highest severity level (ERROR > WARNING > DEFAULT > DEBUG)
|
|
3977
|
+
* - `warningCount` (number) - Count of WARNING level observations
|
|
3978
|
+
* - `errorCount` (number) - Count of ERROR level observations
|
|
3979
|
+
* - `defaultCount` (number) - Count of DEFAULT level observations
|
|
3980
|
+
* - `debugCount` (number) - Count of DEBUG level observations
|
|
3981
|
+
*
|
|
3982
|
+
* ### Scores (requires join with scores table)
|
|
3983
|
+
* - `scores_avg` (number) - Average of numeric scores (alias: `scores`)
|
|
3984
|
+
* - `score_categories` (categoryOptions) - Categorical score values
|
|
3985
|
+
*
|
|
3986
|
+
* ## Filter Examples
|
|
3987
|
+
* ```json
|
|
3988
|
+
* [
|
|
3989
|
+
* {
|
|
3990
|
+
* "type": "datetime",
|
|
3991
|
+
* "column": "timestamp",
|
|
3992
|
+
* "operator": ">=",
|
|
3993
|
+
* "value": "2024-01-01T00:00:00Z"
|
|
3994
|
+
* },
|
|
3995
|
+
* {
|
|
3996
|
+
* "type": "string",
|
|
3997
|
+
* "column": "userId",
|
|
3998
|
+
* "operator": "=",
|
|
3999
|
+
* "value": "user-123"
|
|
4000
|
+
* },
|
|
4001
|
+
* {
|
|
4002
|
+
* "type": "number",
|
|
4003
|
+
* "column": "totalCost",
|
|
4004
|
+
* "operator": ">=",
|
|
4005
|
+
* "value": 0.01
|
|
4006
|
+
* },
|
|
4007
|
+
* {
|
|
4008
|
+
* "type": "arrayOptions",
|
|
4009
|
+
* "column": "tags",
|
|
4010
|
+
* "operator": "all of",
|
|
4011
|
+
* "value": ["production", "critical"]
|
|
4012
|
+
* },
|
|
4013
|
+
* {
|
|
4014
|
+
* "type": "stringObject",
|
|
4015
|
+
* "column": "metadata",
|
|
4016
|
+
* "key": "customer_tier",
|
|
4017
|
+
* "operator": "=",
|
|
4018
|
+
* "value": "enterprise"
|
|
4019
|
+
* }
|
|
4020
|
+
* ]
|
|
4021
|
+
* ```
|
|
4022
|
+
*
|
|
4023
|
+
* ## Performance Notes
|
|
4024
|
+
* - Filtering on `userId`, `sessionId`, or `metadata` may enable skip indexes for better query performance
|
|
4025
|
+
* - Score filters require a join with the scores table and may impact query performance
|
|
3827
4026
|
*/
|
|
3828
4027
|
filter?: string;
|
|
3829
4028
|
}
|
|
@@ -4646,7 +4845,9 @@ declare class Datasets {
|
|
|
4646
4845
|
* await client.datasets.create({
|
|
4647
4846
|
* name: "name",
|
|
4648
4847
|
* description: undefined,
|
|
4649
|
-
* metadata: undefined
|
|
4848
|
+
* metadata: undefined,
|
|
4849
|
+
* inputSchema: undefined,
|
|
4850
|
+
* expectedOutputSchema: undefined
|
|
4650
4851
|
* })
|
|
4651
4852
|
*/
|
|
4652
4853
|
create(request: CreateDatasetRequest, requestOptions?: Datasets.RequestOptions): HttpResponsePromise<Dataset>;
|
|
@@ -5647,6 +5848,22 @@ declare class Organizations {
|
|
|
5647
5848
|
*/
|
|
5648
5849
|
getOrganizationProjects(requestOptions?: Organizations.RequestOptions): HttpResponsePromise<OrganizationProjectsResponse>;
|
|
5649
5850
|
private __getOrganizationProjects;
|
|
5851
|
+
/**
|
|
5852
|
+
* Get all API keys for the organization associated with the API key (requires organization-scoped API key)
|
|
5853
|
+
*
|
|
5854
|
+
* @param {Organizations.RequestOptions} requestOptions - Request-specific configuration.
|
|
5855
|
+
*
|
|
5856
|
+
* @throws {@link LangfuseAPI.Error}
|
|
5857
|
+
* @throws {@link LangfuseAPI.UnauthorizedError}
|
|
5858
|
+
* @throws {@link LangfuseAPI.AccessDeniedError}
|
|
5859
|
+
* @throws {@link LangfuseAPI.MethodNotAllowedError}
|
|
5860
|
+
* @throws {@link LangfuseAPI.NotFoundError}
|
|
5861
|
+
*
|
|
5862
|
+
* @example
|
|
5863
|
+
* await client.organizations.getOrganizationApiKeys()
|
|
5864
|
+
*/
|
|
5865
|
+
getOrganizationApiKeys(requestOptions?: Organizations.RequestOptions): HttpResponsePromise<OrganizationApiKeysResponse>;
|
|
5866
|
+
private __getOrganizationApiKeys;
|
|
5650
5867
|
protected _getAuthorizationHeader(): Promise<string | undefined>;
|
|
5651
5868
|
}
|
|
5652
5869
|
|
|
@@ -6770,6 +6987,23 @@ declare function base64ToBytes(base64: string): Uint8Array;
|
|
|
6770
6987
|
declare function bytesToBase64(bytes: Uint8Array): string;
|
|
6771
6988
|
declare function base64Encode(input: string): string;
|
|
6772
6989
|
declare function base64Decode(input: string): string;
|
|
6990
|
+
/**
|
|
6991
|
+
* Generate a random experiment ID (16 hex characters from 8 random bytes).
|
|
6992
|
+
* @internal
|
|
6993
|
+
*/
|
|
6994
|
+
declare function createExperimentId(): Promise<string>;
|
|
6995
|
+
/**
|
|
6996
|
+
* Generate experiment item ID from input hash (first 16 hex chars of SHA-256).
|
|
6997
|
+
* Skips serialization if input is already a string.
|
|
6998
|
+
* @internal
|
|
6999
|
+
*/
|
|
7000
|
+
declare function createExperimentItemId(input: any): Promise<string>;
|
|
7001
|
+
/**
|
|
7002
|
+
* Serialize a value to JSON string, handling undefined/null.
|
|
7003
|
+
* Skips serialization if value is already a string.
|
|
7004
|
+
* @internal
|
|
7005
|
+
*/
|
|
7006
|
+
declare function serializeValue(value: any): string | undefined;
|
|
6773
7007
|
|
|
6774
7008
|
type ParsedMediaReference = {
|
|
6775
7009
|
mediaId: string;
|
|
@@ -6925,4 +7159,186 @@ declare class LangfuseMedia {
|
|
|
6925
7159
|
toJSON(): string | null;
|
|
6926
7160
|
}
|
|
6927
7161
|
|
|
6928
|
-
|
|
7162
|
+
/**
|
|
7163
|
+
* Attribute propagation utilities for Langfuse OpenTelemetry integration.
|
|
7164
|
+
*
|
|
7165
|
+
* This module provides the `propagateAttributes` function for setting trace-level
|
|
7166
|
+
* attributes (userId, sessionId, metadata) that automatically propagate to all child spans
|
|
7167
|
+
* within the context.
|
|
7168
|
+
*/
|
|
7169
|
+
|
|
7170
|
+
type CorrelatedKey = "userId" | "sessionId" | "metadata" | "version" | "tags";
|
|
7171
|
+
declare const experimentKeys: readonly ["experimentId", "experimentName", "experimentMetadata", "experimentDatasetId", "experimentItemId", "experimentItemMetadata", "experimentItemRootObservationId"];
|
|
7172
|
+
type ExperimentKey = (typeof experimentKeys)[number];
|
|
7173
|
+
type PropagatedKey = CorrelatedKey | ExperimentKey;
|
|
7174
|
+
type PropagatedExperimentAttributes = {
|
|
7175
|
+
experimentId: string;
|
|
7176
|
+
experimentName: string;
|
|
7177
|
+
experimentMetadata?: string;
|
|
7178
|
+
experimentDatasetId?: string;
|
|
7179
|
+
experimentItemId: string;
|
|
7180
|
+
experimentItemMetadata?: string;
|
|
7181
|
+
experimentItemRootObservationId: string;
|
|
7182
|
+
};
|
|
7183
|
+
declare const LangfuseOtelContextKeys: Record<PropagatedKey, symbol>;
|
|
7184
|
+
/**
|
|
7185
|
+
* Parameters for propagateAttributes function.
|
|
7186
|
+
*
|
|
7187
|
+
* @public
|
|
7188
|
+
*/
|
|
7189
|
+
interface PropagateAttributesParams {
|
|
7190
|
+
/**
|
|
7191
|
+
* User identifier to associate with all spans in this context.
|
|
7192
|
+
* Must be a string ≤200 characters. Use this to track which user
|
|
7193
|
+
* generated each trace and enable e.g. per-user cost/performance analysis.
|
|
7194
|
+
*/
|
|
7195
|
+
userId?: string;
|
|
7196
|
+
/**
|
|
7197
|
+
* Session identifier to associate with all spans in this context.
|
|
7198
|
+
* Must be a string ≤200 characters. Use this to group related traces
|
|
7199
|
+
* within a user session (e.g., a conversation thread, multi-turn interaction).
|
|
7200
|
+
*/
|
|
7201
|
+
sessionId?: string;
|
|
7202
|
+
/**
|
|
7203
|
+
* Additional key-value metadata to propagate to all spans.
|
|
7204
|
+
* - Keys and values must be strings
|
|
7205
|
+
* - All values must be ≤200 characters
|
|
7206
|
+
* - Use for dimensions like internal correlating identifiers
|
|
7207
|
+
* - AVOID: large payloads, sensitive data, non-string values (will be dropped with warning)
|
|
7208
|
+
*/
|
|
7209
|
+
metadata?: Record<string, string>;
|
|
7210
|
+
/**
|
|
7211
|
+
* Version identifier for parts of your application that are independently versioned, e.g. agents
|
|
7212
|
+
*/
|
|
7213
|
+
version?: string;
|
|
7214
|
+
/**
|
|
7215
|
+
* List of tags to categorize the group of observations
|
|
7216
|
+
*/
|
|
7217
|
+
tags?: string[];
|
|
7218
|
+
/**
|
|
7219
|
+
* If true, propagates attributes using OpenTelemetry baggage for
|
|
7220
|
+
* cross-process/service propagation.
|
|
7221
|
+
*
|
|
7222
|
+
* **Security warning**: When enabled, attribute values are added to HTTP headers
|
|
7223
|
+
* on ALL outbound requests. Only enable if values are safe to transmit via HTTP
|
|
7224
|
+
* headers and you need cross-service tracing.
|
|
7225
|
+
*
|
|
7226
|
+
* @defaultValue false
|
|
7227
|
+
*/
|
|
7228
|
+
asBaggage?: boolean;
|
|
7229
|
+
/**
|
|
7230
|
+
* **INTERNAL USE ONLY** - For Langfuse experiment framework.
|
|
7231
|
+
*
|
|
7232
|
+
* This parameter is used internally by the Langfuse experiment system to propagate
|
|
7233
|
+
* experiment context to child spans. It should NOT be used by external code.
|
|
7234
|
+
*
|
|
7235
|
+
* @internal
|
|
7236
|
+
*/
|
|
7237
|
+
_internalExperiment?: PropagatedExperimentAttributes;
|
|
7238
|
+
}
|
|
7239
|
+
/**
|
|
7240
|
+
* Propagate trace-level attributes to all spans created within this context.
|
|
7241
|
+
*
|
|
7242
|
+
* This function sets attributes on the currently active span AND automatically
|
|
7243
|
+
* propagates them to all new child spans created within the callback. This is the
|
|
7244
|
+
* recommended way to set trace-level attributes like userId, sessionId, and metadata
|
|
7245
|
+
* dimensions that should be consistently applied across all observations in a trace.
|
|
7246
|
+
*
|
|
7247
|
+
* **IMPORTANT**: Call this as early as possible within your trace/workflow. Only the
|
|
7248
|
+
* currently active span and spans created after entering this context will have these
|
|
7249
|
+
* attributes. Pre-existing spans will NOT be retroactively updated.
|
|
7250
|
+
*
|
|
7251
|
+
* **Why this matters**: Langfuse aggregation queries (e.g., total cost by userId,
|
|
7252
|
+
* filtering by sessionId) only include observations that have the attribute set.
|
|
7253
|
+
* If you call `propagateAttributes` late in your workflow, earlier spans won't be
|
|
7254
|
+
* included in aggregations for that attribute.
|
|
7255
|
+
*
|
|
7256
|
+
* @param params - Configuration for attributes to propagate
|
|
7257
|
+
* @param fn - Callback function (sync or async) within which attributes are propagated
|
|
7258
|
+
* @returns The result of the callback function
|
|
7259
|
+
*
|
|
7260
|
+
* @example
|
|
7261
|
+
* Basic usage with user and session tracking:
|
|
7262
|
+
*
|
|
7263
|
+
* ```typescript
|
|
7264
|
+
* import { startActiveObservation, propagateAttributes } from '@langfuse/tracing';
|
|
7265
|
+
*
|
|
7266
|
+
* // Set attributes early in the trace
|
|
7267
|
+
* await startActiveObservation('user_workflow', async (span) => {
|
|
7268
|
+
* await propagateAttributes({
|
|
7269
|
+
* userId: 'user_123',
|
|
7270
|
+
* sessionId: 'session_abc',
|
|
7271
|
+
* metadata: { experiment: 'variant_a', environment: 'production' }
|
|
7272
|
+
* }, async () => {
|
|
7273
|
+
* // All spans created here will have userId, sessionId, and metadata
|
|
7274
|
+
* const llmSpan = startObservation('llm_call', { input: 'Hello' });
|
|
7275
|
+
* // This span inherits: userId, sessionId, experiment, environment
|
|
7276
|
+
* llmSpan.end();
|
|
7277
|
+
*
|
|
7278
|
+
* const gen = startObservation('completion', {}, { asType: 'generation' });
|
|
7279
|
+
* // This span also inherits all attributes
|
|
7280
|
+
* gen.end();
|
|
7281
|
+
* });
|
|
7282
|
+
* });
|
|
7283
|
+
* ```
|
|
7284
|
+
*
|
|
7285
|
+
* @example
|
|
7286
|
+
* Late propagation (anti-pattern):
|
|
7287
|
+
*
|
|
7288
|
+
* ```typescript
|
|
7289
|
+
* await startActiveObservation('workflow', async (span) => {
|
|
7290
|
+
* // These spans WON'T have userId
|
|
7291
|
+
* const earlySpan = startObservation('early_work', { input: 'data' });
|
|
7292
|
+
* earlySpan.end();
|
|
7293
|
+
*
|
|
7294
|
+
* // Set attributes in the middle
|
|
7295
|
+
* await propagateAttributes({ userId: 'user_123' }, async () => {
|
|
7296
|
+
* // Only spans created AFTER this point will have userId
|
|
7297
|
+
* const lateSpan = startObservation('late_work', { input: 'more' });
|
|
7298
|
+
* lateSpan.end();
|
|
7299
|
+
* });
|
|
7300
|
+
*
|
|
7301
|
+
* // Result: Aggregations by userId will miss "early_work" span
|
|
7302
|
+
* });
|
|
7303
|
+
* ```
|
|
7304
|
+
*
|
|
7305
|
+
* @example
|
|
7306
|
+
* Cross-service propagation with baggage (advanced):
|
|
7307
|
+
*
|
|
7308
|
+
* ```typescript
|
|
7309
|
+
* import fetch from 'node-fetch';
|
|
7310
|
+
*
|
|
7311
|
+
* // Service A - originating service
|
|
7312
|
+
* await startActiveObservation('api_request', async () => {
|
|
7313
|
+
* await propagateAttributes({
|
|
7314
|
+
* userId: 'user_123',
|
|
7315
|
+
* sessionId: 'session_abc',
|
|
7316
|
+
* asBaggage: true // Propagate via HTTP headers
|
|
7317
|
+
* }, async () => {
|
|
7318
|
+
* // Make HTTP request to Service B
|
|
7319
|
+
* const response = await fetch('https://service-b.example.com/api');
|
|
7320
|
+
* // userId and sessionId are now in HTTP headers
|
|
7321
|
+
* });
|
|
7322
|
+
* });
|
|
7323
|
+
*
|
|
7324
|
+
* // Service B - downstream service
|
|
7325
|
+
* // OpenTelemetry will automatically extract baggage from HTTP headers
|
|
7326
|
+
* // and propagate to spans in Service B
|
|
7327
|
+
* ```
|
|
7328
|
+
*
|
|
7329
|
+
* @remarks
|
|
7330
|
+
* - **Validation**: All attribute values (userId, sessionId, metadata values)
|
|
7331
|
+
* must be strings ≤200 characters. Invalid values will be dropped with a
|
|
7332
|
+
* warning logged. Ensure values meet constraints before calling.
|
|
7333
|
+
* - **OpenTelemetry**: This uses OpenTelemetry context propagation under the hood,
|
|
7334
|
+
* making it compatible with other OTel-instrumented libraries.
|
|
7335
|
+
* - **Baggage Security**: When `asBaggage=true`, attribute values are added to HTTP
|
|
7336
|
+
* headers on outbound requests. Only use for non-sensitive values and when you
|
|
7337
|
+
* need cross-service tracing.
|
|
7338
|
+
*
|
|
7339
|
+
* @public
|
|
7340
|
+
*/
|
|
7341
|
+
declare function propagateAttributes<A extends unknown[], F extends (...args: A) => ReturnType<F>>(params: PropagateAttributesParams, fn: F): ReturnType<F>;
|
|
7342
|
+
declare function getPropagatedAttributesFromContext(context: Context): Record<string, string | string[]>;
|
|
7343
|
+
|
|
7344
|
+
export { AccessDeniedError, type AnnotationQueue, type AnnotationQueueAssignmentRequest, type AnnotationQueueItem, AnnotationQueueObjectType, AnnotationQueueStatus, type ApiKeyDeletionResponse, type ApiKeyList, type ApiKeyResponse, type ApiKeySummary, type AuthenticationScheme, type BaseEvent, type BasePrompt, type BaseScore, type BaseScoreV1, BlobStorageExportFrequency, BlobStorageExportMode, type BlobStorageIntegrationDeletionResponse, BlobStorageIntegrationFileType, type BlobStorageIntegrationResponse, BlobStorageIntegrationType, type BlobStorageIntegrationsResponse, type BooleanScore, type BooleanScoreV1, type BulkConfig, type CategoricalScore, type CategoricalScoreV1, type ChatMessage, ChatMessageWithPlaceholders, type ChatPrompt, type Comment, CommentObjectType, type ConfigCategory, type CreateAnnotationQueueAssignmentResponse, type CreateAnnotationQueueItemRequest, type CreateAnnotationQueueRequest, type CreateApiKeyRequest, type CreateBlobStorageIntegrationRequest, type CreateChatPromptRequest, type CreateCommentRequest, type CreateCommentResponse, type CreateDatasetItemRequest, type CreateDatasetRequest, type CreateDatasetRunItemRequest, type CreateEventBody, type CreateEventEvent, type CreateGenerationBody, type CreateGenerationEvent, type CreateModelRequest, type CreateObservationEvent, type CreateProjectRequest, CreatePromptRequest, type CreateScoreConfigRequest, type CreateScoreRequest, type CreateScoreResponse, type CreateScoreValue, type CreateSpanBody, type CreateSpanEvent, type CreateTextPromptRequest, type CreateUserRequest, type Dataset, type DatasetItem, type DatasetRun, type DatasetRunItem, type DatasetRunWithItems, DatasetStatus, type DeleteAnnotationQueueAssignmentResponse, type DeleteAnnotationQueueItemResponse, type DeleteDatasetItemResponse, type DeleteDatasetRunResponse, type DeleteMembershipRequest, type DeleteTraceResponse, type DeleteTracesRequest, type EmptyResponse, Error$1 as Error, type FilterConfig, type GetAnnotationQueueItemsRequest, type GetAnnotationQueuesRequest, type GetCommentsRequest, type GetCommentsResponse, type GetDatasetItemsRequest, type GetDatasetRunsRequest, type GetDatasetsRequest, type GetLlmConnectionsRequest, type GetMediaResponse, type GetMediaUploadUrlRequest, type GetMediaUploadUrlResponse, type GetMetricsRequest, type GetModelsRequest, type GetObservationsRequest, type GetPromptRequest, type GetScoreConfigsRequest, type GetScoresRequest, type GetScoresResponse, GetScoresResponseData, type GetScoresResponseDataBoolean, type GetScoresResponseDataCategorical, type GetScoresResponseDataNumeric, type GetScoresResponseTraceData, type GetSessionsRequest, type GetTracesRequest, type HealthResponse, type IngestionError, IngestionEvent, type IngestionRequest, type IngestionResponse, type IngestionSuccess, type IngestionUsage, LANGFUSE_SDK_EXPERIMENT_ENVIRONMENT, LANGFUSE_SDK_NAME, LANGFUSE_SDK_VERSION, LANGFUSE_TRACER_NAME, LangfuseAPIClient, LangfuseAPIError, LangfuseAPITimeoutError, LangfuseMedia, type LangfuseMediaParams, LangfuseOtelContextKeys, LangfuseOtelSpanAttributes, type ListDatasetRunItemsRequest, type ListPromptsMetaRequest, type ListUsersRequest, LlmAdapter, type LlmConnection, LogLevel, Logger, type LoggerConfig, type MapValue, MediaContentType, type MembershipDeletionResponse, type MembershipRequest, type MembershipResponse, MembershipRole, type MembershipsResponse, MethodNotAllowedError, type MetricsResponse, type Model, type ModelPrice, ModelUsageUnit, NotFoundError, type NumericScore, type NumericScoreV1, type Observation, type ObservationBody, ObservationLevel, ObservationType, type Observations$1 as Observations, type ObservationsView, type ObservationsViews, type OpenAiCompletionUsageSchema, type OpenAiResponseUsageSchema, type OpenAiUsage, type OptionalObservationBody, type OrganizationApiKey, type OrganizationApiKeysResponse, type OrganizationProject, type OrganizationProjectsResponse, type OtelAttribute, type OtelAttributeValue, type OtelResource, type OtelResourceSpan, type OtelScope, type OtelScopeSpan, type OtelSpan, type OtelTraceRequest, type OtelTraceResponse, type PaginatedAnnotationQueueItems, type PaginatedAnnotationQueues, type PaginatedDatasetItems, type PaginatedDatasetRunItems, type PaginatedDatasetRuns, type PaginatedDatasets, type PaginatedLlmConnections, type PaginatedModels, type PaginatedSessions, type ParsedMediaReference, type PatchMediaBody, type PlaceholderMessage, type Project, type ProjectDeletionResponse, type Projects$1 as Projects, Prompt, type PromptMeta, type PromptMetaListResponse, PromptType, type PropagateAttributesParams, type ResourceMeta, type ResourceType, type ResourceTypesResponse, type SchemaExtension, type SchemaResource, type SchemasResponse, type ScimEmail, type ScimFeatureSupport, type ScimName, type ScimUser, type ScimUsersListResponse, Score$1 as Score, type ScoreBody, type ScoreConfig, type ScoreConfigs$1 as ScoreConfigs, ScoreDataType, type ScoreEvent, ScoreSource, ScoreV1, type SdkLogBody, type SdkLogEvent, type ServiceProviderConfig, ServiceUnavailableError, type Session, type SessionWithTraces, type Sort, type TextPrompt, type Trace$1 as Trace, type TraceBody, type TraceEvent, type TraceWithDetails, type TraceWithFullDetails, type Traces, UnauthorizedError, type UpdateAnnotationQueueItemRequest, type UpdateEventBody, type UpdateGenerationBody, type UpdateGenerationEvent, type UpdateObservationEvent, type UpdateProjectRequest, type UpdatePromptRequest, type UpdateScoreConfigRequest, type UpdateSpanBody, type UpdateSpanEvent, type UpsertLlmConnectionRequest, type Usage, type UsageDetails, type UserMeta, index$q as annotationQueues, base64Decode, base64Encode, base64ToBytes, index$p as blobStorageIntegrations, bytesToBase64, index$o as comments, index$n as commons, configureGlobalLogger, createExperimentId, createExperimentItemId, createLogger, index$m as datasetItems, index$l as datasetRunItems, index$k as datasets, generateUUID, getEnv, getGlobalLogger, getPropagatedAttributesFromContext, index$j as health, index$i as ingestion, index$h as llmConnections, LoggerSingleton as logger, index$g as media, index$f as metrics, index$e as models, index$d as observations, index$c as opentelemetry, index$b as organizations, index$a as projects, index as promptVersion, index$9 as prompts, propagateAttributes, resetGlobalLogger, safeSetTimeout, index$8 as scim, index$5 as score, index$7 as scoreConfigs, index$6 as scoreV2, serializeValue, index$4 as sessions, index$3 as trace, index$1 as utils };
|