convex-langfuse 0.0.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.
Files changed (52) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +334 -0
  3. package/dist/client/_generated/_ignore.d.ts +1 -0
  4. package/dist/client/_generated/_ignore.d.ts.map +1 -0
  5. package/dist/client/_generated/_ignore.js +3 -0
  6. package/dist/client/_generated/_ignore.js.map +1 -0
  7. package/dist/client/index.d.ts +166 -0
  8. package/dist/client/index.d.ts.map +1 -0
  9. package/dist/client/index.js +223 -0
  10. package/dist/client/index.js.map +1 -0
  11. package/dist/component/_generated/api.d.ts +34 -0
  12. package/dist/component/_generated/api.d.ts.map +1 -0
  13. package/dist/component/_generated/api.js +31 -0
  14. package/dist/component/_generated/api.js.map +1 -0
  15. package/dist/component/_generated/component.d.ts +157 -0
  16. package/dist/component/_generated/component.d.ts.map +1 -0
  17. package/dist/component/_generated/component.js +11 -0
  18. package/dist/component/_generated/component.js.map +1 -0
  19. package/dist/component/_generated/dataModel.d.ts +46 -0
  20. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  21. package/dist/component/_generated/dataModel.js +11 -0
  22. package/dist/component/_generated/dataModel.js.map +1 -0
  23. package/dist/component/_generated/server.d.ts +133 -0
  24. package/dist/component/_generated/server.d.ts.map +1 -0
  25. package/dist/component/_generated/server.js +80 -0
  26. package/dist/component/_generated/server.js.map +1 -0
  27. package/dist/component/convex.config.d.ts +3 -0
  28. package/dist/component/convex.config.d.ts.map +1 -0
  29. package/dist/component/convex.config.js +4 -0
  30. package/dist/component/convex.config.js.map +1 -0
  31. package/dist/component/lib.d.ts +133 -0
  32. package/dist/component/lib.d.ts.map +1 -0
  33. package/dist/component/lib.js +214 -0
  34. package/dist/component/lib.js.map +1 -0
  35. package/dist/component/schema.d.ts +83 -0
  36. package/dist/component/schema.d.ts.map +1 -0
  37. package/dist/component/schema.js +48 -0
  38. package/dist/component/schema.js.map +1 -0
  39. package/package.json +106 -0
  40. package/src/client/_generated/_ignore.ts +1 -0
  41. package/src/client/index.ts +322 -0
  42. package/src/client/setup.test.ts +26 -0
  43. package/src/component/_generated/api.ts +50 -0
  44. package/src/component/_generated/component.ts +222 -0
  45. package/src/component/_generated/dataModel.ts +60 -0
  46. package/src/component/_generated/server.ts +169 -0
  47. package/src/component/convex.config.ts +5 -0
  48. package/src/component/lib.test.ts +130 -0
  49. package/src/component/lib.ts +252 -0
  50. package/src/component/schema.ts +66 -0
  51. package/src/component/setup.test.ts +11 -0
  52. package/src/test.ts +18 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,334 @@
