@telemetry-dev/tanstack-ai 0.1.0
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/LICENSE +21 -0
- package/README.md +95 -0
- package/dist/index.d.mts +40 -0
- package/dist/index.mjs +681 -0
- package/package.json +62 -0
- package/src/config.ts +48 -0
- package/src/index.ts +2 -0
- package/src/middleware.ts +659 -0
- package/src/otel.ts +247 -0
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@telemetry-dev/tanstack-ai",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TanStack AI telemetry integration for telemetry.dev: chat() middleware emitting OpenTelemetry GenAI spans.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"genai",
|
|
7
|
+
"llm",
|
|
8
|
+
"observability",
|
|
9
|
+
"opentelemetry",
|
|
10
|
+
"tanstack",
|
|
11
|
+
"telemetry",
|
|
12
|
+
"tracing"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://telemetry.dev",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/telemetry-dev/telemetry.dev.git",
|
|
19
|
+
"directory": "packages/tanstack-ai"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"src"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.mts",
|
|
29
|
+
"import": "./dist/index.mjs",
|
|
30
|
+
"default": "./dist/index.mjs"
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@opentelemetry/api": "^1.9.1",
|
|
39
|
+
"@opentelemetry/otlp-transformer": "^0.218.0",
|
|
40
|
+
"@opentelemetry/resources": "^2.7.1",
|
|
41
|
+
"@opentelemetry/sdk-metrics": "^2.7.1",
|
|
42
|
+
"@opentelemetry/sdk-trace-base": "^2.7.1"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@opentelemetry/core": "^2.7.1",
|
|
46
|
+
"@tanstack/ai": "0.28.0",
|
|
47
|
+
"@types/node": "^25.5.0",
|
|
48
|
+
"@typescript/native-preview": "7.0.0-dev.20260328.1",
|
|
49
|
+
"typescript": "^6.0.2",
|
|
50
|
+
"vite-plus": "0.1.20",
|
|
51
|
+
"vitest": "npm:@voidzero-dev/vite-plus-test@0.1.20"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@tanstack/ai": ">=0.28.0 <1"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "pnpm exec vp pack",
|
|
58
|
+
"dev": "pnpm exec vp pack --watch",
|
|
59
|
+
"test": "vp test",
|
|
60
|
+
"check": "vp check"
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface TelemetryDevOptions {
|
|
2
|
+
/** telemetry.dev ingest key (`td_live_…`). Falls back to `TELEMETRY_DEV_API_KEY`. When absent the integration is a no-op. */
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
/** Ingest base URL. Falls back to `TELEMETRY_DEV_BASE_URL`, then `https://ingest.telemetry.dev`. */
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
/** Deployment environment label. Falls back to `TELEMETRY_DEV_ENVIRONMENT`, then `production`. */
|
|
7
|
+
environment?: string;
|
|
8
|
+
/** Service name attached to every trace. Falls back to `OTEL_SERVICE_NAME`, then `unknown_service`. */
|
|
9
|
+
serviceName?: string;
|
|
10
|
+
/** Injected fetch implementation. Defaults to `globalThis.fetch`. */
|
|
11
|
+
fetch?: typeof fetch;
|
|
12
|
+
/** Serverless extender (e.g. Cloudflare `ctx.waitUntil`). When provided, `onFinish` does not await the POST. */
|
|
13
|
+
waitUntil?: (p: Promise<unknown>) => void;
|
|
14
|
+
/** Receives any error raised while emitting telemetry; the integration never throws into the SDK. */
|
|
15
|
+
onError?: (error: unknown) => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ResolvedConfig {
|
|
19
|
+
apiKey: string | undefined;
|
|
20
|
+
baseUrl: string;
|
|
21
|
+
environment: string;
|
|
22
|
+
serviceName: string;
|
|
23
|
+
fetchImpl: typeof fetch;
|
|
24
|
+
waitUntil?: (p: Promise<unknown>) => void;
|
|
25
|
+
onError?: (error: unknown) => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const DEFAULT_BASE_URL = "https://ingest.telemetry.dev";
|
|
29
|
+
|
|
30
|
+
export function resolveConfig(options: TelemetryDevOptions = {}): ResolvedConfig {
|
|
31
|
+
const env =
|
|
32
|
+
typeof process !== "undefined" && process.env
|
|
33
|
+
? process.env
|
|
34
|
+
: ({} as Record<string, string | undefined>);
|
|
35
|
+
const baseUrl = (options.baseUrl ?? env.TELEMETRY_DEV_BASE_URL ?? DEFAULT_BASE_URL).replace(
|
|
36
|
+
/\/+$/,
|
|
37
|
+
"",
|
|
38
|
+
);
|
|
39
|
+
return {
|
|
40
|
+
apiKey: options.apiKey ?? env.TELEMETRY_DEV_API_KEY,
|
|
41
|
+
baseUrl,
|
|
42
|
+
environment: options.environment ?? env.TELEMETRY_DEV_ENVIRONMENT ?? "production",
|
|
43
|
+
serviceName: options.serviceName ?? env.OTEL_SERVICE_NAME ?? "unknown_service",
|
|
44
|
+
fetchImpl: options.fetch ?? globalThis.fetch,
|
|
45
|
+
waitUntil: options.waitUntil,
|
|
46
|
+
onError: options.onError,
|
|
47
|
+
};
|
|
48
|
+
}
|
package/src/index.ts
ADDED