@@ -44,6 +44,9 @@ export class LiteralClient {
44
44
instrumentation : ReturnType < typeof instrumentation > ;
45
45
store : AsyncLocalStorage < StoredContext > =
46
46
new AsyncLocalStorage < StoredContext > ( ) ;
47
+ globalMetadata : {
48
+ release ?: string ;
49
+ } = { } ;
47
50
48
51
/**
49
52
* Initialize a new Literal AI Client.
@@ -52,18 +55,21 @@ export class LiteralClient {
52
55
* @param options.apiUrl The URL of the Literal AI API. Defaults to the LITERAL_API_URL env var, or https://cloud.getliteral.ai.
53
56
* @param options.environment The environment to use for the Literal AI API.
54
57
* @param options.disabled If set to true, no call will be made to the Literal AI API.
58
+ * @param options.release The release version of your application. This helps track which release an event came from.
55
59
* @returns A new LiteralClient instance.
56
60
*/
57
61
constructor ( {
58
62
apiKey,
59
63
apiUrl,
60
64
environment,
61
- disabled
65
+ disabled,
66
+ release
62
67
} : {
63
68
apiKey ?: string ;
64
69
apiUrl ?: string ;
65
70
environment ?: Environment ;
66
71
disabled ?: boolean ;
72
+ release ?: string ;
67
73
} = { } ) {
68
74
if ( ! apiKey ) {
69
75
apiKey = process . env . LITERAL_API_KEY ;
@@ -76,6 +82,11 @@ export class LiteralClient {
76
82
this . api = new API ( this , apiKey , apiUrl , environment , disabled ) ;
77
83
this . openai = openai ( this ) ;
78
84
this . instrumentation = instrumentation ( this ) ;
85
+ const formattedRelease = release ?. trim ( ) ;
86
+
87
+ if ( formattedRelease ) {
88
+ this . globalMetadata . release = formattedRelease ;
89
+ }
79
90
}
80
91
81
92
/**
@@ -229,6 +240,7 @@ export class LiteralClient {
229
240
return {
230
241
wrap : async < T > ( cb : ( ) => T ) => {
231
242
const currentStore = this . store . getStore ( ) ;
243
+ const metadata = { ...this . globalMetadata , ...options ?. metadata } ;
232
244
233
245
return this . store . run (
234
246
{
@@ -237,7 +249,7 @@ export class LiteralClient {
237
249
currentStore ?. currentExperimentItemRunId ?? null ,
238
250
currentStep : currentStore ?. currentStep ?? null ,
239
251
rootRun : currentStore ?. rootRun ?? null ,
240
- metadata : options ?. metadata ?? null ,
252
+ metadata,
241
253
tags : options ?. tags ?? null ,
242
254
stepId : options ?. stepId ?? null
243
255
} ,
0 commit comments