1
+ # convex-langfuse
2
+
3
+ **Send LLM traces, generations, and scores from your Convex app to Langfuse.** Reactive local queries, OpenTelemetry-native ingestion.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/convex-langfuse)](https://www.npmjs.com/package/convex-langfuse)
6
+ [![Convex Component](https://www.convex.dev/components/badge/sholajegede/convex-langfuse)](https://www.convex.dev/components/sholajegede/convex-langfuse)
7
+ [![npm downloads](https://img.shields.io/npm/dw/convex-langfuse)](https://www.npmjs.com/package/convex-langfuse)
8
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](./LICENSE)
9
+
10
+ ```ts
11
+ const langfuse = new Langfuse(components.convexLangfuse, {
12
+ publicKey: process.env.LANGFUSE_PUBLIC_KEY!,
13
+ secretKey: process.env.LANGFUSE_SECRET_KEY!,
14
+ });
15
+
16
+ // Log a completed LLM call
17
+ const { traceId } = await langfuse.logGeneration(ctx, {
18
+ name: "chat-completion",
19
+ userId: "user_123",
20
+ model: "gpt-5",
21
+ input: prompt,
22
+ output: completion,
23
+ inputTokens: 120,
24
+ outputTokens: 340,
25
+ });
26
+
27
+ // Attach a user rating or eval score to it
28
+ await langfuse.recordScore(ctx, { traceId, name: "user-rating", value: 1 });
29
+ ```
30
+
31
+ ## What this does
32
+
33
+ Most Langfuse integrations assume a long-lived Node process that can hold an OpenTelemetry span open for the duration of an LLM call. Convex actions are short, stateless, request/response functions — there's no "open a span, await a stream, close it later." This component is built for that shape: you call it once, with the finished input/output/timing/usage already in hand, and it does the rest.
34
+
35
+ Under the hood it exports a single completed [OpenTelemetry span](https://langfuse.com/integrations/native/opentelemetry) per call, using Langfuse's documented span attribute conventions (`langfuse.observation.*`, `langfuse.trace.*`) — no OpenTelemetry SDK dependency, just `fetch`. This matters more than it sounds: Langfuse's older `/api/public/ingestion` batch endpoint is **deprecated and sunsets on Langfuse Cloud on November 16, 2026**. Building against the OTLP endpoint from day one means this component doesn't need a rewrite in a few months.
36
+
37
+ Alongside the export, every trace, generation, and score is mirrored into Convex tables so you can query them reactively — build a live "recent generations" or "token usage" view without a separate call to Langfuse's API.
38
+
39
+ - **One-shot logging** — `logGeneration()` / `logSpan()` take a finished call and export it as a proper Langfuse trace + observation
40
+ - **Scoring** — `recordScore()` attaches an evaluation or user-rating score to any trace
41
+ - **Reactive local queries** — traces, observations, and scores are all queryable live from Convex
42
+ - **No SDK dependency** — talks to Langfuse's OTLP/HTTP and Scores REST endpoints directly over `fetch`
43
+
44
+ ## Table of Contents
45
+
46
+ - [Install](#install)
47
+ - [Quick Start](#quick-start)
48
+ - [Usage](#usage)
49
+ - [Continuing a Trace](#continuing-a-trace)
50
+ - [API Reference](#api-reference)
51
+ - [Type Reference](#type-reference)
52
+ - [Database Schema](#database-schema)
53
+ - [Testing](#testing)
54
+ - [Example App](#example-app)
55
+ - [Limitations](#limitations)
56
+ - [Troubleshooting](#troubleshooting)
57
+ - [Contributing](#contributing)
58
+ - [Changelog](#changelog)
59
+
60
+ ## Install
61
+
62
+ ```bash
63
+ npm install convex-langfuse
64
+ ```
65
+
66
+ **Requirements:** Convex v1.33.1 or later, Node.js 18+, a [Langfuse](https://langfuse.com) project (Cloud or self-hosted, OTel-compatible)
67
+
68
+ ## Quick Start
69
+
70
+ Three steps to send traces from your Convex app to Langfuse.
71
+
72
+ ### 1. Add the component
73
+
74
+ In `convex/convex.config.ts`:
75
+
76
+ ```ts
77
+ import { defineApp } from "convex/server";
78
+ import convexLangfuse from "convex-langfuse/convex.config";
79
+
80
+ const app = defineApp();
81
+ app.use(convexLangfuse);
82
+
83
+ export default app;
84
+ ```
85
+
86
+ ### 2. Set environment variables
87
+
88
+ ```bash
89
+ npx convex env set LANGFUSE_PUBLIC_KEY pk-lf-xxxxxxxxxxxx
90
+ npx convex env set LANGFUSE_SECRET_KEY sk-lf-xxxxxxxxxxxx
91
+ ```
92
+
93
+ ### 3. Initialize the client
94
+
95
+ In `convex/observability.ts`:
96
+
97
+ ```ts
98
+ import { components } from "./_generated/api";
99
+ import { Langfuse } from "convex-langfuse";
100
+
101
+ export const langfuse = new Langfuse(components.convexLangfuse, {
102
+ publicKey: process.env.LANGFUSE_PUBLIC_KEY!,
103
+ secretKey: process.env.LANGFUSE_SECRET_KEY!,
104
+ // baseUrl defaults to the EU Langfuse Cloud region — set it for US/JP/self-hosted
105
+ });
106
+ ```
107
+
108
+ Import `langfuse` from this file in any Convex action that calls an LLM.
109
+
110
+ ## Usage
111
+
112
+ ### Log a generation
113
+
114
+ ```ts
115
+ export const chat = action({
116
+ args: { userId: v.string(), prompt: v.string() },
117
+ handler: async (ctx, args) => {
118
+ const completion = await callYourModel(args.prompt);
119
+
120
+ const { traceId } = await langfuse.logGeneration(ctx, {
121
+ name: "chat-completion",
122
+ userId: args.userId,
123
+ model: "gpt-5",
124
+ input: args.prompt,
125
+ output: completion,
126
+ inputTokens: completion.usage.inputTokens,
127
+ outputTokens: completion.usage.outputTokens,
128
+ });
129
+
130
+ return { completion, traceId };
131
+ },
132
+ });
133
+ // Returns: { traceId, observationId }
134
+ ```
135
+
136
+ ### Log a non-LLM step
137
+
138
+ ```ts
139
+ await langfuse.logSpan(ctx, {
140
+ traceId,
141
+ name: "vector-search",
142
+ input: { query },
143
+ output: { matches },
144
+ });
145
+ ```
146
+
147
+ ### Record a score
148
+
149
+ ```ts
150
+ export const rate = action({
151
+ args: { traceId: v.string(), value: v.number() },
152
+ handler: async (ctx, args) => {
153
+ await langfuse.recordScore(ctx, {
154
+ traceId: args.traceId,
155
+ name: "user-rating",
156
+ value: args.value, // e.g. 1 for thumbs up, 0 for thumbs down
157
+ });
158
+ return null;
159
+ },
160
+ });
161
+ ```
162
+
163
+ ### Read a trace reactively
164
+
165
+ ```ts
166
+ export const getTrace = query({
167
+ args: { traceId: v.string() },
168
+ handler: async (ctx, args) => langfuse.getTrace(ctx, args),
169
+ });
170
+
171
+ export const getObservations = query({
172
+ args: { traceId: v.string() },
173
+ handler: async (ctx, args) => langfuse.listObservations(ctx, args),
174
+ });
175
+ ```
176
+
177
+ ## Continuing a Trace
178
+
179
+ Pass the `traceId` returned from the first call into subsequent `logGeneration()`/`logSpan()` calls to group multiple observations (a retrieval step, then a generation, then a tool call) under one trace in the Langfuse UI:
180
+
181
+ ```ts
182
+ const { traceId } = await langfuse.logSpan(ctx, { name: "retrieve-context", ... });
183
+ await langfuse.logGeneration(ctx, { traceId, name: "generate-answer", ... });
184
+ ```
185
+
186
+ ## API Reference
187
+
188
+ | Method | Kind | Description |
189
+ | --- | --- | --- |
190
+ | `logGeneration(ctx, args)` | action | Exports a completed LLM call as a Langfuse generation |
191
+ | `logSpan(ctx, args)` | action | Exports a completed non-LLM step as a Langfuse span |
192
+ | `recordScore(ctx, args)` | action | Attaches an evaluation/rating score to a trace |
193
+ | `getTrace(ctx, args)` | query | Fetch one trace by id |
194
+ | `listTracesByUser(ctx, args)` | query | List a user's traces, newest first |
195
+ | `listTracesBySession(ctx, args)` | query | List a session's traces, newest first |
196
+ | `listObservations(ctx, args)` | query | List a trace's observations, oldest first |
197
+ | `listScores(ctx, args)` | query | List a trace's scores |
198
+ | `listRecentTraces(ctx, args?)` | query | Every trace, newest first, regardless of user/session — for a history view or dashboard |
199
+ | `getStats(ctx)` | query | Aggregate trace/observation/score counts for a small dashboard |
200
+
201
+ ## Type Reference
202
+
203
+ ```ts
204
+ type LogObservationArgs = {
205
+ traceId?: string; // omit to start a new trace
206
+ traceName?: string;
207
+ userId?: string;
208
+ sessionId?: string;
209
+ tags?: string[];
210
+ release?: string;
211
+ traceMetadata?: Record<string, unknown>;
212
+
213
+ name: string;
214
+ input?: unknown;
215
+ output?: unknown;
216
+ model?: string;
217
+ inputTokens?: number;
218
+ outputTokens?: number;
219
+ level?: "DEBUG" | "DEFAULT" | "WARNING" | "ERROR";
220
+ statusMessage?: string;
221
+ metadata?: Record<string, unknown>;
222
+ startTime?: number; // ms epoch, defaults to now
223
+ endTime?: number; // ms epoch, defaults to startTime
224
+ };
225
+
226
+ type Trace = {
227
+ traceId: string;
228
+ name: string;
229
+ userId?: string;
230
+ sessionId?: string;
231
+ tags?: string[];
232
+ metadata?: string;
233
+ release?: string;
234
+ };
235
+
236
+ type Observation = {
237
+ observationId: string;
238
+ traceId: string;
239
+ type: "span" | "generation" | "event" | "embedding" | "agent" | "tool"
240
+ | "chain" | "retriever" | "guardrail" | "evaluator";
241
+ name: string;
242
+ input?: string;
243
+ output?: string;
244
+ model?: string;
245
+ inputTokens?: number;
246
+ outputTokens?: number;
247
+ level: "DEBUG" | "DEFAULT" | "WARNING" | "ERROR";
248
+ statusMessage?: string;
249
+ metadata?: string;
250
+ startedAt: number;
251
+ endedAt: number;
252
+ };
253
+
254
+ type Score = {
255
+ scoreId: string;
256
+ traceId: string;
257
+ name: string;
258
+ value: number;
259
+ comment?: string;
260
+ };
261
+ ```
262
+
263
+ ## Database Schema
264
+
265
+ ```ts
266
+ traces: {
267
+ traceId, name, userId?, sessionId?, tags?, metadata?, release?,
268
+ createdAt, updatedAt,
269
+ }
270
+
271
+ observations: {
272
+ observationId, traceId, type, name, input?, output?, model?,
273
+ inputTokens?, outputTokens?, level, statusMessage?, metadata?,
274
+ startedAt, endedAt, createdAt,
275
+ }
276
+
277
+ scores: {
278
+ scoreId, traceId, name, value, comment?, createdAt,
279
+ }
280
+ ```
281
+
282
+ `listRecentTraces()` and `getStats()` read across these tables directly with a full scan — fine for a history view or small dashboard, not intended as a high-volume production query path.
283
+
284
+ ## Testing
285
+
286
+ ```bash
287
+ npm run test
288
+ ```
289
+
290
+ Component logic is tested with [`convex-test`](https://www.npmjs.com/package/convex-test) in `src/component/lib.test.ts`. Import `convex-langfuse/test` in your own app to register this component's schema against your test instance.
291
+
292
+ ## Example App
293
+
294
+ `example/` is a full Vite + React demo that exercises the entire component end to end against your own Langfuse account:
295
+
296
+ - **Log a generation** — simulate a finished chat completion (model, prompt, completion, token counts, tags) and export it as a Langfuse generation.
297
+ - **Continue the trace** — attach a non-LLM step (a retrieval, a tool call, a guardrail check) to the same trace via `logSpan()`.
298
+ - **Rate the response** — attach a 👍/👎 `recordScore()` call, with an optional comment.
299
+ - **Trace explorer** — look up any trace by id, or browse the traces recorded for a given user/session, all reactive.
300
+ - **History** — every trace ever recorded in the deployment, newest first, independent of the browser-local demo identity that resets on reload. Expand a trace to see its full generation/step/score detail, and hit **Replay this** to recreate the whole scenario as a brand-new trace live, without retyping anything — useful for anyone poking at the demo who wants to see the flow without filling out forms themselves.
301
+ - **Activity console** — a side-docked live log of every call this app makes into the Langfuse client. Since Langfuse ingestion is one-way (no webhooks call back into Convex), this is the closest thing to a live feed the example has.
302
+
303
+ Run it from the repo root:
304
+
305
+ ```bash
306
+ npm install --legacy-peer-deps
307
+ npx convex env set LANGFUSE_PUBLIC_KEY pk-lf-xxxxxxxxxxxx
308
+ npx convex env set LANGFUSE_SECRET_KEY sk-lf-xxxxxxxxxxxx
309
+ npm run dev
310
+ ```
311
+
312
+ `npm run dev` starts the Convex backend and the Vite frontend together — there's no need to `cd example` or run either one separately.
313
+
314
+ ## Limitations
315
+
316
+ - No live/streaming spans — each call exports one already-finished observation. For a call you want to see "in progress," log it once it completes rather than trying to open and later close a span.
317
+ - Trace-level fields (`userId`, `sessionId`, `tags`, `metadata`) are attached to every span you log under that trace, per Langfuse's own OTel guidance for filterable trace attributes — there's no separate "create trace" call.
318
+ - This component does not vendor the Langfuse SDK or an OpenTelemetry SDK; it constructs minimal OTLP/HTTP JSON payloads directly, which keeps it dependency-free but means it only covers the attributes this README documents.
319
+
320
+ ## Troubleshooting
321
+
322
+ **Nothing shows up in the Langfuse UI** — confirm `baseUrl` matches your project's region (EU, US, JP, HIPAA, or your self-hosted URL) and that the OTLP endpoint isn't blocked by a firewall between Convex and Langfuse.
323
+
324
+ **401 from Langfuse** — `publicKey`/`secretKey` are combined into a Basic auth header; confirm both are set and belong to the same project.
325
+
326
+ **Generation shows no cost/usage** — cost is computed by Langfuse from `inputTokens`/`outputTokens` and the model's pricing table; confirm `model` matches a model name Langfuse recognizes for your provider.
327
+
328
+ ## Contributing
329
+
330
+ See [CONTRIBUTING.md](./CONTRIBUTING.md).
331
+
332
+ ## Changelog
333
+
334
+ See [CHANGELOG.md](./CHANGELOG.md).
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=_ignore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_ignore.d.ts","sourceRoot":"","sources":["../../../src/client/_generated/_ignore.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // This is only here so convex-test can detect a _generated folder
3
+ //# sourceMappingURL=_ignore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_ignore.js","sourceRoot":"","sources":["../../../src/client/_generated/_ignore.ts"],"names":[],"mappings":";AAAA,kEAAkE"}