@withgateway/sdk 0.1.3 → 0.1.5
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/context/index.mjs +3 -0
- package/dist/context/index.mjs.map +1 -1
- package/dist/experiments/index.mjs +2 -0
- package/dist/experiments/index.mjs.map +1 -1
- package/dist/index-DnowA8MG.d.mts +447 -0
- package/dist/index-DnowA8MG.d.ts +447 -0
- package/dist/index.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +1715 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1686 -19
- package/dist/index.mjs.map +1 -1
- package/dist/memory/index.mjs +3 -0
- package/dist/memory/index.mjs.map +1 -1
- package/dist/personas/index.d.mts +102 -0
- package/dist/personas/index.d.ts +102 -0
- package/dist/personas/index.js +205 -0
- package/dist/personas/index.js.map +1 -0
- package/dist/personas/index.mjs +180 -0
- package/dist/personas/index.mjs.map +1 -0
- package/dist/replay/index.d.mts +351 -0
- package/dist/replay/index.d.ts +351 -0
- package/dist/replay/index.js +1094 -0
- package/dist/replay/index.js.map +1 -0
- package/dist/replay/index.mjs +1057 -0
- package/dist/replay/index.mjs.map +1 -0
- package/dist/security/index.mjs +2 -0
- package/dist/security/index.mjs.map +1 -1
- package/dist/sessions/index.d.mts +143 -0
- package/dist/sessions/index.d.ts +143 -0
- package/dist/sessions/index.js +320 -0
- package/dist/sessions/index.js.map +1 -0
- package/dist/sessions/index.mjs +288 -0
- package/dist/sessions/index.mjs.map +1 -0
- package/dist/tracing/index.d.mts +3 -1
- package/dist/tracing/index.d.ts +3 -1
- package/dist/tracing/index.js +435 -8
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +431 -8
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/users/index.d.mts +81 -0
- package/dist/users/index.d.ts +81 -0
- package/dist/users/index.js +168 -0
- package/dist/users/index.js.map +1 -0
- package/dist/users/index.mjs +144 -0
- package/dist/users/index.mjs.map +1 -0
- package/package.json +25 -1
- package/dist/index-Caw3XVub.d.mts +0 -193
- package/dist/index-Caw3XVub.d.ts +0 -193
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/users/index.ts"],"sourcesContent":["/**\n * End-user profiles — attribute usage and ROI to the real people behind\n * your agent's traffic.\n *\n * Profiles pair with the platform's per-user usage metrics (traces, tokens,\n * lifetime cost) on the Users page. Attributes merge by default, so pushing\n * an incremental ROI fact is one call:\n *\n * ```typescript\n * import { UsersClient } from \"@withgateway/sdk/users\";\n *\n * const users = UsersClient.fromEnv();\n * await users.update(\"user-123\", {\n * displayName: \"Acme Corp — Jane D.\",\n * attributes: { plan: \"enterprise\", account_value: \"48000\" },\n * });\n * ```\n *\n * Tip: `identify(\"user-123\", { attributes: {...} })` does this in the\n * background AND attributes the current trace/session to the user.\n *\n * Mirrors the Python SDK's `gatewaysdk.users` module.\n */\n\ntype UserProfile = {\n userId: string;\n displayName: string | null;\n email: string | null;\n attributes: Record<string, string>;\n notes: string | null;\n};\n\ntype UserProfileUpdate = {\n displayName?: string;\n email?: string;\n attributes?: Record<string, string>;\n notes?: string;\n /**\n * Attributes merge with the stored set by default. Set `merge: false`\n * to replace the stored attributes wholesale.\n */\n merge?: boolean;\n};\n\ntype UsersClientConfig = {\n host: string;\n publicKey: string;\n secretKey: string;\n timeoutSeconds?: number;\n debug?: boolean;\n};\n\ntype UsersClientFromEnvConfig = Partial<UsersClientConfig>;\n\n/** Raised when the Gateway user-profiles API cannot complete a request. */\nexport class UserProfileError extends Error {\n constructor(message: string, options?: { cause?: unknown }) {\n super(message);\n this.name = \"UserProfileError\";\n this.cause = options?.cause;\n }\n}\n\n/** Client for Gateway's end-user profile endpoints (Basic project keys). */\nexport class UsersClient {\n private readonly host: string;\n private readonly publicKey: string;\n private readonly secretKey: string;\n private readonly timeoutSeconds: number;\n private readonly debug: boolean;\n\n constructor(config: UsersClientConfig) {\n this.host = config.host.replace(/\\/$/, \"\");\n this.publicKey = config.publicKey;\n this.secretKey = config.secretKey;\n this.timeoutSeconds = config.timeoutSeconds ?? 15;\n this.debug = config.debug ?? false;\n }\n\n /** Create a client from GATEWAY_HOST / GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY. */\n static fromEnv(config: UsersClientFromEnvConfig = {}) {\n const host = config.host ?? process.env.GATEWAY_HOST;\n const publicKey = config.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;\n const secretKey = config.secretKey ?? process.env.GATEWAY_SECRET_KEY;\n\n const missing = [\n [\"host\", host],\n [\"publicKey\", publicKey],\n [\"secretKey\", secretKey],\n ]\n .filter(([, value]) => !value)\n .map(([name]) => name);\n\n if (missing.length > 0) {\n throw new UserProfileError(\n `Missing Gateway user-profile configuration: ${missing.join(\", \")}`,\n );\n }\n\n return new UsersClient({\n ...config,\n host: host!,\n publicKey: publicKey!,\n secretKey: secretKey!,\n });\n }\n\n /** Fetch a user's stored profile. */\n async get(userId: string): Promise<UserProfile> {\n return parseProfile(\n await this.requestJson(\n \"GET\",\n `/api/public/user-profiles/${encodeURIComponent(userId)}`,\n ),\n );\n }\n\n /**\n * Upsert a user's profile. `attributes` merge with the stored set unless\n * `merge: false` (which replaces it).\n */\n async update(\n userId: string,\n update: UserProfileUpdate = {},\n ): Promise<UserProfile> {\n const body: Record<string, unknown> = {\n userId,\n attributes: update.attributes ?? {},\n mergeAttributes: update.merge ?? true,\n ...(update.displayName !== undefined\n ? { displayName: update.displayName }\n : {}),\n ...(update.email !== undefined ? { email: update.email } : {}),\n ...(update.notes !== undefined ? { notes: update.notes } : {}),\n };\n return parseProfile(\n await this.requestJson(\"POST\", \"/api/public/user-profiles\", body),\n );\n }\n\n private async requestJson(\n method: \"GET\" | \"POST\",\n path: string,\n payload?: Record<string, unknown>,\n ): Promise<Record<string, unknown>> {\n let response: Response;\n try {\n response = await fetch(`${this.host}${path}`, {\n method,\n headers: {\n Authorization: this.authHeader(),\n \"Content-Type\": \"application/json\",\n },\n ...(payload ? { body: JSON.stringify(payload) } : {}),\n signal: AbortSignal.timeout(this.timeoutSeconds * 1000),\n });\n } catch (error) {\n throw new UserProfileError(\n `${method} ${path} failed: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n\n const text = await response.text();\n if (!response.ok) {\n throw new UserProfileError(\n `${method} ${path} failed (${response.status}): ${text.slice(0, 500)}`,\n );\n }\n\n this.log(\"%s %s -> %s\", method, path, response.status);\n return safeJson(text);\n }\n\n private authHeader() {\n return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(\n \"base64\",\n )}`;\n }\n\n private log(message: string, ...args: unknown[]) {\n if (this.debug) {\n console.log(`[gateway.users] ${message}`, ...args);\n }\n }\n}\n\nfunction parseProfile(payload: Record<string, unknown>): UserProfile {\n return {\n userId: String(payload.userId ?? \"\"),\n displayName:\n typeof payload.displayName === \"string\" ? payload.displayName : null,\n email: typeof payload.email === \"string\" ? payload.email : null,\n attributes: parseAttributes(payload.attributes),\n notes: typeof payload.notes === \"string\" ? payload.notes : null,\n };\n}\n\nfunction parseAttributes(value: unknown): Record<string, string> {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return {};\n const attributes: Record<string, string> = {};\n for (const [key, entry] of Object.entries(value as Record<string, unknown>)) {\n attributes[key] = String(entry);\n }\n return attributes;\n}\n\nfunction safeJson(value: string): Record<string, unknown> {\n try {\n const parsed = JSON.parse(value);\n return parsed && typeof parsed === \"object\" && !Array.isArray(parsed)\n ? (parsed as Record<string, unknown>)\n : {};\n } catch {\n return {};\n }\n}\n\nexport const users = {\n fromEnv: UsersClient.fromEnv,\n};\n\nexport type {\n UserProfile,\n UserProfileUpdate,\n UsersClientConfig,\n UsersClientFromEnvConfig,\n};\n"],"mappings":";;;;AAuDO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAC1C,YAAY,SAAiB,SAA+B;AAC1D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,QAAQ,SAAS;AAAA,EACxB;AACF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AE;AAAA,MACjE;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEQ,IAAI,YAAoB,MAAiB;AAC/C,QAAI,KAAK,OAAO;AACd,cAAQ,IAAI,mBAAmB,OAAO,IAAI,GAAG,IAAI;AAAA,IACnD;AAAA,EACF;AACF;AAEA,SAAS,aAAa,SAA+C;AACnE,SAAO;AAAA,IACL,QAAQ,OAAO,QAAQ,UAAU,EAAE;AAAA,IACnC,aACE,OAAO,QAAQ,gBAAgB,WAAW,QAAQ,cAAc;AAAA,IAClE,OAAO,OAAO,QAAQ,UAAU,WAAW,QAAQ,QAAQ;AAAA,IAC3D,YAAY,gBAAgB,QAAQ,UAAU;AAAA,IAC9C,OAAO,OAAO,QAAQ,UAAU,WAAW,QAAQ,QAAQ;AAAA,EAC7D;AACF;AAEA,SAAS,gBAAgB,OAAwC;AAC/D,MAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,EAAG,QAAO,CAAC;AACzE,QAAM,aAAqC,CAAC;AAC5C,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAgC,GAAG;AAC3E,eAAW,GAAG,IAAI,OAAO,KAAK;AAAA,EAChC;AACA,SAAO;AACT;AAEA,SAAS,SAAS,OAAwC;AACxD,MAAI;AACF,UAAM,SAAS,KAAK,MAAM,KAAK;AAC/B,WAAO,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,MAAM,IAC/D,SACD,CAAC;AAAA,EACP,QAAQ;AACN,WAAO,CAAC;AAAA,EACV;AACF;AAEO,IAAM,QAAQ;AAAA,EACnB,SAAS,YAAY;AACvB;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@withgateway/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -26,6 +26,21 @@
|
|
|
26
26
|
"import": "./dist/memory/index.mjs",
|
|
27
27
|
"require": "./dist/memory/index.js"
|
|
28
28
|
},
|
|
29
|
+
"./personas": {
|
|
30
|
+
"types": "./dist/personas/index.d.ts",
|
|
31
|
+
"import": "./dist/personas/index.mjs",
|
|
32
|
+
"require": "./dist/personas/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./replay": {
|
|
35
|
+
"types": "./dist/replay/index.d.ts",
|
|
36
|
+
"import": "./dist/replay/index.mjs",
|
|
37
|
+
"require": "./dist/replay/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./sessions": {
|
|
40
|
+
"types": "./dist/sessions/index.d.ts",
|
|
41
|
+
"import": "./dist/sessions/index.mjs",
|
|
42
|
+
"require": "./dist/sessions/index.js"
|
|
43
|
+
},
|
|
29
44
|
"./tracing": {
|
|
30
45
|
"types": "./dist/tracing/index.d.ts",
|
|
31
46
|
"import": "./dist/tracing/index.mjs",
|
|
@@ -35,6 +50,11 @@
|
|
|
35
50
|
"types": "./dist/security/index.d.ts",
|
|
36
51
|
"import": "./dist/security/index.mjs",
|
|
37
52
|
"require": "./dist/security/index.js"
|
|
53
|
+
},
|
|
54
|
+
"./users": {
|
|
55
|
+
"types": "./dist/users/index.d.ts",
|
|
56
|
+
"import": "./dist/users/index.mjs",
|
|
57
|
+
"require": "./dist/users/index.js"
|
|
38
58
|
}
|
|
39
59
|
},
|
|
40
60
|
"files": [
|
|
@@ -95,6 +115,10 @@
|
|
|
95
115
|
"optional": true
|
|
96
116
|
}
|
|
97
117
|
},
|
|
118
|
+
"optionalDependencies": {
|
|
119
|
+
"@arizeai/openinference-instrumentation-anthropic": "^0.1.15",
|
|
120
|
+
"@arizeai/openinference-instrumentation-openai": "^4.1.5"
|
|
121
|
+
},
|
|
98
122
|
"devDependencies": {
|
|
99
123
|
"@anthropic-ai/sdk": "^0.79.0",
|
|
100
124
|
"@opentelemetry/api": "^1.9.0",
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Types for the tracing module.
|
|
3
|
-
*/
|
|
4
|
-
interface TracingConfig {
|
|
5
|
-
/**
|
|
6
|
-
* Gateway server URL (e.g., "https://app.gateway.dev").
|
|
7
|
-
* Falls back to GATEWAY_HOST or GATEWAY_HOST env var.
|
|
8
|
-
*/
|
|
9
|
-
host?: string;
|
|
10
|
-
/**
|
|
11
|
-
* Public key for authentication (pk-lf-...).
|
|
12
|
-
* Falls back to GATEWAY_PUBLIC_KEY or GATEWAY_PUBLIC_KEY env var.
|
|
13
|
-
*/
|
|
14
|
-
publicKey?: string;
|
|
15
|
-
/**
|
|
16
|
-
* Secret key for authentication (sk-lf-...).
|
|
17
|
-
* Falls back to GATEWAY_SECRET_KEY or GATEWAY_SECRET_KEY env var.
|
|
18
|
-
*/
|
|
19
|
-
secretKey?: string;
|
|
20
|
-
/**
|
|
21
|
-
* Service name for resource attributes.
|
|
22
|
-
* Defaults to "gatewaysdk-tracing".
|
|
23
|
-
*/
|
|
24
|
-
serviceName?: string;
|
|
25
|
-
/**
|
|
26
|
-
* Environment name (e.g., "production", "staging").
|
|
27
|
-
* Sets resource attribute for filtering traces in Gateway.
|
|
28
|
-
*/
|
|
29
|
-
environment?: string;
|
|
30
|
-
/**
|
|
31
|
-
* Application version (e.g., "1.2.3", git SHA).
|
|
32
|
-
* Sets resource attribute for tracking regressions.
|
|
33
|
-
*/
|
|
34
|
-
version?: string;
|
|
35
|
-
/**
|
|
36
|
-
* Whether to enable debug logging to console.
|
|
37
|
-
* Defaults to false.
|
|
38
|
-
*/
|
|
39
|
-
debug?: boolean;
|
|
40
|
-
/**
|
|
41
|
-
* Whether to automatically add ExperimentSpanProcessor when imported
|
|
42
|
-
* from the main entry ("@withgateway/sdk"). Has no effect when imported
|
|
43
|
-
* from the subpath ("@withgateway/sdk/tracing") — use customSpanProcessors
|
|
44
|
-
* instead.
|
|
45
|
-
* Defaults to true.
|
|
46
|
-
*/
|
|
47
|
-
enableExperiments?: boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Additional span processors to register with the provider.
|
|
50
|
-
* These are added before the BatchSpanProcessor (which handles export).
|
|
51
|
-
*
|
|
52
|
-
* When using the main entry (`import { tracing } from "@withgateway/sdk"`),
|
|
53
|
-
* ExperimentSpanProcessor is automatically added unless enableExperiments
|
|
54
|
-
* is false. When using the subpath import, pass it here manually:
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```typescript
|
|
58
|
-
* import * as tracing from "@withgateway/sdk/tracing";
|
|
59
|
-
* import { ExperimentSpanProcessor } from "@withgateway/sdk/experiments";
|
|
60
|
-
*
|
|
61
|
-
* tracing.init({ customSpanProcessors: [new ExperimentSpanProcessor()] });
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
customSpanProcessors?: unknown[];
|
|
65
|
-
/**
|
|
66
|
-
* Custom OTLP endpoint URL. If not provided, derived from host.
|
|
67
|
-
*/
|
|
68
|
-
endpoint?: string;
|
|
69
|
-
/**
|
|
70
|
-
* Batch processor configuration.
|
|
71
|
-
*/
|
|
72
|
-
batch?: {
|
|
73
|
-
/** Max spans buffered in memory. Default: 2048 */
|
|
74
|
-
maxQueueSize?: number;
|
|
75
|
-
/** How often to flush spans (ms). Default: 5000 */
|
|
76
|
-
scheduledDelayMillis?: number;
|
|
77
|
-
/** Max spans per export call. Default: 512 */
|
|
78
|
-
maxExportBatchSize?: number;
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
interface TracingState {
|
|
82
|
-
initialized: boolean;
|
|
83
|
-
provider: unknown | null;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Initialization and lifecycle management for GatewaySDK tracing.
|
|
88
|
-
*
|
|
89
|
-
* This module provides the core init(), shutdown(), and flush() functions
|
|
90
|
-
* for managing the OpenTelemetry TracerProvider lifecycle.
|
|
91
|
-
*
|
|
92
|
-
* Mirrors the Python SDK's tracing.init() for a consistent developer experience.
|
|
93
|
-
*/
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Initialize GatewaySDK tracing with automatic OpenTelemetry configuration.
|
|
97
|
-
*
|
|
98
|
-
* This function configures OpenTelemetry with a connection to Gateway
|
|
99
|
-
* and sets up the ExperimentSpanProcessor for automatic experiment tagging.
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```typescript
|
|
103
|
-
* import { tracing } from "@withgateway/sdk";
|
|
104
|
-
*
|
|
105
|
-
* // Using environment variables (GATEWAY_HOST, GATEWAY_PUBLIC_KEY, GATEWAY_SECRET_KEY)
|
|
106
|
-
* tracing.init();
|
|
107
|
-
*
|
|
108
|
-
* // Or with explicit configuration
|
|
109
|
-
* tracing.init({
|
|
110
|
-
* host: "https://app.gateway.dev",
|
|
111
|
-
* publicKey: "pk-lf-...",
|
|
112
|
-
* secretKey: "sk-lf-...",
|
|
113
|
-
* serviceName: "my-agent",
|
|
114
|
-
* environment: "production",
|
|
115
|
-
* });
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
declare function init(config?: TracingConfig): void;
|
|
119
|
-
/**
|
|
120
|
-
* Force flush all pending spans without shutting down.
|
|
121
|
-
*
|
|
122
|
-
* Useful for ensuring spans are exported at specific points
|
|
123
|
-
* (e.g., after completing a batch of work) without ending the tracing session.
|
|
124
|
-
*
|
|
125
|
-
* @returns Promise that resolves when flush completes
|
|
126
|
-
*/
|
|
127
|
-
declare function flush(): Promise<void>;
|
|
128
|
-
/**
|
|
129
|
-
* Force flush all pending spans and shutdown the tracer provider.
|
|
130
|
-
*
|
|
131
|
-
* This function should be called before process exit to ensure all spans
|
|
132
|
-
* are exported. It is safe to call multiple times.
|
|
133
|
-
*
|
|
134
|
-
* @example
|
|
135
|
-
* ```typescript
|
|
136
|
-
* import { tracing } from "@withgateway/sdk";
|
|
137
|
-
*
|
|
138
|
-
* tracing.init();
|
|
139
|
-
*
|
|
140
|
-
* // On shutdown
|
|
141
|
-
* process.on("SIGTERM", async () => {
|
|
142
|
-
* await tracing.shutdown();
|
|
143
|
-
* process.exit(0);
|
|
144
|
-
* });
|
|
145
|
-
* ```
|
|
146
|
-
*/
|
|
147
|
-
declare function shutdown(): Promise<void>;
|
|
148
|
-
/**
|
|
149
|
-
* Check if tracing has been initialized.
|
|
150
|
-
*/
|
|
151
|
-
declare function isInitialized(): boolean;
|
|
152
|
-
/**
|
|
153
|
-
* Check if Gateway is configured via environment variables.
|
|
154
|
-
*/
|
|
155
|
-
declare function isGatewayConfigured(): boolean;
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Tracing module for GatewaySDK TypeScript SDK.
|
|
159
|
-
*
|
|
160
|
-
* Provides a simple init() function that configures OpenTelemetry with
|
|
161
|
-
* Gateway, mirroring the Python SDK's tracing.init() experience.
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* ```typescript
|
|
165
|
-
* import { tracing } from "@withgateway/sdk";
|
|
166
|
-
*
|
|
167
|
-
* // Initialize with environment variables
|
|
168
|
-
* tracing.init();
|
|
169
|
-
*
|
|
170
|
-
* // Or with explicit configuration
|
|
171
|
-
* tracing.init({
|
|
172
|
-
* host: "https://app.gateway.dev",
|
|
173
|
-
* publicKey: "pk-lf-...",
|
|
174
|
-
* secretKey: "sk-lf-...",
|
|
175
|
-
* });
|
|
176
|
-
*
|
|
177
|
-
* // Ensure cleanup on shutdown
|
|
178
|
-
* process.on("SIGTERM", () => tracing.shutdown());
|
|
179
|
-
* ```
|
|
180
|
-
*/
|
|
181
|
-
|
|
182
|
-
type _tracingModule_TracingConfig = TracingConfig;
|
|
183
|
-
type _tracingModule_TracingState = TracingState;
|
|
184
|
-
declare const _tracingModule_flush: typeof flush;
|
|
185
|
-
declare const _tracingModule_init: typeof init;
|
|
186
|
-
declare const _tracingModule_isGatewayConfigured: typeof isGatewayConfigured;
|
|
187
|
-
declare const _tracingModule_isInitialized: typeof isInitialized;
|
|
188
|
-
declare const _tracingModule_shutdown: typeof shutdown;
|
|
189
|
-
declare namespace _tracingModule {
|
|
190
|
-
export { type _tracingModule_TracingConfig as TracingConfig, type _tracingModule_TracingState as TracingState, _tracingModule_flush as flush, _tracingModule_init as init, _tracingModule_isGatewayConfigured as isGatewayConfigured, _tracingModule_isInitialized as isInitialized, _tracingModule_shutdown as shutdown };
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export { type TracingConfig as T, _tracingModule as _, type TracingState as a, isGatewayConfigured as b, isInitialized as c, flush as f, init as i, shutdown as s };
|
package/dist/index-Caw3XVub.d.ts
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Types for the tracing module.
|
|
3
|
-
*/
|
|
4
|
-
interface TracingConfig {
|
|
5
|
-
/**
|
|
6
|
-
* Gateway server URL (e.g., "https://app.gateway.dev").
|
|
7
|
-
* Falls back to GATEWAY_HOST or GATEWAY_HOST env var.
|
|
8
|
-
*/
|
|
9
|
-
host?: string;
|
|
10
|
-
/**
|
|
11
|
-
* Public key for authentication (pk-lf-...).
|
|
12
|
-
* Falls back to GATEWAY_PUBLIC_KEY or GATEWAY_PUBLIC_KEY env var.
|
|
13
|
-
*/
|
|
14
|
-
publicKey?: string;
|
|
15
|
-
/**
|
|
16
|
-
* Secret key for authentication (sk-lf-...).
|
|
17
|
-
* Falls back to GATEWAY_SECRET_KEY or GATEWAY_SECRET_KEY env var.
|
|
18
|
-
*/
|
|
19
|
-
secretKey?: string;
|
|
20
|
-
/**
|
|
21
|
-
* Service name for resource attributes.
|
|
22
|
-
* Defaults to "gatewaysdk-tracing".
|
|
23
|
-
*/
|
|
24
|
-
serviceName?: string;
|
|
25
|
-
/**
|
|
26
|
-
* Environment name (e.g., "production", "staging").
|
|
27
|
-
* Sets resource attribute for filtering traces in Gateway.
|
|
28
|
-
*/
|
|
29
|
-
environment?: string;
|
|
30
|
-
/**
|
|
31
|
-
* Application version (e.g., "1.2.3", git SHA).
|
|
32
|
-
* Sets resource attribute for tracking regressions.
|
|
33
|
-
*/
|
|
34
|
-
version?: string;
|
|
35
|
-
/**
|
|
36
|
-
* Whether to enable debug logging to console.
|
|
37
|
-
* Defaults to false.
|
|
38
|
-
*/
|
|
39
|
-
debug?: boolean;
|
|
40
|
-
/**
|
|
41
|
-
* Whether to automatically add ExperimentSpanProcessor when imported
|
|
42
|
-
* from the main entry ("@withgateway/sdk"). Has no effect when imported
|
|
43
|
-
* from the subpath ("@withgateway/sdk/tracing") — use customSpanProcessors
|
|
44
|
-
* instead.
|
|
45
|
-
* Defaults to true.
|
|
46
|
-
*/
|
|
47
|
-
enableExperiments?: boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Additional span processors to register with the provider.
|
|
50
|
-
* These are added before the BatchSpanProcessor (which handles export).
|
|
51
|
-
*
|
|
52
|
-
* When using the main entry (`import { tracing } from "@withgateway/sdk"`),
|
|
53
|
-
* ExperimentSpanProcessor is automatically added unless enableExperiments
|
|
54
|
-
* is false. When using the subpath import, pass it here manually:
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```typescript
|
|
58
|
-
* import * as tracing from "@withgateway/sdk/tracing";
|
|
59
|
-
* import { ExperimentSpanProcessor } from "@withgateway/sdk/experiments";
|
|
60
|
-
*
|
|
61
|
-
* tracing.init({ customSpanProcessors: [new ExperimentSpanProcessor()] });
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
customSpanProcessors?: unknown[];
|
|
65
|
-
/**
|
|
66
|
-
* Custom OTLP endpoint URL. If not provided, derived from host.
|
|
67
|
-
*/
|
|
68
|
-
endpoint?: string;
|
|
69
|
-
/**
|
|
70
|
-
* Batch processor configuration.
|
|
71
|
-
*/
|
|
72
|
-
batch?: {
|
|
73
|
-
/** Max spans buffered in memory. Default: 2048 */
|
|
74
|
-
maxQueueSize?: number;
|
|
75
|
-
/** How often to flush spans (ms). Default: 5000 */
|
|
76
|
-
scheduledDelayMillis?: number;
|
|
77
|
-
/** Max spans per export call. Default: 512 */
|
|
78
|
-
maxExportBatchSize?: number;
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
interface TracingState {
|
|
82
|
-
initialized: boolean;
|
|
83
|
-
provider: unknown | null;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Initialization and lifecycle management for GatewaySDK tracing.
|
|
88
|
-
*
|
|
89
|
-
* This module provides the core init(), shutdown(), and flush() functions
|
|
90
|
-
* for managing the OpenTelemetry TracerProvider lifecycle.
|
|
91
|
-
*
|
|
92
|
-
* Mirrors the Python SDK's tracing.init() for a consistent developer experience.
|
|
93
|
-
*/
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Initialize GatewaySDK tracing with automatic OpenTelemetry configuration.
|
|
97
|
-
*
|
|
98
|
-
* This function configures OpenTelemetry with a connection to Gateway
|
|
99
|
-
* and sets up the ExperimentSpanProcessor for automatic experiment tagging.
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```typescript
|
|
103
|
-
* import { tracing } from "@withgateway/sdk";
|
|
104
|
-
*
|
|
105
|
-
* // Using environment variables (GATEWAY_HOST, GATEWAY_PUBLIC_KEY, GATEWAY_SECRET_KEY)
|
|
106
|
-
* tracing.init();
|
|
107
|
-
*
|
|
108
|
-
* // Or with explicit configuration
|
|
109
|
-
* tracing.init({
|
|
110
|
-
* host: "https://app.gateway.dev",
|
|
111
|
-
* publicKey: "pk-lf-...",
|
|
112
|
-
* secretKey: "sk-lf-...",
|
|
113
|
-
* serviceName: "my-agent",
|
|
114
|
-
* environment: "production",
|
|
115
|
-
* });
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
declare function init(config?: TracingConfig): void;
|
|
119
|
-
/**
|
|
120
|
-
* Force flush all pending spans without shutting down.
|
|
121
|
-
*
|
|
122
|
-
* Useful for ensuring spans are exported at specific points
|
|
123
|
-
* (e.g., after completing a batch of work) without ending the tracing session.
|
|
124
|
-
*
|
|
125
|
-
* @returns Promise that resolves when flush completes
|
|
126
|
-
*/
|
|
127
|
-
declare function flush(): Promise<void>;
|
|
128
|
-
/**
|
|
129
|
-
* Force flush all pending spans and shutdown the tracer provider.
|
|
130
|
-
*
|
|
131
|
-
* This function should be called before process exit to ensure all spans
|
|
132
|
-
* are exported. It is safe to call multiple times.
|
|
133
|
-
*
|
|
134
|
-
* @example
|
|
135
|
-
* ```typescript
|
|
136
|
-
* import { tracing } from "@withgateway/sdk";
|
|
137
|
-
*
|
|
138
|
-
* tracing.init();
|
|
139
|
-
*
|
|
140
|
-
* // On shutdown
|
|
141
|
-
* process.on("SIGTERM", async () => {
|
|
142
|
-
* await tracing.shutdown();
|
|
143
|
-
* process.exit(0);
|
|
144
|
-
* });
|
|
145
|
-
* ```
|
|
146
|
-
*/
|
|
147
|
-
declare function shutdown(): Promise<void>;
|
|
148
|
-
/**
|
|
149
|
-
* Check if tracing has been initialized.
|
|
150
|
-
*/
|
|
151
|
-
declare function isInitialized(): boolean;
|
|
152
|
-
/**
|
|
153
|
-
* Check if Gateway is configured via environment variables.
|
|
154
|
-
*/
|
|
155
|
-
declare function isGatewayConfigured(): boolean;
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Tracing module for GatewaySDK TypeScript SDK.
|
|
159
|
-
*
|
|
160
|
-
* Provides a simple init() function that configures OpenTelemetry with
|
|
161
|
-
* Gateway, mirroring the Python SDK's tracing.init() experience.
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* ```typescript
|
|
165
|
-
* import { tracing } from "@withgateway/sdk";
|
|
166
|
-
*
|
|
167
|
-
* // Initialize with environment variables
|
|
168
|
-
* tracing.init();
|
|
169
|
-
*
|
|
170
|
-
* // Or with explicit configuration
|
|
171
|
-
* tracing.init({
|
|
172
|
-
* host: "https://app.gateway.dev",
|
|
173
|
-
* publicKey: "pk-lf-...",
|
|
174
|
-
* secretKey: "sk-lf-...",
|
|
175
|
-
* });
|
|
176
|
-
*
|
|
177
|
-
* // Ensure cleanup on shutdown
|
|
178
|
-
* process.on("SIGTERM", () => tracing.shutdown());
|
|
179
|
-
* ```
|
|
180
|
-
*/
|
|
181
|
-
|
|
182
|
-
type _tracingModule_TracingConfig = TracingConfig;
|
|
183
|
-
type _tracingModule_TracingState = TracingState;
|
|
184
|
-
declare const _tracingModule_flush: typeof flush;
|
|
185
|
-
declare const _tracingModule_init: typeof init;
|
|
186
|
-
declare const _tracingModule_isGatewayConfigured: typeof isGatewayConfigured;
|
|
187
|
-
declare const _tracingModule_isInitialized: typeof isInitialized;
|
|
188
|
-
declare const _tracingModule_shutdown: typeof shutdown;
|
|
189
|
-
declare namespace _tracingModule {
|
|
190
|
-
export { type _tracingModule_TracingConfig as TracingConfig, type _tracingModule_TracingState as TracingState, _tracingModule_flush as flush, _tracingModule_init as init, _tracingModule_isGatewayConfigured as isGatewayConfigured, _tracingModule_isInitialized as isInitialized, _tracingModule_shutdown as shutdown };
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export { type TracingConfig as T, _tracingModule as _, type TracingState as a, isGatewayConfigured as b, isInitialized as c, flush as f, init as i, shutdown as s };
|