Compare commits

...
124 Commits
Author SHA1 Message Date
Nimar e22e79d598 chore: release v3.171.0 2026-04-27 13:33:02 +09:00
NimarandGitHub ce72b55b3c chore(deps): axios 1.15.2 and dedupe (#13365)
* chore(deps): axios 1.15.2 and dedupe

* clean
2026-04-27 03:06:46 +00:00
fbef5ab2f0 perf(clickhouse): pre-filter traces in CTE for analytics integration joins (#13364)
Pre-filters the trace JOIN in a CTE so the trace timestamp window prunes
partitions directly instead of living alongside the LEFT JOIN where the
planner cannot push it down. Applied to the score and generation analytics
queries that drive the PostHog and Mixpanel exports.

Switches `grace_hash` from unconditional to retry-gated: first attempt uses
ClickHouse's `auto` algorithm, retries fall back to `grace_hash` so an OOM
recovers without manual intervention while healthy syncs stay fast.

Note: the generation analytics query previously used `LEFT JOIN ... WHERE
t.project_id = {projectId}` which silently dropped generations whose trace
was missing or outside the 7-day window. With the CTE-based LEFT JOIN those
generations now ship with NULL trace fields instead.

Refs: LFE-9475

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 02:28:37 +00:00
marliessophieandGitHub c9c841508e chore: hide eval preview if user has not ingested with otel in the past 7 days (#13343)
* chore: hide eval preview if user has not ingested with otel in the past 7 days

* chore: push
2026-04-27 01:00:32 +00:00
Steffen SchmitzandGitHub 39510c9d46 chore: add langfuse JP to region picker (#13361)
* chore: add langfuse JP to region picker

* chore: add JP
2026-04-27 00:21:55 +00:00
Hassieb PakzadandGitHub 9cfaa7571a feat(model-prices): add gpt-5.5) (#13354) 2026-04-25 10:34:19 +00:00
marliessophieandGitHub 1694bc4d52 fix: add breadcrumb to dataset items page (#13344)
chore(web): remove dataset breadcrumb utility test
2026-04-24 12:51:50 +00:00
Valery MeleshkinandGitHub 76fdf528f1 perf(clickhouse): scores query in events.all scans all partitions (#13336) 2026-04-24 09:44:33 +00:00
NimarandGitHub f2f0de7207 fix(dev): fix seed command (#13337) 2026-04-24 07:51:22 +00:00
31adc47680 fix(shared): cap analytics observations CTE upper bound (LFE-9475) (#13329)
The observations_agg CTE in getTracesForAnalyticsIntegrations only had a
lower bound on o.start_time, so ClickHouse scanned observations from
minTimestamp - 1h to the end of the table on every run. For long-lived
projects or repeated retries this is an unbounded scan.

Cap the CTE at maxTimestamp + OBSERVATIONS_TO_TRACE_INTERVAL (2 days),
matching the existing observation-to-trace join convention elsewhere in
the file. Traces outside [minTimestamp, maxTimestamp) are already
filtered in the outer SELECT, and in steady state the 30-min now-buffer
ensures a trace's observations have settled well before the window
boundary advances, so the cap does not truncate data that would
otherwise be emitted.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-23 17:00:48 +00:00
604c0be87f fix(worker): cap PostHog export window at next UTC day boundary (LFE-9475) (#13326)
* fix(worker): cap PostHog export window at next UTC day boundary (LFE-9475)

When a PostHog integration failed repeatedly, lastSyncAt never advanced
and each hourly retry re-scanned an ever-growing window against
ClickHouse. Cap maxTimestamp at the next UTC day boundary after
lastSyncAt so per-run work is bounded and aligned with the toDate(...)
partition/ordering keys. Healthy integrations are unaffected because
now - 30min wins whenever the sync is within a day of present. Initial
backfills (no lastSyncAt) skip the cap to avoid pathological
day-by-day stepping from 2000-01-01.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(worker): use project createdAt as PostHog sync floor on first run

Replace the 2000-01-01 fallback for minTimestamp with the project's
createdAt. No trace data can precede it, so this is a tight lower bound
that lets the day-cap also apply to initial backfills. Old projects
still catch up incrementally (one UTC day per hourly run) instead of
re-scanning all of history in one shot.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: update comments

* fix(shared): use half-open upper bound for analytics integration queries

Switch the primary event-timestamp filter from `<=` to `<` in the four
getXForAnalyticsIntegrations queries (traces, generations, scores,
events). Since the PostHog and Mixpanel schedulers advance
`lastSyncAt` to the previous run's `maxTimestamp`, a row whose
timestamp falls exactly on a window boundary was previously emitted
once per run on both sides. Half-open semantics ensure each row is
emitted exactly once across consecutive runs. Secondary trace-join
upper bounds (7-day lookback for metadata) stay `<=` because they are
range optimizations, not emission bounds.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-23 16:36:38 +00:00
443e7d443a feat(scores-api): allow source=ANNOTATION on POST /api/public/scores (#13286)
* feat(scores-api): allow source=ANNOTATION on POST /api/public/scores

Expose the `source` field on the create-score request so callers can
post scores as `ANNOTATION` (or `EVAL`). This unblocks LLM-prefilled
scores that show up in an annotation queue for a human reviewer.

When `source` is `ANNOTATION`, `configId` is required unless
`dataType` is `CORRECTION` (matches the existing tRPC annotation
contract).

Ref: LFE-9330

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(scores-api): narrow source to API/ANNOTATION and enforce rule on ingestion path

Addresses review feedback:

- Drop EVAL from the public create-score surface. EVAL remains a valid
  stored/query value but is reserved for internal evaluator outputs; external
  callers should use API (default) or ANNOTATION. Narrowed via a new
  `CreateScoreSource` enum in Fern and inline zod enum at `PostScoresBody`.
- Move the "ANNOTATION requires configId unless CORRECTION" constraint into
  `validateAndInflateScore` so it applies to both the REST `POST /scores` path
  and the ingestion/SDK path (`POST /ingestion` → score-create event), closing
  the gap flagged on the PR. The zod refine on `PostScoresBody` is kept so REST
  callers still get a synchronous 400 instead of an async drop.
- Fix the stale path in the `PostScoresBody` comment that pointed to a
  non-existent file.
- Add a servertest covering the ingestion path: HTTP returns 207, worker drops
  the ANNOTATION-without-configId event, sentinel score confirms the batch was
  processed.

Ref: LFE-9330

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* refactor(scores-api): replace magic strings with ScoreSourceEnum and a named subset schema

Follow-up to review feedback on stringly-typed source checks.

- Add PublicApiCreateScoreSourceArray / Domain / Type in domain/scores.ts
  with `satisfies readonly ScoreSourceType[]` so the public-API subset stays
  provably ⊂ ScoreSourceArray at compile time. Dropping a value from
  ScoreSourceArray would now break this declaration first.
- Use PublicApiCreateScoreSourceDomain on PostScoresBody instead of the
  inline z.enum(["API", "ANNOTATION"]).
- Reference ScoreSourceEnum.ANNOTATION / ScoreSourceEnum.API and
  ScoreDataTypeEnum.CORRECTION instead of raw string literals in the
  PostScoresBody refine and in validateAndInflateScore.

No behavior change; all source-field tests continue to pass.

Ref: LFE-9330

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(scores-api): clarify which entry points trigger the annotation/configId check

The "REST create-score path vs ingestion/SDK path" phrasing was misleading:
both are REST, just different HTTP endpoints (/scores vs /ingestion). Spell
that out and note that both funnel through this function in the worker.

Ref: LFE-9330

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* refactor(scores-api): consolidate annotation/configId rule into a shared predicate

- Drop unused PublicApiCreateScoreSourceArray/Type exports; inline the
  subset tuple into the Domain declaration.
- Add `isAnnotationScoreMissingConfigId` + ANNOTATION_SCORE_REQUIRES_CONFIG_ID_MESSAGE
  in domain/scores.ts. Both the zod refine on PostScoresBody and the throw in
  validateAndInflateScore now call the same predicate with the same message,
  removing the copy-pasted rule and its comments.
- Trim redundant prose comments that duplicated the predicate's intent.

Net -18 lines. No behavior change; all 6 source-field tests still pass.

Ref: LFE-9330

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test(scores-api): unit-test validateAndInflateScore and expose source on client Fern

Addresses PR review feedback:

- Add unit tests for validateAndInflateScore covering the configId tenancy
  check (the reviewer's specific ask) plus the ANNOTATION/configId rule.
  Direct function calls — no HTTP, no queue, no sentinel waiting; each test
  runs in <400ms.
- Drop the flaky ingestion-endpoint sentinel test that asserted the same
  ANNOTATION drop behavior; coverage is now more precise at the function
  level where the rule actually lives.
- Add `source` + `CreateScoreSource` to the client Fern definition so the
  public client spec matches the server Fern surface. Regenerated the
  corresponding OpenAPI.

Ref: LFE-9330

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-23 16:01:17 +00:00
steffen911 6c32b797b3 chore: release v3.170.0 2026-04-23 17:06:12 +02:00
76b019cdfe chore(worker): harden cloud free tier usage threshold job (#13322)
Wrap each day of the usage aggregation loop in its own span with
langfuse.free_tier.dayStart/dayEnd/dayDate/daysAgo attributes so daily
work is visible individually in traces. Extend the ClickHouse
request_timeout to 120s on the three per-day count queries, and retry
each query up to two additional times on failure — a single re-run is
cheap compared to a full job retry.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-23 13:44:54 +00:00
cd3d02b75f fix(web): prevent crash on invalid JSONPath in dataset mapping editor (#13253)
* fix(web): prevent crash on invalid JSONPath in dataset mapping editor

CustomMappingEditor crashed the dialog when a user entered a malformed
JSONPath (e.g. `$..[?(@.x=)]`), because MappingPreviewPanel called
applyFieldMappingConfig in a useMemo and jsonpath-plus threw during
render. applyFieldMappingConfig now wraps evaluateJsonPath in a safe
helper, reports failures via a new onJsonPathError callback, and returns
undefined for that entry/field instead of throwing. applyFullMapping
propagates the callback so json_path_error entries carry the actual
source field and mapping key.

On the frontend, MappingPreviewPanel surfaces the error as a destructive
banner and invalidates validation when a schema is present. Notice boxes
are deduplicated into a small IssueList/IssueItem helper.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(web): surface invalid JSON path in evaluator prompt preview

renderPromptPreviewFromObservation used to discard the error returned by
extractValueFromObject, so an invalid jsonSelector silently rendered the
raw column value. Surface it inline as `<invalid JSON path "X": …>` so
the user sees which mapping is broken instead of getting a misleading
preview (or a generic "Unexpected Error" toast via useExtractVariables).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(web): show real error message when evaluator variable extraction fails

useExtractVariables was forwarding plain Errors (e.g. invalid JSON path
thrown by jsonpath-plus) to trpcErrorToast, whose non-TRPC fallback
renders a generic "Unexpected Error" toast and drops the actual message.
Use showErrorToast directly so the user sees "Invalid JSON path: …"
instead of a useless generic error.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(web): label evaluator extraction error as JSON path issue

"Failed to extract variable" read like a semantic failure. The only
throw path in extractValueFromObject is the jsonpath-plus call, so any
error surfaced here is a JSON path syntax problem — reflect that in the
toast title so users know where to look.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(web): include JSON path in evaluator extraction error toast

Match the phrasing of the dataset mapping banner and preview inline
message so all three surfaces show both the offending path and the
underlying parser message.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore(web,shared): standardize on "JSONPath" in user-facing strings

"JSON path" / "JSON Path" / "json path" were used interchangeably in
dataset mapping, evaluator preview, and their shared helpers. Use the
canonical "JSONPath" everywhere these strings surface to the user so the
three error surfaces read consistently.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Revert "fix(web): surface invalid JSON path in evaluator prompt preview"

This reverts commit f943fd87f. Scope creep relative to LFE-9336 — the
inline <invalid JSONPath …> marker inside a rendered prompt is noisy,
and the batch-actions preview is a separate concern that deserves its
own pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(web): distinguish JSONPath syntax errors from misses in final preview

FinalPreviewStep collapsed both json_path_error and json_path_miss into
a single amber "did not match" banner, so a syntax error reaching this
step (possible when the field has no schema or for metadata mappings)
was rendered as a soft warning with misleading wording. Split the
errors by type and render syntax errors with destructive styling and
"invalid syntax" wording, while keeping misses as amber warnings. When
a card has both, prefer the destructive treatment and combine the two
counts into one line. Extract the banner chrome into a small IssueBanner
helper to share variant styling between the top banner and per-card
footer.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* refactor(shared): return errors/misses from applyFieldMappingConfig

Replace the onJsonPathMiss/onJsonPathError callback parameters on
applyFieldMappingConfig with a direct FieldMappingResult return shape
of { value, misses, errors }. Callers no longer mutate external arrays
via closures — applyFullMapping consumes result.misses / result.errors
directly and MappingPreviewPanel destructures them out of the return.

Also tightens per-field fault isolation semantics in applyFullMapping
and cleans up a couple of low-value comments.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* refactor(web): extract shared IssueBanner from mapping preview panels

MappingPreviewPanel and FinalPreviewStep were each carrying their own
variant lookups, notice-box markup, and icon pickers for the error /
warning JSONPath chrome. Consolidate into a single
AddObservationsToDatasetDialog/components/IssueBanner module that exports:

- IssueBanner, IssueList, IssueItem components
- issueChromeVariants (border + bg + text for banner / list / card footer)
- issueCardVariants (outer card border with an explicit "none" variant)
- issueTextVariants (text color for children that override CSS inheritance)
- issueIcons (variant -> lucide icon)

Both callers now compose cva output with their layout classes via cn().
No visual change; colors and spacing are identical.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(web): address PR review nits on JSONPath extraction + preview copy

useExtractVariables was labelling every error that reached the toast
effect as "Invalid JSONPath in variable mapping", including unrelated
runtime errors that hit the outer Promise.all().catch() branch. Replace
the plain Error state with a discriminated ExtractionError so only
errors surfaced by extractValueFromObject use the JSONPath title;
unexpected failures fall back to a generic "Failed to extract variable".

FinalPreviewStep's per-card footer rendered "1 path have invalid
syntax" for a single error; move the verb into the ternary so the
singular reads "1 path has invalid syntax".

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-23 12:15:27 +00:00
10d6637ea0 feat(experiments): add enabled toggle for remote dataset run trigger (#13221) (#13289)
* feat(experiments): add enabled toggle for remote dataset run trigger (#13221)

* feat(experiments): add enabled toggle for remote dataset run trigger

Allows users to temporarily disable the remote trigger without losing
the configured URL and default payload.

- Add `remoteExperimentEnabled` boolean column (default true) to the
  `datasets` table
- Add an "Enable trigger" switch to the upsert form
- Hide the "Run" button in the experiment dialog when disabled
- Server-side early return in `triggerRemoteExperiment` when disabled
  (returns `{ success: true, skipped: true }`)

Motivation: once a URL is configured, every Run click fetches the URL
and shows a "Failed to trigger remote experiment" error toast if the
endpoint is unreachable. The only way to silence it today is to delete
the URL, which is lossy. This adds a simple toggle to pause the trigger
while keeping the config.

Backward compatible: default is `true` at both column and form levels,
so existing datasets behave identically.

* fix(public-api): include remoteExperimentEnabled in Dataset v2 response schema

Without this, POST/GET/PUT /api/public/v2/datasets responses fail strict
Zod validation with "Unrecognized key: remoteExperimentEnabled" since the
tRPC/API layer now returns this field for the new toggle.

* fix(experiments): address review feedback on enabled toggle

- deleteRemoteExperiment: reset remoteExperimentEnabled back to true so
  a later upsert without the optional enabled flag does not silently
  inherit the previously disabled state
- RemoteExperimentTriggerModal.onSuccess: distinguish the
  { success: true, skipped: true } response and show a "Remote trigger
  is disabled" toast instead of the misleading success toast
- allDatasets: add remoteExperimentEnabled to the Omit exclusion list
  so the $queryRaw return type matches the actual SQL SELECT (the
  field is not fetched, so the type annotation would otherwise lie)

* fix(public-api): select remoteExperimentEnabled in list dataset handlers

GET /api/public/datasets (v1) and GET /api/public/v2/datasets (v2) both
use an explicit Prisma select that narrows the return type. The APIDataset
response schema now requires remoteExperimentEnabled, so the select needs
to include it or the build fails with "Property 'remoteExperimentEnabled'
is missing".

The single-dataset GETs (v1 /datasets/[name] and v2 /datasets/[datasetName])
use the default all-fields findFirst, so they're already fine.

---------

Co-authored-by: Nimar <l.nimar.b@gmail.com>

* chore: fix migration order

* refactor: remove remoteExperimentEnabled field from API dataset types and endpoints

* refactor: wording

* test: ensure remote experiment fields are not exposed in public API responses

* chore: wording nits

* fix: invalidate remote experiment cache on dataset removal in RemoteExperimentUpsertForm

---------

Co-authored-by: Yuto Toya <97585904+toyayuto@users.noreply.github.com>
Co-authored-by: Nimar <l.nimar.b@gmail.com>
2026-04-23 11:15:18 +00:00
7d9a396bcf chore(observability): upgrade opentelemetry and datadog SDKs (#12737)
* chore(observability): upgrade opentelemetry and datadog SDKs

* fix(ci): disable tracing in tests-web startup

* fix(ci): remove local codex files from pr

* test(worker): retry bedrock llm connection smoke tests

* chore; revert pipeline changes

* revert(test): remove bedrock retry logic from llm connection tests

Reverts the retry/backoff additions from cdaacaf45 — these should be
handled in a separate PR since they are unrelated to the OTel/DD upgrade.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* chore; disable DD tracing for web tests

* chore: downgrade dd-trace to 5.82.0

* chore: downgrade prisma instrumentation

* chore: bump dd-trace-js

* chore: release v3.170.0-0

* revert release push

---------

Co-authored-by: steffen911 <steffen@langfuse.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Steffen Schmitz <steffenschmitz@hotmail.de>
2026-04-23 08:55:37 +00:00
marliessophieandGitHub fb3dcf8d60 feat(ui): add floating multi-select action bar (#12851)
* fix(ui): simplify floating action bar selection count

* chore: address feedback

* style: opacity and button order

* chore: fix

* chore: format number

* chore: push

* style: action bar

* style: ring style with backdrop

* chore: push

* fix: disabled prop on button

* chore: push

* feat(table): add highlightAllRows prop to ExperimentCompareTable, ExperimentGridView, and ExperimentItemsTable components

* chore: push

* fix: row selection state
2026-04-23 08:03:28 +00:00
52fa068d90 feat: add 5-minute and 20-minute blob storage export frequency options (#13126)
* feat: add 5-minute and 20-minute blob storage export frequency options

Add sub-hourly export frequency options (every 5 minutes, every 20 minutes)
to the blob storage integration, in addition to the existing hourly/daily/weekly.
The scheduler cron is updated from hourly to every 5 minutes to support the
new intervals.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: remove 5-minute export option, reduce lag buffer from 30 to 20 minutes

Per reviewer feedback, 5-minute export frequency is too granular given
internal data paths that may take longer in the worst case. Keeps only
the 20-minute option as the new minimum frequency, adjusts the lag
buffer to 20 minutes, and updates the queue schedule accordingly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: address PR review feedback for blob storage export frequency changes

- Add removeRepeatable for old hourly cron pattern to prevent duplicate schedules
- Extract lag buffer duration into BLOB_STORAGE_LAG_BUFFER_MS constant
- Add every_20_minutes to Fern BlobStorageExportFrequency enum
- Update lag buffer docs from 30 to 20 minutes
- Fix test comment referencing old 30-min lag buffer

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: update test timing assertion from 30-min to 20-min lag buffer

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: export BLOB_STORAGE_LAG_BUFFER_MS and use it in tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: prettier formatting for exportFrequency enum in types.ts

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-22 15:49:38 +00:00
e51b3ebcd0 feat(ui): decode unicode escapes in PrettyJsonView for trace detail (#13223)
* feat(ui): decode unicode escapes in PrettyJsonView for trace detail

Apply decodeUnicodeEscapesOnly() recursively to parsed JSON in the trace
detail PrettyJsonView so that \uXXXX sequences (produced by Python SDK's
json.dumps with ensure_ascii=True) are decoded to their original
characters when viewing traces in the UI.

This is a follow-up to PR #12882 which applied the same decoder to the
batch export pipeline, and to the earlier IOTableCell change (PR #9686).
Together these ensure non-ASCII content (e.g. Japanese, Chinese, Korean)
renders correctly everywhere a user encounters it in Langfuse.

Uses greedy mode to cover both \uXXXX (single-escaped) and \\uXXXX
(double-escaped) ingest paths. Only \uXXXX escapes are decoded; other
escapes (\n, \t, \", etc.) are left untouched.

Refs #10972

* test(ui): add unit tests for decodeUnicodeInJson in PrettyJsonView

Cover primitive passthrough, string decoding (including double-escaped
greedy mode), recursive decoding of arrays / nested objects, surrogate
pairs, and mixed already-decoded input. Same style as unicode.clienttest
from PR #12882.

* refactor(ui): make decodeUnicodeInJson iterative and bounded

Address review feedback from @nimarb on PR #13223: very large or deeply
nested JSON payloads could blow the call stack or freeze the browser tab.

- Replace recursion with an explicit-stack iterative walk, so stack depth
  is no longer bounded by JS engine limits.
- Add two guards:
  - DECODE_UNICODE_MAX_NODES (50,000): stop decoding once the total number
    of visited entries exceeds the budget; remaining values are kept as-is.
  - DECODE_UNICODE_MAX_DEPTH (200): do not descend into subtrees past this
    depth; the subtree is returned undecoded.
- Export the caps so tests can assert behavior at the boundary.

Tests: two new cases in PrettyJsonView.clienttest.ts -- one for chains
~10x deeper than MAX_DEPTH (must not throw), one for arrays larger than
MAX_NODES (first entries decoded, tail preserved verbatim).

* fix(ui): clone parsedJson for JSONView and decode escaped object keys

Address follow-up review feedback on PR #13223.

1. JSONView was receiving `parsedJson` directly, but JSONView internally
   calls `deepParseJson` which mutates nested string fields in place. Since
   baseTableData[].rawChildData holds references back into `parsedJson`,
   sharing the same reference corrupted the table's lazy-loaded children
   (parsed sub-objects replaced the original maxDepth:2 strings). Pass a
   `structuredClone` of `parsedJson` to JSONView via a `useMemo` so the two
   views stay independent without cloning on every render.

2. `decodeUnicodeInJson` was decoding values but leaving object keys as-is.
   Payloads like `{"\\u4f60\\u597d": "value"}` ended up with escaped keys
   alongside decoded values. Apply `decodeUnicodeEscapesOnly` to keys too.

Two new tests cover key decoding (flat + nested); existing tests cover the
value path.

---------

Co-authored-by: Nimar <l.nimar.b@gmail.com>
2026-04-22 13:39:19 +00:00
NimarandGitHub eaeaef0c3a fix(widgets): handle pivot table legacy sorting (#13306) 2026-04-22 13:22:16 +00:00
Valery MeleshkinandGitHub 4a5fe63c34 chore: add ingestion_size_stats table and MVs to dev-tables (#13307)
Track event size distributions across projects via a MergeTree table
fed by two materialized views (one from traces, one from observations).
Every insert including updates gets its own row for full ingestion
visibility.
2026-04-22 13:16:09 +00:00
4e8f0221fc refactor(web): Do not reuse table name for observations and events table (#13204)
* refactor(web): Do not reuse table name for observations and events table

* Resolve PR comments

---------

Co-authored-by: Nimar <l.nimar.b@gmail.com>
2026-04-22 12:14:08 +00:00
bc9ef188b4 fix(evals): fix score filtering on evaluator runs page (#13225)
* fix(evals): remove broken score value filter from evaluator runs page

The score value filter on the evaluator runs page never worked because
it LEFT JOINed the PostgreSQL scores table, but scores live in
ClickHouse. Remove the filter from the UI and strip it in the backend
for backward compatibility with bookmarked URLs.

Closes LFE-9279

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(evals): remove session ID filter and column from evaluator runs page

The session ID filter/column depended on the Postgres `traces` table via
LEFT JOIN, but traces now live in ClickHouse so the join never resolved.
Drop the UI filter facet, table column, and the unused traces JOIN.

Also generalize the bookmarked-URL stripping into a DEPRECATED_FILTER_COLUMNS
constant (currently scoreValue + sessionId).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-22 11:57:10 +00:00
NimarandGitHub e3c741d3b5 feat(widgets): distinguish between available and called tools in filter (#13281)
* feat(widgets): distinguish between available and called tools in filter

* add file

* refactor

* add tests

* fix build

* up

* fix build

* fix scores

* fix observations release
2026-04-22 11:52:12 +00:00
Ben BachemandGitHub 97342f5830 feat(prompts): Add time window filtering to prompt metrics (#13282)
* feat(prompts): Add time window filtering to prompt metrics

* Normalize time window for prompt metrics to start of day / end of day

* Add explanatory tooltip to "last used" and "first used" columns
2026-04-22 11:07:55 +00:00
Ben BachemandGitHub 6508550cc7 refactor(web): Always allow toggling V4 in dev mode (#13284) 2026-04-22 09:45:34 +00:00
Hassieb PakzadandGitHub 2012bd14ee fix(web): migrate unstable eval unit tests to vitest (#13300) 2026-04-22 11:11:54 +02:00
Hassieb PakzadandGitHub ecb0d443ad feat(api): add unstable evals public endpoints (#12829) 2026-04-22 10:51:46 +02:00
585b50ae76 refactor(web): migrate test framework from Jest to Vitest (#13191)
* refactor(web): migrate test framework from Jest to Vitest

Replace Jest with Vitest in the web package for faster test execution
and native ESM/TypeScript support without requiring next/jest SWC transforms.

- Replace jest/jest-environment-jsdom/@types/jest with vitest/@vitejs/plugin-react/vite-tsconfig-paths
- Add vitest.config.mts with 3 projects (client/server/e2e-server) matching the original Jest config
- Convert all jest.* API calls to vi.* equivalents across ~28 test files
- Convert jest.requireActual() to async vi.importActual() with async factory functions
- Remove @jest-environment docblock pragmas (environment set in vitest config)
- Add resolveWorkspaceDeps vite plugin for pnpm strict mode compatibility
- Set testTimeout to 30s to match previous Jest/next-jest default

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(web): fix type error in jumptoplayground test mock

Cast vi.importActual("zod") to any to satisfy both the TypeScript
compiler and the consistent-type-imports lint rule.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: remove jest from shared tsconfig types

The nextjs.json shared tsconfig included "jest" in the types array,
which required @types/jest to be installed. Since we migrated to vitest,
vitest globals are provided via web/vitest-env.d.ts instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: update CI pipeline to use vitest instead of jest

Replace jest CLI calls with vitest equivalents in the GitHub Actions
pipeline. Also regenerate pnpm-lock.yaml to remove stale jest entries.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(web): include client project in test:watch

The old Jest test:watch ran all projects. The Vitest migration narrowed
it to only --project server, silently excluding *.clienttest.{ts,tsx}
files from watch mode.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor(web): simplify vitest shared aliases and add web to root workspace

- Auto-generate @langfuse/shared resolve aliases from its package.json
  exports instead of hardcoding each subpath
- Add web to root vitest.workspace.ts alongside worker

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(web): address PR review feedback

- Update AGENTS.md quick commands to use vitest positional patterns
  instead of Jest --testPathPatterns flag
- Move admin-access-webhook.servertest.ts from src/__tests__/async/ to
  src/__tests__/server/async/ so it matches the server project include
  pattern (was silently orphaned under both Jest and Vitest)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(web): fix admin-access-webhook test for 5-minute dedupe window

The dedupe window was increased from 60s to 5 minutes in bbd209194 but
the test was never updated because it was orphaned (not picked up by any
test project). Now that it runs, fix the test to advance the clock past
the actual 5-minute window.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor(web): simplify vitest config using deps.inline

Replace the custom resolve aliases, resolveWorkspaceDeps plugin, and
esbuild.tsconfigRaw workaround with a single deps.inline config — the
same approach used by the worker package. This tells Vitest to process
@langfuse/* packages through its transform pipeline using normal Node
resolution (following pnpm symlinks) instead of Vite's strict exports
resolver.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* chore(web): remove unnecessary vitest-env.d.ts

Test files are excluded from the build tsconfig, and vitest injects
global types at runtime when globals: true is set. The declaration
file is not needed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(web): add vitest/globals to tsconfig types and update docs

- Add "vitest/globals" to web/tsconfig.json types so Next.js build
  can resolve describe/it/expect in test files (fixes CI build error)
- Move @testing-library/jest-dom/vitest to client project setupFiles
  instead of per-file imports
- Update CONTRIBUTING.md, AGENTS.md, and skill reference docs to
  replace Jest references with Vitest

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(web): add @testing-library/jest-dom to tsconfig types

Without this, IDE shows type errors on jest-dom matchers like
toBeInTheDocument() in client test files. The setupFiles config
registers the matchers at runtime but doesn't provide the types.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: correct file location paths in testing-guide.md

Update three embedded file location annotations from async/ to server/
to match the actual directory structure.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(web): enable parallel server tests, clean up CONTRIBUTING.md diff, revert turborepo skill

- Remove fileParallelism: false from server/e2e-server projects to
  enable parallel test execution (faster CI)
- Rewrite CONTRIBUTING.md changes preserving original CRLF line endings
  to minimize diff noise
- Revert turborepo dependencies.md change (generic skill, not repo-specific)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(web): restore sequential server tests, clean up docs

- Add maxWorkers: 1 to server/e2e-server projects to match Jest's
  --runInBand (shared DB requires sequential execution)
- Clean CONTRIBUTING.md diff (preserve CRLF line endings)
- Revert turborepo skill change (generic skill, not repo-specific)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: align CONTRIBUTING.md test command description with example

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(web): convert remaining jest.* calls in controller.clienttest.ts

New test code merged from main still used jest.mock/jest.fn/jest.mocked
instead of vi.* equivalents.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Nimar <l.nimar.b@gmail.com>
2026-04-22 08:25:56 +00:00
439e9dbbbd chore(ci): pin action version comments to immutable patch tags (#13291)
Tightens `# v1`/`# v2`/`# v6` floating-major comments on SHA-pinned
actions to their exact patch-level tags (`v1.8.4`, `v2.1.0`, `v2.6.1`,
`v6.1.1`). Same SHAs, no behavior change — just removes ambiguity about
which release the pin corresponds to, and keeps the comment truthful if
the upstream major ever moves to a new SHA (which is exactly what bit
us on actions/setup-node in langfuse-js).

Left alone:
- winterjung/split — only publishes a `v2` floating tag; no patch-level
  tag exists to tighten to.
- orange-buffalo/dependabot-auto-rebase — pins a `v1` branch head (not
  a tag). Switching off a mutable ref is a separate decision.
- .github/workflows/ci.yml.template — not an active workflow.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 17:21:11 +00:00
marliessophieandGitHub 9e59c2c2a7 fix(web): prevent DataTable onRowClick when clicking interactive elements (#12881) 2026-04-21 16:00:52 +00:00
82a4ac4926 feat(api): add DELETE endpoint for LLM connections (#13247)
* feat(api): add DELETE endpoint for LLM connections

Adds `DELETE /api/public/llm-connections/{id}` so API clients (e.g. the
Terraform provider) can fully manage the lifecycle of LLM connections.
Mirrors the tRPC delete behavior by pausing dependent evaluator configs
when the connection is removed.

Refs: langfuse/terraform-provider-langfuse#19,
langfuse/terraform-provider-langfuse#20

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: remove admin api key auth

* chore: revert

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 15:05:23 +00:00
d205b39edf fix(onboarding): add PH button capture for 'try demo project' (#13251)
* add capturing for demo project button

* delete duplicate entry 'delete_form_open' in posthog client capture

---------

Co-authored-by: Nimar <l.nimar.b@gmail.com>
2026-04-21 12:33:43 +00:00
Ben BachemandGitHub c735ea914a feat(web): Add region selector to user menu (#13270)
* feat(web): Add region selector to user menu

* Only show region switcher in cloud region

* Create `isProductionRegion` function

* Use same regions for auth and user navigation
2026-04-21 12:17:57 +00:00
marliessophieandGitHub 4c2be93bd1 feat(experiments): add support to trigger evals (#13240)
* feat(experiments): add support to trigger evals

* feat: add experiment comparison and batch evaluation actions to tables

* refactor: add experimentRootObservationsOnly config to batch action and event stream

* fix: types & build error

* feat: enhance evaluator selection with dynamic scope labels and improve evaluation dialog messaging

* chore: fix

* feat: add experimentItemExpectedOutput field to event query builder

* feat: add 'Is Experiment Item Root Span' column to events table and update related mappings

* fix: experiment cost preview

* chore: gate experiment dialog

* chore: build
2026-04-21 12:13:23 +00:00
marliessophieandGitHub ac393ee675 chore(experiments): remove outdated peek view code (#13009)
* chore(experiments): remove outdated peek view code

* chore:push
2026-04-21 12:03:20 +00:00
020c344211 feat: detect SDK version from langfuse events table (#13203)
* feat: detect SDK version from langfuse events table

* chore: push

* feat(events): set preferred Clickhouse service for SDK metadata retrieval

* refactor: rename SDK metadata functions for clarity and update documentation

* refactor(events): update metadata selection to use selectMetadataExpanded for full values

* tests: ai sdk test case

* refactor: enhance SDK metadata extraction to include telemetrySdkName for improved identification

---------

Co-authored-by: Nimar <l.nimar.b@gmail.com>
2026-04-21 11:59:05 +00:00
e5074f2ead fix(storage): disable default S3 checksums for GCS multipart uploads (#13280)
AWS SDK v3 >= 3.729 sends a composite CRC32 header on
CompleteMultipartUpload by default, which GCS's S3-compat layer rejects
with a 412 PreconditionFailed. Set requestChecksumCalculation and
responseChecksumValidation to WHEN_REQUIRED so buffered multipart and
lib-storage Upload both work against GCS HMAC endpoints.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 11:42:24 +00:00
Steffen SchmitzandGitHub 8226dd89dc fix(audit-logs): capture after-state and normalise resource ids for member role changes (#13278)
- `updateOrgMembership` now passes the updated record as `after` so org-level
  role changes log both before and after in the audit trail.
- `updateProjectRole` passes `updatedProjectMembership` as `after`, uses
  `action: "create"` when the upsert creates a new row, and standardises the
  `resourceId` to `projectId--userId` across create/update/delete so one
  membership can be tracked end-to-end.

Fixes LFE-9056.
2026-04-21 11:08:05 +00:00
96fed782c6 fix(batch-actions): allow dialog close on status step and fix Go to Dataset 404 (#13277)
fix(batch-actions): allow dialog dismissal on status step and fix Go to Dataset 404

Previously the add-observations-to-dataset dialog blocked ESC / outside-click
on the status step, and the "Go to Dataset" link 404'd for datasets whose ids
contain slashes (e.g. seed datasets named `folder/simple-dataset`). Allow
ambient dismissal except while the batch action is in flight, and navigate
via `router.push` with an encoded dataset id so Next.js doesn't decode `%2F`
back to `/` on render.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 11:06:27 +00:00
77ef07bc7f fix(dashboards): exclude TEXT and CORRECTION scores from scores-numeric view (#13276)
Replace the scores-numeric segment's "does not contain CATEGORICAL"
exclusion with a positive allow-list of data_type IN ('NUMERIC', 'BOOLEAN').
Previously, free-text (TEXT) and correction scores leaked into the
scores-numeric view because only CATEGORICAL was excluded; their null
numeric values also distorted avg/min/max aggregations.

The positive allow-list is safer by default — any future data_type value
added to the enum is excluded unless explicitly opted in.

Refs https://linear.app/langfuse/issue/LFE-9399

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 09:46:56 +00:00
Ben BachemandGitHub 00784f72c5 refactor(web): Enable react/no-unused-prop-types eslint rule (#13209)
* chore(web): Enable `react/no-unused-prop-types` eslint rule

* refactor(web): Fix react/no-unused-prop-types eslint warnings

* Avoid false positives around react-table cells using satisfies

* Update pivot-table.clienttest.tsx to remove `accessibilityLayer` prop
2026-04-21 09:05:57 +00:00
Ben BachemandGitHub fdc3d2f1f8 fix(web): Use overflow-auto instead of overflow-scroll for main content (#13267) 2026-04-21 08:59:22 +00:00
Ben BachemandGitHub 253a4f8cd0 chore(web): Remove @headlessui packages (#13275) 2026-04-21 08:13:04 +00:00
Ben BachemandGitHub c3438490e7 fix(web): Stale search highlights (#13237)
* fix(web): Stale search highlights

* refactor(web): Do not compute search match ranges twice

* Fix PR review issue about active match not being restored

* Resolve PR comment

* Split `useSyncMessageSearchMessages` useEffects
2026-04-21 07:40:38 +00:00
Ben BachemandGitHub f993eb1efc fix(web): Improve skeleton loading state for tables (#13235)
* fix(web): Improve skeleton loading state for tables

* Resolve PR comments

* Add missing loadingCell arguments

* Resolve more PR comments

* Add loading cell for metadata column in scores table

* Resolve PR comments
2026-04-21 07:30:01 +00:00
NimarandGitHub 210b6bfe2a chore(deps): bump dompurify to 3.4.0 (#13272) 2026-04-20 23:50:05 +02:00
e488990476 chore(worker): include fileKey in OTEL ingestion failure logs (#13271)
Emit the S3 fileKey on every OTEL ingestion failure path so operators can
scan their log platform for dropped or errored batches and feed the list
into worker/src/scripts/replayIngestionEventsV2. Covers: masking
fail-closed drops, observation parse failures, per-event record
creation/eval/write failures, and the job-level ForbiddenError/catch
fallthrough. The masking drop log additionally carries orgId and the
propagated callback headers to support zero-trust audit trails.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 16:31:29 +00:00
a7ecf440f7 chore(tests): use gemini-2.5-flash-lite for GoogleAIStudio tests (#13265)
Avoids rate limit conflicts when VertexAI and GoogleAIStudio tests
run concurrently against the same model.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-20 16:22:56 +00:00
Valery MeleshkinandGitHub 9d62604937 chore: bump bullmq to 5.73.5 (#13256) 2026-04-20 18:25:23 +02:00
8834a3af42 fix(datasets): fix errors during json schema generation (#13193)
* fix(datasets): downgrade schema example error to warn to avoid Sentry noise

json-schema-faker can crash on certain user-provided schemas (e.g. arrays
without items). The function already gracefully returns "" and the UI hides the
example section, but console.error was captured by Sentry's capture_console
integration. Downgrade to console.warn so this expected edge case no longer
triggers alerts.

Fixes LANGFUSE-4S5

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat(datasets): upgrade json-schema-faker to 0.6.1 and migrate to async API

- Upgrade json-schema-faker from 0.5.9 to 0.6.1 (ESM-only, zero deps,
  TypeScript rewrite) which fixes the array-without-items crash
- Migrate from deprecated synchronous default-export API to the new named
  async `generateJson` export with per-call options
- Update callers (DatasetSchemaHoverCard, NewDatasetItemForm) to handle
  async generation with proper cancellation cleanup
- Add Jest moduleNameMapper + transformIgnorePatterns for ESM-only package
- Refactor jest.config.mjs to pre-resolve configs and avoid duplicate calls

Fixes LANGFUSE-4S5

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor(datasets): revert jest.config.mjs changes, use virtual mock in test

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* chore(datasets): remove generateSchemaExample test file

ESM-only json-schema-faker@0.6.1 can't be resolved by Jest's CJS
resolver without jest.config changes. The wrapper is trivial — drop the
test rather than adding workarounds.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* test(datasets): add generateSchemaExample tests with Jest ESM resolution

Add moduleNameMapper for json-schema-faker (ESM-only package) so Jest
can resolve it, and restore the client tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(datasets): add type assertion for JsonSchema compatibility

Prisma.JsonValue narrows to JsonObject | JsonArray which isn't
assignable to json-schema-faker's JsonSchema type. Cast explicitly
since we already guard for non-objects.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor(datasets): remove unnecessary cancellation in schema example effects

Schema generation is near-instant — cancellation cleanup adds
complexity for no practical benefit.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(datasets): merge moduleNameMapper with Next.js defaults in jest config

Spread sharedOverrides was overwriting Next.js's built-in
moduleNameMapper (CSS, assets, server-only). Use a helper that merges
our ESM mapper with the resolved config's existing mappings instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(datasets): add type annotation to withEsmMapper parameter

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(datasets): add cancellation guard to NewDatasetItemForm schema effect

Rapidly switching datasets could let a stale promise overwrite the
correct placeholder. Add cancelled flag for the multi-dependency effect.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(datasets): prevent cascading re-runs and user input overwrite in schema effect

- Remove inputValue/expectedOutputValue from the effect dependency array
  to prevent form.setValue triggering cascading effect re-runs
- Use form.getValues() at both dispatch and resolution time to avoid
  overwriting content the user typed while generation was in-flight

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(datasets): add cancellation guard to DatasetSchemaHoverCard effect

For consistency with NewDatasetItemForm's async pattern.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-20 15:36:51 +00:00
Ben BachemandGitHub 533d0f0029 refactor(traces): Remove unused updateTags mutation from router (#13269) 2026-04-20 15:36:42 +00:00
cd9ae6d0c3 feat(auth): allow configuration of ID Token signed response alg (#12333)
* feat(auth): allow configuration of ID Token signed response alg

* fix(auth.ts): linter compliance

---------

Co-authored-by: Steffen Schmitz <steffen@langfuse.com>
Co-authored-by: Tobias Wochinger <tobias.wochinger@clickhouse.com>
2026-04-20 14:20:50 +00:00
Ben BachemandGitHub 88313c1d82 refactor(web): Make useSidebarFilterState state location more explicit (#13150)
* refactor(web): Make `useSidebarFilterState` state location more explicit

* Use discriminated union for state location & further cleanup

* Remove incorrect if condition

* Update peek readme

* Remove unneccessary usePeekTableState hooks
2026-04-20 14:20:09 +00:00
Ben BachemandGitHub b5bada7b21 refactor(web): Remove unused components and hooks (#13148) 2026-04-20 13:29:24 +00:00
b3e2e2dfd6 ci: pin useblacksmith/setup-docker-builder comment to v1.6.0 (#13266)
The SHA 5241b2e9 resolves to v1.6.0, not the floating v1 tag. Fixes
zizmor ref-version-mismatch alerts #500 and #501.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 13:28:20 +00:00
5a7420ec2a ci: run zizmor on fork PRs by failing on findings (#13263)
Fork PRs don't receive security-events: write on GITHUB_TOKEN, so the
SARIF upload path is unavailable. Previously the whole job was skipped
on fork PRs, meaning contributor changes to workflows bypassed zizmor.
Add a fork-PR step without advanced-security that fails the job on
findings so contributors see the error directly; keep the SARIF upload
step for trusted events so the code-scanning ruleset still blocks merges.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 15:16:09 +02:00
Hassieb PakzadandGitHub 5abbf2c5a3 fix(model-prices): add match on claude-haiku-4-5 (#13254) 2026-04-20 13:21:42 +02:00
Valery MeleshkinandGitHub 06ee77746a feat: emit .rate and .time metrics with shard tags for DataDog aggregation (#13249)
feat: emit .rate and .time metrics with shard tags for DataDog
aggregation
2026-04-20 09:54:43 +00:00
d8bab6b29f feat(web): warn about unencoded special characters in DATABASE_URL on migration failure (#13186)
* feat(web): warn about unencoded special characters in DATABASE_URL on migration failure

When Prisma migrations fail, the error message now detects whether the
DATABASE_URL credentials contain special characters that need percent-encoding
and prints an actionable hint with an example and documentation link.

Closes #3923

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat(web): add ClickHouse password special character detection on migration failure

Extends the migration failure diagnostics to also check CLICKHOUSE_PASSWORD
for characters (&, =, #, ?, %, +, @) that would break the query-string
interpolation in the ClickHouse migration script.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* chore: feedback

* chore: patch

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-20 07:25:22 +00:00
Steffen SchmitzandGitHub f3ad6ae999 chore: prefix batch export logs (#13246) 2026-04-17 19:15:14 +00:00
011ce23d7f chore(scim): add [SCIM] log prefix and operation confirmations (#13245)
Prefix every SCIM API log with [SCIM] so they can be filtered out of
aggregate logs. Add user-id-based confirmation logs after PUT/PATCH
provisioning and deprovisioning and after DELETE, mirroring the
existing POST assignment log, so operations can be traced without
emitting userName/email. Drop the email from the 409 already-exists
log in POST /Users and log the existing membership userId instead.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 18:53:44 +00:00
b8b5c6012a fix(security): use constant-time comparison for admin API key auth (#13208)
* fix(security): use constant-time comparison for admin API key auth

Replace direct string comparison (!==) with crypto.timingSafeEqual for
ADMIN_API_KEY verification to prevent timing side-channel attacks
(CWE-208). This aligns with the secure pattern already used for project
API key authentication in createAuthedProjectAPIRoute.ts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(security): handle timingSafeEqual byte-length mismatch in admin auth

Align AdminApiAuthService with the project-scoped admin-key check in
createAuthedProjectAPIRoute.ts: drop the JS-string-length pre-check (which
misreads UTF-8 byte length and can crash on multibyte tokens) and wrap
timingSafeEqual in try/catch. Remove the dead !env.ADMIN_API_KEY guard
already handled by the early-return. Replace the duplicated inline admin
key comparison in createNewSsoConfigHandler with AdminApiAuthService so
both admin paths share one timing-safe implementation, and add
cross-reference comments between the two remaining call sites.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 16:59:00 +00:00
53a0e9d074 fix(security): sanitize score config names to prevent CSS injection (#13206)
* fix(security): sanitize score config names to prevent CSS injection

Score config names were interpolated unsanitized into a <style
dangerouslySetInnerHTML> block in ChartStyle, allowing stored CSS
injection via crafted config names (e.g. `x}*{background:red}/*`).

- Sanitize ChartConfig keys at the render site in chart.tsx (defense in
  depth for existing data)
- Add ScoreConfigNameSchema in shared domain with regex validation
  (^[\w\s.()-]+$) for use at input boundaries
- Apply name validation to tRPC create/update and public API POST/PUT
  score-config endpoints

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* chore: score config docs

* chore: udnerscores

* chore: adjust chart.tsx schema

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 15:25:23 +00:00
Valery MeleshkinandGitHub 9dacef8c25 fix: make new queue depth metrics usable in cloud watch (#13241) 2026-04-17 15:24:15 +00:00
Valery MeleshkinandGitHub 29026c361f chore: deterministic CloudUsageMeteringQueue init (#13239) 2026-04-17 14:22:08 +00:00
Steffen SchmitzandGitHub 3e1b5992d4 fix: coerce AUTH_SSO_TIMEOUT to number (#13199)
* fix: coerce AUTH_SSO_TIMEOUT to number

* Update AUTH_SSO_TIMEOUT to be positive integer
2026-04-17 13:27:34 +00:00
Nimar 2c4a486edd chore: release v3.169.0 2026-04-17 14:43:16 +02:00
Ben BachemandGitHub ade2c3cff2 fix(prompts): Prevent text overlap when adding prompt reference (#13236) 2026-04-17 12:35:30 +00:00
Valery MeleshkinandGitHub 3089778d7d feat: QueueMetricsRunner collects queue metrics on a fixed schedule and aggegates sharded queue metrics (#13231) 2026-04-17 12:23:51 +00:00
Ben BachemandGitHub 7221ba1018 chore: Update pull request template to clarify chore and refactor types (#13166) 2026-04-17 12:17:33 +00:00
NimarandGitHub a851d49c5e chore(skill): pnpm upgrade skill doesnt change lock file manually (#13234) 2026-04-17 11:59:20 +00:00
NimarandGitHub bcf993a74d chore(deps): bump follow-redirects 1160 (#13233) 2026-04-17 11:51:24 +00:00
NimarandGitHub 7b1ddc6182 chore(deps): bump protobufjs to 7.5.5 (#13232)
* chore(deps): bump protobufjs to 7.5.5

* dedupe
2026-04-17 11:22:54 +00:00
628156a39e fix(ci): use exact release tags in action version comments (#13229)
The zizmor ref-version-mismatch rule flags hash-pinned actions whose
version comment references a moving major tag (e.g. `# v2`) instead of
the exact release tag the hash belongs to. Update the three flagged
actions:

- aws-actions/amazon-ecr-login: `# v2` → `# v2.1.2`
- github/codeql-action/upload-sarif (snyk-worker): `# v4` → `# v4.35.1`
- github/codeql-action/upload-sarif (snyk-web): `# v4` → `# v4.35.1`

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 09:49:05 +00:00
marliessophieandGitHub 59d0e620f0 fix: update managed ragas-faithfulness-evaluator with proper scoring and prompt details (#13226)
* fix: update managed ragas-faithfulness-evaluator with proper scoring and prompt details

* chore: push
2026-04-17 09:41:29 +00:00
Ben Bachem 23f1a51b2e chore: release v3.168.0 2026-04-17 10:36:00 +02:00
Ben BachemandGitHub 285f980b56 fix(web): Hide irrelevant filters in subtables (#13136) 2026-04-17 08:26:56 +00:00
df4d782182 fix(evals): return full JSONPath slice result and deduplicate eval JSONPath logic (#13200)
* fix(evals): return full JSONPath slice result and deduplicate eval JSONPath logic

JSONPath slice expressions (e.g. $[1:]) returned only the first matched
element due to an unconditional result[0] in parseJsonDefault. Now
multi-match results return the full array while single-match results
remain unwrapped for backward compatibility.

Also consolidates three separate JSONPath evaluation paths (UI preview,
trace eval, observation eval) into the shared extractValueFromObject,
removing duplicated logic from the worker. The snakeToCamel column ID
fallback and parseUnknownToString remain in the worker since they are
database-specific concerns.

Closes LFE-8416

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(evals): address PR review — scope parseMultiEncodedJson, fix error logging and test expectations

- Only call parseMultiEncodedJson when a jsonSelector is present to avoid
  mutating formatting on the no-selector passthrough path.
- Preserve the raw original value (not the parsed one) in the error
  fallback.
- Add error logging in extractObservationVariables (was already done in
  parseDatabaseRowToString but missed here).
- Update three pre-existing test expectations to match the new unwrap
  semantics: single-match results are unwrapped, non-matching paths
  return empty string instead of "[]".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(evals): update evalService test expectations for single-match unwrap

Four more test assertions in evalService.test.ts still expected
array-wrapped JSONPath results (e.g. '["Hello world"]'). Updated to
match the new unwrap semantics for single-match queries.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* test(evals): remove duplicate slice/single-element tests from extractObservationVariables

These cases are already covered by extractValueFromObject.test.ts.
The pre-existing tests ($.prompt, $.response, non-matching path) remain
as integration tests for the observation eval path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* style(evals): use @langfuse/shared alias instead of relative path in test import

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-17 07:49:55 +00:00
Hassieb PakzadandGitHub 571005d2f3 feat(model-prices): add claude-opus-4-7 (#13214)
* feat(model-prices): add claude-opus-4-7

* push

* push
2026-04-16 16:53:44 +00:00
Ben BachemandGitHub 6fc9ea6bad fix: Missing trace tags in v4 table and detail view (#13165)
* fix: Missing trace tags in v4 table and detail view

* Resolve review comments

* Add comment

* Add missing `isRoot` condition
2026-04-16 15:47:13 +00:00
marliessophieandGitHub d4aa05a4d2 chore(trpc): handling of errors with body parse issues (#13211) 2026-04-16 15:09:44 +00:00
Steffen SchmitzandGitHub aecb6ef2be fix: prevent ip validation bypass for image URL validation (#13207)
fix: prevent ip validation bypass for URL validation
2026-04-16 13:47:23 +00:00
824758349d chore(ci): remove GitHub Actions that rely on Node 20 (#13194)
* chore(ci): replace fkirc/skip-duplicate-actions with inline gh script

Remove third-party action dependency and replicate the tree-hash
deduplication logic using gh api. Compares the current commit's git
tree SHA against recent successful workflow runs to skip redundant CI.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* chore(ci): replace ravsamhq/notify-slack-action with slackapi/slack-github-action

Switch to the official Slack GitHub Action (v3.0.1) for failure
notifications. Uses Block Kit payload for richer messages with
branch/tag, actor, and a direct link to the workflow run.

Also removes the now-unnecessary SLACK_WEBHOOK_URL entry from the
zizmor secrets-outside-env allowlist since the webhook is now passed
via action input rather than env var.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 13:10:35 +00:00
2839f659bb fix(otel): prevent prototype pollution in OTel attribute key parsing (#13201)
Crafted OTel attribute keys like `gen_ai.prompt.__proto__.POLLUTED` could
pollute Object.prototype via the nested-object construction in
convertKeyPathToNestedObject. Guard against dangerous keys (__proto__,
constructor, prototype) and use Object.create(null) for result objects.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 12:45:12 +00:00
marliessophieandGitHub 8dd7b23a3e fix(annotation): render session-level screens subject to fast preview mode on/off (#13178)
* fix(annotation): properly handle session-level-annotation subject to v4

* fix: hide counter

* chore: push

* refactor: simplify

* chore: push

* chore: push
2026-04-16 08:14:58 +00:00
3e61ecc84f feat(tracing): tracing setup page with prompt (#13045)
* draft v1 for skill based onbording

* small ui change

* feat(web): redesign traces onboarding for agent-first setup

* formatting fix

* reuse env component

* add new events to posthog list

* adjsut padding

* feat(web): redesign traces onboarding and clean up setup helpers

* formatting fix

* fix(web): simplify base URL fallback for onboarding env setup

* fix(web): normalize SSR base URL fallback on Vercel

* rename to TracesSetupOnboardingCard

* remove duplicate code for baseurl calling

* catch error on copy button

* add 'copy pormpt' text to button

* fix(web): move copy button above prompt text to avoid overlap

* revert(web): restore HostNameProject and useLangfuseEnvCode from main

Made-with: Cursor

* ui: align layout left

* ui/smaller

* refine video positioning

* refine ui

* ui refinement

* ui refinement

* handle API key access

* edit copy button

* align api key access with existing components

* rmv text

* remove classname

* rmv classname form splashscreen

* rmv cn from splashscreen

* rmv comments

* Update web/src/features/setup/components/TracesSetupOnboardingCard.tsx

Co-authored-by: Nimar <l.nimar.b@gmail.com>

* Update web/src/features/setup/components/TracesSetupOnboardingCard.tsx

Co-authored-by: Nimar <l.nimar.b@gmail.com>

* standardize padding + add spacing from before

---------

Co-authored-by: Nimar <l.nimar.b@gmail.com>
2026-04-15 09:58:25 +00:00
marliessophieandGitHub 692789d0f5 fix(worker): sync managed evaluator vars on template updates (#13164)
* fix(worker): sync managed evaluator vars on template updates

* chore: timestamp

* chore: filter based on project id

* Revert "chore: filter based on project id"

This reverts commit 132ac226ad68c3dec25194433e99f95261974294.

* fix: update log message for managed evaluators upsert completion
2026-04-15 08:35:05 +00:00
864055f593 perf(dual-write): clamp min start time to past day and optimize trace sorting (#13172)
* perf(dual-write): clamp min start time to past day and optimize trace sorting

* chore: exclude project_id 'cmbktgdyf0059ad07yexqm2gp' from dual write

* chore: introducing LANGFUSE_EVENT_PROPAGATION_EXCLUDE_PROJECT_IDS

---------

Co-authored-by: Valery Meleshkin <valeriy@langfuse.com>
2026-04-15 08:31:45 +00:00
Valery MeleshkinandGitHub f741f84e97 chore: add redis.full_command to redis traces (#13169) 2026-04-14 16:42:31 +00:00
marliessophieandGitHub c2ff2c8b7d fix(experiments): keep referenced prompts single-row in compact density (#13167) 2026-04-14 15:09:30 +00:00
NimarandGitHub 02abecaaeb chore(security): fix snyk code scanning (#13158)
* chore(security): fix snyk code scanning

* cleanup

* guard
2026-04-14 13:30:38 +00:00
5d99c5a4a9 chore(v4): default new orgs to v4 (#13105)
* chore(v4): default new orgs to v4

* add rollout file

* simplify

* fix toggle shown on sign up

* persist in db

* exclude demo org

* fix order

* rename

* larger rename

* simpify cloud handling

* no test

* fix

* fix ondismiss

* max transactional

* feat: default new users to observation-level evals (#13151)

* feat: default new users to experiments beta (#13154)

* fix time

---------

Co-authored-by: marliessophie <74332854+marliessophie@users.noreply.github.com>
2026-04-14 12:55:22 +00:00
aa76b348e8 fix(ci): handle invalid security-severity in Snyk SARIF output (#13163)
fix(ci): handle null/undefined security-severity in Snyk SARIF output

Snyk emits invalid security-severity values (null, "undefined", "null")
that cause codeql-action/upload-sarif to reject the file. Replace the
sed-based fix with jq to handle all non-numeric values.

See: https://github.com/github/codeql-action/issues/2187

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 12:11:32 +00:00
56c27d4a63 fix(slack): remove redundant timestamp footer from Slack notifications (#13152)
Slack natively timestamps every message. Our custom footer showed the
worker's server timezone which confused users in different timezones.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 11:51:29 +00:00
7c150e7f77 ci: reapply GH Actions hardening with deploy secret fix (#13161)
* Revert "revert: ci: harden + monitor GH actions with zizmor (#13048) (#13155)"

This reverts commit 4ff398eda0.

* ci: pass deploy secrets explicitly to reusable workflow

Environment secrets don't auto-resolve in reusable workflows.
See: https://github.com/actions/runner/issues/3206

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 11:43:48 +00:00
Tobias WochingerandGitHub 4ff398eda0 revert: ci: harden + monitor GH actions with zizmor (#13048) (#13155)
Revert "ci: harden + monitor GH actions with zizmor (#13048)"

This reverts commit 818fd3b16e.
2026-04-14 10:24:56 +00:00
Ben BachemandGitHub 471e150a87 fix(traces): Use single-line skeletons for table with small row height (#13138) 2026-04-14 09:36:33 +00:00
Ben BachemandGitHub 01df1ede47 fix(web): Preserve whitespace in message search controller (#13096)
* fix(web): Preserve whitespace in message search controller

* Fix tests

* Clear search on blur if whitespace only
2026-04-14 09:35:53 +00:00
Valery MeleshkinandGitHub 0debc7274e fix: rename migration from a cleaned up name to avoid repeated reapplication (#13153)
fix: rename migration from a cleaned up name to avoid repeated
reapplication
2026-04-14 09:26:08 +00:00
e91a046d40 feat(slack): show change author in Slack prompt notification (#13149)
* feat(slack): show change author in Slack prompt notification

Display the user who made the change in the Slack notification message
for prompt version events. Falls back to email when name is unavailable,
and shows "API User" for API key-initiated changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(slack): escape mrkdwn in change author and use || for empty string fallback

Escape &, <, > in user name/email to prevent Slack mrkdwn injection
(e.g. <!channel> triggering mass notifications). Use || instead of ??
so empty string names fall back to email correctly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(slack): escape all user-controlled mrkdwn fields in prompt notification

Apply escapeSlackMrkdwn to prompt.name, prompt.tags, and
prompt.commitMessage to prevent injection via those fields too.
Labels are safe (validated by PROMPT_LABEL_REGEX).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 08:44:04 +00:00
818fd3b16e ci: harden + monitor GH actions with zizmor (#13048)
* Add zizmor workflow and skip forked Claude review PRs

* ci: test if workflow breaks

* ci: add dependabot cooldown

* ci: zizmor auto-fixes

* ci: harden GitHub Actions workflows

* ci: refine zizmor workflow configuration

* ci: scope sdk and snyk secrets to environments

* ci: address zizmor workflow review feedback

* ci: fix license check

* ci: align sdk workflow secret handling

* ci: enable snyk checks on pull requests

* ci: remove temporary snyk pull request trigger

* ci: bump back to the zizmor minimum of 7 days

* style: move to nicer config syntax for secrets-outside-of-env

* ci: fix template-injection warnings in pipeline digest step

Move step outputs and matrix values from ${{ }} interpolation in run
blocks to env variables, preventing potential shell code injection.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(ci): fix broken heredoc expansion in Docker publish steps

The publish-manifest steps used <<'EOF' (single-quoted heredoc) which
suppresses bash variable expansion, and the env vars were never defined
in those steps. This meant every tag-triggered release would fail with
literal ${VAR} strings passed as Docker tags.

- Change <<'EOF' to <<EOF to enable variable expansion
- Add env: blocks defining STEPS_META_*_OUTPUTS_TAGS from step outputs
- Move remaining ${{ matrix.* }} interpolations to env vars

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* ci: rename reserved GITHUB_ env var prefix to INPUT_

Rename GITHUB_EVENT_INPUTS_CONFIRM to INPUT_CONFIRM. GitHub reserves
the GITHUB_ prefix for built-in runner variables.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* ci: use environment secret instead of inherit

* ci: switch to latest action

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 08:23:19 +00:00
Max DeichmannandGitHub d65ee4f6cb chore: add sampling for sharded queues (#13143)
* chore: add sampling for sharded queues

* chore: add sampling for sharded queues

* chore: add sampling for sharded queues

* fix(worker): constrain queue metrics sample rate

* Delete worker/src/__tests__/env.test.ts
2026-04-13 18:54:45 +00:00
Hassieb PakzadandGitHub 7d15ee9ed4 feat(cache): add local l1 cache for model match (#12977) 2026-04-13 20:13:42 +02:00
NimarandGitHub 29faeb31e5 chore(deps): run pnpm dedupe (#13142) 2026-04-13 17:30:55 +00:00
Valery MeleshkinandGitHub e7892863c4 chore: add bloom_filter index on experiment_id to events_core (#13141) 2026-04-13 16:32:27 +00:00
Jannik MaierhöferandGitHub c8faf987a7 feat(ui): remove tier from pylon issue field and change warning message (#13140)
feat(ui): remove tier from pylon issue field and change warnong message
2026-04-13 16:11:32 +00:00
Valery MeleshkinandGitHub de75917221 fix: count histogram UI switching during widget editing (#13128) 2026-04-13 15:04:36 +00:00
marliessophieandGitHub 9440dc24c1 chore(experiments): release public beta on cloud (#13131)
* chore(experiments): release public beta on cloud

* chore: push
2026-04-13 14:50:47 +00:00
Hassieb PakzadandGitHub ce7297a42f fix(email): add project name to evaluator pause notifications (#13135)
* fix(email): add project name to evaluator pause notifications

* push
2026-04-13 16:29:05 +02:00
Hassieb PakzadandGitHub 35e837700e fix(otel): normalize gen ai usage details (#13110) 2026-04-13 16:21:45 +02:00
Valery MeleshkinandGitHub 41c529ddc0 chore: Initialize local databases during cloud setup and maintenance scripts (#13106)
* revert(codex): remove setup_cloud AGENTS entry

* fix(codex): install golang-migrate in cloud services

* fix(codex): verify migrate binary integrity
2026-04-13 14:06:37 +00:00
c091da7c3d fix(evals): make evaluation prompt read-only in view-only template mode (#13047) (#13137)
Fix(evals): make evaluation prompt read-only in view-only template mode

Co-authored-by: Pratima Patel <pratimapatel2008@gmail.com>
2026-04-13 11:59:35 +00:00
Hassieb PakzadandGitHub f72184cc01 fix(llm-schemas): allow CUD access for project members (#13134) 2026-04-13 13:24:57 +02:00
ee7aca767e fix(shared): treat end-of-life model errors as non-retryable (#13129)
* fix(shared): treat end-of-life model errors as non-retryable

Extract non-retryable error patterns into a shared constant and add
"reached the end of its life" to the list so that Bedrock end-of-life
model errors surface immediately instead of being retried.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor(shared): keep isNonRetryableLLMErrorMessage private

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(shared): extract status code from AWS SDK $metadata.httpStatusCode

The AWS SDK puts the HTTP status on `$metadata.httpStatusCode`, not on
`.status` or `.response.status`. Without this, the fallback defaulted to
500, making 4xx errors appear retryable.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* test: use real ResourceNotFoundException from AWS SDK

Instead of hardcoding the error shape, resolve and instantiate the real
`ResourceNotFoundException` from `@aws-sdk/client-bedrock-runtime` via
`@langchain/aws`'s dependency tree.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 09:41:27 +00:00
dependabot[bot]GitHubdependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>Tobias WochingerClaude Opus 4.6
073cd30cc1 ci(deps): bump the github-actions group across 1 directory with 16 updates (#13114)
* ci(deps): bump the github-actions group across 1 directory with 16 updates

Bumps the github-actions group with 16 updates in the / directory:

| Package | From | To |
| --- | --- | --- |
| [actions/checkout](https://github.com/actions/checkout) | `2.7.0` | `6.0.2` |
| [aws-actions/configure-aws-credentials](https://github.com/aws-actions/configure-aws-credentials) | `4.3.1` | `6.1.0` |
| [aws-actions/amazon-ecr-login](https://github.com/aws-actions/amazon-ecr-login) | `2.1.1` | `2.1.2` |
| [actions/github-script](https://github.com/actions/github-script) | `7.1.0` | `9.0.0` |
| [github/codeql-action](https://github.com/github/codeql-action) | `3.35.1` | `4.35.1` |
| [codespell-project/actions-codespell](https://github.com/codespell-project/actions-codespell) | `2.1` | `2.2` |
| [actions/setup-node](https://github.com/actions/setup-node) | `4.4.0` | `6.3.0` |
| [pilosus/action-pip-license-checker](https://github.com/pilosus/action-pip-license-checker) | `2.0.0` | `3.1.0` |
| [dorny/paths-filter](https://github.com/dorny/paths-filter) | `3.0.2` | `4.0.1` |
| [pnpm/action-setup](https://github.com/pnpm/action-setup) | `2.4.1` | `5.0.0` |
| [actions/cache](https://github.com/actions/cache) | `4.3.0` | `5.0.4` |
| [docker/login-action](https://github.com/docker/login-action) | `2.2.0` | `4.1.0` |
| [actions/upload-artifact](https://github.com/actions/upload-artifact) | `4.6.2` | `7.0.1` |
| [docker/metadata-action](https://github.com/docker/metadata-action) | `4.6.0` | `6.0.0` |
| [actions/download-artifact](https://github.com/actions/download-artifact) | `4.1.8` | `8.0.1` |
| [actions/stale](https://github.com/actions/stale) | `9.1.0` | `10.2.0` |



Updates `actions/checkout` from 2.7.0 to 6.0.2
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2.7.0...de0fac2e4500dabe0009e67214ff5f5447ce83dd)

Updates `aws-actions/configure-aws-credentials` from 4.3.1 to 6.1.0
- [Release notes](https://github.com/aws-actions/configure-aws-credentials/releases)
- [Changelog](https://github.com/aws-actions/configure-aws-credentials/blob/main/CHANGELOG.md)
- [Commits](https://github.com/aws-actions/configure-aws-credentials/compare/7474bc4690e29a8392af63c5b98e7449536d5c3a...ec61189d14ec14c8efccab744f656cffd0e33f37)

Updates `aws-actions/amazon-ecr-login` from 2.1.1 to 2.1.2
- [Release notes](https://github.com/aws-actions/amazon-ecr-login/releases)
- [Changelog](https://github.com/aws-actions/amazon-ecr-login/blob/main/CHANGELOG.md)
- [Commits](https://github.com/aws-actions/amazon-ecr-login/compare/183a1442edf41672e66566b7fc560e297a290896...f2e9fc6c2b355c1890b65e6f6f0e2ac3e6e22f78)

Updates `actions/github-script` from 7.1.0 to 9.0.0
- [Release notes](https://github.com/actions/github-script/releases)
- [Commits](https://github.com/actions/github-script/compare/f28e40c7f34bde8b3046d885e986cb6290c5673b...3a2844b7e9c422d3c10d287c895573f7108da1b3)

Updates `github/codeql-action` from 3.35.1 to 4.35.1
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/v3.35.1...c10b8064de6f491fea524254123dbe5e09572f13)

Updates `codespell-project/actions-codespell` from 2.1 to 2.2
- [Release notes](https://github.com/codespell-project/actions-codespell/releases)
- [Commits](https://github.com/codespell-project/actions-codespell/compare/406322ec52dd7b488e48c1c4b82e2a8b3a1bf630...8f01853be192eb0f849a5c7d721450e7a467c579)

Updates `actions/setup-node` from 4.4.0 to 6.3.0
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/49933ea5288caeca8642d1e84afbd3f7d6820020...53b83947a5a98c8d113130e565377fae1a50d02f)

Updates `pilosus/action-pip-license-checker` from 2.0.0 to 3.1.0
- [Release notes](https://github.com/pilosus/action-pip-license-checker/releases)
- [Changelog](https://github.com/pilosus/action-pip-license-checker/blob/main/CHANGELOG.md)
- [Commits](https://github.com/pilosus/action-pip-license-checker/compare/cc7a461bfa27b44ad187b8578c881ef5138c13fd...e909b0226ff49d3235c99c4585bc617f49fff16a)

Updates `dorny/paths-filter` from 3.0.2 to 4.0.1
- [Release notes](https://github.com/dorny/paths-filter/releases)
- [Changelog](https://github.com/dorny/paths-filter/blob/master/CHANGELOG.md)
- [Commits](https://github.com/dorny/paths-filter/compare/de90cc6fb38fc0963ad72b210f1f284cd68cea36...fbd0ab8f3e69293af611ebaee6363fc25e6d187d)

Updates `pnpm/action-setup` from 2.4.1 to 5.0.0
- [Release notes](https://github.com/pnpm/action-setup/releases)
- [Commits](https://github.com/pnpm/action-setup/compare/v2.4.1...fc06bc1257f339d1d5d8b3a19a8cae5388b55320)

Updates `actions/cache` from 4.3.0 to 5.0.4
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](https://github.com/actions/cache/compare/0057852bfaa89a56745cba8c7296529d2fc39830...668228422ae6a00e4ad889ee87cd7109ec5666a7)

Updates `docker/login-action` from 2.2.0 to 4.1.0
- [Release notes](https://github.com/docker/login-action/releases)
- [Commits](https://github.com/docker/login-action/compare/v2.2.0...4907a6ddec9925e35a0a9e82d7399ccc52663121)

Updates `actions/upload-artifact` from 4.6.2 to 7.0.1
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/ea165f8d65b6e75b540449e92b4886f43607fa02...043fb46d1a93c77aae656e7c1c64a875d1fc6a0a)

Updates `docker/metadata-action` from 4.6.0 to 6.0.0
- [Release notes](https://github.com/docker/metadata-action/releases)
- [Commits](https://github.com/docker/metadata-action/compare/818d4b7b91585d195f67373fd9cb0332e31a7175...030e881283bb7a6894de51c315a6bfe6a94e05cf)

Updates `actions/download-artifact` from 4.1.8 to 8.0.1
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/fa0a91b85d4f404e444e00e005971372dc801d16...3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c)

Updates `actions/stale` from 9.1.0 to 10.2.0
- [Release notes](https://github.com/actions/stale/releases)
- [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/stale/compare/5bef64f19d7facfb25b37b414482c7164d639639...b5d41d4e1d5dceea10e7104786b73624c18a190f)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: 6.0.2
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: aws-actions/configure-aws-credentials
  dependency-version: 6.1.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: aws-actions/amazon-ecr-login
  dependency-version: 2.1.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github-actions
- dependency-name: actions/github-script
  dependency-version: 9.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: github/codeql-action
  dependency-version: 4.35.1
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: codespell-project/actions-codespell
  dependency-version: '2.2'
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: github-actions
- dependency-name: actions/setup-node
  dependency-version: 6.3.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: pilosus/action-pip-license-checker
  dependency-version: 3.1.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: dorny/paths-filter
  dependency-version: 4.0.1
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: pnpm/action-setup
  dependency-version: 5.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: actions/cache
  dependency-version: 5.0.4
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: docker/login-action
  dependency-version: 4.1.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: actions/upload-artifact
  dependency-version: 7.0.1
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: docker/metadata-action
  dependency-version: 6.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: actions/download-artifact
  dependency-version: 8.0.1
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
- dependency-name: actions/stale
  dependency-version: 10.2.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix(ci): correct version comments on pinned GitHub Action hashes

pnpm/action-setup hash corresponds to v5.0.0 (not v3/v2),
astral-sh/setup-uv hash corresponds to v8.0.0 (not v8).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* style: fix typo

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tobias Wochinger <tobias.wochinger@clickhouse.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 09:37:48 +00:00
fe76bd280f feat: add OCI Object Storage Native SDK integration with IAM auth options (#12379)
* OCI Object Storage Native SDK client Integration for StorageService with identity access Management options.
Updated tests accordingly.
Updated docker file with env variables and build options to build from code.
Updated package json file with OCI libraries used for Object Storage.
Added a sample .env file with instructions on how to use workload_identity' | 'instance_principal' | 'resource_principal' | 'oci_profile' | 'session_token.
Added !.env.dev-oci.example to gitignore to commit the file.

* Update StorageService.ts

Fixed Lint errors

* Added the pnpm lock file

* Add uploadFileBuffered per upstream PR requirements; rename env vars to langfuse_ prefix

Implemented uploadFileBuffered to satisfy requirements introduced by an upstream pull request.
Updated environment variable names to use the langfuse_ prefix for consistency/alignment

* Remove prisma-extension-kysely dependency

* Remove prisma-extension-kysely from pnpm-lock.yaml

Removed prisma-extension-kysely dependency and related entries.

---------

Co-authored-by: Steffen Schmitz <steffen@langfuse.com>
2026-04-13 11:27:44 +02:00
eb7ee42b8b feat(experiments): direct-write prompt experiment root events (#13044)
* feat(experiments): direct-write prompt experiment root events

* feat(tracing): centralize internal direct event writes

* push

* chore: move asRecord function to utils and update references in experiment service

* chore: move type coercion functions to utils for better organization and reuse

* chore(tracing): refactor internal tracing to use new events writer interface

* fix(experimentService): fix dataset item version conversion

* fix: remove invalid dependency

* fixup(tracing): ensure ordering key parity with experiment backfill

* fix: do not write to events table for self-hosters

* test: fix

* test: fix

* fix: do not write to events-table for self-hosters

* fix: rebase

* chore: type

* fix: skip remapping of IDs for self-hosters

* fix: test

* chore: push

* chore: move away from de-duplication approach

* chore: push

---------

Co-authored-by: Marlies Mayerhofer <74332854+marliessophie@users.noreply.github.com>
2026-04-13 07:47:04 +00:00
Ben BachemandGitHub d3d16272ed fix(web): Create new TableCellWithCopyButton for ApiKeyList (#13057)
* fix(web): Create new `TableCellWithCopyButton` for `ApiKeyList`

* Fix react re-rendering issue after copying text

* Handle rejections when copying to clipboard

* Simplify useCopyToClipboard tests
2026-04-13 07:43:56 +00:00
Ben BachemandGitHub 42f7361090 fix(web): Prevent toast error when toggling v4 with selected saved view (#13077)
* fix(web): Prevent toast error when toggling v4 with selected saved view

* Prevent table being rendered until flag is initialized

* Add mistakenly removed "as const" to StringParam
2026-04-13 07:43:45 +00:00
marliessophieandGitHub dd083cc867 chore(experiments): rewrite metrics aggregation for total cost and latency to skip trace-level aggregation (#13104)
* chore(experiments): rewrite metrics aggregation for total cost and latency to skip trace-level aggregation

* fix(experiments): handle null values in latency and total cost cells in ExperimentsTable

* fix: typo
2026-04-13 07:22:44 +00:00
9c6e749c97 feat(web): add support for AWS Bedrock API Keys (Bearer Tokens) (#13098)
* feat(web): add support for AWS Bedrock API Keys (Bearer Tokens)

Add Bedrock API key authentication as an alternative to AWS access keys
(SigV4) for Amazon Bedrock LLM connections. Users can now choose between
AWS access keys and Bedrock API keys via a tab-based selector in the UI.

- Add BedrockApiKeySchema and BedrockAccessKeysSchema as a discriminated
  union in shared credential schemas
- Add resolveBedrockAuth() to route between bearer token and SigV4 auth
- Add server-side validation of Bedrock credentials on create and update
- Derive and expose a safe authMethod enum (api-key, access-keys,
  default-credentials) in the tRPC list response without leaking secrets
- Add auth method tab selector to the create/update LLM API key form
- Add Bedrock credential validation to the public API PUT endpoint
- Add comprehensive unit, integration, and e2e tests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* ci: add secret

* fix(web): fix Bedrock DefaultCredentials test for cloud environment

The test assumed updating to BEDROCK_USE_DEFAULT_CREDENTIALS would
succeed, but the test env sets NEXT_PUBLIC_LANGFUSE_CLOUD_REGION="DEV"
which makes the server reject default credentials. Updated the test to
assert the expected rejection on cloud deployments.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(web): add self-hosted happy path test for DefaultCredentials update

The previous fix only asserted cloud rejection. Add back the original
happy-path test that temporarily sets NEXT_PUBLIC_LANGFUSE_CLOUD_REGION
to undefined (simulating self-hosted) so the update-to-DefaultCredentials
path is actually exercised.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(web): add .min(1) to BedrockAccessKeysSchema, guard default creds in public API

- Add .min(1) to accessKeyId and secretAccessKey in BedrockAccessKeysSchema
  to reject empty-string credentials at validation time
- Add cloud guard in PUT /api/public/llm-connections rejecting the
  BEDROCK_USE_DEFAULT_CREDENTIALS sentinel on Langfuse Cloud
- Fix DefaultCredentials tests: use per-test env override with try/finally
  to simulate self-hosted deployments
- Add public API tests for sentinel rejection and invalid credential JSON

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 07:14:44 +00:00
Valery MeleshkinandGitHub ff97a3b413 fix: github oauth should check issuer (#13115) 2026-04-10 21:18:55 +02:00
523 changed files with 27605 additions and 12878 deletions
+1 -1
View File
@@ -124,7 +124,7 @@ Minimum verification matrix:
- `*/dist/*`
- `packages/shared/prisma/generated/*`
- Public API contract changes must update Fern sources in `fern/apis/**` and
regenerated outputs; never hand-edit `generated/**`.
regenerated outputs. Never hand-edit `generated/**`.
- Keep tests independent and parallel-safe.
- For bug fixes, write the failing test first, confirm it fails, then fix the
bug.
@@ -130,8 +130,8 @@ web/src/
│ │ ├── public/ # Public REST APIs
│ │ └── trpc/ # tRPC endpoint
│ └── [routes].tsx # Next.js pages
├── __tests__/ # Jest tests
│ └── async/ # Integration tests
├── __tests__/ # Vitest tests
│ └── server/ # Integration tests
├── instrumentation.ts # OpenTelemetry (FIRST IMPORT)
└── env.mjs # Environment config
```
@@ -359,12 +359,12 @@ Write tests for all new features and bug fixes. See [testing-guide.md](reference
**Test Types:**
| Type | Framework | Location | Purpose |
| ----------- | --------- | --------------------------------------- | ---------------------------- |
| Integration | Jest | `web/src/__tests__/async/` | Full API endpoint testing |
| tRPC | Jest | `web/src/__tests__/async/` | tRPC procedures with auth |
| Service | Jest | `web/src/__tests__/async/repositories/` | Repository/service functions |
| Worker | Vitest | `worker/src/__tests__/` | Queue processors & streams |
| Type | Framework | Location | Purpose |
| ----------- | --------- | ------------------------------------------ | ---------------------------- |
| Integration | Vitest | `web/src/__tests__/server/` | Full API endpoint testing |
| tRPC | Vitest | `web/src/__tests__/server/` | tRPC procedures with auth |
| Service | Vitest | `web/src/__tests__/server/repositories/` | Repository/service functions |
| Worker | Vitest | `worker/src/__tests__/` | Queue processors & streams |
**Quick Examples:**
@@ -570,7 +570,7 @@ Environment variable validation with Zod, package-specific configs (web/env.mjs
### [testing-guide.md](references/testing-guide.md)
Integration tests (Public API with makeZodVerifiedAPICall), tRPC tests (createInnerTRPCContext, appRouter.createCaller), service-level tests (repository/service functions), worker tests (vitest with streams), test isolation principles, running tests (Jest for web, vitest for worker)
Integration tests (Public API with makeZodVerifiedAPICall), tRPC tests (createInnerTRPCContext, appRouter.createCaller), service-level tests (repository/service functions), worker tests (vitest with streams), test isolation principles, running tests (Vitest for web and worker)
**Skill Status**: COMPLETE ✅
**Line Count**: ~540 lines
@@ -810,16 +810,17 @@ class UserService {
import { UserService } from "../services/userService";
import { userRepository } from "../repositories/UserRepository";
import { ConflictError } from "../utils/errors";
import type { Mock } from "vitest";
// Mock repository
jest.mock("../repositories/UserRepository");
vi.mock("../repositories/UserRepository");
describe("UserService", () => {
let userService: UserService;
beforeEach(() => {
userService = new UserService();
jest.clearAllMocks();
vi.clearAllMocks();
});
describe("createUser", () => {
@@ -831,8 +832,8 @@ describe("UserService", () => {
roles: ["user"],
};
(userRepository.emailExists as jest.Mock).mockResolvedValue(false);
(userRepository.create as jest.Mock).mockResolvedValue({
(userRepository.emailExists as Mock).mockResolvedValue(false);
(userRepository.create as Mock).mockResolvedValue({
userID: "123",
...userData,
});
@@ -855,7 +856,7 @@ describe("UserService", () => {
roles: ["user"],
};
(userRepository.emailExists as jest.Mock).mockResolvedValue(true);
(userRepository.emailExists as Mock).mockResolvedValue(true);
// Act & Assert
await expect(userService.createUser(userData)).rejects.toThrow(
@@ -20,9 +20,9 @@ Langfuse uses multiple testing strategies for different layers:
| Test Type | Framework | Location | Purpose |
|-----------|-----------|----------|---------|
| Integration | Jest | `web/src/__tests__/async/` | Full API endpoint testing |
| tRPC | Jest | `web/src/__tests__/async/` | tRPC procedure testing with auth |
| Service | Jest | `web/src/__tests__/async/repositories/` | Repository/service function testing |
| Integration | Vitest | `web/src/__tests__/server/` | Full API endpoint testing |
| tRPC | Vitest | `web/src/__tests__/server/` | tRPC procedure testing with auth |
| Service | Vitest | `web/src/__tests__/server/repositories/` | Repository/service function testing |
| Worker | Vitest | `worker/src/__tests__/` | Queue processors and streams |
---
@@ -31,7 +31,7 @@ Langfuse uses multiple testing strategies for different layers:
Test full REST API endpoints end-to-end using HTTP requests.
**File location:** `web/src/__tests__/async/datasets-api.servertest.ts`
**File location:** `web/src/__tests__/server/datasets-api.servertest.ts`
```typescript
import { makeZodVerifiedAPICall } from "../helpers";
@@ -73,7 +73,7 @@ describe("Dataset API", () => {
Test individual repository/service functions with isolated data.
**File location:** `web/src/__tests__/async/repositories/event-repository.servertest.ts`
**File location:** `web/src/__tests__/server/repositories/event-repository.servertest.ts`
```typescript
import {
@@ -186,7 +186,7 @@ describe("Event Repository Tests", () => {
Test tRPC procedures with caller pattern and auth context.
**File location:** `web/src/__tests__/async/automations-trpc.servertest.ts`
**File location:** `web/src/__tests__/server/automations-trpc.servertest.ts`
```typescript
import { appRouter } from "@/src/server/api/root";
@@ -505,23 +505,20 @@ const projectId = "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a";
## Running Tests
### Web Tests (Jest)
### Web Tests (Vitest)
```bash
# Run all tests
pnpm test
# Run all server tests
pnpm --filter web run test
# Run sync tests
pnpm test-sync
# Run async tests
pnpm test -- --testPathPattern="async"
# Run all client tests
pnpm --filter web run test-client
# Run specific test file
pnpm test -- --testPathPattern="datasets-api"
pnpm --filter web run test -- datasets-api
# Run specific test
pnpm test -- --testPathPattern="datasets-api" --testNamePattern="should create dataset"
# Run watch mode
pnpm --filter web run test:watch
```
### Worker Tests (Vitest)
@@ -537,16 +534,6 @@ pnpm run test --filter=worker -- batchExport
pnpm run test --filter=worker -- batchExport -t "should export observations"
```
### Coverage
```bash
# Web coverage
pnpm test -- --coverage
# Worker coverage
pnpm run test --filter=worker -- --coverage
```
---
**Related Files:**
@@ -28,6 +28,9 @@ Use this skill for interactive dependency bumps in Langfuse.
- If the current parent range does not cover the requested transitive version,
upgrade that parent dependency instead of adding the target package directly
unless the user explicitly wants that.
- Never manually edit `pnpm-lock.yaml`; regenerate lockfile changes with
`pnpm` commands only. If a lockfile-only refresh causes unrelated churn,
adjust the pnpm command and rerun instead of patching the lockfile by hand.
- If a compatible transitive package still stays pinned after the normal
refresh path, you may suggest `pnpm dedupe` to the user as an optional manual
follow-up, but do not run it automatically and do not require it.
@@ -94,13 +94,13 @@ cd packages/utils && bun add lodash
```bash
# pnpm
pnpm add jest --save-dev --filter=web --filter=@repo/ui
pnpm add vitest --save-dev --filter=web --filter=@repo/ui
# npm
npm install jest --save-dev --workspace=web --workspace=@repo/ui
npm install vitest --save-dev --workspace=web --workspace=@repo/ui
# yarn (v2+)
yarn workspaces foreach -R --from '{web,@repo/ui}' add jest --dev
yarn workspaces foreach -R --from '{web,@repo/ui}' add vitest --dev
```
### Internal Packages
+196
View File
@@ -0,0 +1,196 @@
#####################################################################
# .env (template) — OCI Object Storage / S3-compatible configuration
#
# IMPORTANT SECURITY NOTES (Oracle best practice)
# - Prefer OCI-native auth (Instance Principal / Workload Identity / Resource Principal)
# over static keys.
# - If you must use static keys, store them in a secure secret manager
# (e.g., Kubernetes Secret / OCI Vault) and inject at runtime.
# - Rotate/revoke any credentials that were previously shared or committed.
#####################################################################
#####################################################################
# 1) Storage/Auth category (CHOOSE ONE)
#
# The app can read/write/download to/from an OCI object store for:
# - Batch exports (exports/)
# - Media uploads (media/)
# - Event uploads (events/)
#
# Pick exactly ONE auth mechanism for OCI-native object storage by setting:
# LANGFUSE_USE_OCI_NATIVE_OBJECT_STORAGE=true
# LANGFUSE_OCI_AUTH_TYPE=<one of the values below>
#
# Supported values:
# workload_identity | instance_principal | resource_principal | oci_profile | session_token
#####################################################################
#####################################################################
# Category A — OCI Object Storage with INSTANCE PRINCIPAL (recommended on OCI Compute)
# Use when:
# - Running on OCI Compute with IAM set up (dynamic group + policies)
#
# Set:
# LANGFUSE_USE_OCI_NATIVE_OBJECT_STORAGE=true
# LANGFUSE_OCI_AUTH_TYPE=instance_principal
#
# NOTE: Do NOT set *_ACCESS_KEY_ID / *_SECRET_ACCESS_KEY in this category.
#####################################################################
#####################################################################
# Category B — OCI Object Storage with WORKLOAD IDENTITY (common on OKE)
# Use when:
# - Running on OKE with OCI Workload Identity configured
#
# Set:
# LANGFUSE_USE_OCI_NATIVE_OBJECT_STORAGE=true
# LANGFUSE_OCI_AUTH_TYPE=workload_identity
#
# Optional (only if your environment requires additional CA trust):
# NODE_EXTRA_CA_CERTS=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
#
# NOTE: Do NOT set *_ACCESS_KEY_ID / *_SECRET_ACCESS_KEY in this category.
#####################################################################
#####################################################################
# Category C — OCI Object Storage with RESOURCE PRINCIPAL (common for OCI services)
# Use when:
# - Running inside an OCI service/runtime that injects Resource Principal env vars
# (e.g., certain managed services / automation contexts)
#
# Set:
# LANGFUSE_USE_OCI_NATIVE_OBJECT_STORAGE=true
# LANGFUSE_OCI_AUTH_TYPE=resource_principal
#
# NOTE: Do NOT set *_ACCESS_KEY_ID / *_SECRET_ACCESS_KEY in this category.
#####################################################################
#####################################################################
# Category D — OCI Object Storage with OCI CONFIG PROFILE (developer local)
# Use when:
# - You have an OCI config file locally or mounted in the runtime
# - You want to use a named profile
#
# Set:
# LANGFUSE_USE_OCI_NATIVE_OBJECT_STORAGE=true
# LANGFUSE_OCI_AUTH_TYPE=oci_profile
# OCI_CONFIG_FILE=/path/to/oci/config
# OCI_CONFIG_PROFILE=DEFAULT
#
# NOTE: Avoid adding config files into images; mount/inject securely.
#####################################################################
#####################################################################
# Category E — OCI Object Storage with SESSION TOKEN (short-lived user auth)
# Use when:
# - You use OCI CLI session authentication (short-lived token flow)
# - USE oci session authenticate
# - Appropriate for interactive/dev use; less common for long-running services
#
# Set:
# LANGFUSE_USE_OCI_NATIVE_OBJECT_STORAGE=true
# LANGFUSE_OCI_AUTH_TYPE=session_token
# OCI_CONFIG_FILE=/path/to/oci/config
# OCI_CONFIG_PROFILE=DEFAULT
#####################################################################
#####################################################################
# Other possible setup — Non-OCI provider (AWS S3 / GCP / Azure / MinIO / etc.)
# Use when:
# - Your object storage is NOT OCI Object Storage
#
# Set:
# LANGFUSE_USE_OCI_NATIVE_OBJECT_STORAGE=false
#
# Then configure endpoints/regions/credentials for your provider.
#####################################################################
#####################################################################
# 2) Feature: S3 Batch Export
#
# Required (when enabled):
# - *_BUCKET, *_REGION, *_ENDPOINT, *_PREFIX
# Optional:
# - *_EXTERNAL_ENDPOINT
# - *_FORCE_PATH_STYLE=true (needed for many S3-compatible providers like MinIO)
#
# Credentials:
# - Set *_ACCESS_KEY_ID/_SECRET_ACCESS_KEY ONLY for static-key auth
# (non-OCI S3-compatible providers)
#####################################################################
LANGFUSE_S3_BATCH_EXPORT_ENABLED=true
LANGFUSE_S3_BATCH_EXPORT_BUCKET=langfuse-bucket
LANGFUSE_S3_BATCH_EXPORT_PREFIX=exports/
# OCI example region/endpoint:
LANGFUSE_S3_BATCH_EXPORT_REGION=us-chicago-1
LANGFUSE_S3_BATCH_EXPORT_ENDPOINT=https://objectstorage.us-chicago-1.oraclecloud.com
LANGFUSE_S3_BATCH_EXPORT_EXTERNAL_ENDPOINT=https://objectstorage.us-chicago-1.oraclecloud.com
# MinIO / S3-compat setting (safe to keep true for many S3-compatible endpoints)
LANGFUSE_S3_BATCH_EXPORT_FORCE_PATH_STYLE=true
# Static-key auth (non-OCI). Leave blank/commented for OCI-native auth types above.
LANGFUSE_S3_BATCH_EXPORT_ACCESS_KEY_ID=__REPLACE_ME__
LANGFUSE_S3_BATCH_EXPORT_SECRET_ACCESS_KEY=__REPLACE_ME__
#####################################################################
# 3) Feature: S3 Media Upload
#####################################################################
LANGFUSE_S3_MEDIA_UPLOAD_BUCKET=langfuse-bucket
LANGFUSE_S3_MEDIA_UPLOAD_PREFIX=media/
LANGFUSE_S3_MEDIA_UPLOAD_REGION=us-chicago-1
LANGFUSE_S3_MEDIA_UPLOAD_ENDPOINT=https://objectstorage.us-chicago-1.oraclecloud.com
LANGFUSE_S3_MEDIA_UPLOAD_FORCE_PATH_STYLE=true
# Static-key auth (non-OCI). Leave blank/commented for OCI-native auth types above.
LANGFUSE_S3_MEDIA_UPLOAD_ACCESS_KEY_ID=__REPLACE_ME__
LANGFUSE_S3_MEDIA_UPLOAD_SECRET_ACCESS_KEY=__REPLACE_ME__
#####################################################################
# 4) Feature: S3 Event Upload (optional)
#####################################################################
LANGFUSE_S3_EVENT_UPLOAD_BUCKET=langfuse-bucket
LANGFUSE_S3_EVENT_UPLOAD_PREFIX=events/
LANGFUSE_S3_EVENT_UPLOAD_REGION=us-chicago-1
LANGFUSE_S3_EVENT_UPLOAD_ENDPOINT=https://objectstorage.us-chicago-1.oraclecloud.com
LANGFUSE_S3_EVENT_UPLOAD_FORCE_PATH_STYLE=true
# Static-key auth (non-OCI). Leave blank/commented for OCI-native auth types above.
LANGFUSE_S3_EVENT_UPLOAD_ACCESS_KEY_ID=__REPLACE_ME__
LANGFUSE_S3_EVENT_UPLOAD_SECRET_ACCESS_KEY=__REPLACE_ME__
#####################################################################
# 5) OCI native auth configuration (used by oci_profile / session_token)
#####################################################################
# Only required when LANGFUSE_OCI_AUTH_TYPE is: oci_profile OR session_token
OCI_CONFIG_FILE=__REPLACE_ME__/config
OCI_CONFIG_PROFILE=DEFAULT
#####################################################################
# 6) Troubleshooting notes (comments only)
#
# - If you see TLS errors to the endpoint in Kubernetes/OKE, set NODE_EXTRA_CA_CERTS to the
# correct CA bundle path for your environment.
# - If using MinIO or certain S3-compatible providers and you get bucket addressing errors,
# set *_FORCE_PATH_STYLE=true.
# - If downloads work inside the cluster but not externally, configure
# LANGFUSE_S3_BATCH_EXPORT_EXTERNAL_ENDPOINT to a publicly reachable endpoint/DNS.
#####################################################################
+1
View File
@@ -153,6 +153,7 @@ LANGFUSE_AI_FEATURES_PROJECT_ID=7a88fb47-b4e2-43b8-a06c-a5ce950dc53a
# Langfuse AI Bedrock credentials
AWS_ACCESS_KEY_ID="A123456789"
AWS_SECRET_ACCESS_KEY="SAK123456789"
LANGFUSE_LLM_CONNECTION_BEDROCK_API_KEY="1234567890abcdef"
LANGFUSE_AWS_BEDROCK_REGION="eu-west-1"
LANGFUSE_AWS_BEDROCK_MODEL="eu.anthropic.claude-3-haiku-20240307-v1:0"
+9
View File
@@ -69,6 +69,7 @@ OTEL_SERVICE_NAME="langfuse"
# AUTH_GOOGLE_ALLOWED_DOMAINS=langfuse.com,google.com # optional allowlist of workspace domains that can sign in via Google
# AUTH_GOOGLE_CLIENT_AUTH_METHOD=
# AUTH_GOOGLE_CHECKS=
# AUTH_GOOGLE_ID_TOKEN_SIGNED_RESPONSE_ALG=
# AUTH_GITHUB_CLIENT_ID=
# AUTH_GITHUB_CLIENT_SECRET=
# AUTH_GITHUB_ALLOW_ACCOUNT_LINKING=false
@@ -86,6 +87,7 @@ OTEL_SERVICE_NAME="langfuse"
# AUTH_GITLAB_ISSUER=
# AUTH_GITLAB_CLIENT_AUTH_METHOD=
# AUTH_GITLAB_CHECKS=
# AUTH_GITLAB_ID_TOKEN_SIGNED_RESPONSE_ALG=
# AUTH_GITLAB_URL=
# AUTH_AZURE_AD_CLIENT_ID=
# AUTH_AZURE_AD_CLIENT_SECRET=
@@ -93,30 +95,35 @@ OTEL_SERVICE_NAME="langfuse"
# AUTH_AZURE_AD_ALLOW_ACCOUNT_LINKING=false
# AUTH_AZURE_AD_CLIENT_AUTH_METHOD=
# AUTH_AZURE_AD_CHECKS=
# AUTH_AZURE_AD_ID_TOKEN_SIGNED_RESPONSE_ALG=
# AUTH_OKTA_CLIENT_ID=
# AUTH_OKTA_CLIENT_SECRET=
# AUTH_OKTA_ISSUER=
# AUTH_OKTA_ALLOW_ACCOUNT_LINKING=false
# AUTH_OKTA_CLIENT_AUTH_METHOD=
# AUTH_OKTA_CHECKS=
# AUTH_OKTA_ID_TOKEN_SIGNED_RESPONSE_ALG=
# AUTH_AUTH0_CLIENT_ID=
# AUTH_AUTH0_CLIENT_SECRET=
# AUTH_AUTH0_ISSUER=
# AUTH_AUTH0_ALLOW_ACCOUNT_LINKING=false
# AUTH_AUTH0_CLIENT_AUTH_METHOD=
# AUTH_AUTH0_CHECKS=
# AUTH_AUTH0_ID_TOKEN_SIGNED_RESPONSE_ALG=
# AUTH_COGNITO_CLIENT_ID=
# AUTH_COGNITO_CLIENT_SECRET=
# AUTH_COGNITO_ISSUER=
# AUTH_COGNITO_ALLOW_ACCOUNT_LINKING=false
# AUTH_COGNITO_CLIENT_AUTH_METHOD=
# AUTH_COGNITO_CHECKS=
# AUTH_COGNITO_ID_TOKEN_SIGNED_RESPONSE_ALG=
# AUTH_KEYCLOAK_CLIENT_ID=
# AUTH_KEYCLOAK_CLIENT_SECRET=
# AUTH_KEYCLOAK_ISSUER=
# AUTH_KEYCLOAK_ALLOW_ACCOUNT_LINKING=false
# AUTH_KEYCLOAK_CLIENT_AUTH_METHOD=
# AUTH_KEYCLOAK_CHECKS=
# AUTH_KEYCLOAK_ID_TOKEN_SIGNED_RESPONSE_ALG=
# AUTH_KEYCLOAK_NAME=
# AUTH_WORKOS_CLIENT_ID=
# AUTH_WORKOS_CLIENT_SECRET=
@@ -133,12 +140,14 @@ OTEL_SERVICE_NAME="langfuse"
# AUTH_CUSTOM_ID_TOKEN=false # optional, default is true
# AUTH_CUSTOM_CLIENT_AUTH_METHOD=
# AUTH_CUSTOM_CHECKS=
# AUTH_CUSTOM_ID_TOKEN_SIGNED_RESPONSE_ALG=
# AUTH_JUMPCLOUD_CLIENT_ID=
# AUTH_JUMPCLOUD_CLIENT_SECRET=
# AUTH_JUMPCLOUD_ISSUER=
# AUTH_JUMPCLOUD_ALLOW_ACCOUNT_LINKING=
# AUTH_JUMPCLOUD_CLIENT_AUTH_METHOD=
# AUTH_JUMPCLOUD_CHECKS=
# AUTH_JUMPCLOUD_ID_TOKEN_SIGNED_RESPONSE_ALG=
# AUTH_JUMPCLOUD_SCOPE=
# Transactional email, optional
+2 -2
View File
@@ -15,10 +15,10 @@ Fixes # (issue)
<!-- Please delete bullets that are not relevant. -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Chore (refactoring code, technical debt, workflow improvements)
- [ ] Chore (tooling, dependencies, CI, workflows, repo upkeep, or other maintenance work)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Refactor (does not change functionality, e.g. code style improvements, linting)
- [ ] Refactor (restructures existing code without changing behavior, e.g. simplify logic, split modules, reduce duplication)
- [ ] This change requires a documentation update
## Mandatory Tasks
+3 -1
View File
@@ -12,7 +12,7 @@ updates:
schedule:
interval: "daily"
cooldown:
default-days: 5
default-days: 7
versioning-strategy: "increase"
commit-message:
prefix: chore
@@ -54,6 +54,8 @@ updates:
directory: "/"
schedule:
interval: "weekly"
cooldown:
default-days: 8
commit-message:
prefix: ci
include: scope
+47 -20
View File
@@ -10,10 +10,21 @@ on:
type: string
description: Name of the service to be deployed, e.g. web-ingestion, web, or worker.
required: true
# Environment secrets don't auto-resolve in reusable workflows.
# See: https://github.com/actions/runner/issues/3206
secrets:
AWS_ACCESS_KEY_ID:
required: true
AWS_SECRET_ACCESS_KEY:
required: true
SENTRY_AUTH_TOKEN:
required: false
jobs:
ecs-deploy:
runs-on: blacksmith-4vcpu-ubuntu-2404
environment: ${{ inputs.environment }}
permissions:
contents: read
steps:
- name: Get app name
uses: winterjung/split@a211a1c46e35fcdc4097d59dd6282d4a9859651b # v2
@@ -22,52 +33,68 @@ jobs:
msg: ${{ inputs.service }}
separator: "-"
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Authenticate with AWS
# GitHub/AWS recommend to use OIDC here: https://github.com/aws-actions/configure-aws-credentials?tab=readme-ov-file#oidc
# Probably more painful to configure, but would remove all long-lived credentials.
uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a # v4
uses: aws-actions/configure-aws-credentials@ec61189d14ec14c8efccab744f656cffd0e33f37 # v6.1.0
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ vars.AWS_REGION }}
- name: Login to AWS ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@183a1442edf41672e66566b7fc560e297a290896 # v2
uses: aws-actions/amazon-ecr-login@f2e9fc6c2b355c1890b65e6f6f0e2ac3e6e22f78 # v2.1.2
- name: Build, tag, and push Docker image
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ steps.split.outputs._0 }}
IMAGE_TAG: ${{ github.sha }}
STEPS_SPLIT_OUTPUTS__0: ${{ steps.split.outputs._0 }}
VARS_NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: ${{ vars.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION }}
VARS_NEXT_LANGFUSE_TRACING_SAMPLE_RATE: ${{ vars.NEXT_LANGFUSE_TRACING_SAMPLE_RATE }}
VARS_NEXT_PUBLIC_SENTRY_ENVIRONMENT: ${{ vars.NEXT_PUBLIC_SENTRY_ENVIRONMENT }}
VARS_NEXT_PUBLIC_DEMO_ORG_ID: ${{ vars.NEXT_PUBLIC_DEMO_ORG_ID }}
VARS_NEXT_PUBLIC_DEMO_PROJECT_ID: ${{ vars.NEXT_PUBLIC_DEMO_PROJECT_ID }}
VARS_NEXT_PUBLIC_SENTRY_DSN: ${{ vars.NEXT_PUBLIC_SENTRY_DSN }}
VARS_NEXT_PUBLIC_POSTHOG_KEY: ${{ vars.NEXT_PUBLIC_POSTHOG_KEY }}
VARS_NEXT_PUBLIC_POSTHOG_HOST: ${{ vars.NEXT_PUBLIC_POSTHOG_HOST }}
VARS_NEXT_PUBLIC_PLAIN_APP_ID: ${{ vars.NEXT_PUBLIC_PLAIN_APP_ID }}
VARS_SENTRY_ORG: ${{ vars.SENTRY_ORG }}
VARS_SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }}
VARS_NEXT_PUBLIC_LANGFUSE_TRACING_SAMPLE_RATE: ${{ vars.NEXT_PUBLIC_LANGFUSE_TRACING_SAMPLE_RATE }}
SECRETS_SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
run: |
docker build \
-t $REGISTRY/$REPOSITORY:$IMAGE_TAG \
-f ./${{ steps.split.outputs._0 }}/Dockerfile \
--build-arg NEXT_PUBLIC_LANGFUSE_CLOUD_REGION=${{ vars.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION }} \
--build-arg NEXT_LANGFUSE_TRACING_SAMPLE_RATE=${{ vars.NEXT_LANGFUSE_TRACING_SAMPLE_RATE }} \
--build-arg NEXT_PUBLIC_SENTRY_ENVIRONMENT=${{ vars.NEXT_PUBLIC_SENTRY_ENVIRONMENT }} \
--build-arg NEXT_PUBLIC_DEMO_ORG_ID=${{ vars.NEXT_PUBLIC_DEMO_ORG_ID }} \
--build-arg NEXT_PUBLIC_DEMO_PROJECT_ID=${{ vars.NEXT_PUBLIC_DEMO_PROJECT_ID }} \
--build-arg NEXT_PUBLIC_SENTRY_DSN=${{ vars.NEXT_PUBLIC_SENTRY_DSN }} \
--build-arg NEXT_PUBLIC_BUILD_ID=${{ github.sha }} \
--build-arg NEXT_PUBLIC_POSTHOG_KEY=${{ vars.NEXT_PUBLIC_POSTHOG_KEY }} \
--build-arg NEXT_PUBLIC_POSTHOG_HOST=${{ vars.NEXT_PUBLIC_POSTHOG_HOST }} \
--build-arg NEXT_PUBLIC_PLAIN_APP_ID=${{ vars.NEXT_PUBLIC_PLAIN_APP_ID }} \
--build-arg SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }} \
--build-arg SENTRY_ORG=${{ vars.SENTRY_ORG }} \
--build-arg SENTRY_PROJECT=${{ vars.SENTRY_PROJECT }} \
--build-arg NEXT_PUBLIC_LANGFUSE_TRACING_SAMPLE_RATE=${{ vars.NEXT_PUBLIC_LANGFUSE_TRACING_SAMPLE_RATE }} \
-f ./${STEPS_SPLIT_OUTPUTS__0}/Dockerfile \
--build-arg NEXT_PUBLIC_LANGFUSE_CLOUD_REGION=${VARS_NEXT_PUBLIC_LANGFUSE_CLOUD_REGION} \
--build-arg NEXT_LANGFUSE_TRACING_SAMPLE_RATE=${VARS_NEXT_LANGFUSE_TRACING_SAMPLE_RATE} \
--build-arg NEXT_PUBLIC_SENTRY_ENVIRONMENT=${VARS_NEXT_PUBLIC_SENTRY_ENVIRONMENT} \
--build-arg NEXT_PUBLIC_DEMO_ORG_ID=${VARS_NEXT_PUBLIC_DEMO_ORG_ID} \
--build-arg NEXT_PUBLIC_DEMO_PROJECT_ID=${VARS_NEXT_PUBLIC_DEMO_PROJECT_ID} \
--build-arg NEXT_PUBLIC_SENTRY_DSN=${VARS_NEXT_PUBLIC_SENTRY_DSN} \
--build-arg NEXT_PUBLIC_BUILD_ID=${IMAGE_TAG} \
--build-arg NEXT_PUBLIC_POSTHOG_KEY=${VARS_NEXT_PUBLIC_POSTHOG_KEY} \
--build-arg NEXT_PUBLIC_POSTHOG_HOST=${VARS_NEXT_PUBLIC_POSTHOG_HOST} \
--build-arg NEXT_PUBLIC_PLAIN_APP_ID=${VARS_NEXT_PUBLIC_PLAIN_APP_ID} \
--build-arg SENTRY_AUTH_TOKEN=${SECRETS_SENTRY_AUTH_TOKEN} \
--build-arg SENTRY_ORG=${VARS_SENTRY_ORG} \
--build-arg SENTRY_PROJECT=${VARS_SENTRY_PROJECT} \
--build-arg NEXT_PUBLIC_LANGFUSE_TRACING_SAMPLE_RATE=${VARS_NEXT_PUBLIC_LANGFUSE_TRACING_SAMPLE_RATE} \
.
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG
- name: Render AWS ECS Task Definition
id: render-task-definition
uses: aws-actions/amazon-ecs-render-task-definition@77954e213ba1f9f9cb016b86a1d4f6fcdea0d57e # v1
uses: aws-actions/amazon-ecs-render-task-definition@77954e213ba1f9f9cb016b86a1d4f6fcdea0d57e # v1.8.4
with:
container-name: ${{ inputs.service }}
image: ${{ steps.login-ecr.outputs.registry }}/${{ steps.split.outputs._0 }}:${{ github.sha }}
task-definition-family: ${{ inputs.environment }}-${{ inputs.service }}
- name: Update AWS ECS Service
uses: aws-actions/amazon-ecs-deploy-task-definition@fc8fc60f3a60ffd500fcb13b209c59d221ac8c8c # v2
uses: aws-actions/amazon-ecs-deploy-task-definition@fc8fc60f3a60ffd500fcb13b209c59d221ac8c8c # v2.6.1
with:
task-definition: ${{ steps.render-task-definition.outputs.task-definition }}
service: ${{ inputs.environment }}-${{ inputs.service }}
+2
View File
@@ -9,6 +9,8 @@ on:
issue_comment:
types: [created]
permissions: {}
jobs:
retrigger_cla:
# Only run on PR comments (not issue comments) with the /check-cla command
@@ -1,14 +1,15 @@
name: Claude Review on Maintainer PRs
on:
pull_request_target:
pull_request:
types:
- opened
- ready_for_review
jobs:
comment:
if: github.event.pull_request.draft == false
# Only run on PRs that are not drafts and are from the same repository (i.e., not from forks)
if: github.event.pull_request.draft == false && github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
permissions:
issues: write
@@ -16,7 +17,7 @@ jobs:
steps:
- name: Check author permission and existing review request
id: check
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const owner = context.repo.owner;
@@ -57,7 +58,7 @@ jobs:
- name: Add Claude review comment
if: steps.check.outputs.should_comment == 'true'
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
await github.rest.issues.createComment({
+5 -3
View File
@@ -55,11 +55,13 @@ jobs:
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
steps:
- name: Checkout repository
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@5c8a8a642e79153f5d047b10ec1cba1d1cc65699 # v3
uses: github/codeql-action/init@c10b8064de6f491fea524254123dbe5e09572f13 # v4.35.1
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
@@ -87,6 +89,6 @@ jobs:
exit 1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@5c8a8a642e79153f5d047b10ec1cba1d1cc65699 # v3
uses: github/codeql-action/analyze@c10b8064de6f491fea524254123dbe5e09572f13 # v4.35.1
with:
category: "/language:${{matrix.language}}"
+4 -2
View File
@@ -22,6 +22,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Codespell
uses: codespell-project/actions-codespell@406322ec52dd7b488e48c1c4b82e2a8b3a1bf630 # v2
uses: codespell-project/actions-codespell@8f01853be192eb0f849a5c7d721450e7a467c579 # v2.2
@@ -6,6 +6,8 @@ on:
- main
workflow_dispatch:
permissions: {}
jobs:
rebase-dependabot:
runs-on: ubuntu-latest
+14 -5
View File
@@ -27,6 +27,8 @@ on:
- prod-jp
required: true
permissions: {}
concurrency:
# Support concurrent `push` and `workflow_dispatch`` actions
group: deploy-${{ github.event_name }}-${{ github.ref }}
@@ -41,7 +43,7 @@ jobs:
steps:
- name: Get affected services
id: affected-services
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
if (context.eventName === "workflow_dispatch") {
@@ -56,7 +58,7 @@ jobs:
return "[]"
result-encoding: string
- name: Print services to build
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
services: ${{ steps.affected-services.outputs.result }}
with:
@@ -71,7 +73,7 @@ jobs:
steps:
- name: Get affected environments
id: affected-environments
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
if (context.eventName === "workflow_dispatch") {
@@ -88,7 +90,7 @@ jobs:
return "[]"
result-encoding: string
- name: Print environments to build
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
environments: ${{ steps.affected-environments.outputs.result }}
with:
@@ -99,7 +101,14 @@ jobs:
ecs-deploy:
uses: ./.github/workflows/_deploy_ecs_service.yml
needs: [affected-services, affected-environments]
secrets: inherit
permissions:
contents: read
# Environment secrets must be passed explicitly to reusable workflows.
# See: https://github.com/actions/runner/issues/3206
secrets:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
strategy:
matrix:
service: ${{ fromJson(needs.affected-services.outputs.services) }}
+12 -4
View File
@@ -9,15 +9,21 @@ on:
branches:
- "main"
permissions:
contents: read
checks: write # Needed to create a check run for the license compliance check results
jobs:
license_check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Setup node
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: 18
@@ -32,7 +38,7 @@ jobs:
- name: Check license-checker CSV file without headers
id: license_check_report
uses: pilosus/action-pip-license-checker@cc7a461bfa27b44ad187b8578c881ef5138c13fd # v2
uses: pilosus/action-pip-license-checker@e909b0226ff49d3235c99c4585bc617f49fff16a # v3.1.0
with:
external: "npm-license-checker.csv"
external-format: "csv"
@@ -44,6 +50,8 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Echo error
if: failure()
run: echo "::error::${{ steps.license_check_report.outputs.report }}"
run: echo "::error::${STEPS_LICENSE_CHECK_REPORT_OUTPUTS_REPORT}"
env:
STEPS_LICENSE_CHECK_REPORT_OUTPUTS_REPORT: ${{ steps.license_check_report.outputs.report }}
- name: Delete license-checker CSV file
run: rm npm-license-checker.csv
+222 -82
View File
@@ -12,6 +12,9 @@ on:
branches:
- "**"
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
@@ -24,19 +27,39 @@ jobs:
llm_connections_changed: ${{ steps.filter.outputs.llm_connections }}
timeout-minutes: 15
permissions:
contents: read
pull-requests: read
steps:
# Replaces fkirc/skip-duplicate-actions — skips runs whose git tree
# was already tested in a prior successful run of this workflow.
- id: skip_check
uses: fkirc/skip-duplicate-actions@f75f66ce1886f00957d99748a42c724f4330bdcf # v5
with:
do_not_skip: '["workflow_dispatch"]'
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
env:
GH_TOKEN: ${{ github.token }}
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "should_skip=false" >> "$GITHUB_OUTPUT"
exit 0
fi
CURRENT_TREE=$(gh api "repos/${{ github.repository }}/git/commits/${{ github.sha }}" --jq '.tree.sha')
MATCH=$(gh api "repos/${{ github.repository }}/actions/workflows/pipeline.yml/runs?status=success&per_page=20" \
--jq "[.workflow_runs[] | select(.id != ${{ github.run_id }} and .head_commit.tree_id == \"$CURRENT_TREE\")] | first | .head_sha // empty")
if [[ -n "$MATCH" ]]; then
echo "::notice::Tree $CURRENT_TREE already tested in a prior successful run (commit $MATCH) — skipping"
echo "should_skip=true" >> "$GITHUB_OUTPUT"
else
echo "should_skip=false" >> "$GITHUB_OUTPUT"
fi
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
# Recommended for paths-filter action
# may save additional git fetch roundtrip if
# merge-base is found within latest N commits
fetch-depth: 20
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3
persist-credentials: false
- uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
id: filter
with:
filters: |
@@ -50,17 +73,19 @@ jobs:
- pre-job
if: needs.pre-job.outputs.should_skip != 'true'
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d # v3
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0
with:
version: 10.33.0
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 # zizmor: ignore[cache-poisoning] lint job dependency cache only; no released artifacts are built or published from this cached state
with:
node-version: 24
cache: "pnpm"
cache-dependency-path: "pnpm-lock.yaml"
- name: Setup Turbo cache
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4 # zizmor: ignore[cache-poisoning] lint cache only; publish jobs rebuild artifacts and do not restore this cache
with:
path: .turbo
key: ${{ runner.os }}-turbo-lint-${{ github.sha }}
@@ -82,13 +107,14 @@ jobs:
- pre-job
if: needs.pre-job.outputs.should_skip != 'true'
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d # v3
persist-credentials: false
- uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0
with:
version: 10.33.0
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 # zizmor: ignore[cache-poisoning] prettier check dependency cache only; no released artifacts are built or published from this cached state
with:
node-version: 24
cache: "pnpm"
@@ -129,10 +155,12 @@ jobs:
DOCKER_COMPOSE_FILE: docker-compose.build.yml
steps:
- name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Login to Docker Hub
if: github.repository == 'langfuse/langfuse' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME_READ }}
password: ${{ secrets.DOCKERHUB_TOKEN_READ }}
@@ -178,7 +206,7 @@ jobs:
done
- name: Upload docker diagnostics
if: failure()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: test-docker-build-diagnostics-${{ github.run_id }}-${{ github.run_attempt }}
path: /tmp/docker-diagnostics
@@ -197,23 +225,25 @@ jobs:
deploy-mode: ["", "-azure", "-redis-cluster"]
shard: [1, 2, 3]
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Install golang-migrate for Clickhouse migrations
run: |
curl -L https://github.com/golang-migrate/migrate/releases/download/v4.19.1/migrate.linux-amd64.tar.gz | tar xvz
sudo mv migrate /usr/bin/migrate
which migrate
- uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d # v3
- uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0
with:
version: 10.33.0
- name: Login to Docker Hub
if: github.repository == 'langfuse/langfuse' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME_READ }}
password: ${{ secrets.DOCKERHUB_TOKEN_READ }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 # zizmor: ignore[cache-poisoning] test job dependency cache only; no released artifacts are built or published from this cached state
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
@@ -231,15 +261,16 @@ jobs:
echo "LANGFUSE_TRACE_DELETE_CONCURRENCY=100" >> .env
echo "ADMIN_API_KEY=admin-api-key" >> .env
echo "LANGFUSE_EE_LICENSE_KEY=langfuse_ee_test" >> .env
echo "LANGFUSE_SKIP_EVALUATOR_MODEL_CALL_VALIDATION=true" >> .env
- name: Setup Turbo cache
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4 # zizmor: ignore[cache-poisoning] test job cache only; publish jobs rebuild artifacts and do not restore this cache
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- name: Cache Next.js builds
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4 # zizmor: ignore[cache-poisoning] test-only Next.js cache; not consumed by artifact publishing or release jobs
with:
path: |
~/.npm
@@ -291,11 +322,11 @@ jobs:
LANGFUSE_INIT_USER_PASSWORD: "password"
- name: run tests
working-directory: web
run: npx dotenv -e ../.env.test -e ../.env -- npx jest --verbose --runInBand --detectOpenHandles --selectProjects server --shard=${{ matrix.shard }}/3
run: npx dotenv -e ../.env.test -e ../.env -- vitest run --project server --shard=${{ matrix.shard }}/3
- name: run test-client
if: matrix.deploy-mode == '' && matrix.shard == 1
working-directory: web
run: npx dotenv -e ../.env.test -e ../.env -- npx jest --verbose --runInBand --detectOpenHandles --selectProjects client
run: npx dotenv -e ../.env.test -e ../.env -- vitest run --project client
tests-worker:
timeout-minutes: 20
@@ -310,18 +341,20 @@ jobs:
postgres-version: [12, 15]
deploy-mode: ["", "-azure", "-redis-cluster"]
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d # v3
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0
with:
version: 10.33.0
- name: Login to Docker Hub
if: github.repository == 'langfuse/langfuse' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME_READ }}
password: ${{ secrets.DOCKERHUB_TOKEN_READ }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 # zizmor: ignore[cache-poisoning] worker test dependency cache only; no release artifacts are produced from this cache
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
@@ -381,18 +414,20 @@ jobs:
if: startsWith(github.ref, 'refs/tags/') || (needs.pre-job.outputs.should_skip != 'true' && (needs.pre-job.outputs.llm_connections_changed == 'true' || github.event_name == 'workflow_dispatch'))
name: test-worker-llm-connections (node24, pg15)
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d # v3
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0
with:
version: 10.33.0
- name: Login to Docker Hub
if: github.repository == 'langfuse/langfuse' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME_READ }}
password: ${{ secrets.DOCKERHUB_TOKEN_READ }}
- name: Use Node.js 24
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 # zizmor: ignore[cache-poisoning] llm-connection test dependency cache only; privileged secrets are used here, but this cache is not consumed by artifact publishing
with:
node-version: 24
cache: "pnpm"
@@ -442,6 +477,7 @@ jobs:
LANGFUSE_LLM_CONNECTION_BEDROCK_ACCESS_KEY_ID: ${{ secrets.LANGFUSE_LLM_CONNECTION_BEDROCK_ACCESS_KEY_ID }}
LANGFUSE_LLM_CONNECTION_BEDROCK_SECRET_ACCESS_KEY: ${{ secrets.LANGFUSE_LLM_CONNECTION_BEDROCK_SECRET_ACCESS_KEY }}
LANGFUSE_LLM_CONNECTION_BEDROCK_REGION: ${{ secrets.LANGFUSE_LLM_CONNECTION_BEDROCK_REGION }}
LANGFUSE_LLM_CONNECTION_BEDROCK_API_KEY: ${{ secrets.LANGFUSE_LLM_CONNECTION_BEDROCK_API_KEY }}
LANGFUSE_LLM_CONNECTION_VERTEXAI_KEY: ${{ secrets.LANGFUSE_LLM_CONNECTION_VERTEXAI_KEY }}
LANGFUSE_LLM_CONNECTION_GOOGLEAISTUDIO_KEY: ${{ secrets.LANGFUSE_LLM_CONNECTION_GOOGLEAISTUDIO_KEY }}
@@ -451,23 +487,25 @@ jobs:
- pre-job
if: needs.pre-job.outputs.should_skip != 'true'
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d # v3
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0
with:
version: 10.33.0
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 # zizmor: ignore[cache-poisoning] e2e dependency cache only; release images are rebuilt later without restoring this cache
with:
node-version: 24
cache: "pnpm"
cache-dependency-path: "pnpm-lock.yaml"
- name: Login to Docker Hub
if: github.repository == 'langfuse/langfuse' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME_READ }}
password: ${{ secrets.DOCKERHUB_TOKEN_READ }}
- name: Setup Turbo cache
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4 # zizmor: ignore[cache-poisoning] e2e cache only; no published artifact path restores this cache
with:
path: .turbo
key: ${{ runner.os }}-turbo-e2e-${{ github.sha }}
@@ -475,7 +513,7 @@ jobs:
${{ runner.os }}-turbo-e2e-
${{ runner.os }}-turbo-
- name: Cache Next.js builds
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4 # zizmor: ignore[cache-poisoning] e2e-only Next.js cache; not part of any artifact build or publishing flow
with:
path: |
~/.npm
@@ -528,17 +566,19 @@ jobs:
- pre-job
if: needs.pre-job.outputs.should_skip != 'true'
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Login to Docker Hub
if: github.repository == 'langfuse/langfuse' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME_READ }}
password: ${{ secrets.DOCKERHUB_TOKEN_READ }}
- uses: pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d # v3
- uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0
with:
version: 10.33.0
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 # zizmor: ignore[cache-poisoning] server e2e dependency cache only; release/publish steps rebuild separately
with:
node-version: 24
cache: "pnpm"
@@ -589,7 +629,8 @@ jobs:
all-ci-passed:
# This allows us to have a branch protection rule for tests and deploys with matrix
runs-on: blacksmith-4vcpu-ubuntu-2404
needs: [
needs:
[
lint,
prettier-check,
tests-web,
@@ -620,16 +661,58 @@ jobs:
run: exit 1
working-directory: .
- name: Notify Slack
uses: ravsamhq/notify-slack-action@be814b201e233b2dc673608aa46e5447c8ab13f2 # v2
if: always() && github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
if: failure() && github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1
with:
status: ${{ job.status }}
notify_when: "failure"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
{
"text": "❌ CI failed on ${{ github.ref_name }}",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "❌ CI Failed",
"emoji": true
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Branch/Tag:*\n`${{ github.ref_name }}`"
},
{
"type": "mrkdwn",
"text": "*Triggered by:*\n${{ github.actor }}"
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Workflow Logs",
"emoji": true
},
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"style": "danger"
}
]
}
]
}
- name: Output job results
run: |
echo "Job results: ${{ steps.set-success-output.outputs.success }}"
echo "Job results: ${STEPS_SET_SUCCESS_OUTPUT_OUTPUTS_SUCCESS}"
env:
STEPS_SET_SUCCESS_OUTPUT_OUTPUTS_SUCCESS: ${{ steps.set-success-output.outputs.success }}
build-docker-image-release:
needs: all-ci-passed
@@ -671,25 +754,27 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Set NEXT_PUBLIC_BUILD_ID
run: echo "NEXT_PUBLIC_BUILD_ID=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Log in to the GitHub Container registry
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Docker Hub
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Setup Blacksmith Builder
uses: useblacksmith/setup-docker-builder@5241b2e9423e8b1fa37ed6050ecb62d0fb9a4e38 # v1
uses: useblacksmith/setup-docker-builder@5241b2e9423e8b1fa37ed6050ecb62d0fb9a4e38 # v1.6.0
- name: Extract metadata (labels) for Docker
id: meta
uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175 # v4
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0
with:
images: |
ghcr.io/langfuse/${{ matrix.image_name }}
@@ -706,7 +791,7 @@ jobs:
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v3') && !contains(github.ref, '-rc') }}
- name: Build and push image by digest to GitHub Container Registry (${{ matrix.component }}, ${{ matrix.platform_tag }})
id: build-ghcr
uses: useblacksmith/build-push-action@cbd1f60d194a98cb3be5523b15134501eaf0fbf3 # v2
uses: useblacksmith/build-push-action@cbd1f60d194a98cb3be5523b15134501eaf0fbf3 # v2.1.0
with:
context: .
file: ${{ matrix.dockerfile }}
@@ -717,7 +802,7 @@ jobs:
sbom: false
- name: Build and push image by digest to Docker Hub (${{ matrix.component }}, ${{ matrix.platform_tag }})
id: build-dockerhub
uses: useblacksmith/build-push-action@cbd1f60d194a98cb3be5523b15134501eaf0fbf3 # v2
uses: useblacksmith/build-push-action@cbd1f60d194a98cb3be5523b15134501eaf0fbf3 # v2.1.0
with:
context: .
file: ${{ matrix.dockerfile }}
@@ -727,17 +812,21 @@ jobs:
provenance: false
sbom: false
- name: Record pushed digests
env:
DIGEST_GHCR: ${{ steps.build-ghcr.outputs.digest }}
DIGEST_DOCKERHUB: ${{ steps.build-dockerhub.outputs.digest }}
PLATFORM_TAG: ${{ matrix.platform_tag }}
run: |
if [ -z '${{ steps.build-ghcr.outputs.digest }}' ] || [ -z '${{ steps.build-dockerhub.outputs.digest }}' ]; then
if [ -z "$DIGEST_GHCR" ] || [ -z "$DIGEST_DOCKERHUB" ]; then
echo "Missing registry digest output"
exit 1
fi
mkdir -p "$RUNNER_TEMP/digests/ghcr" "$RUNNER_TEMP/digests/dockerhub"
printf '%s\n' '${{ steps.build-ghcr.outputs.digest }}' > "$RUNNER_TEMP/digests/ghcr/${{ matrix.platform_tag }}.txt"
printf '%s\n' '${{ steps.build-dockerhub.outputs.digest }}' > "$RUNNER_TEMP/digests/dockerhub/${{ matrix.platform_tag }}.txt"
printf '%s\n' "$DIGEST_GHCR" > "$RUNNER_TEMP/digests/ghcr/${PLATFORM_TAG}.txt"
printf '%s\n' "$DIGEST_DOCKERHUB" > "$RUNNER_TEMP/digests/dockerhub/${PLATFORM_TAG}.txt"
- name: Upload release digests
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: release-digests-${{ matrix.component }}-${{ matrix.platform_tag }}
path: |
@@ -765,27 +854,27 @@ jobs:
steps:
- name: Log in to the GitHub Container registry
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Docker Hub
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Setup Blacksmith Builder
uses: useblacksmith/setup-docker-builder@5241b2e9423e8b1fa37ed6050ecb62d0fb9a4e38 # v1
uses: useblacksmith/setup-docker-builder@5241b2e9423e8b1fa37ed6050ecb62d0fb9a4e38 # v1.6.0
- name: Download release digests
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
pattern: release-digests-${{ matrix.component }}-*
merge-multiple: true
path: ${{ runner.temp }}/digests
- name: Extract metadata (tags) for GitHub Container Registry
id: meta-ghcr
uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175 # v4
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0
with:
images: ghcr.io/langfuse/${{ matrix.image_name }}
flavor: |
@@ -800,7 +889,7 @@ jobs:
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v3') && !contains(github.ref, '-rc') }}
- name: Extract metadata (tags) for Docker Hub
id: meta-dockerhub
uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175 # v4
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0
with:
images: langfuse/${{ matrix.image_name }}
flavor: |
@@ -814,6 +903,10 @@ jobs:
type=semver,pattern={{major}},enable=${{ !contains(github.ref, '-rc') }}
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v3') && !contains(github.ref, '-rc') }}
- name: Publish multi-platform manifest to GitHub Container Registry
env:
STEPS_META_GHCR_OUTPUTS_TAGS: ${{ steps.meta-ghcr.outputs.tags }}
IMAGE_NAME: ${{ matrix.image_name }}
COMPONENT: ${{ matrix.component }}
run: |
ghcr_tags=()
ghcr_sources=()
@@ -821,23 +914,27 @@ jobs:
while IFS= read -r tag; do
[ -n "$tag" ] || continue
ghcr_tags+=("-t" "$tag")
done <<'EOF'
${{ steps.meta-ghcr.outputs.tags }}
done <<EOF
${STEPS_META_GHCR_OUTPUTS_TAGS}
EOF
shopt -s nullglob
for digest_file in "$RUNNER_TEMP"/digests/ghcr/*.txt; do
digest="$(cat "$digest_file")"
ghcr_sources+=("ghcr.io/langfuse/${{ matrix.image_name }}@$digest")
ghcr_sources+=("ghcr.io/langfuse/${IMAGE_NAME}@$digest")
done
if [ "${#ghcr_sources[@]}" -lt 2 ]; then
echo "Expected amd64 and arm64 GHCR digests for ${{ matrix.component }}"
echo "Expected amd64 and arm64 GHCR digests for $COMPONENT"
exit 1
fi
docker buildx imagetools create "${ghcr_tags[@]}" "${ghcr_sources[@]}"
- name: Publish multi-platform manifest to Docker Hub
env:
STEPS_META_DOCKERHUB_OUTPUTS_TAGS: ${{ steps.meta-dockerhub.outputs.tags }}
IMAGE_NAME: ${{ matrix.image_name }}
COMPONENT: ${{ matrix.component }}
run: |
dockerhub_tags=()
dockerhub_sources=()
@@ -845,29 +942,32 @@ jobs:
while IFS= read -r tag; do
[ -n "$tag" ] || continue
dockerhub_tags+=("-t" "$tag")
done <<'EOF'
${{ steps.meta-dockerhub.outputs.tags }}
done <<EOF
${STEPS_META_DOCKERHUB_OUTPUTS_TAGS}
EOF
shopt -s nullglob
for digest_file in "$RUNNER_TEMP"/digests/dockerhub/*.txt; do
digest="$(cat "$digest_file")"
dockerhub_sources+=("langfuse/${{ matrix.image_name }}@$digest")
dockerhub_sources+=("langfuse/${IMAGE_NAME}@$digest")
done
if [ "${#dockerhub_sources[@]}" -lt 2 ]; then
echo "Expected amd64 and arm64 Docker Hub digests for ${{ matrix.component }}"
echo "Expected amd64 and arm64 Docker Hub digests for $COMPONENT"
exit 1
fi
docker buildx imagetools create "${dockerhub_tags[@]}" "${dockerhub_sources[@]}"
- name: Inspect published manifests
run: |
ghcr_first_tag="$(printf '%s\n' "${{ steps.meta-ghcr.outputs.tags }}" | sed -n '1p')"
dockerhub_first_tag="$(printf '%s\n' "${{ steps.meta-dockerhub.outputs.tags }}" | sed -n '1p')"
ghcr_first_tag="$(printf '%s\n' "${STEPS_META_GHCR_OUTPUTS_TAGS}" | sed -n '1p')"
dockerhub_first_tag="$(printf '%s\n' "${STEPS_META_DOCKERHUB_OUTPUTS_TAGS}" | sed -n '1p')"
docker buildx imagetools inspect "$ghcr_first_tag"
docker buildx imagetools inspect "$dockerhub_first_tag"
env:
STEPS_META_GHCR_OUTPUTS_TAGS: ${{ steps.meta-ghcr.outputs.tags }}
STEPS_META_DOCKERHUB_OUTPUTS_TAGS: ${{ steps.meta-dockerhub.outputs.tags }}
notify-docker-image-release:
needs:
@@ -880,10 +980,50 @@ jobs:
if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
run: exit 1
- name: Notify Slack
uses: ravsamhq/notify-slack-action@be814b201e233b2dc673608aa46e5447c8ab13f2 # v2
if: always()
if: failure()
uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1
with:
status: ${{ job.status }}
notify_when: "failure"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
{
"text": "❌ Docker release failed on ${{ github.ref_name }}",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "❌ Docker Release Failed",
"emoji": true
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Tag:*\n`${{ github.ref_name }}`"
},
{
"type": "mrkdwn",
"text": "*Triggered by:*\n${{ github.actor }}"
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Workflow Logs",
"emoji": true
},
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"style": "danger"
}
]
}
]
}
@@ -12,6 +12,8 @@ concurrency:
group: promote-main-to-production
cancel-in-progress: false
permissions: {}
jobs:
promote:
runs-on: ubuntu-latest
@@ -19,16 +21,19 @@ jobs:
steps:
- name: Validate confirmation
run: |
if [ "${{ github.event.inputs.confirm }}" != "promote" ]; then
if [ "${INPUT_CONFIRM}" != "promote" ]; then
echo "Input 'confirm' must be 'promote'."
exit 1
fi
env:
INPUT_CONFIRM: ${{ github.event.inputs.confirm }}
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: main
fetch-depth: 0
token: ${{ secrets.GH_ACCESS_TOKEN }}
persist-credentials: false
- name: Print commit refs
run: |
@@ -41,4 +46,6 @@ jobs:
fi
- name: Force push main to production
run: git push origin +main:production
run: git push "https://x-access-token:${GH_ACCESS_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" +main:production
env:
GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
+7 -2
View File
@@ -5,15 +5,20 @@ on:
tags:
- "v3.[0-9]+.[0-9]+" # Semantic version tags
permissions: {}
jobs:
release:
runs-on: ubuntu-latest
environment: "protected branches"
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: main # Always checkout main even for tagged releases
fetch-depth: 0
token: ${{ secrets.GH_ACCESS_TOKEN }}
persist-credentials: false
- name: Push to production
run: git push origin +main:production
run: git push "https://x-access-token:${GH_ACCESS_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" +main:production
env:
GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
+10 -4
View File
@@ -12,20 +12,26 @@ concurrency:
group: sdk-api-spec-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
generate-sdk-api-specs:
runs-on: ubuntu-latest
environment: "protected branches"
steps:
- name: Checkout repository
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Install pnpm
uses: pnpm/action-setup@eae0cfeb286e66ffb5155f1a79b90583a127a68b # v2
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0
with:
version: 10.33.0
- name: Setup Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: "24"
cache: "pnpm"
@@ -39,7 +45,7 @@ jobs:
run: npx fern-api generate --api server --force
- name: Install uv
uses: astral-sh/setup-uv@cec208311dfd045dd5311c1add060b2062131d57 # v8
uses: astral-sh/setup-uv@cec208311dfd045dd5311c1add060b2062131d57 # v8.0.0
with:
version: "0.11.2"
+28 -19
View File
@@ -3,46 +3,55 @@ on:
push:
branches: ["production", "main"]
permissions:
contents: read
security-events: write
jobs:
snyk:
runs-on: ubuntu-latest
environment: snyk
steps:
- uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Set up Snyk CLI
uses: snyk/actions/setup@9adf32b1121593767fc3c057af55b55db032dc04 # master
with:
snyk-version: v1.1304.0
- name: Run Snyk to check Docker image for vulnerabilities
# Snyk can be used to break the build when it detects vulnerabilities.
# In this case we want to upload the issues to GitHub Code Scanning
continue-on-error: true
uses: snyk/actions/docker@9adf32b1121593767fc3c057af55b55db032dc04 # master
env:
# In order to use the Snyk Action you will need to have a Snyk API token.
# See https://docs.snyk.io/integrations/ci-cd-integrations/github-actions-integration#getting-your-snyk-token
# or you can sign up for free at https://snyk.io/login
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
image: langfuse/langfuse
args: --sarif-file-output=snyk.sarif
- name: Fix SARIF file
run: |
snyk container test langfuse/langfuse \
--file=web/Dockerfile \
--sarif-file-output=snyk.sarif
- name: Normalize SARIF file
if: always()
run: |
if [ -f snyk.sarif ]; then
# Fix undefined security severity values in SARIF file
sed -i 's/"security-severity": "undefined"/"security-severity": "0"/g' snyk.sarif
# Snyk emits invalid security-severity values. upload-sarif requires a numeric string.
sed -i \
-e 's/"security-severity": "undefined"/"security-severity": "0"/g' \
-e 's/"security-severity": "null"/"security-severity": "0"/g' \
-e 's/"security-severity": null/"security-severity": "0"/g' \
snyk.sarif
echo "SARIF file fixed"
else
echo "No SARIF file found"
fi
- name: Echo SARIF file for debugging
if: always()
run: |
if [ -f snyk.sarif ]; then
echo "=== SARIF File Contents ==="
cat snyk.sarif
echo "=== End of SARIF File ==="
else
echo "No SARIF file found to display"
fi
- name: Upload result to GitHub Code Scanning
uses: github/codeql-action/upload-sarif@c10b8064de6f491fea524254123dbe5e09572f13 # v4
uses: github/codeql-action/upload-sarif@c10b8064de6f491fea524254123dbe5e09572f13 # v4.35.1
if: always()
with:
sarif_file: snyk.sarif
category: snyk-container-web
- name: Echo SARIF file for debugging
if: failure() && hashFiles('snyk.sarif') != ''
run: cat snyk.sarif
+28 -19
View File
@@ -3,46 +3,55 @@ on:
push:
branches: ["production", "main"]
permissions:
contents: read
security-events: write
jobs:
snyk:
runs-on: ubuntu-latest
environment: snyk
steps:
- uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Set up Snyk CLI
uses: snyk/actions/setup@9adf32b1121593767fc3c057af55b55db032dc04 # master
with:
snyk-version: v1.1304.0
- name: Run Snyk to check Docker image for vulnerabilities
# Snyk can be used to break the build when it detects vulnerabilities.
# In this case we want to upload the issues to GitHub Code Scanning
continue-on-error: true
uses: snyk/actions/docker@9adf32b1121593767fc3c057af55b55db032dc04 # master
env:
# In order to use the Snyk Action you will need to have a Snyk API token.
# See https://docs.snyk.io/integrations/ci-cd-integrations/github-actions-integration#getting-your-snyk-token
# or you can sign up for free at https://snyk.io/login
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
image: langfuse/langfuse-worker
args: --sarif-file-output=snyk.sarif
- name: Fix SARIF file
run: |
snyk container test langfuse/langfuse-worker \
--file=worker/Dockerfile \
--sarif-file-output=snyk.sarif
- name: Normalize SARIF file
if: always()
run: |
if [ -f snyk.sarif ]; then
# Fix undefined security severity values in SARIF file
sed -i 's/"security-severity": "undefined"/"security-severity": "0"/g' snyk.sarif
# Snyk emits invalid security-severity values. upload-sarif requires a numeric string.
sed -i \
-e 's/"security-severity": "undefined"/"security-severity": "0"/g' \
-e 's/"security-severity": "null"/"security-severity": "0"/g' \
-e 's/"security-severity": null/"security-severity": "0"/g' \
snyk.sarif
echo "SARIF file fixed"
else
echo "No SARIF file found"
fi
- name: Echo SARIF file for debugging
if: always()
run: |
if [ -f snyk.sarif ]; then
echo "=== SARIF File Contents ==="
cat snyk.sarif
echo "=== End of SARIF File ==="
else
echo "No SARIF file found to display"
fi
- name: Upload result to GitHub Code Scanning
uses: github/codeql-action/upload-sarif@c10b8064de6f491fea524254123dbe5e09572f13 # v4
uses: github/codeql-action/upload-sarif@c10b8064de6f491fea524254123dbe5e09572f13 # v4.35.1
if: always()
with:
sarif_file: snyk.sarif
category: snyk-container-worker
- name: Echo SARIF file for debugging
if: failure() && hashFiles('snyk.sarif') != ''
run: cat snyk.sarif
+1 -1
View File
@@ -10,7 +10,7 @@ jobs:
issues: write
pull-requests: write
steps:
- uses: actions/stale@5bef64f19d7facfb25b37b414482c7164d639639 # v9
- uses: actions/stale@b5d41d4e1d5dceea10e7104786b73624c18a190f # v10.2.0
with:
days-before-issue-stale: 30
days-before-issue-close: 14
+1 -1
View File
@@ -19,7 +19,7 @@ jobs:
pull-requests: read
steps:
- name: Validate PR title follows conventional commits
uses: amannn/action-semantic-pull-request@48f256284bd46cdaab1048c3721360e808335d50 # v6
uses: amannn/action-semantic-pull-request@48f256284bd46cdaab1048c3721360e808335d50 # v6.1.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
+43
View File
@@ -0,0 +1,43 @@
---
name: Check GitHub Actions
on:
workflow_dispatch:
push:
branches:
- "main"
merge_group:
pull_request:
branches:
- "main"
permissions: {}
jobs:
zizmor:
name: Check GitHub Actions security
runs-on: ubuntu-latest
permissions:
security-events: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Run zizmor (fork PR - fail on findings)
# Fork PRs don't get security-events: write on GITHUB_TOKEN, so SARIF
# upload isn't possible. Fail the job on findings instead so contributors
# see the error directly in the PR check.
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
uses: zizmorcore/zizmor-action@b1d7e1fb5de872772f31590499237e7cce841e8e # v0.5.3
- name: Run zizmor (trusted - upload SARIF)
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
uses: zizmorcore/zizmor-action@b1d7e1fb5de872772f31590499237e7cce841e8e # v0.5.3
with:
# Means that the action will only report issues, but not fail the workflow.
# Blocking merges are handled by rulesets:
# https://docs.github.com/en/code-security/concepts/code-scanning/about-code-scanning-alerts#pull-request-check-failures-for-code-scanning-alerts
advanced-security: true
+21
View File
@@ -0,0 +1,21 @@
rules:
secrets-outside-env:
config:
allow:
# Shared read-only CI credentials used to avoid Docker Hub rate limits in test jobs.
- DOCKERHUB_USERNAME_READ
- DOCKERHUB_TOKEN_READ
# Shared integration-test credentials intentionally kept together for the multi-provider LLM connection test job.
- LANGFUSE_LLM_CONNECTION_OPENAI_KEY
- LANGFUSE_LLM_CONNECTION_ANTHROPIC_KEY
- LANGFUSE_LLM_CONNECTION_AZURE_KEY
- LANGFUSE_LLM_CONNECTION_AZURE_BASE_URL
- LANGFUSE_LLM_CONNECTION_AZURE_MODEL
- LANGFUSE_LLM_CONNECTION_BEDROCK_ACCESS_KEY_ID
- LANGFUSE_LLM_CONNECTION_BEDROCK_SECRET_ACCESS_KEY
- LANGFUSE_LLM_CONNECTION_BEDROCK_API_KEY
- LANGFUSE_LLM_CONNECTION_BEDROCK_REGION
- LANGFUSE_LLM_CONNECTION_VERTEXAI_KEY
- LANGFUSE_LLM_CONNECTION_GOOGLEAISTUDIO_KEY
# Fern token is generation-only; GitHub write actions are handled by GH_ACCESS_TOKEN in a protected environment.
- FERN_TOKEN
+1
View File
@@ -47,6 +47,7 @@ yarn-error.log*
!.env.dev-redis-cluster.example
!.env.prod.example
!.env.test.example
!.env.dev-oci.example
# vercel
.vercel
+5 -7
View File
@@ -316,18 +316,16 @@ Tests automatically create the PostgreSQL test database if it doesn't exist and
### Tests in the `web` package (public API)
We're using Jest with in the `web` package. Therefore, if you want to provide an argument to the test runner, do it directly without an intermittent `--`.
There are two types of unit tests:
We're using Vitest in the `web` package. There are two types of unit tests:
- `test` (server tests)
- `test-client`
To run a specific test, for example the test: `"should handle special characters in prompt names"` in `prompts.v2.servertest.ts`, run:
To run a specific test by name within a file, run:
```sh
cd web # or with --filter=web
pnpm test --testPathPatterns="prompts\.v2\.servertest" --testNamePattern="should handle special characters in prompt names"
pnpm test -- prompts.v2.servertest -t "should handle special characters in prompt names"
```
To run all tests:
@@ -344,7 +342,7 @@ pnpm run test:watch
### Tests in the `worker` package
For the `worker` package, we're using `vitest` to run unit tests.
For the `worker` package, we're also using Vitest to run unit tests.
```sh
pnpm run test --filter=worker -- FILE_YOU_WANT_TO_TEST.ts -t "test name"
@@ -357,7 +355,7 @@ We use GitHub Actions for CI/CD, the configuration is in [`.github/workflows/pip
CI on `main` and `pull_request`
- Check Linting
- E2E test of API using Jest
- E2E test of API using Vitest
- E2E tests of UI using Playwright
CD on `main`
+2
View File
@@ -31,6 +31,8 @@ services:
CLICKHOUSE_PASSWORD: ${CLICKHOUSE_PASSWORD:-clickhouse} # CHANGEME
CLICKHOUSE_CLUSTER_ENABLED: ${CLICKHOUSE_CLUSTER_ENABLED:-false}
LANGFUSE_USE_AZURE_BLOB: ${LANGFUSE_USE_AZURE_BLOB:-false}
LANGFUSE_USE_OCI_NATIVE_OBJECT_STORAGE: ${LANGFUSE_USE_OCI_NATIVE_OBJECT_STORAGE:-false}
LANGFUSE_OCI_AUTH_TYPE: ${LANGFUSE_OCI_AUTH_TYPE:-workload_identity}
LANGFUSE_S3_EVENT_UPLOAD_BUCKET: ${LANGFUSE_S3_EVENT_UPLOAD_BUCKET:-langfuse}
LANGFUSE_S3_EVENT_UPLOAD_REGION: ${LANGFUSE_S3_EVENT_UPLOAD_REGION:-auto}
LANGFUSE_S3_EVENT_UPLOAD_ACCESS_KEY_ID: ${LANGFUSE_S3_EVENT_UPLOAD_ACCESS_KEY_ID:-minio}
+19
View File
@@ -32,6 +32,9 @@ types:
configId:
type: optional<string>
docs: Reference a score config on a score. When set, the score name must equal the config name and scores must comply with the config's range and data type. For categorical scores, the value must map to a config category. Numeric scores might be constrained by the score config's max and min values
source:
type: optional<CreateScoreSource>
docs: The source of the score. Defaults to API. Set to ANNOTATION to prefill scores (e.g. from an LLM) for a human reviewer to verify in an annotation queue. When source is ANNOTATION, a configId is required unless dataType is CORRECTION. EVAL is reserved for internal evaluator outputs and is not accepted on this endpoint.
examples:
- value:
name: "novelty"
@@ -77,6 +80,22 @@ types:
name: "hallucination"
value: 0
datasetRunId: "7891-5678-90ab-hijk"
- value:
name: "accuracy"
value: 0.9
dataType: "NUMERIC"
configId: "9203-4567-89ab-cdef"
traceId: "cdef-1234-5678-90ab"
source: "ANNOTATION"
CreateScoreSource:
docs: |
Source values accepted when creating a score via the public API.
EVAL is reserved for internal evaluator outputs and is intentionally not
exposed here.
enum:
- API
- ANNOTATION
ScoreDataType:
enum:
@@ -56,6 +56,7 @@ types:
BlobStorageExportFrequency:
enum:
- every_20_minutes
- hourly
- daily
- weekly
@@ -138,8 +139,8 @@ types:
- `up_to_date` — all available data has been exported; next export is scheduled for the future
**ETL usage**: poll this endpoint and check for `up_to_date` status. Compare `lastSyncAt` against your
ETL bookmark to determine if new data is available. Note that exports run with a 30-minute lag buffer,
so `lastSyncAt` will always be at least 30 minutes behind real-time.
ETL bookmark to determine if new data is available. Note that exports run with a 20-minute lag buffer,
so `lastSyncAt` will always be at least 20 minutes behind real-time.
enum:
- idle
- queued
@@ -46,6 +46,9 @@ types:
configId:
type: optional<string>
docs: Reference a score config on a score. The unique langfuse identifier of a score config. When passing this field, the dataType and stringValue fields are automatically populated.
source:
type: optional<CreateScoreSource>
docs: The source of the score. Defaults to API. Set to ANNOTATION to prefill scores (e.g. from an LLM) for a human reviewer to verify in an annotation queue. When source is ANNOTATION, a configId is required unless dataType is CORRECTION. EVAL is reserved for internal evaluator outputs and is not accepted on this endpoint.
examples:
- value:
name: "novelty"
@@ -90,6 +93,22 @@ types:
value: "Great explanation of the concept"
dataType: "TEXT"
traceId: "cdef-1234-5678-90ab"
- value:
name: "accuracy"
value: 0.9
dataType: "NUMERIC"
configId: "9203-4567-89ab-cdef"
traceId: "cdef-1234-5678-90ab"
source: "ANNOTATION"
queueId: "aq-1234-5678-90ab-cdef"
CreateScoreSource:
docs: |
Source values accepted when creating a score via the public REST API.
EVAL is reserved for internal evaluator outputs and is intentionally not
exposed here — use commons.ScoreSource when reading scores.
enum:
- API
- ANNOTATION
CreateScoreResponse:
properties:
id:
@@ -26,6 +26,13 @@ service:
path: /llm-connections
request: UpsertLlmConnectionRequest
response: LlmConnection
delete:
method: DELETE
docs: Delete an LLM connection by id. Evaluators that depend on the deleted connection are automatically paused.
path: /llm-connections/{id}
path-parameters:
id: string
response: DeleteLlmConnectionResponse
types:
LlmConnection:
@@ -96,6 +103,10 @@ types:
- **VertexAI**: Optional. If provided, must be `{"location": "<gcp-location>"}` (e.g., `{"location":"us-central1"}`)
- **Other adapters**: Not supported. Omit this field or set to null.
DeleteLlmConnectionResponse:
properties:
message: string
LlmAdapter:
enum:
- value: anthropic
@@ -54,7 +54,9 @@ types:
meta: pagination.MetaResponse
CreateScoreConfigRequest:
properties:
name: string
name:
type: string
docs: "Name of the score config. Max 35 characters. Only letters, numbers, underscores, spaces, periods, parentheses, and hyphens are allowed."
dataType: commons.ScoreConfigDataType
categories:
type: optional<list<commons.ConfigCategory>>
@@ -75,7 +77,7 @@ types:
docs: The status of the score config showing if it is archived or not
name:
type: optional<string>
docs: The name of the score config
docs: "Name of the score config. Max 35 characters. Only letters, numbers, underscores, spaces, periods, parentheses, and hyphens are allowed."
categories:
type: optional<list<commons.ConfigCategory>>
docs: Configure custom categories for categorical scores. Pass a list of objects with `label` and `value` properties. Categories are autogenerated for boolean configs and cannot be passed
@@ -0,0 +1,564 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json
types:
EvaluatorType:
docs: |
The evaluator engine type.
The unstable public API currently supports only LLM-as-a-judge evaluators.
enum:
- llm_as_judge
EvaluatorScope:
docs: |
Where an evaluator comes from.
- `project`: created in your project
- `managed`: provided by Langfuse
enum:
- project
- managed
EvaluationRuleTarget:
docs: |
The ingestion object type that should trigger evaluation runs.
Choose the target first, because it changes both the valid filter columns and the valid variable-mapping sources:
- `observation` evaluates live-ingested observations such as generations, spans, and events.
It supports mapping from `input`, `output`, and `metadata`.
- `experiment` evaluates live experiment executions and can additionally map `expected_output`.
It currently supports filtering by `datasetId`.
Discover valid dataset IDs with `GET /api/public/v2/datasets`, then use the returned dataset `id` values in your filter.
enum:
- observation
- experiment
EvaluationRuleStatus:
docs: |
Effective runtime status of the evaluation rule.
- `active`: enabled and currently runnable.
- `inactive`: disabled by configuration.
- `paused`: enabled, but Langfuse has blocked execution until the underlying issue is resolved.
enum:
- active
- inactive
- paused
EvaluationRuleMappingSource:
docs: |
Source field used to populate a prompt variable.
Use these values when mapping evaluator prompt variables to live data.
Target-specific rules:
- `target=observation` supports `input`, `output`, and `metadata`
- `target=experiment` supports `input`, `output`, `metadata`, and `expected_output`
Source semantics:
- `input`: the observation or experiment input payload
- `output`: the observation or experiment output payload
- `metadata`: the metadata object for the target. Combine with `jsonPath` when you need one nested field instead of the whole object.
- `expected_output`: the experiment item's expected output. Only valid for `target=experiment`.
enum:
- input
- output
- metadata
- expected_output
EvaluatorModelConfig:
docs: |
Optional explicit model configuration for an evaluator.
If omitted, Langfuse uses the project's default evaluation model.
If provided, the model must be available to the project when the evaluator or evaluation rule is enabled.
To discover valid configured `provider` values for a project, call `GET /api/public/llm-connections` and read the `provider` field from the returned connections.
Use a `provider` value that matches one of the connections already configured in the same project.
Recovery guidance:
- If evaluator creation returns `422` with `code=evaluator_preflight_failed`, either provide a valid explicit `modelConfig` here or configure the project's default evaluation model, then retry the same request.
properties:
provider:
type: string
docs: |
Provider identifier to use for this evaluator, for example `openai` or `anthropic`.
To discover valid values for the current project, call `GET /api/public/llm-connections` and use one of the returned `provider` values.
model:
type: string
docs: Model identifier exposed by the provider, for example `gpt-4.1-mini`.
examples:
- value:
provider: openai
model: gpt-4.1-mini
EvaluatorOutputDataType:
docs: |
Structured score type returned by an evaluator.
This controls the type of score value Langfuse stores for evaluation results:
- `NUMERIC`: a numeric score such as `0.82`
- `BOOLEAN`: a boolean score such as `true`
- `CATEGORICAL`: one or more category labels from a fixed list
enum:
- NUMERIC
- BOOLEAN
- CATEGORICAL
EvaluatorOutputFieldDefinition:
properties:
description:
type: string
docs: Human-readable instructions for what the evaluator should return in this field.
EvaluatorOutputDefinition:
docs: |
Structured output definition to send when creating an evaluator.
Agent guidance:
- `dataType` is required.
- Do not send `version`; that is an internal storage detail and is not part of the public request contract.
- For `NUMERIC` and `BOOLEAN`, provide `reasoning.description` and `score.description`.
- For `CATEGORICAL`, also provide `score.categories` and `score.shouldAllowMultipleMatches`.
discriminant: dataType
union:
NUMERIC:
type: PublicNumericEvaluatorOutputDefinition
BOOLEAN:
type: PublicBooleanEvaluatorOutputDefinition
CATEGORICAL:
type: PublicCategoricalEvaluatorOutputDefinition
examples:
- name: Numeric
value:
dataType: NUMERIC
reasoning:
description: Explain why the answer is correct or incorrect.
score:
description: Return a score between 0 and 1.
- name: Boolean
value:
dataType: BOOLEAN
reasoning:
description: Explain why the output satisfies the requirement.
score:
description: Return true if the output satisfies the requirement, otherwise false.
- name: Categorical
value:
dataType: CATEGORICAL
reasoning:
description: Explain which category best fits the output.
score:
description: Choose the best category.
categories:
- correct
- partially_correct
- incorrect
shouldAllowMultipleMatches: false
PublicNumericEvaluatorOutputDefinition:
properties:
dataType:
type: EvaluatorOutputDataType
docs: Always `NUMERIC`.
reasoning:
type: EvaluatorOutputFieldDefinition
score:
type: EvaluatorOutputFieldDefinition
PublicBooleanEvaluatorOutputDefinition:
properties:
dataType:
type: EvaluatorOutputDataType
docs: Always `BOOLEAN`.
reasoning:
type: EvaluatorOutputFieldDefinition
score:
type: EvaluatorOutputFieldDefinition
PublicCategoricalEvaluatorOutputScoreDefinition:
properties:
description:
type: string
categories:
type: list<string>
shouldAllowMultipleMatches:
type: boolean
PublicCategoricalEvaluatorOutputDefinition:
properties:
dataType:
type: EvaluatorOutputDataType
docs: Always `CATEGORICAL`.
reasoning:
type: EvaluatorOutputFieldDefinition
score:
type: PublicCategoricalEvaluatorOutputScoreDefinition
PublicEvaluatorOutputDefinition:
docs: |
Evaluator output definition returned by the public API.
This response always includes `dataType` and never includes an internal output-definition `version`.
Legacy stored evaluator definitions are normalized into this shape before they are returned.
Use this response shape when deciding how to interpret future evaluation scores:
- `NUMERIC`: expect numeric score values
- `BOOLEAN`: expect `true` / `false`
- `CATEGORICAL`: expect one or more values from `score.categories`
discriminant: dataType
union:
NUMERIC:
type: PublicNumericEvaluatorOutputDefinition
BOOLEAN:
type: PublicBooleanEvaluatorOutputDefinition
CATEGORICAL:
type: PublicCategoricalEvaluatorOutputDefinition
examples:
- name: PublicNumeric
value:
dataType: NUMERIC
reasoning:
description: Explain why the answer is correct or incorrect.
score:
description: Return a score between 0 and 1.
- name: PublicCategorical
value:
dataType: CATEGORICAL
reasoning:
description: Explain which label best fits the output.
score:
description: Choose the best label.
categories:
- correct
- partially_correct
- incorrect
shouldAllowMultipleMatches: false
EvaluationRuleStringFilterOperator:
enum:
- name: Equals
value: "="
- name: Contains
value: contains
- name: DoesNotContain
value: does not contain
- name: StartsWith
value: starts with
- name: EndsWith
value: ends with
EvaluationRuleNumberFilterOperator:
enum:
- name: Equals
value: "="
- name: GreaterThan
value: ">"
- name: LessThan
value: "<"
- name: GreaterThanOrEqual
value: ">="
- name: LessThanOrEqual
value: "<="
EvaluationRuleOptionsFilterOperator:
enum:
- name: AnyOf
value: any of
- name: NoneOf
value: none of
EvaluationRuleArrayOptionsFilterOperator:
enum:
- name: AnyOf
value: any of
- name: NoneOf
value: none of
- name: AllOf
value: all of
EvaluationRuleBooleanFilterOperator:
enum:
- name: Equals
value: "="
- name: NotEquals
value: "<>"
EvaluationRuleNullFilterOperator:
enum:
- name: IsNull
value: is null
- name: IsNotNull
value: is not null
DateTimeEvaluationRuleFilter:
properties:
column:
type: string
docs: Column to filter on.
operator:
type: EvaluationRuleNumberFilterOperator
docs: Comparison operator for datetime values.
value:
type: datetime
docs: Datetime value to compare against.
StringEvaluationRuleFilter:
properties:
column:
type: string
docs: Column to filter on.
operator:
type: EvaluationRuleStringFilterOperator
value:
type: string
NumberEvaluationRuleFilter:
properties:
column:
type: string
docs: Column to filter on.
operator:
type: EvaluationRuleNumberFilterOperator
value:
type: double
StringOptionsEvaluationRuleFilter:
properties:
column:
type: string
docs: Column to filter on.
operator:
type: EvaluationRuleOptionsFilterOperator
value:
type: list<string>
docs: One or more allowed string values.
ArrayOptionsEvaluationRuleFilter:
properties:
column:
type: string
docs: Column to filter on.
operator:
type: EvaluationRuleArrayOptionsFilterOperator
value:
type: list<string>
docs: One or more array elements to match.
StringObjectEvaluationRuleFilter:
properties:
column:
type: string
docs: Object-valued column to filter on. In the unstable public API this is currently `metadata`.
key:
type: string
docs: Top-level key inside the object-valued column to filter on.
operator:
type: EvaluationRuleStringFilterOperator
value:
type: string
NumberObjectEvaluationRuleFilter:
properties:
column:
type: string
docs: Object-valued column to filter on.
key:
type: string
docs: Key inside the object-valued column to filter on.
operator:
type: EvaluationRuleNumberFilterOperator
value:
type: double
CategoryOptionsEvaluationRuleFilter:
properties:
column:
type: string
docs: Object-valued column to filter on.
key:
type: string
docs: Key inside the object-valued column to filter on.
operator:
type: EvaluationRuleOptionsFilterOperator
value:
type: list<string>
BooleanEvaluationRuleFilter:
properties:
column:
type: string
docs: Column to filter on.
operator:
type: EvaluationRuleBooleanFilterOperator
value:
type: boolean
NullEvaluationRuleFilter:
properties:
column:
type: string
docs: Column to filter on. In the unstable public API this is currently `parentObservationId`.
operator:
type: EvaluationRuleNullFilterOperator
value:
type: optional<string>
docs: Ignored placeholder value. Clients may omit it or send an empty string.
EvaluationRuleMapping:
docs: |
Maps one evaluator prompt variable to one source field from the target object.
How to build a valid mapping list:
1. Create the evaluator or fetch it with `GET /evaluators/{id}`.
2. Read the evaluator `variables` array.
3. Add exactly one mapping object for each variable in that array.
4. Use the variable name exactly as returned, without braces such as `{{` or `}}`.
5. Choose a `source` that is valid for the selected `target`.
`jsonPath` is optional. Use it only when the selected source is a JSON object and you want to extract one nested field before inserting it into the evaluator prompt.
Recovery guidance:
- `invalid_variable_mapping`: the variable name is unknown for this evaluator, or the selected `source` is not valid for the chosen `target`
- `missing_variable_mapping`: one or more evaluator variables are not mapped yet
- `duplicate_variable_mapping`: the same evaluator variable appears more than once
- `invalid_json_path`: the JSONPath expression is malformed. Remove it or correct it.
properties:
variable:
type: string
docs: |
Prompt variable name without braces.
Example: for the prompt `Judge {{input}} against {{output}}`, use `input` and `output`.
source:
type: EvaluationRuleMappingSource
docs: |
Source field that should populate the prompt variable.
Quick reference:
- `target=observation`: `input`, `output`, `metadata`
- `target=experiment`: `input`, `output`, `metadata`, `expected_output`
jsonPath:
type: optional<string>
docs: |
Optional JSONPath selector applied to the selected source before it is passed to the evaluator prompt.
Requirements:
- Must start with `$`
- Must be a syntactically valid JSONPath expression
- Most useful with `source=metadata`
examples:
- name: BasicObservationMapping
value:
variable: input
source: input
- name: MetadataProjectionMapping
value:
variable: customer_tier
source: metadata
jsonPath: "$.customer.tier"
- name: ExperimentExpectedOutputMapping
value:
variable: expected_output
source: expected_output
EvaluationRuleFilter:
docs: |
One filter condition used to decide whether a live-ingested target should be evaluated.
An evaluation rule can include zero or more filter objects. All filters must be satisfied for the target to run.
How to build a valid filter object:
- Pick the `target` first, because it changes the supported columns.
- Pick the filter `type`. That determines which fields are required.
- Use `key` only for object filters such as `metadata`.
- Use the correct `value` shape for the chosen filter `type`.
Operator quick reference by filter `type`:
- `string`: `"="`, `contains`, `does not contain`, `starts with`, `ends with`
- `number`: `"="`, `">"`, `"<"`, `">="`, `"<="`
- `datetime`: `"="`, `">"`, `"<"`, `">="`, `"<="`
- `stringOptions`: `any of`, `none of`
- `arrayOptions`: `any of`, `none of`, `all of`
- `stringObject`: same operators as `string`
- `null`: `is null`, `is not null`
Supported columns by target:
- `target=observation`
- `type`: `stringOptions`, operators `any of` / `none of`, values `GENERATION`, `SPAN`, `EVENT`
- `name`: `stringOptions`, operators `any of` / `none of`
- `environment`: `stringOptions`, operators `any of` / `none of`
- `level`: `stringOptions`, operators `any of` / `none of`, values `DEBUG`, `DEFAULT`, `WARNING`, `ERROR`
- `version`: `string`
- `traceName`: `stringOptions`, operators `any of` / `none of`
- `userId`: `string`
- `sessionId`: `string`
- `tags`: `arrayOptions`, operators `any of` / `none of` / `all of`
- `metadata`: `stringObject` with `key`
- `parentObservationId`: `null`, operators `is null` / `is not null`
- `calledToolNames`: `arrayOptions`, operators `any of` / `none of` / `all of`
- `toolCalls`: `number`
- `target=experiment`
- `datasetId`: `stringOptions`, operators `any of` / `none of`
Use dataset `id` values from `GET /api/public/v2/datasets`, not dataset names.
Recovery guidance:
- `invalid_filter_value` with `details.column` but no `invalidValues`: the selected `column` is not supported for the chosen `target`
- `invalid_filter_value` with `details.invalidValues`: the selected values are not allowed for that column. Replace them with one of `details.allowedValues` when provided.
- `invalid_filter_value` for `column=datasetId`: call `GET /api/public/v2/datasets`, then retry with dataset `id` values from that response.
discriminant: type
union:
"datetime":
type: DateTimeEvaluationRuleFilter
"string":
type: StringEvaluationRuleFilter
"number":
type: NumberEvaluationRuleFilter
"stringOptions":
type: StringOptionsEvaluationRuleFilter
"categoryOptions":
type: CategoryOptionsEvaluationRuleFilter
"arrayOptions":
type: ArrayOptionsEvaluationRuleFilter
"stringObject":
type: StringObjectEvaluationRuleFilter
"numberObject":
type: NumberObjectEvaluationRuleFilter
"boolean":
type: BooleanEvaluationRuleFilter
"null":
type: NullEvaluationRuleFilter
examples:
- name: ObservationTypeFilter
value:
type: stringOptions
column: type
operator: any of
value:
- GENERATION
- name: ObservationMetadataFilter
value:
type: stringObject
column: metadata
key: customerTier
operator: "="
value: enterprise
- name: ObservationRootOnlyFilter
value:
type: "null"
column: parentObservationId
operator: is null
- name: ObservationTagsFilter
value:
type: arrayOptions
column: tags
operator: any of
value:
- production
- name: ExperimentDatasetFilter
value:
type: stringOptions
column: datasetId
operator: any of
value:
- "550e8400-e29b-41d4-a716-446655440000"
@@ -0,0 +1,269 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json
types:
PublicApiErrorCode:
docs: |
Machine-readable error code returned by the unstable evaluators API.
SDKs, CLIs, and agents should branch on `code` rather than parsing the human-readable `message`.
The HTTP status still indicates the broad error class, while `code` gives the specific failure reason.
enum:
- authentication_failed
- access_denied
- invalid_request
- invalid_query
- invalid_body
- invalid_filter_value
- invalid_json_path
- invalid_variable_mapping
- missing_variable_mapping
- duplicate_variable_mapping
- resource_not_found
- name_conflict
- evaluator_preflight_failed
- conflict
- unprocessable_content
- rate_limited
- method_not_allowed
- internal_error
PublicApiValidationIssue:
docs: |
One validation issue returned for malformed request bodies or query parameters.
This mirrors the most important parts of a Zod issue: a machine-readable `code`,
a human-readable `message`, and a structured `path`.
properties:
code:
type: string
docs: Machine-readable validation issue code emitted by the server validator.
message:
type: string
docs: Human-readable explanation of the validation failure.
path:
type: list<unknown>
docs: Path to the invalid field, for example `["mapping", 0, "jsonPath"]`.
PublicApiErrorDetails:
docs: |
Optional structured context attached to an unstable-evals error.
The populated fields depend on the error `code`:
- request parsing failures populate `issues`
- filter validation failures populate `field`, `column`, `invalidValues`, and `allowedValues`
- variable mapping failures populate `field`, `variable`, or `variables`
- JSONPath validation failures populate `field`, `variable`, and `value`
- evaluator preflight failures populate `evaluatorName`, `provider`, and `model`
- rate limiting populates `retryAfterSeconds`, `limit`, `remaining`, and `resetAt`
properties:
issues:
type: optional<list<PublicApiValidationIssue>>
docs: Validation issues for malformed request bodies or query parameters.
field:
type: optional<string>
docs: Path-like reference to the failing field, for example `mapping[1].jsonPath`.
column:
type: optional<string>
docs: Filter column that failed validation.
invalidValues:
type: optional<list<string>>
docs: Unsupported values supplied by the caller.
allowedValues:
type: optional<list<string>>
docs: Allowed values for the failing filter column.
variable:
type: optional<string>
docs: Evaluator variable involved in the failure.
variables:
type: optional<list<string>>
docs: Multiple evaluator variables involved in the failure, for example missing mappings.
value:
type: optional<string>
docs: Raw invalid value supplied by the caller.
evaluatorName:
type: optional<string>
docs: Evaluator name used during preflight validation.
provider:
type: optional<nullable<string>>
docs: Provider resolved during evaluator preflight, if any.
model:
type: optional<nullable<string>>
docs: Model resolved during evaluator preflight, if any.
retryAfterSeconds:
type: optional<integer>
docs: Suggested retry delay for rate-limited requests.
limit:
type: optional<integer>
docs: Numeric limit associated with the failure, for example the active evaluation-rule cap or the current rate-limit window.
remaining:
type: optional<integer>
docs: Remaining requests in the current rate-limit window.
resetAt:
type: optional<string>
docs: ISO-8601 timestamp when the current rate-limit window resets.
PublicApiError:
docs: |
Standard error envelope for the unstable evaluators API.
Response handling guidance:
- Use the HTTP status code for the broad class of failure.
- Use `code` for precise branching in SDKs, CLIs, or agents.
- Inspect `details` for field-level validation context such as invalid filter values, malformed JSONPath expressions, or missing variable mappings.
- Retry only after fixing the specific issue described by `code` and `details`.
properties:
message:
type: string
docs: Human-readable description of the failure.
code:
type: PublicApiErrorCode
docs: Stable machine-readable error code.
details:
type: optional<PublicApiErrorDetails>
docs: Optional structured error context. Inspect the populated fields based on `code`.
examples:
- name: InvalidFilterValue
value:
message: 'Filter column "type" contains unsupported value(s): INVALID'
code: invalid_filter_value
details:
field: filter[0].value
column: type
invalidValues:
- INVALID
allowedValues:
- GENERATION
- SPAN
- EVENT
- name: InvalidExperimentDatasetFilterValue
value:
message: 'Filter column "datasetId" contains dataset id(s) that do not exist in this project: dataset-prod'
code: invalid_filter_value
details:
field: filter[0].value
column: datasetId
invalidValues:
- dataset-prod
- name: EvaluatorPreflightFailed
value:
message: 'No valid LLM model found for evaluator "answer-correctness". No default model or custom model configured for project project_123'
code: evaluator_preflight_failed
details:
evaluatorName: answer-correctness
provider: null
model: null
- name: MissingVariableMapping
value:
message: "Missing mappings for evaluator variable(s): output"
code: missing_variable_mapping
details:
field: mapping
variables:
- output
- name: InvalidJsonPath
value:
message: 'Mapping for variable "customer_tier" has an invalid jsonPath "$[". JSONPath expressions must use balanced quotes, brackets, and parentheses.'
code: invalid_json_path
details:
field: mapping[0].jsonPath
variable: customer_tier
value: "$["
- name: NameConflict
value:
message: 'An evaluation rule named "answer-quality-live" already exists in this project. Use PATCH /api/public/unstable/evaluation-rules/erule_123 to update it instead of creating a duplicate.'
code: name_conflict
details:
field: name
- name: ActiveEvaluationRuleLimit
value:
message: This project already has the maximum number of active evaluation rules (50). Disable an existing active evaluation rule before enabling another one.
code: conflict
details:
limit: 50
- name: RateLimited
value:
message: Rate limit exceeded
code: rate_limited
details:
retryAfterSeconds: 60
limit: 1000
remaining: 0
resetAt: "2026-03-30T10:00:00.000Z"
errors:
BadRequestError:
docs: |
Request parsing or validation failed.
Typical unstable-eval examples:
- malformed request body or query parameters
- unsupported filter value
- invalid JSONPath selector
- missing or duplicate variable mappings
Recovery guidance:
- read `details.issues` for malformed bodies or queries
- read `details.column`, `details.invalidValues`, and `details.allowedValues` for filter problems
- for `details.column=datasetId`, call `GET /api/public/v2/datasets` and retry with dataset `id` values from that response
- read `details.variable` or `details.variables` for mapping problems
status-code: 400
type: PublicApiError
UnauthorizedError:
docs: |
Authentication failed.
Typical unstable-eval examples:
- the API key or secret key is invalid
- the request uses the wrong host or stale credentials
status-code: 401
type: PublicApiError
AccessDeniedError:
docs: |
Authenticated, but the caller is not allowed to access the requested resource.
Typical unstable-eval examples:
- using an organization-scoped key against project-scoped evaluator endpoints
- using a valid key that lacks the required access level for this resource
status-code: 403
type: PublicApiError
NotFoundError:
docs: The requested evaluator or evaluation rule does not exist within the authorized project.
status-code: 404
type: PublicApiError
MethodNotAllowedError:
docs: The HTTP method is not supported for this endpoint.
status-code: 405
type: PublicApiError
ConflictError:
docs: |
The request conflicts with existing state.
Typical unstable-eval examples:
- evaluator version changed during concurrent creation
- an evaluation rule name already exists in the project, so the caller should PATCH the existing resource instead
- enabling another evaluation rule would exceed the project limit of 50 active evaluation rules
- the underlying state changed between read and write operations, so the client should retry
Recovery guidance:
- for `name_conflict`, PATCH the existing evaluation rule instead of creating another one
- for the active-limit conflict, disable another active evaluation rule before enabling a new one
status-code: 409
type: PublicApiError
UnprocessableContentError:
docs: |
The request is syntactically valid, but Langfuse cannot accept it in its current form.
The most important unstable-eval case is `code=evaluator_preflight_failed`, which means the evaluator cannot currently run with the resolved model configuration.
Recovery guidance:
- configure the project's default evaluation model, or send a valid explicit evaluator `modelConfig`
- once the model configuration is valid, retry the same request
status-code: 422
type: PublicApiError
TooManyRequestsError:
docs: The project is rate limited. Retry after the interval described in the response headers and error details.
status-code: 429
type: PublicApiError
InternalServerError:
docs: An unexpected server-side error occurred.
status-code: 500
type: PublicApiError
@@ -0,0 +1,494 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json
imports:
commons: ./commons.yml
errors: ./errors.yml
pagination: ../utils/pagination.yml
service:
auth: true
base-path: /api/public/unstable
endpoints:
create:
docs: |
Create an evaluation rule.
An evaluation rule defines **what** incoming data should be evaluated and **how prompt variables should be populated** from that data.
Use this resource after choosing an evaluator from the evaluator endpoints.
Key rules:
- `name` must be unique within the project for public evaluation rules
- `target` must be `observation` or `experiment`
- `evaluator.name` + `evaluator.scope` must identify an existing evaluator family returned by the evaluator endpoints
- Langfuse resolves that family to its latest version before saving the evaluation rule
- for `target=experiment`, use dataset `id` values from `GET /api/public/v2/datasets` when filtering by `datasetId`
- every evaluator prompt variable must be mapped exactly once
- `expected_output` mappings are only valid for `target=experiment`
- if `enabled=true`, Langfuse validates that the referenced evaluator can currently run
- at most 50 evaluation rules can be effectively active in one project at the same time
If an evaluation rule with the same `name` already exists in the project, the API returns `409`.
In that case, update the existing resource with `PATCH /api/public/unstable/evaluation-rules/{evaluationRuleId}` instead of creating a second one.
If enabling this resource would exceed the 50-active limit, the API also returns `409`.
In that case, disable or pause another active evaluation rule before enabling a new one.
Current scope:
- evaluation rules are live-ingestion rules only
- they do not trigger historical backfills
Recovery guidance:
- `400 invalid_filter_value`: fix the filter `column` or `value` using `details.column`, `details.invalidValues`, and `details.allowedValues`
- `400 invalid_filter_value` with `details.column=datasetId`: call `GET /api/public/v2/datasets`, then retry with dataset `id` values from that response
- `400 missing_variable_mapping`: fetch the evaluator again and make sure every variable in `variables` appears exactly once in `mapping`
- `400 duplicate_variable_mapping`: remove repeated mappings for the same variable
- `400 invalid_variable_mapping`: switch to a valid `source` for the selected `target`, or fix the variable name
- `400 invalid_json_path`: remove or correct the `jsonPath`
- `422 evaluator_preflight_failed`: the selected evaluator cannot run with the resolved model configuration. Fix the evaluator/default model setup, then retry the create request.
method: POST
path: /evaluation-rules
request: CreateEvaluationRuleRequest
response: EvaluationRule
errors:
- errors.BadRequestError
- errors.UnauthorizedError
- errors.AccessDeniedError
- errors.NotFoundError
- errors.ConflictError
- errors.MethodNotAllowedError
- errors.UnprocessableContentError
- errors.TooManyRequestsError
- errors.InternalServerError
examples:
- name: CreateObservationEvaluationRule
docs: Deploy an evaluator to score live generations only.
request:
name: answer-correctness-live
evaluator:
name: answer-correctness
scope: project
target: observation
enabled: true
sampling: 1
filter:
- type: stringOptions
column: type
operator: any of
value:
- GENERATION
mapping:
- variable: input
source: input
- variable: output
source: output
response:
body:
id: erule_123
name: answer-correctness-live
evaluator:
id: evaltmpl_123
name: answer-correctness
scope: project
target: observation
enabled: true
status: active
pausedReason: null
pausedMessage: null
sampling: 1
filter:
- type: stringOptions
column: type
operator: any of
value:
- GENERATION
mapping:
- variable: input
source: input
- variable: output
source: output
createdAt: "2026-03-30T09:20:00.000Z"
updatedAt: "2026-03-30T09:20:00.000Z"
- name: CreateExperimentEvaluationRule
docs: Deploy an evaluator to compare experiment outputs against expected outputs. Discover valid dataset IDs with `GET /api/public/v2/datasets` first.
request:
name: experiment-expected-output-match
evaluator:
name: expected-output-match
scope: project
target: experiment
enabled: true
sampling: 0.5
filter:
- type: stringOptions
column: datasetId
operator: any of
value:
- "550e8400-e29b-41d4-a716-446655440000"
mapping:
- variable: output
source: output
- variable: expected_output
source: expected_output
response:
body:
id: erule_456
name: experiment-expected-output-match
evaluator:
id: evaltmpl_456
name: expected-output-match
scope: project
target: experiment
enabled: true
status: active
pausedReason: null
pausedMessage: null
sampling: 0.5
filter:
- type: stringOptions
column: datasetId
operator: any of
value:
- "550e8400-e29b-41d4-a716-446655440000"
mapping:
- variable: output
source: output
- variable: expected_output
source: expected_output
createdAt: "2026-03-30T09:30:00.000Z"
updatedAt: "2026-03-30T09:30:00.000Z"
list:
docs: |
List evaluation rules in the authenticated project.
Each item describes one live evaluation rule and its effective runtime status.
method: GET
path: /evaluation-rules
request:
name: ListEvaluationRulesRequest
query-parameters:
page:
type: optional<integer>
docs: 1-based page number. Defaults to `1`.
limit:
type: optional<integer>
docs: Maximum number of items per page. Defaults to `50`.
response: EvaluationRules
errors:
- errors.BadRequestError
- errors.UnauthorizedError
- errors.AccessDeniedError
- errors.MethodNotAllowedError
- errors.TooManyRequestsError
- errors.InternalServerError
get:
docs: |
Get one evaluation rule by its identifier.
Use this endpoint to inspect the current evaluator, target, mapping, filters, and effective runtime status.
method: GET
path: /evaluation-rules/{evaluationRuleId}
path-parameters:
evaluationRuleId:
type: string
docs: Evaluation rule identifier returned by the evaluation rule endpoints.
response: EvaluationRule
errors:
- errors.BadRequestError
- errors.UnauthorizedError
- errors.AccessDeniedError
- errors.NotFoundError
- errors.MethodNotAllowedError
- errors.TooManyRequestsError
- errors.InternalServerError
update:
docs: |
Update an evaluation rule.
Typical uses:
- enable or disable live execution
- switch to another evaluator
- adjust sampling
- change filters
- update variable mappings
Important behavior:
- provide only the fields you want to change
- if you provide `evaluator`, Langfuse resolves that evaluator family to its latest version before saving
- changing `target`, `filter`, or `mapping` must still produce a valid target-specific configuration
- if you change `target`, also send a compatible `filter` and `mapping` in the same request unless the existing ones are still valid for the new target
- if the resulting config is enabled, Langfuse re-validates that the selected evaluator can run
- if the update would move a non-active evaluation rule into the active state and the project already has 50 active evaluation rules, the API returns `409`
Recovery guidance:
- if the update fails with `missing_variable_mapping` or `invalid_variable_mapping` after changing `evaluator` or `target`, resend the request with a complete new `mapping`
- if the update fails with `invalid_filter_value` after changing `target`, resend the request with a target-compatible `filter`
method: PATCH
path: /evaluation-rules/{evaluationRuleId}
path-parameters:
evaluationRuleId:
type: string
docs: Evaluation rule identifier.
request: UpdateEvaluationRuleRequest
response: EvaluationRule
errors:
- errors.BadRequestError
- errors.UnauthorizedError
- errors.AccessDeniedError
- errors.NotFoundError
- errors.MethodNotAllowedError
- errors.UnprocessableContentError
- errors.TooManyRequestsError
- errors.InternalServerError
delete:
docs: |
Delete an evaluation rule.
This removes the live-ingestion rule only. It does not delete the referenced evaluator.
method: DELETE
path: /evaluation-rules/{evaluationRuleId}
path-parameters:
evaluationRuleId:
type: string
docs: Evaluation rule identifier.
response: DeleteEvaluationRuleResponse
errors:
- errors.BadRequestError
- errors.UnauthorizedError
- errors.AccessDeniedError
- errors.NotFoundError
- errors.MethodNotAllowedError
- errors.TooManyRequestsError
- errors.InternalServerError
types:
EvaluationRule:
docs: |
Live evaluation rule for incoming data.
An evaluation rule answers:
- which evaluator should be used
- which target objects should trigger scoring
- how often scoring should run
- which target fields should populate each evaluator variable
- whether the deployment is active, inactive, or paused
Important status semantics:
- `enabled` is the desired on/off setting from the client
- `status` is the effective runtime state after Langfuse applies validation and blocking rules
- `enabled=true` with `status=paused` means the rule should run, but Langfuse has paused it until the underlying problem is fixed
properties:
id:
type: string
docs: Stable evaluation rule identifier.
name:
type: string
docs: Human-readable deployment name. This is independent from the evaluator name.
evaluator:
type: EvaluationRuleEvaluator
docs: |
Evaluator currently used by this rule.
`name` and `scope` identify the evaluator family conceptually.
`id` is the currently active evaluator version in that family.
If you create a newer project version with the same evaluator name later, existing evaluation rules are moved to it automatically.
target:
type: commons.EvaluationRuleTarget
docs: Target object type that should trigger scoring.
enabled:
type: boolean
docs: Desired enabled state configured by the client.
status:
type: commons.EvaluationRuleStatus
docs: Effective runtime status after Langfuse applies validation and blocking rules.
pausedReason:
type: nullable<string>
docs: Machine-readable reason when `status=paused`, otherwise `null`.
pausedMessage:
type: nullable<string>
docs: Human-readable explanation when `status=paused`, otherwise `null`.
sampling:
type: double
docs: |
Fraction of matching target objects that should be evaluated.
Must be greater than `0` and less than or equal to `1`.
- `1` means evaluate every matching target.
- `0.25` means evaluate approximately 25% of matching targets.
filter:
type: list<commons.EvaluationRuleFilter>
docs: List of filter conditions used to decide whether a target should be evaluated.
mapping:
type: list<commons.EvaluationRuleMapping>
docs: Variable mappings used to populate the evaluator prompt from the live target object.
createdAt:
type: datetime
docs: Timestamp when the evaluation rule was created.
updatedAt:
type: datetime
docs: Timestamp when the evaluation rule was last updated.
examples:
- value:
id: erule_123
name: answer-correctness-live
evaluator:
id: evaltmpl_123
name: answer-correctness
scope: project
target: observation
enabled: true
status: active
pausedReason: null
pausedMessage: null
sampling: 1
filter:
- type: stringOptions
column: type
operator: any of
value:
- GENERATION
mapping:
- variable: input
source: input
- variable: output
source: output
createdAt: "2026-03-30T09:20:00.000Z"
updatedAt: "2026-03-30T09:20:00.000Z"
EvaluationRules:
docs: Paginated list of evaluation rules.
properties:
data:
type: list<EvaluationRule>
docs: Evaluation rules in the current page.
meta:
type: pagination.MetaResponse
docs: Standard pagination metadata.
CreateEvaluationRuleRequest:
docs: |
Request body for creating an evaluation rule.
Checklist for agents and SDK clients:
- reference an existing evaluator family by `evaluator.name` and `evaluator.scope`
- choose `target=observation` or `target=experiment`
- if `target=experiment` and you want a dataset filter, call `GET /api/public/v2/datasets` first and use dataset `id` values in `filter[].value`
- fetch or inspect the evaluator first, then provide a complete variable mapping for every evaluator variable listed in `variables`
- optionally narrow execution with `filter`
- set `enabled=true` only when you want live execution immediately
properties:
name:
type: string
docs: Human-readable deployment name.
evaluator:
type: EvaluationRuleEvaluatorReference
docs: |
Evaluator family to use.
Use `name` and `scope` from the evaluator endpoints.
Langfuse resolves that family to its latest version before saving the rule.
target:
type: commons.EvaluationRuleTarget
docs: Target object type to evaluate.
enabled:
type: boolean
docs: Whether the deployment should be active immediately after creation.
sampling:
type: optional<double>
docs: Optional sampling fraction. Defaults to `1`.
filter:
type: optional<list<commons.EvaluationRuleFilter>>
docs: |
Optional filter list.
Omit or pass an empty list to evaluate all matching targets for the selected `target`.
Each filter object must use a column that is valid for that `target`.
For `target=experiment`, `column=datasetId` expects dataset `id` values from `GET /api/public/v2/datasets`, not dataset names.
mapping:
type: list<commons.EvaluationRuleMapping>
docs: |
Required variable mappings.
Every evaluator variable must appear exactly once.
Build this list from the evaluator `variables` array returned by the evaluator endpoints.
UpdateEvaluationRuleRequest:
docs: |
Partial update body for an evaluation rule.
Provide only the fields you want to change.
An empty body is rejected.
Practical guidance:
- If you only want to rename the rule or change sampling, send just those fields.
- If you change `evaluator`, send a fresh `mapping` unless you are certain the existing mapping still matches the evaluator variables.
- If you change `target`, usually send both `filter` and `mapping` in the same request.
- If you change an experiment `datasetId` filter, call `GET /api/public/v2/datasets` and use dataset `id` values from that response.
properties:
name:
type: optional<string>
docs: Updated deployment name.
evaluator:
type: optional<EvaluationRuleEvaluatorReference>
docs: |
Updated evaluator family.
Langfuse resolves the provided evaluator family to its latest version before saving the rule.
target:
type: optional<commons.EvaluationRuleTarget>
docs: Updated target object type.
enabled:
type: optional<boolean>
docs: Updated desired enabled state.
sampling:
type: optional<double>
docs: Updated sampling fraction.
filter:
type: optional<list<commons.EvaluationRuleFilter>>
docs: |
Updated filter list.
For `target=experiment`, `column=datasetId` expects dataset `id` values from `GET /api/public/v2/datasets`, not dataset names.
mapping:
type: optional<list<commons.EvaluationRuleMapping>>
docs: Updated variable mappings.
DeleteEvaluationRuleResponse:
docs: Confirmation response returned after successful deletion.
properties:
message:
type: string
docs: Always `Evaluation rule successfully deleted`.
EvaluationRuleEvaluatorReference:
docs: |
Evaluator family reference used when creating or updating an evaluation rule.
`name` and `scope` are enough to identify the evaluator family in the authenticated project context.
properties:
name:
type: string
docs: Evaluator family name.
scope:
type: commons.EvaluatorScope
docs: Whether the evaluator family is project-owned or Langfuse-managed.
EvaluationRuleEvaluator:
docs: |
Resolved evaluator currently used by the evaluation rule.
`id` is the exact active evaluator version.
`name` and `scope` identify the evaluator family conceptually.
properties:
id:
type: string
docs: Identifier of the exact evaluator version currently used by the rule.
name:
type: string
docs: Evaluator family name.
scope:
type: commons.EvaluatorScope
docs: Whether the evaluator family is project-owned or Langfuse-managed.
@@ -0,0 +1,250 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json
imports:
commons: ./commons.yml
errors: ./errors.yml
pagination: ../utils/pagination.yml
service:
auth: true
base-path: /api/public/unstable
endpoints:
create:
docs: |
Create an evaluator in the authenticated project.
Use evaluators to define **how** Langfuse should score data: the prompt, the expected structured output, and the optional model configuration.
Naming behavior:
- If this is a new evaluator name in your project, Langfuse creates version `1`.
- If the name already exists in your project, Langfuse creates the next version and returns it.
- When a new project version is created, existing evaluation rules in that project automatically move to the newest version for that evaluator name.
Recommended workflow:
1. Create the evaluator.
2. Read the returned `variables` array.
3. Read the returned `outputDefinition.dataType` so the client knows whether future scores will be numeric, boolean, or categorical.
4. Create one or more evaluation rules that reference the returned evaluator family using `name` and `scope`.
Recovery guidance:
- `422` with `code=evaluator_preflight_failed`: the evaluator cannot run with the resolved model configuration. Add a valid explicit `modelConfig`, or configure the project's default evaluation model, then retry the same request.
- `400` with `code=invalid_body`: the request shape is malformed. Use the structured `details.issues` array to fix the specific fields and retry.
- `400` with `code=invalid_body` on `outputDefinition`: send `dataType`, `reasoning.description`, and `score.description`. Do not send `version`; it is not part of the public request shape.
Unstable API note:
- This surface may evolve while the underlying evaluation data model is being redesigned.
method: POST
path: /evaluators
request: CreateEvaluatorRequest
response: Evaluator
errors:
- errors.BadRequestError
- errors.UnauthorizedError
- errors.AccessDeniedError
- errors.MethodNotAllowedError
- errors.ConflictError
- errors.UnprocessableContentError
- errors.TooManyRequestsError
- errors.InternalServerError
examples:
- name: CreateEvaluatorVersion
docs: Create a new version of an evaluator named `answer-correctness`.
request:
name: answer-correctness
prompt: |
You are grading an answer.
Input:
{{input}}
Output:
{{output}}
Return a score between 0 and 1.
outputDefinition:
dataType: NUMERIC
reasoning:
description: Explain why the score was assigned.
score:
description: Correctness score between 0 and 1.
modelConfig:
provider: openai
model: gpt-4.1-mini
response:
body:
id: evaltmpl_123
name: answer-correctness
version: 2
scope: project
type: llm_as_judge
prompt: |
You are grading an answer.
Input:
{{input}}
Output:
{{output}}
Return a score between 0 and 1.
variables:
- input
- output
outputDefinition:
dataType: NUMERIC
reasoning:
description: Explain why the score was assigned.
score:
description: Correctness score between 0 and 1.
modelConfig:
provider: openai
model: gpt-4.1-mini
evaluationRuleCount: 0
createdAt: "2026-03-30T09:00:00.000Z"
updatedAt: "2026-03-30T09:00:00.000Z"
list:
docs: |
List the evaluators available to the authenticated project.
Important behavior:
- This endpoint returns the latest version of each available evaluator.
- Results can include evaluators from your project and Langfuse-managed evaluators.
- If the same evaluator name exists in both places, both are returned as separate items with different `scope` values.
method: GET
path: /evaluators
request:
name: ListEvaluatorsRequest
query-parameters:
page:
type: optional<integer>
docs: 1-based page number. Defaults to `1`.
limit:
type: optional<integer>
docs: Maximum number of items per page. Defaults to `50`.
response: Evaluators
errors:
- errors.BadRequestError
- errors.UnauthorizedError
- errors.AccessDeniedError
- errors.MethodNotAllowedError
- errors.TooManyRequestsError
- errors.InternalServerError
get:
docs: |
Get one evaluator by `id`.
Use this endpoint when you want the prompt, output definition, model configuration, and derived variables for the evaluator you plan to use in an evaluation rule.
method: GET
path: /evaluators/{evaluatorId}
path-parameters:
evaluatorId:
type: string
docs: Evaluator identifier returned by the evaluator endpoints.
response: Evaluator
errors:
- errors.BadRequestError
- errors.UnauthorizedError
- errors.AccessDeniedError
- errors.NotFoundError
- errors.MethodNotAllowedError
- errors.TooManyRequestsError
- errors.InternalServerError
types:
Evaluator:
docs: |
One evaluator that can be used for scoring.
An evaluator describes **how** to score data:
- prompt
- extracted prompt variables
- output schema
- optional explicit model configuration
It does not define **which** live objects are evaluated. That is the job of `evaluation-rules`.
For agent clients, the most important fields are:
- `variables`: use these exact names when building the evaluation-rule `mapping` array
- `outputDefinition`: tells you the expected score type and the evaluator's response instructions
- `modelConfig`: tells you whether the evaluator uses the project default model (`null`) or an explicit provider/model
Versioning behavior:
- `GET /evaluators` returns the latest version of each available evaluator.
- `GET /evaluators/{id}` can return an older version.
- Evaluation rules always run against the latest version for the selected evaluator name within the same source (`project` or `managed`).
properties:
id:
type: string
docs: Identifier of this evaluator.
name:
type: string
docs: Evaluator name.
version:
type: integer
docs: Version number of this evaluator.
scope:
type: commons.EvaluatorScope
docs: "Where this evaluator comes from: your project or Langfuse-managed defaults."
type:
type: commons.EvaluatorType
docs: Evaluator engine type. Currently always `llm_as_judge`.
prompt:
type: string
docs: Prompt template used during evaluation.
variables:
type: list<string>
docs: |
Variables extracted from the evaluator prompt.
Every variable in this list must be mapped exactly once when creating an evaluation rule.
outputDefinition:
type: commons.PublicEvaluatorOutputDefinition
docs: |
Structured output schema returned by this evaluator.
Responses always include `dataType` and omit the internal output-definition `version`.
Use `dataType` to decide how future scores should be interpreted.
modelConfig:
type: nullable<commons.EvaluatorModelConfig>
docs: Explicit model configuration, or `null` when the project default evaluation model is used.
evaluationRuleCount:
type: integer
docs: Number of evaluation rules in the project that currently use this evaluator version.
createdAt:
type: datetime
docs: Timestamp when this evaluator was created.
updatedAt:
type: datetime
docs: Timestamp when this evaluator was last updated.
Evaluators:
properties:
data:
type: list<Evaluator>
meta:
type: pagination.MetaResponse
CreateEvaluatorRequest:
docs: |
Request body for creating an evaluator.
If the same `name` already exists in your project, Langfuse creates the next version and returns it.
Existing evaluation rules in the same project are then moved to that new latest version automatically.
properties:
name:
type: string
docs: Evaluator name within the authenticated project.
prompt:
type: string
docs: Prompt template used by the evaluator.
outputDefinition:
type: commons.EvaluatorOutputDefinition
docs: |
Structured output schema the evaluator must return.
Always send `dataType`.
Do not send `version`; it is an internal storage detail and not part of the public request contract.
modelConfig:
type: optional<nullable<commons.EvaluatorModelConfig>>
docs: Optional explicit model configuration. Omit or set to `null` to use the project default evaluation model.
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "langfuse",
"version": "3.167.4",
"version": "3.171.0",
"author": "engineering@langfuse.com",
"license": "MIT",
"private": true,
+1
View File
@@ -95,6 +95,7 @@ export default [
},
],
"react/jsx-key": ["error", { warnOnDuplicates: true }],
"react/no-unused-prop-types": "warn",
},
},
];
-1
View File
@@ -27,7 +27,6 @@
"isolatedModules": true,
"jsx": "preserve",
"types": [
"jest",
"node"
],
},
+4
View File
@@ -25,11 +25,15 @@ Use root [AGENTS.md](../../AGENTS.md) for monorepo-level rules.
- Main exports: `src/index.ts`
- DB clients and types: `src/db.ts`
- Server exports: `src/server/index.ts`
- Server cache utilities: `src/server/cache/*`
- Domain model types: `src/domain/*`
- Repository layer: `src/server/repositories/*`
- Queue payload schemas: `src/server/queues.ts`
- Queue helpers: `src/server/redis/*`
- Postgres schema: `prisma/schema.prisma`
- For unstable public eval APIs, the public `evaluatorId` is currently the
exact `EvalTemplate.id`. Latest-version family grouping is derived from
`(projectId, name)` rather than stored on extra evaluator identity fields.
- Prisma migrations: `prisma/migrations/*`
- ClickHouse migrations: `clickhouse/migrations/{clustered,unclustered}/*`
- Seeder and support scripts: `scripts/seeder/*`, `clickhouse/scripts/*`
@@ -372,7 +372,8 @@ CREATE TABLE IF NOT EXISTS events_core
INDEX idx_session_id session_id TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_created_at created_at TYPE minmax GRANULARITY 1,
INDEX idx_updated_at updated_at TYPE minmax GRANULARITY 1,
INDEX idx_provided_model_name provided_model_name TYPE bloom_filter(0.01) GRANULARITY 2
INDEX idx_provided_model_name provided_model_name TYPE bloom_filter(0.01) GRANULARITY 2,
INDEX idx_experiment_id experiment_id TYPE bloom_filter(0.01) GRANULARITY 1
)
ENGINE = ReplacingMergeTree(event_ts, is_deleted)
PARTITION BY toYYYYMM(start_time)
@@ -456,6 +457,52 @@ SELECT
is_deleted
FROM events_full;
-- Diagnostic table to track event size distributions across projects.
-- Every insert (including updates) produces a row — no deduplication.
-- See LFE-9402 for context.
CREATE TABLE IF NOT EXISTS ingestion_size_stats (
project_id String,
trace_id String,
span_id String,
created_at DateTime64(3),
input_size UInt64,
output_size UInt64,
metadata_size UInt64,
total_size UInt64
) ENGINE = MergeTree
PRIMARY KEY (toStartOfHour(created_at), project_id)
ORDER BY (toStartOfHour(created_at), project_id, trace_id, span_id, created_at);
-- MV: observations -> ingestion_size_stats
CREATE MATERIALIZED VIEW IF NOT EXISTS ingestion_size_stats_observations_mv
TO ingestion_size_stats AS
SELECT
project_id,
trace_id,
id AS span_id,
created_at,
length(coalesce(input, '')) AS input_size,
length(coalesce(output, '')) AS output_size,
arraySum(arrayMap(k -> length(k), mapKeys(metadata)))
+ arraySum(arrayMap(v -> length(v), mapValues(metadata))) AS metadata_size,
byteSize(*) AS total_size
FROM observations;
-- MV: traces -> ingestion_size_stats
CREATE MATERIALIZED VIEW IF NOT EXISTS ingestion_size_stats_traces_mv
TO ingestion_size_stats AS
SELECT
project_id,
id AS trace_id,
concat('t-', id) AS span_id,
created_at,
length(coalesce(input, '')) AS input_size,
length(coalesce(output, '')) AS output_size,
arraySum(arrayMap(k -> length(k), mapKeys(metadata)))
+ arraySum(arrayMap(v -> length(v), mapValues(metadata))) AS metadata_size,
byteSize(*) AS total_size
FROM traces;
CREATE VIEW analytics_events_core AS
SELECT
project_id,
+8 -5
View File
@@ -69,11 +69,11 @@
"ch:drop": "bash clickhouse/scripts/drop.sh",
"ch:dev-tables": "bash clickhouse/scripts/dev-tables.sh",
"ch:reset": "pnpm run ch:down && pnpm run ch:up && pnpm run ch:seed && pnpm run ch:dev-tables",
"ch:seed": "dotenv -e ../../.env -- ts-node -r tsconfig-paths/register -r dotenv/config --compiler-options '{\"module\":\"CommonJS\"}' scripts/seeder/seed-clickhouse.ts",
"ch:seed": "dotenv -e ../../.env -- ts-node -r dotenv/config --compiler-options '{\"module\":\"CommonJS\"}' scripts/seeder/seed-clickhouse.ts",
"load:setup": "dotenv -e ../../.env -- tsx scripts/seeder/load-seed-clickhouse.ts"
},
"prisma": {
"seed": "ts-node -r tsconfig-paths/register -r dotenv/config --compiler-options {\"module\":\"CommonJS\"} scripts/seeder/seed-postgres.ts"
"seed": "ts-node -r dotenv/config --compiler-options {\"module\":\"CommonJS\"} scripts/seeder/seed-postgres.ts"
},
"dependencies": {
"@anthropic-ai/tokenizer": "^0.0.4",
@@ -100,20 +100,23 @@
"ajv": "^8.18.0",
"ajv-formats": "^3.0.1",
"bcryptjs": "^2.4.3",
"bullmq": "^5.34.10",
"bullmq": "^5.73.5",
"date-fns": "^3.6.0",
"dd-trace": "^5.65.0",
"dd-trace": "5.97.0",
"decimal.js": "^10.4.3",
"exponential-backoff": "^3.1.2",
"ioredis": "^5.8.2",
"ioredis": "^5.10.1",
"ipaddr.js": "^2.2.0",
"jsonpath-plus": "10.3.0",
"langchain": "^1.3.0",
"langfuse-langchain": "3.38.20",
"lodash": "^4.18.1",
"lossless-json": "^4.1.1",
"lru-cache": "^11.2.7",
"next-auth": "^4.24.13",
"nodemailer": "^7.0.11",
"oci-common": "^2.125.0",
"oci-objectstorage": "^2.125.0",
"safe-regex2": "^5.0.0",
"undici": "^7.24.6",
"uuid": "^9.0.1",
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "datasets" ADD COLUMN "remote_experiment_enabled" BOOLEAN NOT NULL DEFAULT true;
+4 -3
View File
@@ -585,6 +585,7 @@ model Dataset {
metadata Json?
remoteExperimentUrl String? @map("remote_experiment_url")
remoteExperimentPayload Json? @map("remote_experiment_payload")
remoteExperimentEnabled Boolean @default(true) @map("remote_experiment_enabled")
inputSchema Json? @map("input_schema") @db.Json
expectedOutputSchema Json? @map("expected_output_schema") @db.Json
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
@@ -915,9 +916,9 @@ model EvalTemplate {
projectId String? @map("project_id")
project Project? @relation(fields: [projectId], references: [id], onDelete: Cascade)
name String
version Int
prompt String
name String
version Int
prompt String
partner String? // e.g. "ragas", describes the partner that created the template
@@ -55,7 +55,6 @@ async function main() {
name: "Demo User",
email: "demo@langfuse.com",
password: await hash("password", 12),
featureFlags: ["experimentsV4Enabled"],
},
create: {
id: seedUserId1,
@@ -63,7 +62,6 @@ async function main() {
email: "demo@langfuse.com",
password: await hash("password", 12),
image: "https://static.langfuse.com/langfuse-dev%2Fexample-avatar.png",
featureFlags: ["experimentsV4Enabled"],
},
});
const user2 = await prisma.user.upsert({
+1 -1
View File
@@ -1 +1 @@
export const VERSION = "v3.167.4";
export const VERSION = "v3.171.0";
@@ -116,6 +116,7 @@ export const EventsObservationSchema = ObservationSchema.extend({
userId: z.string().nullable(),
sessionId: z.string().nullable(),
traceName: z.string().nullable(),
tags: z.array(z.string()).optional(),
bookmarked: z.boolean().optional(),
public: z.boolean().optional(),
});
@@ -7,6 +7,13 @@ export const ScoreConfigCategory = z.object({
value: z.number(),
});
/** Input-only schema for score config names. Use at API/tRPC boundaries, not for DB reads. */
export const ScoreConfigNameSchema = z
.string()
.min(1)
.max(35)
.regex(/^[\p{L}\p{N}_ .()-]+$/u, "Name contains invalid characters");
// Numeric config fields
export const NumericConfigFields = z.object({
maxValue: z.number().nullish(),
+29
View File
@@ -10,6 +10,35 @@ export const ScoreSourceEnum = {
export const ScoreSourceDomain = z.enum(ScoreSourceArray);
export type ScoreSourceType = z.infer<typeof ScoreSourceDomain>;
/**
* Source values external callers may set on the public create-score endpoint.
* EVAL is reserved for internal evaluator outputs. The `satisfies` clause
* keeps this a provable subset of {@link ScoreSourceArray} at compile time.
*/
export const PublicApiCreateScoreSourceDomain = z.enum([
ScoreSourceEnum.API,
ScoreSourceEnum.ANNOTATION,
] as const satisfies readonly ScoreSourceType[]);
/**
* Annotation scores need a matching score config so they can render in the
* annotation queue UI. CORRECTION scores are the one exception — by design
* they never carry a configId. This predicate + message are shared by the
* zod refine on {@link PostScoresBody} (sync 400 on REST) and the check in
* `validateAndInflateScore` (async drop for ingestion/SDK callers).
*/
export const ANNOTATION_SCORE_REQUIRES_CONFIG_ID_MESSAGE =
"configId is required when source is ANNOTATION (except for CORRECTION scores).";
export const isAnnotationScoreMissingConfigId = (body: {
source?: ScoreSourceType | null;
configId?: string | null;
dataType?: ScoreDataTypeType;
}): boolean =>
body.source === ScoreSourceEnum.ANNOTATION &&
!body.configId &&
body.dataType !== ScoreDataTypeEnum.CORRECTION;
export const CORRECTION_NAME = "output" as const;
export const TEXT_SCORE_MAX_LENGTH = 500 as const;
@@ -5,6 +5,7 @@ import z from "zod";
export enum TableViewPresetTableName {
Traces = "traces",
Observations = "observations",
ObservationsEvents = "observations-events",
Scores = "scores",
Sessions = "sessions",
SessionDetail = "session-detail",
@@ -13,8 +14,7 @@ export enum TableViewPresetTableName {
ExperimentItems = "experiment-items",
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const TableViewPresetDomainSchema = z.object({
export const TableViewPresetDomainSchema = z.object({
id: z.string(),
projectId: z.string().nullable(),
createdAt: z.date(),
@@ -25,7 +25,7 @@ const TableViewPresetDomainSchema = z.object({
filters: z.array(singleFilter),
columnOrder: z.array(z.string()),
columnVisibility: z.record(z.string(), z.boolean()),
searchQuery: z.string().optional(),
searchQuery: z.string().nullable(),
orderBy: orderBy,
});
+27
View File
@@ -57,6 +57,18 @@ const EnvSchema = z.object({
.optional(),
LANGFUSE_CACHE_MODEL_MATCH_ENABLED: z.enum(["true", "false"]).default("true"),
LANGFUSE_CACHE_MODEL_MATCH_TTL_SECONDS: z.coerce.number().default(86400), // 24 hours
LANGFUSE_LOCAL_CACHE_MODEL_MATCH_ENABLED: z
.enum(["true", "false"])
.default("false"),
LANGFUSE_LOCAL_CACHE_MODEL_MATCH_TTL_MS: z.coerce
.number()
.positive()
.default(10_000),
LANGFUSE_LOCAL_CACHE_MODEL_MATCH_MAX: z.coerce
.number()
.int()
.positive()
.default(20_000),
LANGFUSE_CACHE_PROMPT_ENABLED: z.enum(["true", "false"]).default("true"),
LANGFUSE_CACHE_PROMPT_TTL_SECONDS: z.coerce.number().default(3600), // 1h
CLICKHOUSE_URL: z.string().url(),
@@ -179,6 +191,21 @@ const EnvSchema = z.object({
.default("true"),
LANGFUSE_USE_GOOGLE_CLOUD_STORAGE: z.enum(["true", "false"]).default("false"),
LANGFUSE_GOOGLE_CLOUD_STORAGE_CREDENTIALS: z.string().optional(),
LANGFUSE_USE_OCI_NATIVE_OBJECT_STORAGE: z
.enum(["true", "false"])
.default("false"),
LANGFUSE_OCI_AUTH_TYPE: z
.enum([
"workload_identity",
"instance_principal",
"resource_principal",
"oci_profile",
"session_token",
])
.optional(),
LANGFUSE_OCI_CONFIG_FILE: z.string().optional(),
LANGFUSE_OCI_CONFIG_PROFILE: z.string().optional(),
NODE_EXTRA_CA_CERTS: z.string().optional(),
STRIPE_SECRET_KEY: z.string().optional(),
LANGFUSE_ENABLE_BLOB_STORAGE_FILE_LOG: z
+6
View File
@@ -324,4 +324,10 @@ export const eventsTableCols: ColumnDefinition[] = [
internal: "length(e.tool_calls)",
nullable: true,
},
{
name: "Is Experiment Item Root Span",
id: "isExperimentItemRootSpan",
type: "boolean",
internal: "e.experiment_item_root_span_id = e.span_id",
},
];
@@ -22,8 +22,22 @@ export type MappingError = {
message: string;
};
export type JsonPathMissInfo = {
sourceField: SourceField;
jsonPath: string;
mappingKey: string | null;
};
export type JsonPathErrorInfo = JsonPathMissInfo & { message: string };
export type FieldMappingResult = {
value: unknown;
misses: JsonPathMissInfo[];
errors: JsonPathErrorInfo[];
};
/**
* Test if a JSON path is valid against the given data
* Test if a JSONPath is valid against the given data
*/
export function testJsonPath(props: { jsonPath: string; data: unknown }): {
success: boolean;
@@ -43,7 +57,7 @@ export function testJsonPath(props: { jsonPath: string; data: unknown }): {
}
/**
* Evaluate a JSON path against the given data and return the result
* Evaluate a JSONPath against the given data and return the result
*/
export function evaluateJsonPath(data: unknown, jsonPath: string): unknown {
const parsed = typeof data === "string" ? parseJsonPrioritised(data) : data;
@@ -51,13 +65,14 @@ export function evaluateJsonPath(data: unknown, jsonPath: string): unknown {
path: jsonPath,
json: parsed as string | object,
wrap: false,
eval: false,
});
return result;
}
/**
* Check if a value is a JSON path (starts with $)
* Check if a value is a JSONPath (starts with $)
*/
export function isJsonPath(value: string): boolean {
return value.startsWith("$");
@@ -87,93 +102,116 @@ export function applyFieldMappingConfig(props: {
observation: ObservationData;
config: FieldMappingConfig;
defaultSourceField: SourceField;
onJsonPathMiss?: (info: {
sourceField: SourceField;
jsonPath: string;
mappingKey: string | null;
}) => void;
}): unknown {
const { observation, config, defaultSourceField, onJsonPathMiss } = props;
}): FieldMappingResult {
const { observation, config, defaultSourceField } = props;
const misses: JsonPathMissInfo[] = [];
const errors: JsonPathErrorInfo[] = [];
const safeEvaluate = (
sourceField: SourceField,
jsonPath: string,
mappingKey: string | null,
): { success: true; value: unknown } | { success: false } => {
try {
return {
success: true,
value: evaluateJsonPath(observation[sourceField], jsonPath),
};
} catch (error) {
errors.push({
sourceField,
jsonPath,
mappingKey,
message: error instanceof Error ? error.message : "Invalid JSONPath",
});
return { success: false };
}
};
const withValue = (value: unknown): FieldMappingResult => ({
value,
misses,
errors,
});
switch (config.mode) {
case "full":
// Return the full source field
return observation[defaultSourceField];
return withValue(observation[defaultSourceField]);
case "none":
// Return null (will be written as Prisma.DbNull)
return null;
// null is written as Prisma.DbNull
return withValue(null);
case "custom":
if (!config.custom) {
return observation[defaultSourceField];
}
case "custom": {
if (!config.custom) return withValue(observation[defaultSourceField]);
if (config.custom.type === "root") {
// Root mode: extract single value using JSON path
const rootConfig = config.custom.rootConfig;
if (!rootConfig) {
return observation[defaultSourceField];
}
if (!rootConfig) return withValue(observation[defaultSourceField]);
const sourceData = observation[rootConfig.sourceField];
const result = evaluateJsonPath(sourceData, rootConfig.jsonPath);
if (result === undefined && onJsonPathMiss) {
onJsonPathMiss({
const evaluated = safeEvaluate(
rootConfig.sourceField,
rootConfig.jsonPath,
null,
);
if (!evaluated.success) return withValue(undefined);
if (evaluated.value === undefined) {
misses.push({
sourceField: rootConfig.sourceField,
jsonPath: rootConfig.jsonPath,
mappingKey: null,
});
}
return result;
return withValue(evaluated.value);
}
if (config.custom.type === "keyValueMap") {
// Key-value map mode: build object from entries
// Supports dot notation for nested objects (e.g., "context.user_id")
const keyValueMapConfig = config.custom.keyValueMapConfig;
if (!keyValueMapConfig || keyValueMapConfig.entries.length === 0) {
return observation[defaultSourceField];
return withValue(observation[defaultSourceField]);
}
const result: Record<string, unknown> = {};
for (const entry of keyValueMapConfig.entries) {
// Skip entries with empty values
if (!entry.value && entry.value !== "") {
continue;
}
if (!entry.value && entry.value !== "") continue;
let resolvedValue: unknown;
if (isJsonPath(entry.value)) {
// It's a JSON path - evaluate it
const sourceData = observation[entry.sourceField];
resolvedValue = evaluateJsonPath(sourceData, entry.value);
if (resolvedValue === undefined && onJsonPathMiss) {
onJsonPathMiss({
sourceField: entry.sourceField,
jsonPath: entry.value,
mappingKey: entry.key,
});
const evaluated = safeEvaluate(
entry.sourceField,
entry.value,
entry.key,
);
if (!evaluated.success) {
resolvedValue = undefined;
} else {
resolvedValue = evaluated.value;
if (resolvedValue === undefined) {
misses.push({
sourceField: entry.sourceField,
jsonPath: entry.value,
mappingKey: entry.key,
});
}
}
} else {
// It's a literal string (including empty string)
resolvedValue = entry.value;
}
// Use dot notation path setter for nested objects
if (entry.key.includes(".")) {
setNestedValue(result, entry.key, resolvedValue);
} else {
result[entry.key] = resolvedValue;
}
}
return result;
return withValue(result);
}
return observation[defaultSourceField];
return withValue(observation[defaultSourceField]);
}
default:
return observation[defaultSourceField];
return withValue(observation[defaultSourceField]);
}
}
@@ -213,47 +251,45 @@ export function applyFullMapping(props: {
const results: Record<string, unknown> = {};
for (const field of fields) {
const onJsonPathMiss = (info: {
sourceField: SourceField;
jsonPath: string;
mappingKey: string | null;
}) => {
errors.push({
type: "json_path_miss",
targetField: field.key,
sourceField: info.sourceField,
jsonPath: info.jsonPath,
mappingKey: info.mappingKey,
message: `JSON path "${info.jsonPath}" did not match any data in "${info.sourceField}"${info.mappingKey ? ` (key: "${info.mappingKey}")` : ""}`,
});
};
try {
results[field.key] = applyFieldMappingConfig({
const result = applyFieldMappingConfig({
observation,
config: field.config,
defaultSourceField: field.defaultSourceField,
onJsonPathMiss,
});
} catch (error) {
// Capture rare JSONPath evaluation errors (e.g. malformed filter expressions)
const sourceField =
field.config.mode === "custom" && field.config.custom?.type === "root"
? (field.config.custom.rootConfig?.sourceField ??
field.defaultSourceField)
: field.defaultSourceField;
const jsonPath =
field.config.mode === "custom" && field.config.custom?.type === "root"
? (field.config.custom.rootConfig?.jsonPath ?? "")
: "";
results[field.key] = result.value;
for (const miss of result.misses) {
errors.push({
type: "json_path_miss",
targetField: field.key,
sourceField: miss.sourceField,
jsonPath: miss.jsonPath,
mappingKey: miss.mappingKey,
message: `JSONPath "${miss.jsonPath}" did not match any data in "${miss.sourceField}"${miss.mappingKey ? ` (key: "${miss.mappingKey}")` : ""}`,
});
}
for (const err of result.errors) {
errors.push({
type: "json_path_error",
targetField: field.key,
sourceField: err.sourceField,
jsonPath: err.jsonPath,
mappingKey: err.mappingKey,
message: `JSONPath evaluation error for "${field.key}"${err.mappingKey ? ` (key: "${err.mappingKey}")` : ""}: ${err.message}`,
});
}
} catch (error) {
// Isolate per-field faults so a throw from one mapping doesn't abort
// the remaining fields on the same observation.
errors.push({
type: "json_path_error",
targetField: field.key,
sourceField,
jsonPath,
sourceField: field.defaultSourceField,
jsonPath: "",
mappingKey: null,
message: `JSON path evaluation error for "${field.key}": ${error instanceof Error ? error.message : "Unknown error"}`,
message: `JSONPath evaluation error for "${field.key}": ${error instanceof Error ? error.message : "Unknown error"}`,
});
results[field.key] = undefined;
}
@@ -268,7 +304,7 @@ export function applyFullMapping(props: {
}
/**
* Generate autocomplete suggestions for JSON paths based on the data structure
* Generate autocomplete suggestions for JSONPaths based on the data structure
*/
export function generateJsonPathSuggestions(
data: unknown,
@@ -25,6 +25,7 @@ export enum ActionId {
ObservationAddToAnnotationQueue = "observation-add-to-annotation-queue",
ObservationAddToDataset = "observation-add-to-dataset",
ObservationBatchEvaluation = "observation-run-batched-evaluation",
ExperimentCompare = "experiment-compare",
}
const ActionIdSchema = z.nativeEnum(ActionId);
@@ -12,6 +12,35 @@ export type EvalTargetObject =
export const EvalTargetObjectSchema = z.enum(Object.values(EvalTargetObject));
// Batch action source tables that support evaluation
export const BatchEvalSourceTable = {
EVENTS: "events",
EXPERIMENT_ITEMS: "experiment-items",
EXPERIMENTS: "experiments",
} as const;
export type BatchEvalSourceTable =
(typeof BatchEvalSourceTable)[keyof typeof BatchEvalSourceTable];
export const BatchEvalSourceTableSchema = z.enum([
BatchEvalSourceTable.EVENTS,
BatchEvalSourceTable.EXPERIMENT_ITEMS,
BatchEvalSourceTable.EXPERIMENTS,
]);
/**
* Maps a batch evaluation source table to its corresponding eval target object.
* - "events" → EvalTargetObject.EVENT (observation-scoped evaluators)
* - "experiment-items" / "experiments" → EvalTargetObject.EXPERIMENT (experiment-scoped evaluators)
*/
export function getEvalTargetObjectFromSourceTable(
sourceTable: BatchEvalSourceTable,
): EvalTargetObject {
return sourceTable === BatchEvalSourceTable.EVENTS
? EvalTargetObject.EVENT
: EvalTargetObject.EXPERIMENT;
}
export const langfuseObjects = [
"trace",
"span",
+23 -11
View File
@@ -53,14 +53,24 @@ function parseMultiEncodedJson(value: unknown): unknown {
}
function parseJsonDefault(selectedColumn: unknown, jsonSelector: string) {
// selectedColumn should already be preprocessed by preprocessObjectWithJsonFields
// so we can directly use it with JSONPath
// JSONPath can only query objects/arrays — return primitives as-is
if (typeof selectedColumn !== "object" || selectedColumn === null) {
return selectedColumn;
}
const result = JSONPath({
path: jsonSelector,
json: selectedColumn as any, // JSONPath accepts unknown but types are strict
eval: false,
});
return Array.isArray(result) && result.length > 0 ? result[0] : undefined;
if (!Array.isArray(result) || result.length === 0) {
return undefined;
}
// For single-match queries (e.g. $.name), return the unwrapped value.
// For multi-match queries (e.g. $[1:], $[*].name), return the full array.
return result.length === 1 ? result[0] : result;
}
export function extractValueFromObject(
@@ -69,12 +79,7 @@ export function extractValueFromObject(
jsonSelector?: string,
parseJson?: (selectedColumn: unknown, jsonSelector: string) => unknown,
): { value: string; error: Error | null } {
let selectedColumn = obj[selectedColumnId];
// Simple preprocessing: attempt to parse to valid JSON object
if (typeof selectedColumn === "string") {
selectedColumn = parseMultiEncodedJson(selectedColumn);
}
const selectedColumn = obj[selectedColumnId];
const jsonParser = parseJson || parseJsonDefault;
@@ -82,14 +87,21 @@ export function extractValueFromObject(
let error: Error | null = null;
if (jsonSelector && selectedColumn) {
// Only parse multi-encoded JSON when a selector is present — avoids
// mutating formatting (e.g. whitespace) for the no-selector passthrough.
const parsed =
typeof selectedColumn === "string"
? parseMultiEncodedJson(selectedColumn)
: selectedColumn;
try {
jsonSelectedColumn = jsonParser(selectedColumn, jsonSelector);
jsonSelectedColumn = jsonParser(parsed, jsonSelector);
} catch (err) {
error =
err instanceof Error
? err
: new Error("There was an unknown error parsing the JSON");
jsonSelectedColumn = selectedColumn; // Fallback to original value
jsonSelectedColumn = selectedColumn; // Fallback to raw original value
}
} else {
jsonSelectedColumn = selectedColumn;
@@ -4,8 +4,12 @@ import { stringDateTime } from "../../../../utils/typeChecks";
import { applyScoreValidation } from "../../../../utils/scores";
import { PostScoreBodyFoundationSchema } from "../shared";
import {
ANNOTATION_SCORE_REQUIRES_CONFIG_ID_MESSAGE,
isAnnotationScoreMissingConfigId,
PublicApiCreateScoreSourceDomain,
ScoreDataTypeDomain,
ScoreSourceDomain,
ScoreSourceEnum,
TEXT_SCORE_MAX_LENGTH,
} from "../../../../domain/scores";
import { singleFilter } from "../../../../interfaces/filters";
@@ -75,11 +79,12 @@ export const GetScoresQuery = z.object({
});
// POST /scores
/**
* PostScoresBody is copied for the ingestion API as `ScoreBody`. Please copy any changes here in `packages/shared/src/features/ingestion/types.ts`
*/
// Roughly mirrors ScoreBody in `packages/shared/src/server/ingestion/types.ts`;
// keep them in sync for fields that cross both surfaces.
export const PostScoresBody = applyScoreValidation(
PostScoreBodyFoundationSchema.and(
PostScoreBodyFoundationSchema.extend({
source: PublicApiCreateScoreSourceDomain.default(ScoreSourceEnum.API),
}).and(
z.discriminatedUnion("dataType", [
z.object({
value: z.number(),
@@ -116,7 +121,10 @@ export const PostScoresBody = applyScoreValidation(
}),
]),
),
);
).refine((data) => !isAnnotationScoreMissingConfigId(data), {
message: ANNOTATION_SCORE_REQUIRES_CONFIG_ID_MESSAGE,
path: ["configId"],
});
export const PostScoresResponse = z.object({ id: z.string() });
@@ -11,12 +11,25 @@ export const VERTEXAI_USE_DEFAULT_CREDENTIALS =
export const BedrockConfigSchema = z.object({ region: z.string() });
export type BedrockConfig = z.infer<typeof BedrockConfigSchema>;
export const BedrockCredentialSchema = z
export const BedrockAccessKeysSchema = z
.object({
accessKeyId: z.string(),
secretAccessKey: z.string(),
accessKeyId: z.string().min(1),
secretAccessKey: z.string().min(1),
})
.optional();
.strict();
export type BedrockAccessKeys = z.infer<typeof BedrockAccessKeysSchema>;
export const BedrockApiKeySchema = z
.object({
apiKey: z.string().min(1),
})
.strict();
export type BedrockApiKey = z.infer<typeof BedrockApiKeySchema>;
export const BedrockCredentialSchema = z.union([
BedrockAccessKeysSchema,
BedrockApiKeySchema,
]);
export type BedrockCredential = z.infer<typeof BedrockCredentialSchema>;
export const VertexAIConfigSchema = z
+1
View File
@@ -0,0 +1 @@
export * from "./localCache";
+172
View File
@@ -0,0 +1,172 @@
import { LRUCache } from "lru-cache";
import { logger } from "../logger";
import { recordGauge, recordIncrement } from "../instrumentation";
export type LocalCacheLoadResult<V> = {
value: V | undefined;
ttlMs?: number;
source?: string;
};
export type LocalCacheConfig = {
namespace: string;
enabled: boolean;
ttlMs: number;
max: number;
};
export class LocalCache<V extends {}> {
private readonly config: LocalCacheConfig;
private readonly cache: LRUCache<string, V>;
constructor(config: LocalCacheConfig) {
this.config = config;
const dispose: LRUCache.Disposer<string, V> = (_value, _key, reason) => {
if (reason === "evict") {
this.record("evict");
this.recordSizeMetrics();
}
};
const baseOptions = {
ttlAutopurge: false as const,
allowStale: false as const,
updateAgeOnGet: false as const,
updateAgeOnHas: false as const,
dispose,
};
this.cache = new LRUCache<string, V>({
...baseOptions,
ttl: config.ttlMs,
max: config.max,
});
this.logInfo("Initialized local cache", {
enabled: config.enabled,
ttlMs: config.ttlMs,
max: config.max,
});
}
get(key: string): V | undefined {
if (!this.config.enabled) {
return undefined;
}
const value = this.cache.get(key);
this.record(value === undefined ? "miss" : "hit");
this.logDebug(
value === undefined ? "Local cache miss" : "Local cache hit",
{
size: this.cache.size,
keyLength: key.length,
},
);
return value;
}
set(key: string, value: V): void {
if (!this.config.enabled) {
return;
}
const ttlMs = this.config.ttlMs;
try {
this.cache.set(key, value, { ttl: ttlMs });
this.record("set");
this.recordSizeMetrics();
this.logDebug("Stored local cache entry", {
ttlMs,
size: this.cache.size,
keyLength: key.length,
});
} catch (error) {
logger.error(
`Failed to set local cache entry for namespace ${this.config.namespace}`,
error,
);
}
}
clear(): void {
this.cache.clear();
this.record("clear");
this.recordSizeMetrics();
this.logDebug("Cleared local cache");
}
async getOrLoad(
key: string,
loader: () => Promise<LocalCacheLoadResult<V>>,
): Promise<LocalCacheLoadResult<V>> {
const cached = this.get(key);
if (cached !== undefined) {
return { value: cached, source: "local" };
}
if (!this.config.enabled) {
this.logDebug("Bypassing disabled local cache", {
keyLength: key.length,
});
return loader();
}
const result = await loader();
this.logDebug("Completed local cache load", {
source: result.source ?? "unknown",
cacheable: result.value !== undefined,
ttlMs: result.ttlMs ?? null,
keyLength: key.length,
});
if (result.value !== undefined) {
this.set(key, result.value);
}
return result;
}
private record(metric: string): void {
recordIncrement(`langfuse.local_cache.${metric}`, 1, {
namespace: this.config.namespace,
});
}
private recordSizeMetrics(): void {
recordGauge("langfuse.local_cache.size_entries", this.cache.size, {
namespace: this.config.namespace,
});
}
private logDebug(message: string, metadata?: Record<string, unknown>): void {
if (!logger.isLevelEnabled("debug")) {
return;
}
const formattedMetadata =
metadata === undefined ? "" : ` ${safeSerialize(metadata)}`;
logger.debug(
`[LocalCache:${this.config.namespace}] ${message}${formattedMetadata}`,
);
}
private logInfo(message: string, metadata?: Record<string, unknown>): void {
const formattedMetadata =
metadata === undefined ? "" : ` ${safeSerialize(metadata)}`;
logger.info(
`[LocalCache:${this.config.namespace}] ${message}${formattedMetadata}`,
);
}
}
const safeSerialize = (value: unknown): string => {
try {
return JSON.stringify(value);
} catch {
return "[unserializable]";
}
};
+2
View File
@@ -1,4 +1,5 @@
export * from "./services/StorageService";
export * from "./cache";
export * from "./services/BufferedStreamUploader";
export * from "./services/S3ChunkedUploadStrategy";
export * from "./services/email/organizationInvitation/sendMembershipInvitationEmail";
@@ -28,6 +29,7 @@ export * from "./llm/fetchLLMCompletion";
export * from "./llm/errors";
export * from "./llm/utils";
export * from "./llm/types";
export * from "./llm/internalTraceEvents";
export * from "./llm/compileChatMessages";
export * from "./llm/testModelCall";
export * from "./llm/baseUrlValidation";
@@ -8,6 +8,7 @@ import {
safeMultiDel,
scanKeys,
} from "../";
import { LocalCache } from "../cache";
import { env } from "../../env";
import { Decimal } from "decimal.js";
import { prisma } from "../../db";
@@ -24,6 +25,22 @@ export type ModelWithPrices = {
};
const MODEL_MATCH_CACHE_LOCKED_KEY = "LOCK:model-match-clear";
const DEFAULT_LOCAL_CACHE_MODEL_MATCH_TTL_MS = 10_000;
const DEFAULT_LOCAL_CACHE_MODEL_MATCH_MAX = 20_000;
// This L1 cache is intentionally TTL-only. Cross-container consistency continues
// to come from Redis invalidation plus the short local TTL.
const modelMatchLocalCache = new LocalCache<ModelWithPrices>({
namespace: "model_match",
enabled: env.LANGFUSE_LOCAL_CACHE_MODEL_MATCH_ENABLED === "true",
ttlMs: getPositiveNumberOrDefault(
env.LANGFUSE_LOCAL_CACHE_MODEL_MATCH_TTL_MS,
DEFAULT_LOCAL_CACHE_MODEL_MATCH_TTL_MS,
),
max: getPositiveNumberOrDefault(
env.LANGFUSE_LOCAL_CACHE_MODEL_MATCH_MAX,
DEFAULT_LOCAL_CACHE_MODEL_MATCH_MAX,
),
});
export async function findModel(p: ModelMatchProps): Promise<ModelWithPrices> {
return instrumentAsync(
@@ -33,66 +50,132 @@ export async function findModel(p: ModelMatchProps): Promise<ModelWithPrices> {
},
async (span) => {
if (logger.isLevelEnabled("debug")) {
logger.debug(`Finding model for ${JSON.stringify(p)}`);
}
const cachedResult = await getModelWithPricesFromRedis(p);
if (cachedResult) {
span.setAttribute("model_match_source", "redis");
if (cachedResult.model === null) {
return { model: null, pricingTiers: [] };
} else {
logger.debug(
`Found model name ${cachedResult.model?.modelName} (id: ${cachedResult.model?.id}) for project ${p.projectId} and model ${p.model}`,
);
span.setAttribute("matched_model_id", cachedResult.model.id);
}
return cachedResult;
}
// try to find model in Postgres
const postgresModel = await findModelInPostgres(p);
if (postgresModel && env.LANGFUSE_CACHE_MODEL_MATCH_ENABLED === "true") {
const pricingTiers = await findPricingTiersForModel(postgresModel.id);
await addModelWithPricingTiersToRedis(p, postgresModel, pricingTiers);
span.setAttribute("matched_model_id", postgresModel.id);
span.setAttribute("model_match_source", "postgres");
span.setAttribute("model_cache_set", "true");
logger.debug(
`Found model name ${postgresModel?.modelName} (id: ${postgresModel?.id}) for project ${p.projectId} and model ${p.model}`,
formatModelMatchDebugMessage("Resolving model match", {
projectId: p.projectId,
model: p.model,
localCacheEnabled:
env.LANGFUSE_LOCAL_CACHE_MODEL_MATCH_ENABLED === "true",
redisCacheEnabled:
env.LANGFUSE_CACHE_MODEL_MATCH_ENABLED === "true",
}),
);
return { model: postgresModel, pricingTiers };
} else if (postgresModel) {
const pricingTiers = await findPricingTiersForModel(postgresModel.id);
span.setAttribute("matched_model_id", postgresModel.id);
span.setAttribute("model_match_source", "postgres");
span.setAttribute("model_cache_set", "false");
}
const localCacheKey = getRedisModelKey(p);
const { source, value } = await modelMatchLocalCache.getOrLoad(
localCacheKey,
async () => {
const cachedResult = await getModelWithPricesFromRedis(p);
if (cachedResult) {
return {
value: cachedResult,
source: "redis",
};
}
logger.debug(
`Found model name ${postgresModel?.modelName} (id: ${postgresModel?.id}) for project ${p.projectId} and model ${p.model}`,
);
return { model: postgresModel, pricingTiers };
} else {
span.setAttribute("model_match_source", "none");
const postgresModel = await findModelInPostgres(p);
if (postgresModel) {
const pricingTiers = await findPricingTiersForModel(
postgresModel.id,
);
if (env.LANGFUSE_CACHE_MODEL_MATCH_ENABLED === "true") {
await addModelNotFoundTokenToRedis(p);
if (env.LANGFUSE_CACHE_MODEL_MATCH_ENABLED === "true") {
await addModelWithPricingTiersToRedis(
p,
postgresModel,
pricingTiers,
);
}
return {
value: { model: postgresModel, pricingTiers },
source: "postgres",
};
}
if (env.LANGFUSE_CACHE_MODEL_MATCH_ENABLED === "true") {
await addModelNotFoundTokenToRedis(p);
}
return {
value: { model: null, pricingTiers: [] },
source: "none",
};
},
);
if (!value || value.model === null) {
span.setAttribute("model_match_source", source ?? "none");
if (
source === "none" &&
env.LANGFUSE_CACHE_MODEL_MATCH_ENABLED === "true"
) {
span.setAttribute("model_cache_set", "true");
}
logger.debug(
`Model not found for project ${p.projectId} and model ${p.model}`,
);
if (logger.isLevelEnabled("debug")) {
logger.debug(
formatModelMatchDebugMessage(
"Model match resolved without a model",
{
projectId: p.projectId,
model: p.model,
source: source ?? "none",
pricingTierCount: 0,
},
),
);
}
return { model: null, pricingTiers: [] };
}
span.setAttribute("model_match_source", source ?? "unknown");
span.setAttribute("matched_model_id", value.model.id);
if (source === "postgres") {
span.setAttribute(
"model_cache_set",
String(env.LANGFUSE_CACHE_MODEL_MATCH_ENABLED === "true"),
);
}
if (logger.isLevelEnabled("debug")) {
logger.debug(
formatModelMatchDebugMessage("Model match resolved", {
projectId: p.projectId,
model: p.model,
source: source ?? "unknown",
matchedModelId: value.model.id,
matchedModelName: value.model.modelName,
pricingTierCount: value.pricingTiers.length,
}),
);
}
return value;
},
);
}
const formatModelMatchDebugMessage = (
message: string,
metadata: Record<string, unknown>,
): string => {
try {
return `${message} ${JSON.stringify(metadata)}`;
} catch {
return `${message} [unserializable]`;
}
};
function getPositiveNumberOrDefault(value: unknown, fallback: number): number {
const parsed = Number(value);
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
}
export const clearModelMatchLocalCache = (): void => {
modelMatchLocalCache.clear();
};
const getModelWithPricesFromRedis = async (
p: ModelMatchProps,
): Promise<ModelWithPrices | null> => {
@@ -1,4 +1,6 @@
import {
ANNOTATION_SCORE_REQUIRES_CONFIG_ID_MESSAGE,
isAnnotationScoreMissingConfigId,
ScoreBodyWithoutConfig,
ScoreConfigDomain,
type ScoreDataTypeType,
@@ -23,6 +25,13 @@ export async function validateAndInflateScore(
) {
const { body, projectId, scoreId } = params;
// Central choke point: both POST /api/public/scores and
// POST /api/public/ingestion enqueue events that run through this function
// in the worker, so enforcing here covers both entry points.
if (isAnnotationScoreMissingConfigId(body)) {
throw new InvalidRequestError(ANNOTATION_SCORE_REQUIRES_CONFIG_ID_MESSAGE);
}
if (body.configId) {
const config = await prisma.scoreConfig.findFirst({
where: {
@@ -9,6 +9,31 @@ import { logger } from "../logger";
// type CallbackFn<T> = () => T;
/**
* IORedis request hook that records the full Redis command as a span attribute.
* Redacts credentials from AUTH/HELLO and values from API key cache operations.
*/
export function ioredisRequestHook(
span: opentelemetry.Span,
{ cmdName, cmdArgs }: { cmdName: string; cmdArgs: unknown[] },
): void {
if (!Array.isArray(cmdArgs) || cmdArgs.length === 0) return;
const cmd = cmdName.toUpperCase();
// AUTH and HELLO carry raw credentials — redact all args
if (cmd === "AUTH" || cmd === "HELLO") {
span.setAttribute("redis.full_command", `${cmdName} [REDACTED]`);
return;
}
const args = [...cmdArgs].map(String);
// Redact API key cache values: SET [prefix:]api-key:{hash} <json>
if (args[0]?.includes("api-key:")) {
for (let i = 1; i < args.length; i++) {
args[i] = "[REDACTED]";
}
}
span.setAttribute("redis.full_command", `${cmdName} ${args.join(" ")}`);
}
export type TCarrier = {
traceparent?: string;
tracestate?: string;
@@ -263,6 +288,25 @@ const flushMetricsToCloudWatch = () => {
});
};
// Metrics ending with these suffixes have their tags flattened into the
// CloudWatch metric name (excluding "unit"). Other metrics are unaffected.
const CW_TAG_FLATTENED_SUFFIXES = [".depth", ".rate"];
function buildCloudWatchKey(
stat: string,
tags?: { [tag: string]: string | number },
): string {
if (!tags || !CW_TAG_FLATTENED_SUFFIXES.some((s) => stat.endsWith(s))) {
return stat;
}
const suffix = Object.entries(tags)
.filter(([k]) => k !== "unit")
.sort(([a], [b]) => a.localeCompare(b))
.map(([k, v]) => `${k}_${v}`)
.join(".");
return suffix ? `${stat}.${suffix}` : stat;
}
export const recordGauge = (
stat: string,
value?: number | undefined,
@@ -273,7 +317,7 @@ export const recordGauge = (
| undefined,
) => {
if (env.ENABLE_AWS_CLOUDWATCH_METRIC_PUBLISHING === "true") {
sendCloudWatchMetric(stat, value ?? 0, true);
sendCloudWatchMetric(buildCloudWatchKey(stat, tags), value ?? 0, true);
}
dd.dogstatsd.gauge(stat, value, tags);
};
@@ -284,7 +328,7 @@ export const recordIncrement = (
tags?: { [tag: string]: string | number } | undefined,
) => {
if (env.ENABLE_AWS_CLOUDWATCH_METRIC_PUBLISHING === "true") {
sendCloudWatchMetric(stat, value ?? 1, false);
sendCloudWatchMetric(buildCloudWatchKey(stat, tags), value ?? 1, false);
}
dd.dogstatsd.increment(stat, value, tags);
};
@@ -19,6 +19,7 @@ import { IterableReadableStream } from "@langchain/core/utils/stream";
import { ChatOpenAI, AzureChatOpenAI } from "@langchain/openai";
import { env } from "../../env";
import GCPServiceAccountKeySchema, {
BedrockAccessKeysSchema,
BedrockConfigSchema,
BedrockCredentialSchema,
VertexAIConfigSchema,
@@ -53,6 +54,14 @@ import { LLMCompletionError } from "./errors";
export type CompletionWithReasoning = { text: string; reasoning?: string };
const NON_RETRYABLE_LLM_ERROR_PATTERNS = [
"Request timed out",
"is not valid JSON",
"Unterminated string in JSON at position",
"TypeError",
"reached the end of its life",
] as const;
const isLangfuseCloud = Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION);
// Maps adapters to the content block types that represent "thinking".
@@ -90,6 +99,52 @@ const googleProviderOptionsSchema = z
})
.optional();
// For using Bedrock API key in Bearer token format
const createBedrockBearerAuth = (token: string) => ({
clientOptions: {
token: { token },
authSchemePreference: ["httpBearerAuth"],
},
});
export function resolveBedrockAuth(params: {
secretKey: string;
allowDefaultCredentials: boolean;
}): {
credentials?: z.infer<typeof BedrockAccessKeysSchema>;
clientOptions?: {
token: { token: string };
authSchemePreference: string[];
};
} {
const { secretKey, allowDefaultCredentials } = params;
if (
secretKey === BEDROCK_USE_DEFAULT_CREDENTIALS &&
allowDefaultCredentials
) {
return {};
}
try {
const parsedCredential = BedrockCredentialSchema.parse(
JSON.parse(secretKey),
);
if ("apiKey" in parsedCredential) {
return createBedrockBearerAuth(parsedCredential.apiKey);
}
return {
credentials: parsedCredential,
};
} catch {
throw new Error(
"Invalid Bedrock credentials. Expected AWS access key JSON or a Bedrock API key.",
);
}
}
type ProcessTracedEvents = () => Promise<void>;
type LLMCompletionParams = {
@@ -363,16 +418,16 @@ export async function fetchLLMCompletion(
// Handle both explicit credentials and default provider chain
// Only allow default provider chain in self-hosted or internal AI features
const isSelfHosted = !isLangfuseCloud;
const credentials =
apiKey === BEDROCK_USE_DEFAULT_CREDENTIALS &&
(isSelfHosted || shouldUseLangfuseAPIKey)
? undefined // undefined = use AWS SDK default credential provider chain
: BedrockCredentialSchema.parse(JSON.parse(apiKey));
const { credentials, clientOptions } = resolveBedrockAuth({
secretKey: apiKey,
allowDefaultCredentials: isSelfHosted || shouldUseLangfuseAPIKey,
});
chatModel = new ChatBedrockConverse({
model: modelParams.model,
region,
credentials,
clientOptions,
temperature: modelParams.temperature,
maxTokens: modelParams.max_tokens,
topP: modelParams.top_p,
@@ -577,20 +632,17 @@ export async function fetchLLMCompletion(
return completion;
} catch (e) {
const responseStatusCode =
(e as any)?.response?.status ?? (e as any)?.status ?? 500;
(e as any)?.response?.status ??
(e as any)?.status ??
// Bedrock errors have status code in $metadata.httpStatusCode
(e as any)?.$metadata?.httpStatusCode ??
500;
const rawMessage = e instanceof Error ? e.message : String(e);
const message = extractCleanErrorMessage(rawMessage);
// Check for non-retryable error patterns in message
const nonRetryablePatterns = [
"Request timed out",
"is not valid JSON",
"Unterminated string in JSON at position",
"TypeError",
];
const hasNonRetryablePattern = nonRetryablePatterns.some((pattern) =>
message.includes(pattern),
const hasNonRetryablePattern = NON_RETRYABLE_LLM_ERROR_PATTERNS.some(
(pattern) => message.includes(pattern),
);
// Determine retryability:
@@ -1,88 +1,22 @@
import CallbackHandler from "langfuse-langchain";
import { GenerationDetails, TraceSinkParams } from "./types";
import { ProcessedTraceEvent, TraceSinkParams } from "./types";
import { buildInternalTraceEventInputs } from "./internalTraceEvents";
import { processEventBatch } from "../ingestion/processEventBatch";
import { logger } from "../logger";
import { traceException } from "../instrumentation";
type TracedEvent = {
type: string;
body: Record<string, unknown>;
};
export function prepareInternalTraceEvents(params: {
events: Array<{
type: string;
timestamp: string;
body: Record<string, unknown>;
}>;
environment: string;
prompt?: TraceSinkParams["prompt"];
}): ProcessedTraceEvent[] {
const { events, environment, prompt } = params;
/**
* Extracts and merges generation details from a list of processed events.
* Handles multiple generation-create and generation-update events with the same id.
*
* Events are merged following the "last non-null value wins" pattern:
* - generation-create events contain: id, name, input, metadata
* - generation-update events contain: output, usage, usageDetails
*
* @returns GenerationDetails or null if no generation events found
*/
export function extractGenerationDetails(
processedEvents: Array<{ type: string; body: Record<string, unknown> }>,
): GenerationDetails | null {
// 1. Filter to only generation events
const generationEvents = processedEvents.filter(
(event) =>
event.type === "generation-create" || event.type === "generation-update",
);
if (generationEvents.length === 0) {
return null;
}
// 2. Get the generation id from first event
const generationId = generationEvents[0].body.id as string;
if (!generationId) {
return null;
}
// 3. Filter to events for this generation id only
const eventsForGeneration = generationEvents.filter(
(event) => event.body.id === generationId,
);
// 4. Merge event bodies (last non-null/non-undefined value wins)
// Similar to IngestionService pattern but simplified for our use case
const mergedBody = eventsForGeneration.reduce(
(acc: Record<string, unknown>, event) => {
for (const [key, value] of Object.entries(event.body)) {
if (value !== undefined && value !== null) {
// Special handling for metadata: deep merge
if (
key === "metadata" &&
typeof value === "object" &&
!Array.isArray(value)
) {
acc[key] = {
...((acc[key] as Record<string, unknown>) || {}),
...(value as Record<string, unknown>),
};
} else {
acc[key] = value;
}
}
}
return acc;
},
{ id: generationId },
);
return {
observationId: generationId,
name: (mergedBody.name as string) || "generation",
input: mergedBody.input,
output: mergedBody.output,
metadata: (mergedBody.metadata as Record<string, unknown>) || {},
};
}
export function prepareTracedEventsForIngestion(
events: TracedEvent[],
{ environment, prompt }: Pick<TraceSinkParams, "environment" | "prompt">,
): TracedEvent[] {
const blockedSpanIds = new Set<string>();
const blockedSpanIds = new Set();
const blockedSpanNames = [
"RunnableLambda",
"StructuredOutputParser",
@@ -91,29 +25,27 @@ export function prepareTracedEventsForIngestion(
];
for (const event of events) {
const eventName = event.body.name;
const eventName = "name" in event.body ? event.body.name : "";
if (typeof eventName !== "string" || eventName.length === 0) {
continue;
}
if (
blockedSpanNames.includes(eventName) &&
typeof event.body.id === "string"
) {
if (blockedSpanNames.includes(eventName as string) && "id" in event.body) {
blockedSpanIds.add(event.body.id);
}
}
return events
.filter((event) => {
if (typeof event.body.id === "string") {
if ("id" in event.body) {
return !blockedSpanIds.has(event.body.id);
}
return true;
})
.map((event) => {
// Inject environment into all events
return {
...event,
body: {
@@ -142,7 +74,8 @@ export function getInternalTracingHandler(traceSinkParams: TraceSinkParams): {
handler: CallbackHandler;
processTracedEvents: () => Promise<void>;
} {
const { prompt, targetProjectId, environment, userId } = traceSinkParams;
const { prompt, targetProjectId, environment, userId, eventsWriter } =
traceSinkParams;
const handler = new CallbackHandler({
_projectId: targetProjectId,
_isLocalEventExportEnabled: true,
@@ -155,41 +88,52 @@ export function getInternalTracingHandler(traceSinkParams: TraceSinkParams): {
const events = await handler.langfuse._exportLocalEvents(
traceSinkParams.targetProjectId,
);
const processedEvents = prepareInternalTraceEvents({
events,
environment,
prompt,
});
const processedEvents = prepareTracedEventsForIngestion(
events as TracedEvent[],
{
environment,
prompt,
},
);
// Legacy write to traces/observations tables
try {
await processEventBatch(
JSON.parse(JSON.stringify(processedEvents)), // stringify to emulate network event batch from network call
{
validKey: true as const,
scope: {
projectId: traceSinkParams.targetProjectId, // Important: this controls into what project traces are ingested.
accessLevel: "project",
} as any,
},
{
isLangfuseInternal: true,
forwardToEventsTable: eventsWriter ? false : undefined, // Do not dual write when we already direct event write
},
);
} catch (processingError) {
traceException(processingError);
logger.error("Failed to process traced events via legacy ingestion", {
error: processingError,
});
}
await processEventBatch(
JSON.parse(JSON.stringify(processedEvents)), // stringify to emulate network event batch from network call
{
validKey: true as const,
scope: {
projectId: traceSinkParams.targetProjectId, // Important: this controls into what project traces are ingested.
accessLevel: "project",
} as any,
},
{
isLangfuseInternal: true,
},
);
// Extract generation details and invoke callback (if provided)
if (traceSinkParams.onGenerationComplete) {
// Direct write to events table
if (eventsWriter) {
try {
const generationDetails = extractGenerationDetails(processedEvents);
if (generationDetails) {
traceSinkParams.onGenerationComplete(generationDetails);
const { rootSpanId, eventInputs } = buildInternalTraceEventInputs({
processedEvents,
traceId: traceSinkParams.traceId,
projectId: targetProjectId,
experimentContext: eventsWriter.experimentContext,
});
if (eventInputs.length > 0) {
await eventsWriter.write({ rootSpanId, eventInputs });
}
} catch (extractionError) {
// Don't fail the LLM call due to generation detail extraction errors
traceException(extractionError);
logger.error("Failed to extract generation details from events", {
error: extractionError,
} catch (writeError) {
traceException(writeError);
logger.error("Failed to direct-write internal traced events", {
error: writeError,
});
}
}
@@ -0,0 +1,417 @@
import {
asBoolean,
asNumberRecord,
asRecord,
asString,
asStringArray,
} from "../../utils/objects";
import { stringifyValue } from "../../utils/stringChecks";
import {
convertCallsToArrays,
convertDefinitionsToMap,
extractToolsFromObservation,
} from "../ingestion/extractToolsBackend";
import { flattenJsonToPathArrays } from "../otel/utils";
import type { ProcessedTraceEvent } from "./types";
export const INTERNAL_TRACE_EVENT_SOURCE = "ingestion-api-dual-write";
export const INTERNAL_TRACE_EXPERIMENT_EVENT_SOURCE =
"ingestion-api-dual-write-experiments";
export type InternalTraceExperimentContext = {
id: string;
name: string;
metadata?: Record<string, unknown>;
description?: string | null;
datasetId: string;
itemId: string;
itemVersion: string;
itemExpectedOutput?: unknown;
itemMetadata?: Record<string, unknown> | null;
};
/**
* Flexible input type for writing events to the events table.
* This is intentionally loose to allow for iteration as the events
* table schema evolves. Only required fields are enforced.
*/
export type InternalTraceEventInput = {
projectId: string;
traceId: string;
spanId: string;
startTimeISO: string;
orgId?: string;
parentSpanId?: string;
name?: string;
type?: string;
environment?: string;
version?: string;
release?: string;
endTimeISO: string;
completionStartTime?: string;
traceName?: string;
tags?: string[];
bookmarked?: boolean;
public?: boolean;
userId?: string;
sessionId?: string;
level?: string;
statusMessage?: string;
promptId?: string;
promptName?: string;
promptVersion?: string;
modelId?: string;
modelName?: string;
modelParameters?: string | Record<string, unknown>;
providedUsageDetails?: Record<string, number>;
usageDetails?: Record<string, number>;
providedCostDetails?: Record<string, number>;
costDetails?: Record<string, number>;
toolDefinitions?: Record<string, string>;
toolCalls?: string[];
toolCallNames?: string[];
input?: string;
output?: string;
metadata: Record<string, unknown>;
source: string;
serviceName?: string;
serviceVersion?: string;
scopeName?: string;
scopeVersion?: string;
telemetrySdkLanguage?: string;
telemetrySdkName?: string;
telemetrySdkVersion?: string;
blobStorageFilePath?: string;
eventRaw?: string;
eventBytes?: number;
experimentId?: string;
experimentName?: string;
experimentMetadataNames?: string[];
experimentMetadataValues?: Array<string | null | undefined>;
experimentDescription?: string;
experimentDatasetId?: string;
experimentItemId?: string;
experimentItemVersion?: string;
experimentItemRootSpanId?: string;
experimentItemExpectedOutput?: string;
experimentItemMetadataNames?: string[];
experimentItemMetadataValues?: Array<string | null | undefined>;
[key: string]: any;
};
type InternalTraceSnapshot = {
spanId: string;
traceId: string;
parentSpanId?: string;
name?: string;
type: "SPAN" | "GENERATION";
environment?: string;
version?: string;
release?: string;
startTimeISO?: string;
endTimeISO?: string;
completionStartTime?: string;
level?: string;
statusMessage?: string;
promptName?: string;
promptVersion?: string;
modelName?: string;
modelParameters?: Record<string, unknown>;
providedUsageDetails?: Record<string, number>;
providedCostDetails?: Record<string, number>;
input?: unknown;
output?: unknown;
metadata: Record<string, unknown>;
tags?: string[];
public?: boolean;
bookmarked?: boolean;
userId?: string;
sessionId?: string;
};
export type MaterializedInternalTrace = {
rootSpanId: string;
snapshots: InternalTraceSnapshot[];
};
function isCreateEvent(type: string): boolean {
return type.endsWith("-create");
}
function getSnapshotType(eventType: string): "SPAN" | "GENERATION" {
return eventType.startsWith("generation-") ? "GENERATION" : "SPAN";
}
function getEventTime(
event: ProcessedTraceEvent,
body: Record<string, unknown>,
): number {
const candidates = [body.startTime, body.timestamp, event.timestamp];
for (const candidate of candidates) {
if (typeof candidate === "string") {
const parsed = new Date(candidate).getTime();
if (!Number.isNaN(parsed)) {
return parsed;
}
}
}
return 0;
}
function getTimestampMs(timestamp?: string): number {
if (!timestamp) {
return 0;
}
const parsed = new Date(timestamp).getTime();
return Number.isNaN(parsed) ? 0 : parsed;
}
function sortEvents(events: ProcessedTraceEvent[]): ProcessedTraceEvent[] {
return [...events].sort((left, right) => {
const timeDelta =
getEventTime(left, left.body) - getEventTime(right, right.body);
if (timeDelta !== 0) {
return timeDelta;
}
if (isCreateEvent(left.type) === isCreateEvent(right.type)) {
return 0;
}
return isCreateEvent(left.type) ? -1 : 1;
});
}
function flattenMetadata(value: unknown): {
names: string[];
values: Array<string | null | undefined>;
} {
const metadata = asRecord(value);
return metadata
? flattenJsonToPathArrays(metadata)
: { names: [], values: [] };
}
function mergeSnapshotEvent(
snapshot: InternalTraceSnapshot,
event: ProcessedTraceEvent,
): InternalTraceSnapshot {
const { body } = event;
const startTime = asString(body.startTime);
const timestamp = asString(body.timestamp) ?? asString(event.timestamp);
const metadata = asRecord(body.metadata);
return {
...snapshot,
traceId: asString(body.traceId) ?? snapshot.traceId,
parentSpanId: asString(body.parentObservationId) ?? snapshot.parentSpanId,
type:
snapshot.type === "GENERATION"
? snapshot.type
: getSnapshotType(event.type),
name: asString(body.name) ?? snapshot.name,
environment: asString(body.environment) ?? snapshot.environment,
version: asString(body.version) ?? snapshot.version,
release: asString(body.release) ?? snapshot.release,
startTimeISO:
startTime ?? snapshot.startTimeISO ?? timestamp ?? snapshot.startTimeISO,
endTimeISO: asString(body.endTime) ?? snapshot.endTimeISO,
completionStartTime:
asString(body.completionStartTime) ?? snapshot.completionStartTime,
level: asString(body.level) ?? snapshot.level,
statusMessage: asString(body.statusMessage) ?? snapshot.statusMessage,
promptName: asString(body.promptName) ?? snapshot.promptName,
promptVersion:
typeof body.promptVersion === "number"
? body.promptVersion.toString()
: (asString(body.promptVersion) ?? snapshot.promptVersion),
modelName: asString(body.model) ?? snapshot.modelName,
modelParameters: asRecord(body.modelParameters) ?? snapshot.modelParameters,
providedUsageDetails:
asNumberRecord(body.usageDetails) ??
asNumberRecord(body.usage) ??
snapshot.providedUsageDetails,
providedCostDetails:
asNumberRecord(body.costDetails) ?? snapshot.providedCostDetails,
input:
body.input !== undefined && body.input !== null
? body.input
: snapshot.input,
output:
body.output !== undefined && body.output !== null
? body.output
: snapshot.output,
metadata: metadata
? { ...snapshot.metadata, ...metadata }
: snapshot.metadata,
tags: asStringArray(body.tags) ?? snapshot.tags,
public: asBoolean(body.public) ?? snapshot.public,
bookmarked: asBoolean(body.bookmarked) ?? snapshot.bookmarked,
userId: asString(body.userId) ?? snapshot.userId,
sessionId: asString(body.sessionId) ?? snapshot.sessionId,
};
}
export function materializeInternalTrace(params: {
processedEvents: ProcessedTraceEvent[];
traceId: string;
}): MaterializedInternalTrace {
const { processedEvents, traceId } = params;
const snapshots = new Map<string, InternalTraceSnapshot>();
const traceCreateEvent = processedEvents.find(
(e) => e.type === "trace-create",
);
const rootSpanId = asString(traceCreateEvent?.body.id) ?? traceId;
for (const event of sortEvents(processedEvents)) {
const spanId = asString(event.body.id);
if (!spanId) {
continue;
}
const existingSnapshot =
snapshots.get(spanId) ??
({
spanId,
traceId: asString(event.body.traceId) ?? traceId,
type: getSnapshotType(event.type),
metadata: {},
} satisfies InternalTraceSnapshot);
snapshots.set(spanId, mergeSnapshotEvent(existingSnapshot, event));
}
const orderedSnapshots = [...snapshots.values()].sort((left, right) => {
if (left.spanId === rootSpanId) {
return -1;
}
if (right.spanId === rootSpanId) {
return 1;
}
return (
getTimestampMs(left.startTimeISO) - getTimestampMs(right.startTimeISO)
);
});
return { rootSpanId, snapshots: orderedSnapshots };
}
export function buildInternalTraceEventInputs(params: {
processedEvents: ProcessedTraceEvent[];
traceId: string;
projectId: string;
experimentContext?: InternalTraceExperimentContext;
}): {
rootSpanId: string;
eventInputs: InternalTraceEventInput[];
} {
const { processedEvents, traceId, projectId, experimentContext } = params;
// Direct write uses original IDs (observation.id === trace.id for root).
// The experiment backfill job skips traces already in events_core via LEFT ANTI JOIN,
// so there's no deduplication concern between direct write and backfill.
const { rootSpanId, snapshots } = materializeInternalTrace({
processedEvents,
traceId,
});
const rootSnapshot = snapshots.find((s) => s.spanId === rootSpanId);
if (!rootSnapshot) {
return { rootSpanId, eventInputs: [] };
}
const experimentMetadata = flattenMetadata(experimentContext?.metadata);
const experimentItemMetadata = flattenMetadata(
experimentContext?.itemMetadata,
);
const source = experimentContext
? INTERNAL_TRACE_EXPERIMENT_EVENT_SOURCE
: INTERNAL_TRACE_EVENT_SOURCE;
const eventInputs = snapshots.map((snapshot) => {
const { toolDefinitions, toolArguments } = extractToolsFromObservation(
snapshot.input,
snapshot.output,
);
const toolCalls = convertCallsToArrays(toolArguments);
const isRoot = snapshot.spanId === rootSpanId;
return {
projectId,
traceId,
spanId: snapshot.spanId,
parentSpanId: isRoot ? undefined : (snapshot.parentSpanId ?? rootSpanId),
name:
snapshot.name ??
(snapshot.type === "GENERATION"
? "generation"
: (rootSnapshot.name ?? "span")),
type: snapshot.type,
environment: snapshot.environment ?? rootSnapshot.environment,
version: snapshot.version ?? rootSnapshot.version,
release: rootSnapshot.release,
startTimeISO:
snapshot.startTimeISO ??
rootSnapshot.startTimeISO ??
new Date().toISOString(),
endTimeISO:
snapshot.endTimeISO ??
snapshot.startTimeISO ??
rootSnapshot.endTimeISO ??
rootSnapshot.startTimeISO ??
new Date().toISOString(),
completionStartTime: snapshot.completionStartTime,
traceName: rootSnapshot.name,
tags: rootSnapshot.tags ?? [],
bookmarked: rootSnapshot.bookmarked,
public: rootSnapshot.public,
userId: rootSnapshot.userId,
sessionId: rootSnapshot.sessionId,
level: snapshot.level ?? "DEFAULT",
statusMessage: snapshot.statusMessage,
promptName: snapshot.promptName,
promptVersion: snapshot.promptVersion,
modelName: snapshot.modelName,
modelParameters: snapshot.modelParameters,
providedUsageDetails: snapshot.providedUsageDetails,
providedCostDetails: snapshot.providedCostDetails,
toolDefinitions: convertDefinitionsToMap(toolDefinitions),
toolCalls: toolCalls.tool_calls,
toolCallNames: toolCalls.tool_call_names,
input:
snapshot.input !== undefined
? stringifyValue(snapshot.input)
: undefined,
output:
snapshot.output !== undefined
? stringifyValue(snapshot.output)
: undefined,
metadata: snapshot.metadata,
source,
experimentId: experimentContext?.id,
experimentName: experimentContext?.name,
experimentMetadataNames: experimentMetadata.names,
experimentMetadataValues: experimentMetadata.values,
experimentDescription: experimentContext?.description ?? undefined,
experimentDatasetId: experimentContext?.datasetId,
experimentItemId: experimentContext?.itemId,
experimentItemVersion: experimentContext?.itemVersion,
experimentItemRootSpanId: experimentContext ? rootSpanId : undefined,
experimentItemExpectedOutput:
experimentContext?.itemExpectedOutput !== undefined &&
experimentContext?.itemExpectedOutput !== null
? stringifyValue(experimentContext.itemExpectedOutput)
: undefined,
experimentItemMetadataNames: experimentItemMetadata.names,
experimentItemMetadataValues: experimentItemMetadata.values,
} satisfies InternalTraceEventInput;
});
return { rootSpanId, eventInputs };
}
+24 -11
View File
@@ -5,6 +5,10 @@ import {
VertexAIConfigSchema,
} from "../../interfaces/customLLMProviderConfigSchemas";
import { JSONObjectSchema } from "../../utils/zod";
import type {
InternalTraceEventInput,
InternalTraceExperimentContext,
} from "./internalTraceEvents";
// disable lint as this is exported and used in web/worker
@@ -429,6 +433,7 @@ export type OpenAIModel = (typeof openAIModels)[number];
export const anthropicModels = [
"claude-sonnet-4-5-20250929",
"claude-haiku-4-5-20251001",
"claude-opus-4-7",
"claude-sonnet-4-6",
"claude-opus-4-6",
"claude-opus-4-5-20251101",
@@ -533,16 +538,22 @@ export enum LangfuseInternalTraceEnvironment {
LLMJudge = "langfuse-llm-as-a-judge",
}
export type ProcessedTraceEvent = {
type: string;
timestamp: string;
body: Record<string, unknown>;
};
/**
* Details of a generation extracted from traced events.
* Used to pass generation information from internal tracing to callbacks.
* Configuration for direct writing of trace events to the events table.
* Used by internal tracing (prompt experiments, evaluations).
*/
export type GenerationDetails = {
observationId: string;
name: string;
input: unknown;
output: unknown;
metadata: Record<string, unknown>;
export type InternalEventsWriter = {
experimentContext?: InternalTraceExperimentContext;
write: (params: {
rootSpanId: string;
eventInputs: InternalTraceEventInput[];
}) => Promise<void>;
};
export type TraceSinkParams = {
@@ -561,8 +572,10 @@ export type TraceSinkParams = {
version: number;
};
/**
* Optional callback invoked after the generation events have been processed.
* Called with merged generation details (from create + update events).
* When provided, traced events are written directly to the events table,
* bypassing the legacy traces/observations ingestion pipeline for the events write.
* Used for internal tracing (prompt experiments, LLM-as-a-judge evaluations). Traced
* events are still written to the legacy traces/observations tables.
*/
onGenerationComplete?: (details: GenerationDetails) => void;
eventsWriter?: InternalEventsWriter;
};
@@ -1315,18 +1315,25 @@ export class OtelIngestionProcessor {
const keys = Object.keys(input).map((key) => key.replace(`${prefix}.`, ""));
const useArray = keys.some((key) => key.match(/^\d+\./));
// Blocklist to prevent prototype pollution via crafted OTel attribute keys
const DANGEROUS_KEYS = new Set(["__proto__", "constructor", "prototype"]);
// Helper function to set a value at a nested path
const setNestedValue = (obj: any, path: string[], value: unknown): void => {
let current = obj;
for (let i = 0; i < path.length - 1; i++) {
const key = path[i];
if (DANGEROUS_KEYS.has(key)) return;
if (!(key in current)) {
// Check if next key is a number to decide if we need an array or object
current[key] = /^\d+$/.test(path[i + 1]) ? [] : {};
}
current = current[key];
}
current[path[path.length - 1]] = value;
const finalKey = path[path.length - 1];
if (!DANGEROUS_KEYS.has(finalKey)) {
current[finalKey] = value;
}
};
if (useArray) {
@@ -1335,7 +1342,7 @@ export class OtelIngestionProcessor {
const pathParts = key.split(".");
const index = parseInt(pathParts[0], 10);
if (!result[index]) {
result[index] = {};
result[index] = Object.create(null);
}
if (pathParts.length === 2) {
// Simple case: 0.content -> result[0].content
@@ -1351,7 +1358,7 @@ export class OtelIngestionProcessor {
}
return result;
} else {
const result: Record<string, unknown> = {};
const result: Record<string, unknown> = Object.create(null);
for (const key of keys) {
const pathParts = key.split(".");
if (pathParts.length === 1) {
@@ -2476,51 +2483,120 @@ export class OtelIngestionProcessor {
}
if (instrumentationScopeName === "pydantic-ai") {
const inputTokens = attributes["gen_ai.usage.input_tokens"];
const outputTokens = attributes["gen_ai.usage.output_tokens"];
const cacheReadTokens =
attributes["gen_ai.usage.cache_read_tokens"] ??
attributes["gen_ai.usage.details.cache_read_input_tokens"];
const cacheWriteTokens =
attributes["gen_ai.usage.cache_write_tokens"] ??
attributes["gen_ai.usage.details.cache_creation_input_tokens"];
return {
input: inputTokens,
output: outputTokens,
input_cache_read: cacheReadTokens,
input_cache_creation: cacheWriteTokens,
};
const usageDetails = this.extractGenericGenAiUsageDetails(attributes);
if (Object.keys(usageDetails).length > 0) return usageDetails;
}
return this.extractGenericGenAiUsageDetails(attributes);
}
private extractGenericGenAiUsageDetails(
attributes: Record<string, unknown>,
): Record<string, number> {
const usageDetails = Object.keys(attributes).filter(
(key) =>
(key.startsWith("gen_ai.usage.") && key !== "gen_ai.usage.cost") ||
key.startsWith("llm.token_count"),
key.startsWith("llm.token_count."),
);
const usageDetailKeyMapping: Record<string, string> = {
prompt_tokens: "input",
completion_tokens: "output",
total_tokens: "total",
input_tokens: "input",
output_tokens: "output",
prompt: "input",
completion: "output",
};
if (usageDetails.length === 0) return {};
return usageDetails.reduce((acc: any, key) => {
const usageDetailKey = key
.replace("gen_ai.usage.", "")
.replace("llm.token_count.", "");
const mappedUsageDetailKey =
usageDetailKeyMapping[usageDetailKey] ?? usageDetailKey;
const value = Number(attributes[key]);
if (!Number.isNaN(value)) {
acc[mappedUsageDetailKey] = value;
}
return acc;
}, {});
const rawUsageDetails = usageDetails.reduce(
(acc: Record<string, number>, key) => {
const usageDetailKey = key
.replace("gen_ai.usage.", "")
.replace("llm.token_count.", "");
const value = Number(attributes[key]);
if (!Number.isNaN(value)) {
acc[usageDetailKey] = value;
}
return acc;
},
{},
);
const inputTokens =
rawUsageDetails["prompt_tokens"] ??
rawUsageDetails["input_tokens"] ??
rawUsageDetails["prompt"];
const outputTokens =
rawUsageDetails["completion_tokens"] ??
rawUsageDetails["output_tokens"] ??
rawUsageDetails["completion"];
const totalTokens =
rawUsageDetails["total_tokens"] ?? rawUsageDetails["total"];
const cacheReadTokens =
rawUsageDetails["cache_read.input_tokens"] ??
rawUsageDetails["cache_read_tokens"] ??
rawUsageDetails["details.cache_read_tokens"] ??
rawUsageDetails["details.cache_read_input_tokens"];
const cacheCreationTokens =
rawUsageDetails["cache_creation.input_tokens"] ??
rawUsageDetails["cache_write_tokens"] ??
rawUsageDetails["details.cache_write_tokens"] ??
rawUsageDetails["details.cache_creation_input_tokens"];
const normalizedUsageDetails = Object.entries(rawUsageDetails).reduce(
(acc: Record<string, number>, [key, value]) => {
if (
[
"prompt_tokens",
"input_tokens",
"prompt",
"completion_tokens",
"output_tokens",
"completion",
"total_tokens",
"total",
"cache_read.input_tokens",
"cache_read_tokens",
"details.cache_read_tokens",
"details.cache_read_input_tokens",
"cache_creation.input_tokens",
"cache_write_tokens",
"details.cache_write_tokens",
"details.cache_creation_input_tokens",
].includes(key)
) {
return acc;
}
const normalizedKey = key.startsWith("details.")
? key.replace("details.", "")
: key;
acc[normalizedKey] = value;
return acc;
},
{},
);
if (inputTokens !== undefined) {
normalizedUsageDetails.input = Math.max(
inputTokens - (cacheReadTokens ?? 0) - (cacheCreationTokens ?? 0),
0,
);
}
if (outputTokens !== undefined) {
normalizedUsageDetails.output = outputTokens;
}
if (totalTokens !== undefined) {
normalizedUsageDetails.total = totalTokens;
}
if (cacheReadTokens !== undefined) {
normalizedUsageDetails.input_cached_tokens = cacheReadTokens;
}
if (cacheCreationTokens !== undefined) {
normalizedUsageDetails.input_cache_creation = cacheCreationTokens;
}
return normalizedUsageDetails;
}
private extractCostDetails(
@@ -181,6 +181,7 @@ const FIELD_SETS = {
"userId",
"sessionId",
"traceName",
"tags",
"toolDefinitions",
"toolCalls",
"toolCallNames",
@@ -217,6 +218,7 @@ const FIELD_SETS = {
"userId",
"sessionId",
"traceName",
"tags",
],
calculated: ["latency", "timeToFirstToken"],
io: ["input", "output"],
@@ -239,6 +241,12 @@ const FIELD_SETS = {
"level",
"statusMessage",
"version",
"userId",
"sessionId",
"traceName",
"tags",
"bookmarked",
"public",
"toolDefinitions",
"toolCalls",
"toolCallNames",
@@ -353,6 +361,9 @@ const FIELD_SETS = {
"toolDefinitions",
"toolCalls",
"toolCallNames",
"experimentId",
"experimentItemRootSpanId",
"experimentItemExpectedOutput",
],
// Experiment items field set
@@ -1710,6 +1721,11 @@ const EXPERIMENTS_AGGREGATION_FIELDS = {
"groupUniqArrayIf(tuple(e.prompt_name, e.prompt_version), e.prompt_name != '') AS prompts",
experimentMetadata:
"any(mapFromArrays(e.experiment_metadata_names, e.experiment_metadata_values)) AS experiment_metadata",
// Metrics fields
totalCost: "SUM(e.total_cost) AS total_cost",
latencyAvg:
"avgIf(date_diff('millisecond', e.start_time, e.end_time), e.span_id = e.experiment_item_root_span_id AND e.end_time IS NOT NULL) AS latency_avg",
} as const;
/**
@@ -1728,6 +1744,7 @@ const EXPERIMENTS_AGGREGATION_FIELD_SETS = {
"prompts",
"experimentMetadata",
] as const,
metrics: ["experimentId", "totalCost", "latencyAvg"] as const,
} as const;
export type ExperimentsAggregationFieldSetName =
@@ -1736,9 +1753,9 @@ export type ExperimentsAggregationFieldSetName =
/**
* ExperimentsAggregationQueryBuilder - Aggregates events by (experiment_id, project_id).
*
* For metrics requiring trace-level aggregation first (cost, latency), use CTEQueryBuilder
* to wrap a trace CTE and re-aggregate at experiment level with selectRaw() + groupBy().
* selectRaw() is intentionally used for explicit two-level aggregation semantics.
* Use the "metrics" field set for cost and latency aggregations:
* - Cost: SUM of all event costs for the experiment
* - Latency: AVG of root span duration (where span_id = experiment_item_root_span_id)
*/
export class ExperimentsAggregationQueryBuilder extends BaseEventsQueryBuilder<
typeof EXPERIMENTS_AGGREGATION_FIELDS
@@ -5,6 +5,7 @@ import { InvalidRequestError } from "../../../errors";
import { isValidTableName } from "../../clickhouse/schemaUtils";
import { logger } from "../../logger";
import {
findUiColumnMapping,
type ColumnDefinition,
type UiColumnMappings,
} from "../../../tableDefinitions";
@@ -173,10 +174,7 @@ const matchAndVerifyTracesUiColumn = (
uiTableDefinitions: UiColumnMappings,
) => {
// tries to match the column name to the clickhouse table name
const uiTable = uiTableDefinitions.find(
(col) =>
col.uiTableName === filter.column || col.uiTableId === filter.column, // matches on the NAME of the column in the UI.
);
const uiTable = findUiColumnMapping(uiTableDefinitions, filter.column);
if (!uiTable) {
const errorMessage = `Column ${filter.column} does not match a UI / CH table mapping.`;
@@ -1,6 +1,9 @@
import z from "zod";
import { OrderByState } from "../../../interfaces/orderBy";
import { UiColumnMappings } from "../../../tableDefinitions";
import {
findUiColumnMapping,
UiColumnMappings,
} from "../../../tableDefinitions";
import { InvalidRequestError } from "../../../errors";
import { logger } from "../../logger";
import type { OrderByDirection, OrderByEntry } from "./event-query-builder";
@@ -30,9 +33,7 @@ export function orderByToClickhouseSql(
Boolean(o),
)) {
// Get column definition to map column to internal name, e.g. "t.id"
const col = tableColumns.find(
(c) => c.uiTableName === ob.column || c.uiTableId === ob.column,
);
const col = findUiColumnMapping(tableColumns, ob.column);
if (!col) {
logger.warn(`Invalid order by column: ${ob.column}`);
@@ -83,9 +84,7 @@ export function orderByToEntries(
for (const ob of orderBy.filter((o): o is OrderByStateNotNull =>
Boolean(o),
)) {
const col = tableColumns.find(
(c) => c.uiTableName === ob.column || c.uiTableId === ob.column,
);
const col = findUiColumnMapping(tableColumns, ob.column);
if (!col) {
logger.warn(`Invalid order by column: ${ob.column}`);
@@ -42,12 +42,25 @@ export class BlobStorageIntegrationQueue {
if (BlobStorageIntegrationQueue.instance) {
logger.debug("Scheduling jobs for BlobStorageIntegrationQueue");
// Remove the old hourly cron pattern — BullMQ keys repeatable jobs by
// name + pattern, so changing the pattern creates a second schedule
// while the old one keeps firing.
BlobStorageIntegrationQueue.instance
.removeRepeatable(QueueJobs.BlobStorageIntegrationJob, {
pattern: "20 * * * *",
})
.catch((err) => {
logger.error(
"Error removing legacy BlobStorageIntegrationJob schedule",
err,
);
});
BlobStorageIntegrationQueue.instance
.add(
QueueJobs.BlobStorageIntegrationJob,
{},
{
repeat: { pattern: "20 * * * *" }, // every hour at 20 minutes past
repeat: { pattern: "*/20 * * * *" }, // every 20 minutes
},
)
.catch((err) => {
@@ -51,21 +51,40 @@ export class CloudUsageMeteringQueue {
jobId: "cloud-usage-metering-recurring",
timestamp: new Date().toISOString(),
});
CloudUsageMeteringQueue.instance.add(
QueueJobs.CloudUsageMeteringJob,
{},
{
// Run at minute 5 of every hour (e.g. 1:05, 2:05, 3:05, etc)
repeat: { pattern: "5 * * * *" },
},
);
CloudUsageMeteringQueue.instance
.add(
QueueJobs.CloudUsageMeteringJob,
{},
{
// Run at minute 5 of every hour (e.g. 1:05, 2:05, 3:05, etc)
repeat: { pattern: "5 * * * *" },
},
)
.catch((err) => {
logger.error(
"[CloudUsageMeteringQueue] Failed to schedule recurring job",
err,
);
});
logger.info("[CloudUsageMeteringQueue] Scheduling bootstrap job", {
jobId: "cloud-usage-metering-bootstrap",
timestamp: new Date().toISOString(),
});
// Bootstrap job to run immediately on startup
CloudUsageMeteringQueue.instance.add(QueueJobs.CloudUsageMeteringJob, {});
// Bootstrap job to run immediately on startup. Safe to enqueue from
// multiple replicas: the handler (handleCloudUsageMeteringJob) is
// idempotent — it acquires a DB lock via optimistic concurrency on the
// cronJobs row and exits early ("not due yet") if the metering interval
// hasn't elapsed. Duplicate jobs are processed sequentially (concurrency: 1)
// and no-op harmlessly.
CloudUsageMeteringQueue.instance
.add(QueueJobs.CloudUsageMeteringJob, {})
.catch((err) => {
logger.error(
"[CloudUsageMeteringQueue] Failed to schedule bootstrap job",
err,
);
});
}
return CloudUsageMeteringQueue.instance;
@@ -115,6 +115,7 @@ export const eventsObservationRecordReadSchema =
user_id: z.string().nullish(),
session_id: z.string().nullish(),
trace_name: z.string().nullish(),
tags: z.array(z.string()).optional(),
bookmarked: z.boolean().optional(),
public: z.boolean().optional(),
});
+172 -20
View File
@@ -51,16 +51,16 @@ import {
queryClickhouse,
queryClickhouseStream,
} from "./clickhouse";
import { ObservationRecordReadType, TraceRecordReadType } from "./definitions";
import {
EventsObservationRecordReadType,
TraceRecordReadType,
} from "./definitions";
import type { AnalyticsObservationEvent } from "../analytics-integrations/types";
import {
ObservationsTableQueryResult,
ObservationTableQuery,
} from "./observations";
import {
convertEventsObservation,
convertObservation,
} from "./observations_converters";
import { convertEventsObservation } from "./observations_converters";
import {
EventsQueryBuilder,
CTEQueryBuilder,
@@ -193,18 +193,22 @@ async function enrichObservationsWithModelData(
async function enrichObservationsWithTraceFields(
observationRecords: Array<EventsObservation & ObservationPriceFields>,
): Promise<FullEventsObservations> {
return observationRecords.map((o) => {
return observationRecords.map((observation) => {
// Remove raw tags field as this is re-mapped to traceTags
const { tags: _tags, ...observationWithoutRawTags } = observation;
return {
...o,
traceTags: [], // TODO pull from PG
...observationWithoutRawTags,
traceTags: observation.tags ?? [],
traceTimestamp: null,
toolDefinitions: o.toolDefinitions ?? null,
toolCalls: o.toolCalls ?? null,
toolDefinitions: observation.toolDefinitions ?? null,
toolCalls: observation.toolCalls ?? null,
// Compute counts from actual data for events table
toolDefinitionsCount: o.toolDefinitions
? Object.keys(o.toolDefinitions).length
toolDefinitionsCount: observation.toolDefinitions
? Object.keys(observation.toolDefinitions).length
: null,
toolCallsCount: observation.toolCalls
? observation.toolCalls.length
: null,
toolCallsCount: o.toolCalls ? o.toolCalls.length : null,
};
});
}
@@ -609,9 +613,19 @@ export const getObservationByIdFromEventsTable = async ({
renderingProps,
preferredClickhouseService: preferredClickhouseService ?? "EventsReadOnly",
});
const mapped = records.map((record) =>
convertObservation(record, renderingProps),
);
const mapped = records.map((record) => {
// Remove raw tags field as this is re-mapped to traceTags
const { tags, ...converted } = convertEventsObservation(
record,
renderingProps,
true,
);
return {
...converted,
traceTags: tags ?? [],
};
});
mapped.forEach((observation) => {
recordDistribution(
@@ -682,7 +696,7 @@ async function getObservationByIdFromEventsTableInternal({
const { query, params } = queryBuilder.buildWithParams();
return await queryClickhouse<ObservationRecordReadType>({
return await queryClickhouse<EventsObservationRecordReadType>({
query,
params,
tags: {
@@ -1072,7 +1086,7 @@ async function getObservationsCountFromEventsTableForPublicApiInternal(
*/
export const getObservationsFromEventsTableForPublicApi = async (
opts: Omit<PublicApiObservationsQuery, "fields">,
): Promise<Array<Observation & ObservationPriceFields>> => {
): Promise<Array<EventsObservation & ObservationPriceFields>> => {
const { projectId } = opts;
// Build query with filters and common CTEs
@@ -1090,12 +1104,15 @@ export const getObservationsFromEventsTableForPublicApi = async (
projectId,
queryBuilder,
);
return await enrichObservationsWithModelData(
const observations = await enrichObservationsWithModelData(
observationRecords,
opts.projectId,
opts.parseIoAsJson ?? true, // V1 API: default to parsing JSON (backwards compatibility)
null, // V1 API: no field groups, return complete observations
);
return observations;
};
/**
@@ -2960,7 +2977,7 @@ export const getEventsForAnalyticsIntegrations = async function* (
"mapFromArrays(arrayReverse(e.metadata_names), arrayReverse(e.metadata_values))['$mixpanel_session_id'] as mixpanel_session_id",
)
.whereRaw(
"e.start_time >= {minTimestamp: DateTime64(3)} AND e.start_time <= {maxTimestamp: DateTime64(3)}",
"e.start_time >= {minTimestamp: DateTime64(3)} AND e.start_time < {maxTimestamp: DateTime64(3)}",
{
minTimestamp: convertDateToClickhouseDateTime(minTimestamp),
maxTimestamp: convertDateToClickhouseDateTime(maxTimestamp),
@@ -3193,3 +3210,138 @@ export const getSessionMetricsFromEvents = async (props: {
total_observations: Number(row.total_observations),
}));
};
/**
* SDK metadata detection result.
* isOtel is always present, other fields are optional (only when non-empty).
*/
export type SdkMetadata = {
isOtel: boolean;
name?: string;
version?: string;
language?: string;
};
/**
* Extract SDK info from v3 metadata object.
* - Old (nested): `scope: {name, version}`, `resourceAttributes: {"telemetry.sdk.language": ...}`
*/
function extractSdkInfoFromMetadata(metadata: Record<string, string>): {
name?: string;
version?: string;
language?: string;
telemetrySdkName?: string;
} {
try {
const scopeJson = metadata["scope"];
const resourceJson = metadata["resourceAttributes"];
const scope = scopeJson ? JSON.parse(scopeJson) : null;
const resource = resourceJson ? JSON.parse(resourceJson) : null;
const name = scope?.name;
const version = scope?.version;
const language = resource?.["telemetry.sdk.language"];
const telemetrySdkName = resource?.["telemetry.sdk.name"];
return {
...(name && { name }),
...(version && { version }),
...(language && { language }),
...(telemetrySdkName && { telemetrySdkName }),
};
} catch {
return {};
}
}
/**
* Infers SDK details from the most recent event in the past 7 days containing Langfuse SDK metadata attributes.
*
* Detection priority:
* - v4+: Direct columns (scope_name, scope_version, telemetry_sdk_language)
* - v3: Nested JSON in metadata (`scope: {name, version}`)
* - v2 and older: No SDK metadata returns isOtel: false
*
* Returns the most recent matching event's SDK info. Projects with no events
* in the past 7 days return isOtel: false (acceptable for inactive projects).
*/
export async function getLatestSdkVersionInfoFromEvents(params: {
projectId: string;
}): Promise<SdkMetadata> {
const { projectId } = params;
// Time filter: last 7 days
const sevenDaysAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
const filter = new FilterList([
new DateTimeFilter({
clickhouseTable: "events_proto",
field: "start_time",
operator: ">=",
value: sevenDaysAgo,
tablePrefix: "e",
}),
]);
const builder = new EventsQueryBuilder({ projectId })
.selectRaw(
"e.scope_name AS scope_name",
"e.scope_version AS scope_version",
"e.telemetry_sdk_language AS telemetry_sdk_language",
)
.selectMetadataExpanded([]) // Full metadata values from events_full
.applyFilters(filter)
// OR condition: v4 has scope_name column, v3 has scope in metadata
.where({
query: "e.scope_name != '' OR hasAny(e.metadata_names, ['scope'])",
params: {},
})
.orderByDefault()
.limit(1);
const { query, params: queryParams } = builder.buildWithParams();
const result = await queryClickhouse<{
scope_name: string;
scope_version: string;
telemetry_sdk_language: string;
metadata: Record<string, string>;
}>({
query,
params: queryParams,
tags: {
feature: "sdk-metadata-detection",
kind: "sdkMetadata",
projectId,
},
preferredClickhouseService: "EventsReadOnly",
});
if (result.length === 0) {
return { isOtel: false };
}
const row = result[0];
// Prefer direct columns (v4), fall back to metadata (v3)
if (row.scope_name) {
return {
isOtel: true,
...(row.scope_name && { name: row.scope_name }),
...(row.scope_version && { version: row.scope_version }),
...(row.telemetry_sdk_language && {
language: row.telemetry_sdk_language,
}),
};
}
// Fall back to metadata extraction for v3 and raw OTel (e.g., Vercel AI SDK)
const { telemetrySdkName, ...sdkInfo } = extractSdkInfoFromMetadata(
row.metadata ?? {},
);
return {
isOtel:
telemetrySdkName === "opentelemetry" ||
Boolean(sdkInfo.name || sdkInfo.version || sdkInfo.language),
...sdkInfo,
};
}
@@ -19,7 +19,6 @@ import {
eventsExperimentsAggregation,
eventsScoresAggregation,
eventsTracesScoresAggregation,
eventsTracesAggregation,
} from "../queries/clickhouse-sql/query-fragments";
import { extractTimeFilter, queryClickhouse } from "../repositories";
import { parseClickhouseUTCDateTimeFormat } from "../repositories/clickhouse";
@@ -174,27 +173,17 @@ export const getExperimentMetricsFromEvents = async (props: {
return [];
}
const tracesBuilder = eventsTracesAggregation({
// Use eventsExperimentsAggregation with "metrics" field set for simplified aggregation
const queryBuilder = eventsExperimentsAggregation({
projectId: props.projectId,
}).whereRaw("e.experiment_id IN ({experimentIds: Array(String)})", {
fieldSet: "metrics",
experimentIds: props.experimentIds,
});
// Build the final query
const queryBuilder = new CTEQueryBuilder()
.withCTEFromBuilder("traces_agg", tracesBuilder)
.from("traces_agg", "ta")
.select(
"ta.experiment_id AS experiment_id",
"SUM(ta.total_cost) AS total_cost",
"AVG(ta.latency_milliseconds) AS latency_avg",
)
.groupBy("ta.project_id", "ta.experiment_id");
const { query, params } = queryBuilder.buildWithParams();
const res = await measureAndReturn({
operationName: "getExperimentsFromEventsGeneric",
operationName: "getExperimentMetricsFromEvents",
projectId: props.projectId,
input: {
params,
@@ -202,7 +191,7 @@ export const getExperimentMetricsFromEvents = async (props: {
feature: "experiments",
type: "experiments-table",
projectId: props.projectId,
operation_name: `getExperimentMetricsFromEvents`,
operation_name: "getExperimentMetricsFromEvents",
},
},
fn: async (input) => {
@@ -23,6 +23,7 @@ import {
observationsTableUiColumnDefinitions,
} from "../tableMappings";
import { OrderByState } from "../../interfaces/orderBy";
import { matchesUiColumnMapping } from "../../tableDefinitions";
import { getTracesByIds } from "./traces";
import { measureAndReturn } from "../clickhouse/measureAndReturn";
import {
@@ -704,15 +705,14 @@ const getObservationsTableInternal = async <T>(
// query optimisation: joining traces onto observations is expensive. Hence, only join if the UI table contains filters on traces.
const traceTableFilter = filter.filter((f) =>
observationsTableTraceUiColumnDefinitions.some(
(c) => c.uiTableId === f.column || c.uiTableName === f.column,
observationsTableTraceUiColumnDefinitions.some((c) =>
matchesUiColumnMapping(c, f.column),
),
);
const orderByTraces = orderBy
? observationsTableTraceUiColumnDefinitions.some(
(c) =>
c.uiTableId === orderBy.column || c.uiTableName === orderBy.column,
? observationsTableTraceUiColumnDefinitions.some((c) =>
matchesUiColumnMapping(c, orderBy.column),
)
: undefined;
@@ -1418,6 +1418,10 @@ export const deleteObservationsOlderThanDays = async (
export const getObservationsWithPromptName = async (
projectId: string,
promptNames: string[],
{
fromTimestamp,
toTimestamp,
}: { fromTimestamp?: Date; toTimestamp?: Date } = {},
) => {
const query = `
SELECT uniq(id) as count, prompt_name
@@ -1425,6 +1429,8 @@ export const getObservationsWithPromptName = async (
WHERE project_id = {projectId: String}
AND prompt_name IN ({promptNames: Array(String)})
AND prompt_name IS NOT NULL
${fromTimestamp ? "AND start_time >= {fromTimestamp: DateTime64(3)}" : ""}
${toTimestamp ? "AND start_time <= {toTimestamp: DateTime64(3)}" : ""}
GROUP BY prompt_name
`;
const rows = await queryClickhouse<{ count: string; prompt_name: string }>({
@@ -1432,6 +1438,12 @@ export const getObservationsWithPromptName = async (
params: {
projectId,
promptNames,
fromTimestamp: fromTimestamp
? convertDateToClickhouseDateTime(fromTimestamp)
: undefined,
toTimestamp: toTimestamp
? convertDateToClickhouseDateTime(toTimestamp)
: undefined,
},
tags: {
feature: "tracing",
@@ -1450,6 +1462,10 @@ export const getObservationsWithPromptName = async (
export const getObservationMetricsForPrompts = async (
projectId: string,
promptIds: string[],
{
fromTimestamp,
toTimestamp,
}: { fromTimestamp?: Date; toTimestamp?: Date } = {},
) => {
const query = `
WITH latencies AS
@@ -1468,6 +1484,8 @@ export const getObservationMetricsForPrompts = async (
AND (prompt_name IS NOT NULL)
AND project_id={projectId: String}
AND prompt_id IN ({promptIds: Array(String)})
${fromTimestamp ? "AND start_time >= {fromTimestamp: DateTime64(3)}" : ""}
${toTimestamp ? "AND start_time <= {toTimestamp: DateTime64(3)}" : ""}
)
SELECT
count(*) AS count,
@@ -1500,6 +1518,12 @@ export const getObservationMetricsForPrompts = async (
params: {
projectId,
promptIds,
...(fromTimestamp
? { fromTimestamp: convertDateToClickhouseDateTime(fromTimestamp) }
: {}),
...(toTimestamp
? { toTimestamp: convertDateToClickhouseDateTime(toTimestamp) }
: {}),
},
tags: {
feature: "tracing",
@@ -1851,10 +1875,31 @@ export const getGenerationsForAnalyticsIntegrations = async function* (
projectName: string,
minTimestamp: Date,
maxTimestamp: Date,
options: { useGraceHash?: boolean } = {},
) {
const traceTable = "traces";
// Pre-filter traces in a CTE so the trace timestamp window prunes partitions
// directly, instead of living alongside the LEFT JOIN where the planner
// cannot push it down. LEFT JOIN keeps generations whose trace is missing or
// outside the 7-day window — they still ship to PostHog with NULL trace
// fields rather than being silently dropped.
const query = `
WITH selected_traces AS (
SELECT
t.project_id as project_id,
t.id as id,
t.name as name,
t.session_id as session_id,
t.user_id as user_id,
t.release as release,
t.tags as tags,
t.metadata['$posthog_session_id'] as posthog_session_id,
t.metadata['$mixpanel_session_id'] as mixpanel_session_id
FROM traces t FINAL
WHERE t.project_id = {projectId: String}
AND t.timestamp >= {minTimestamp: DateTime64(3)} - ${OBSERVATIONS_TO_TRACE_INTERVAL}
AND t.timestamp <= {maxTimestamp: DateTime64(3)} + ${TRACE_TO_OBSERVATIONS_INTERVAL}
)
SELECT
o.name as name,
o.start_time as start_time,
@@ -1876,16 +1921,13 @@ export const getGenerationsForAnalyticsIntegrations = async function* (
t.user_id as trace_user_id,
t.release as trace_release,
t.tags as trace_tags,
t.metadata['$posthog_session_id'] as posthog_session_id,
t.metadata['$mixpanel_session_id'] as mixpanel_session_id
t.posthog_session_id as posthog_session_id,
t.mixpanel_session_id as mixpanel_session_id
FROM observations o FINAL
LEFT JOIN ${traceTable} t FINAL ON o.trace_id = t.id AND o.project_id = t.project_id
LEFT JOIN selected_traces t ON o.trace_id = t.id AND o.project_id = t.project_id
WHERE o.project_id = {projectId: String}
AND t.project_id = {projectId: String}
AND o.start_time >= {minTimestamp: DateTime64(3)}
AND o.start_time <= {maxTimestamp: DateTime64(3)}
AND t.timestamp >= {minTimestamp: DateTime64(3)} - INTERVAL 7 DAY
AND t.timestamp <= {maxTimestamp: DateTime64(3)}
AND o.start_time < {maxTimestamp: DateTime64(3)}
AND o.type = 'GENERATION'
`;
@@ -1904,10 +1946,14 @@ export const getGenerationsForAnalyticsIntegrations = async function* (
},
clickhouseConfigs: {
request_timeout: env.LANGFUSE_CLICKHOUSE_DATA_EXPORT_REQUEST_TIMEOUT_MS,
clickhouse_settings: {
join_algorithm: "grace_hash",
grace_hash_join_initial_buckets: "32",
},
...(options.useGraceHash
? {
clickhouse_settings: {
join_algorithm: "grace_hash",
grace_hash_join_initial_buckets: "32",
},
}
: {}),
},
});
@@ -1995,6 +2041,7 @@ export const getObservationCountsByProjectAndDay = async ({
startDate: convertDateToClickhouseDateTime(startDate),
endDate: convertDateToClickhouseDateTime(endDate),
},
clickhouseConfigs: { request_timeout: 120_000 },
tags: {
feature: "tracing",
type: "observation",
@@ -411,6 +411,7 @@ export function convertEventsObservation(
userId: record.user_id ?? null,
sessionId: record.session_id ?? null,
traceName: record.trace_name ?? null,
tags: record.tags ?? [],
bookmarked: record.bookmarked,
public: record.public,
};
@@ -52,6 +52,10 @@ import {
eventsExperiments,
} from "../queries/clickhouse-sql/query-fragments";
import { scoresTableCols } from "../../tableDefinitions/scoresTable";
import {
findUiColumnMapping,
matchesUiColumnMapping,
} from "../../tableDefinitions";
export const searchExistingAnnotationScore = async (
projectId: string,
@@ -617,6 +621,12 @@ export type GetScoresForObservationsProps<
> = {
projectId: string;
observationIds: string[];
/**
* When provided, adds `AND s.timestamp >= minTimestamp - SCORE_TO_TRACE_OBSERVATIONS_INTERVAL`
* to the query so ClickHouse can prune monthly partitions and avoid full-table scans.
* Pass the minimum startTime of the observations whose scores you are fetching.
*/
minTimestamp?: Date;
limit?: number;
offset?: number;
clickhouseConfigs?: ClickHouseClientConfigOptions;
@@ -634,6 +644,7 @@ export const getScoresForObservations = async <
const {
projectId,
observationIds,
minTimestamp,
limit,
offset,
clickhouseConfigs,
@@ -657,6 +668,7 @@ export const getScoresForObservations = async <
WHERE s.project_id = {projectId: String}
AND s.observation_id IN ({observationIds: Array(String)})
AND s.data_type IN ({dataTypes: Array(String)})
${minTimestamp ? `AND s.timestamp >= {minTimestamp: DateTime64(3)} - ${SCORE_TO_TRACE_OBSERVATIONS_INTERVAL}` : ""}
ORDER BY s.event_ts DESC
LIMIT 1 BY s.id, s.project_id
${limit !== undefined && offset !== undefined ? `limit {limit: Int32} offset {offset: Int32}` : ""}
@@ -678,6 +690,9 @@ export const getScoresForObservations = async <
dataTypes: LISTABLE_SCORE_TYPES,
limit: limit,
offset: offset,
...(minTimestamp
? { minTimestamp: convertDateToClickhouseDateTime(minTimestamp) }
: {}),
},
tags: {
feature: "tracing",
@@ -751,10 +766,8 @@ export const getScoresGroupedByNameSourceType = async ({
// Extract event-level filter entries from the frontend filter state
const eventFilterState = filter.filter((filterEntry) =>
scoresEventsFilterMapping.some(
(col) =>
col.uiTableName === filterEntry.column ||
col.uiTableId === filterEntry.column,
scoresEventsFilterMapping.some((col) =>
matchesUiColumnMapping(col, filterEntry.column),
),
);
@@ -1294,21 +1307,21 @@ const getScoresUiGenericFromEvents = async <T>(props: {
// Trace-level filter entries from the frontend filter state
const traceFilterState = filter.filter((filterEntry) =>
scoresTraceFilterEventsMapping.some(
(col) =>
col.uiTableName === filterEntry.column ||
col.uiTableId === filterEntry.column,
scoresTraceFilterEventsMapping.some((col) =>
matchesUiColumnMapping(col, filterEntry.column),
),
);
const orderByColumn = orderBy
? scoresTableUiColumnDefinitionsFromEvents.find(
(c) =>
(c.uiTableName === orderBy.column ||
c.uiTableId === orderBy.column) &&
c.clickhouseTableName === "traces",
const matchedOrderByColumn = orderBy
? findUiColumnMapping(
scoresTableUiColumnDefinitionsFromEvents,
orderBy.column,
)
: null;
const orderByColumn =
matchedOrderByColumn?.clickhouseTableName === "traces"
? matchedOrderByColumn
: null;
const needsTracesCTE = traceFilterState.length > 0 || !!orderByColumn;
@@ -1806,6 +1819,10 @@ export const getAggregatedScoresForPrompts = async (
projectId: string,
promptIds: string[],
fetchScoreRelation: "observation" | "trace",
{
fromTimestamp,
toTimestamp,
}: { fromTimestamp?: Date; toTimestamp?: Date } = {},
) => {
const query = `
SELECT
@@ -1827,6 +1844,8 @@ export const getAggregatedScoresForPrompts = async (
AND s.project_id = {projectId: String}
AND o.prompt_id IN ({promptIds: Array(String)})
AND o.type = 'GENERATION'
${fromTimestamp ? "AND o.start_time >= {fromTimestamp: DateTime64(3)}" : ""}
${toTimestamp ? "AND o.start_time <= {toTimestamp: DateTime64(3)}" : ""}
AND s.name IS NOT NULL
${fetchScoreRelation === "trace" ? "AND s.observation_id IS NULL" : ""}
AND s.data_type IN ({dataTypes: Array(String)})
@@ -1844,6 +1863,12 @@ export const getAggregatedScoresForPrompts = async (
projectId,
promptIds,
dataTypes: LISTABLE_SCORE_TYPES,
...(fromTimestamp
? { fromTimestamp: convertDateToClickhouseDateTime(fromTimestamp) }
: {}),
...(toTimestamp
? { toTimestamp: convertDateToClickhouseDateTime(toTimestamp) }
: {}),
},
tags: {
feature: "tracing",
@@ -2040,11 +2065,31 @@ export const getScoresForAnalyticsIntegrations = async function* (
projectName: string,
minTimestamp: Date,
maxTimestamp: Date,
options: { useGraceHash?: boolean } = {},
) {
// Subtract 7d from minTimestamp to account for shift in query
const traceTable = "traces";
// Pre-filter traces in a CTE so the trace timestamp window prunes partitions
// directly, instead of living in an OR clause after the LEFT JOIN where the
// planner cannot push it down. Subtract 7d from minTimestamp to keep scores
// whose trace was created before the score window started.
const query = `
WITH selected_traces AS (
SELECT
t.project_id as project_id,
t.id as id,
t.name as name,
t.session_id as session_id,
t.user_id as user_id,
t.release as release,
t.tags as tags,
t.metadata['$posthog_session_id'] as posthog_session_id,
t.metadata['$mixpanel_session_id'] as mixpanel_session_id
FROM traces t FINAL
WHERE t.project_id = {projectId: String}
AND t.timestamp >= {minTimestamp: DateTime64(3)} - INTERVAL 7 DAY
AND t.timestamp <= {maxTimestamp: DateTime64(3)}
)
const query = ` SELECT
SELECT
s.id as id,
s.timestamp as timestamp,
s.name as name,
@@ -2063,27 +2108,19 @@ export const getScoresForAnalyticsIntegrations = async function* (
t.release as trace_release,
t.tags as trace_tags,
s.metadata as metadata,
t.metadata['$posthog_session_id'] as posthog_session_id,
t.metadata['$mixpanel_session_id'] as mixpanel_session_id
t.posthog_session_id as posthog_session_id,
t.mixpanel_session_id as mixpanel_session_id
FROM scores s FINAL
LEFT JOIN ${traceTable} t FINAL ON s.trace_id = t.id AND s.project_id = t.project_id
LEFT JOIN selected_traces t ON s.trace_id = t.id AND s.project_id = t.project_id
WHERE s.project_id = {projectId: String}
AND s.timestamp >= {minTimestamp: DateTime64(3)}
AND s.timestamp <= {maxTimestamp: DateTime64(3)}
AND s.timestamp < {maxTimestamp: DateTime64(3)}
AND s.data_type IN ({dataTypes: Array(String)})
AND (
s.trace_id IS NOT NULL
OR s.session_id IS NOT NULL
OR s.dataset_run_id IS NOT NULL
)
AND (
t.project_id = '' -- use the default value for the string type to filter for absence
OR (
t.project_id = {projectId: String}
AND t.timestamp >= {minTimestamp: DateTime64(3)} - INTERVAL 7 DAY
AND t.timestamp <= {maxTimestamp: DateTime64(3)}
)
)
`;
const records = queryClickhouseStream<Record<string, unknown>>({
@@ -2102,10 +2139,14 @@ export const getScoresForAnalyticsIntegrations = async function* (
},
clickhouseConfigs: {
request_timeout: env.LANGFUSE_CLICKHOUSE_DATA_EXPORT_REQUEST_TIMEOUT_MS,
clickhouse_settings: {
join_algorithm: "grace_hash",
grace_hash_join_initial_buckets: "32",
},
...(options.useGraceHash
? {
clickhouse_settings: {
join_algorithm: "grace_hash",
grace_hash_join_initial_buckets: "32",
},
}
: {}),
},
});
@@ -2267,6 +2308,7 @@ export const getScoreCountsByProjectAndDay = async ({
endDate: convertDateToClickhouseDateTime(endDate),
dataTypes: LISTABLE_SCORE_TYPES,
},
clickhouseConfigs: { request_timeout: 120_000 },
tags: {
feature: "tracing",
type: "score",
@@ -1413,6 +1413,7 @@ export const getTracesForAnalyticsIntegrations = async function* (
projectName: string,
minTimestamp: Date,
maxTimestamp: Date,
options: { useGraceHash?: boolean } = {},
) {
// Determine which trace table to use based on experiment flag
const traceTable = "traces";
@@ -1427,6 +1428,7 @@ export const getTracesForAnalyticsIntegrations = async function* (
FROM observations o FINAL
WHERE o.project_id = {projectId: String}
AND o.start_time >= {minTimestamp: DateTime64(3)} - ${TRACE_TO_OBSERVATIONS_INTERVAL}
AND o.start_time < {maxTimestamp: DateTime64(3)} + ${OBSERVATIONS_TO_TRACE_INTERVAL}
GROUP BY o.project_id, o.trace_id
)
@@ -1449,7 +1451,7 @@ export const getTracesForAnalyticsIntegrations = async function* (
LEFT JOIN observations_agg o ON t.id = o.trace_id AND t.project_id = o.project_id
WHERE t.project_id = {projectId: String}
AND t.timestamp >= {minTimestamp: DateTime64(3)}
AND t.timestamp <= {maxTimestamp: DateTime64(3)}
AND t.timestamp < {maxTimestamp: DateTime64(3)}
`;
const records = queryClickhouseStream<Record<string, unknown>>({
@@ -1467,10 +1469,14 @@ export const getTracesForAnalyticsIntegrations = async function* (
},
clickhouseConfigs: {
request_timeout: env.LANGFUSE_CLICKHOUSE_DATA_EXPORT_REQUEST_TIMEOUT_MS,
clickhouse_settings: {
join_algorithm: "grace_hash",
grace_hash_join_initial_buckets: "32",
},
...(options.useGraceHash
? {
clickhouse_settings: {
join_algorithm: "grace_hash",
grace_hash_join_initial_buckets: "32",
},
}
: {}),
},
});
@@ -1641,6 +1647,7 @@ export const getTraceCountsByProjectAndDay = async ({
startDate: convertDateToClickhouseDateTime(startDate),
endDate: convertDateToClickhouseDateTime(endDate),
},
clickhouseConfigs: { request_timeout: 120_000 },
tags: {
feature: "tracing",
type: "trace",
@@ -1,4 +1,5 @@
import { prisma } from "../../../db";
import { TableViewPresetTableName } from "../../../domain/table-view-presets";
import type {
DefaultViewAssignments,
DefaultViewScope,
@@ -26,26 +27,64 @@ interface ClearDefaultParams {
userId?: string;
}
const getReadCompatibleViewNames = (viewName: string) =>
viewName === TableViewPresetTableName.ObservationsEvents
? [
TableViewPresetTableName.ObservationsEvents,
TableViewPresetTableName.Observations,
]
: [viewName];
const getCanonicalViewName = (viewName: string) =>
viewName === TableViewPresetTableName.ObservationsEvents
? TableViewPresetTableName.ObservationsEvents
: viewName;
const pickPreferredDefaultViewId = (
defaults: {
viewId: string;
viewName: string;
userId: string | null;
}[],
preferredViewNames: string[],
userId: string | null,
) =>
preferredViewNames
.map((viewName) =>
defaults.find((defaultView) => {
return (
defaultView.viewName === viewName && defaultView.userId === userId
);
}),
)
.find(Boolean)?.viewId ?? null;
export class DefaultViewService {
public static async getDefaultAssignments({
projectId,
viewName,
userId,
}: GetResolvedDefaultParams): Promise<DefaultViewAssignments> {
const compatibleViewNames = getReadCompatibleViewNames(viewName);
const defaults = await prisma.defaultView.findMany({
where: {
projectId,
viewName,
viewName: {
in: compatibleViewNames,
},
OR: userId ? [{ userId }, { userId: null }] : [{ userId: null }],
},
});
return {
userDefaultViewId: userId
? (defaults.find((d) => d.userId === userId)?.viewId ?? null)
? pickPreferredDefaultViewId(defaults, compatibleViewNames, userId)
: null,
projectDefaultViewId:
defaults.find((d) => d.userId === null)?.viewId ?? null,
projectDefaultViewId: pickPreferredDefaultViewId(
defaults,
compatibleViewNames,
null,
),
};
}
@@ -87,6 +126,7 @@ export class DefaultViewService {
userId,
}: SetAsDefaultParams): Promise<void> {
const userIdToUse = scope === "user" ? userId : null;
const canonicalViewName = getCanonicalViewName(viewName);
if (scope === "user" && !userId) {
throw new Error("userId is required for user-level defaults");
@@ -99,7 +139,7 @@ export class DefaultViewService {
const existing = await tx.defaultView.findFirst({
where: {
projectId,
viewName,
viewName: canonicalViewName,
userId: userIdToUse,
},
});
@@ -107,14 +147,14 @@ export class DefaultViewService {
if (existing) {
await tx.defaultView.update({
where: { id: existing.id },
data: { viewId },
data: { viewId, viewName: canonicalViewName },
});
} else {
await tx.defaultView.create({
data: {
projectId,
userId: userIdToUse,
viewName,
viewName: canonicalViewName,
viewId,
},
});
@@ -131,6 +171,7 @@ export class DefaultViewService {
userId,
}: ClearDefaultParams): Promise<void> {
const userIdToUse = scope === "user" ? userId : null;
const canonicalViewName = getCanonicalViewName(viewName);
if (scope === "user" && !userId) {
throw new Error("userId is required for clearing user-level defaults");
@@ -139,7 +180,7 @@ export class DefaultViewService {
await prisma.defaultView.deleteMany({
where: {
projectId,
viewName,
viewName: canonicalViewName,
userId: userIdToUse,
},
});
@@ -22,6 +22,10 @@ import { backOff } from "exponential-backoff";
import { ServiceUnavailableError } from "../../errors";
import { BufferedStreamUploader } from "./BufferedStreamUploader";
import { S3ChunkedUploadStrategy } from "./S3ChunkedUploadStrategy";
import * as objectstorage from "oci-objectstorage";
import * as common from "oci-common";
import { UploadManager as OciUploadManager } from "oci-objectstorage";
import { URL } from "node:url";
export interface S3SseConfig {
serverSideEncryption?: string;
@@ -127,6 +131,7 @@ export class StorageServiceFactory {
* @param params.region - Region in which the bucket resides
* @param params.forcePathStyle - Add bucket name into the path instead of the domain name. Mainly used for MinIO.
* @param params.useAzureBlob - Use Azure Blob Storage instead of S3
* @param params.useOCIObjectStorage - Use OCI Object Storage instead of S3
* @param params.useGoogleCloudStorage - Use Google Cloud Storage instead of S3
* @param params.googleCloudCredentials - Google Cloud Storage credentials JSON string or path to credentials file
* @param params.awsSse - Server-side encryption method (e.g., "aws:kms")
@@ -142,6 +147,7 @@ export class StorageServiceFactory {
forcePathStyle: boolean;
useAzureBlob?: boolean;
useGoogleCloudStorage?: boolean;
useOCIObjectStorage?: boolean;
googleCloudCredentials?: string;
awsSse: string | undefined;
awsSseKmsKeyId: string | undefined;
@@ -167,6 +173,13 @@ export class StorageServiceFactory {
};
return new GoogleCloudStorageService(googleParams);
}
if (
params.useOCIObjectStorage !== undefined
? params.useOCIObjectStorage
: env.LANGFUSE_USE_OCI_NATIVE_OBJECT_STORAGE === "true"
) {
return new OCIObjectStorageService(params);
}
return new S3StorageService(params);
}
}
@@ -496,6 +509,10 @@ class S3StorageService implements StorageService {
endpoint: params.endpoint,
region: params.region,
forcePathStyle: params.forcePathStyle,
// Restore pre-v3.729 default so CompleteMultipartUpload doesn't send a
// composite CRC32 header, which GCS's S3-compat layer rejects with 412.
requestChecksumCalculation: "WHEN_REQUIRED",
responseChecksumValidation: "WHEN_REQUIRED",
requestHandler: {
httpsAgent: {
maxSockets: env.LANGFUSE_S3_CONCURRENT_WRITES,
@@ -512,6 +529,8 @@ class S3StorageService implements StorageService {
endpoint: params.externalEndpoint,
region: params.region,
forcePathStyle: params.forcePathStyle,
requestChecksumCalculation: "WHEN_REQUIRED",
responseChecksumValidation: "WHEN_REQUIRED",
requestHandler: {
httpsAgent: {
maxSockets: env.LANGFUSE_S3_CONCURRENT_WRITES,
@@ -1009,3 +1028,492 @@ class GoogleCloudStorageService implements StorageService {
}
}
}
class OCIObjectStorageService implements StorageService {
private client?: objectstorage.ObjectStorageClient;
private clientInit: Promise<void>;
private bucketName: string;
private externalEndpoint?: string;
private namespaceName: string = "";
constructor(params: {
bucketName: string;
endpoint: string | undefined;
externalEndpoint?: string | undefined;
region: string | undefined;
}) {
this.bucketName = params.bucketName;
this.externalEndpoint = params.externalEndpoint;
this.clientInit = this.initClient(params);
}
private async initClient(params: { endpoint?: string; region?: string }) {
let provider: common.AuthenticationDetailsProvider;
switch (env.LANGFUSE_OCI_AUTH_TYPE) {
case "workload_identity": {
provider =
new common.OkeWorkloadIdentityAuthenticationDetailsProvider.OkeWorkloadIdentityAuthenticationDetailsProviderBuilder().build();
break;
}
case "instance_principal": {
provider =
await new common.InstancePrincipalsAuthenticationDetailsProviderBuilder().build();
break;
}
case "resource_principal": {
provider =
common.ResourcePrincipalAuthenticationDetailsProvider.builder();
break;
}
case "oci_profile": {
provider = new common.ConfigFileAuthenticationDetailsProvider(
env.LANGFUSE_OCI_CONFIG_FILE,
env.LANGFUSE_OCI_CONFIG_PROFILE,
);
break;
}
case "session_token": {
provider = new common.SessionAuthDetailProvider(
env.LANGFUSE_OCI_CONFIG_FILE,
env.LANGFUSE_OCI_CONFIG_PROFILE,
);
break;
}
default:
throw new Error(
"OCI auth not configured: set LANGFUSE_OCI_AUTH_TYPE to " +
"'workload_identity' | 'instance_principal' | 'resource_principal' | 'oci_profile' | 'session_token'",
);
}
this.client = new objectstorage.ObjectStorageClient({
authenticationDetailsProvider: provider,
});
const regionId = params.region?.trim();
if (regionId) this.client.region = common.Region.fromRegionId(regionId);
const endpoint = params.endpoint?.trim();
if (endpoint) this.client.endpoint = endpoint;
}
private async ensureClient() {
await this.clientInit;
if (!this.client)
throw new Error("OCI ObjectStorage client failed to initialize");
return this.client;
}
private async ensureNamespace(): Promise<string> {
if (this.namespaceName) return this.namespaceName;
const client = await this.ensureClient();
const nsResp = await client.getNamespace({});
this.namespaceName = nsResp.value ?? "";
return this.namespaceName;
}
private async getClientAndNamespace(): Promise<{
client: objectstorage.ObjectStorageClient;
namespaceName: string;
}> {
const client = await this.ensureClient();
const namespaceName = await this.ensureNamespace(); // uses the same client init + cached namespace
return { client, namespaceName };
}
private async streamToString(
readable: any, // could be many shapes, so use `any`
): Promise<string> {
if (!readable) return "";
// Helper: convert many chunk shapes to Buffer
const toBuffer = (chunk: any): Buffer => {
if (Buffer.isBuffer(chunk)) return chunk;
if (typeof chunk === "string") return Buffer.from(chunk, "utf8");
if (chunk instanceof ArrayBuffer) return Buffer.from(chunk);
// TypedArray / DataView
if (ArrayBuffer.isView(chunk)) {
return Buffer.from(
(chunk as Uint8Array).buffer,
(chunk as any).byteOffset ?? 0,
(chunk as any).byteLength ?? undefined,
);
}
// Fallback: try Buffer.from (may throw)
return Buffer.from(chunk);
};
// 1) Node.js Readable (EventEmitter style)
if (
typeof readable.on === "function" &&
typeof readable.read !== "undefined"
) {
return await new Promise<string>((resolve, reject) => {
const chunks: Buffer[] = [];
readable.on("data", (chunk: any) => {
try {
chunks.push(toBuffer(chunk));
} catch (_err) {
// if conversion fails, push as Buffer of stringified chunk
chunks.push(Buffer.from(String(chunk)));
}
});
readable.on("error", (err: any) => reject(err));
readable.on("end", () => {
resolve(Buffer.concat(chunks).toString("utf8"));
});
});
}
// 2) WHATWG ReadableStream (browser / some fetch-like APIs)
if (typeof readable.getReader === "function") {
const reader = readable.getReader();
const chunks: Buffer[] = [];
try {
while (true) {
const { done, value } = await reader.read();
if (done) break;
chunks.push(toBuffer(value));
}
return Buffer.concat(chunks).toString("utf8");
} finally {
// safe to close reader if available
try {
if (reader.releaseLock) reader.releaseLock();
} catch (_err) {
// intentionally ignore releaseLock errors
}
}
}
// 3) Buffer / Uint8Array / ArrayBuffer direct
if (Buffer.isBuffer(readable)) return readable.toString("utf8");
if (readable instanceof Uint8Array)
return Buffer.from(readable).toString("utf8");
if (readable instanceof ArrayBuffer)
return Buffer.from(readable).toString("utf8");
// 4) Blob (browser)
if (typeof Blob !== "undefined" && readable instanceof Blob) {
const ab = await readable.arrayBuffer();
return Buffer.from(ab).toString("utf8");
}
// 5) Async iterable (some stream implementations)
if (typeof readable[Symbol.asyncIterator] === "function") {
const chunks: Buffer[] = [];
for await (const chunk of readable) {
chunks.push(toBuffer(chunk));
}
return Buffer.concat(chunks).toString("utf8");
}
// 6) Synchronous iterable
if (typeof readable[Symbol.iterator] === "function") {
const chunks: Buffer[] = [];
for (const chunk of readable) {
chunks.push(toBuffer(chunk));
}
return Buffer.concat(chunks).toString("utf8");
}
// 7) Fallback: try string conversion
try {
return String(readable);
} catch (_err) {
// If all else fails, throw a helpful error
throw new TypeError("Unsupported body type passed to streamToString");
}
}
public async uploadFile({
fileName,
fileType,
data,
partSize,
queueSize,
}: UploadFile): Promise<void> {
try {
const { client, namespaceName } = await this.getClientAndNamespace();
const uploadManager = new OciUploadManager(client, {
partSize: partSize ?? 20 * 1024 * 1024,
maxConcurrentUploads: queueSize ?? 5,
});
// UploadManager in the OCI SDK expects content shaped as one of:
// { blob }, { filePath }, or { stream }.
// To work reliably in Node, always provide { stream }.
const stream =
typeof data === "string"
? Readable.from([data])
: data instanceof Readable
? data
: Buffer.isBuffer(data as any)
? Readable.from([data as any])
: Readable.from([String(data)]);
const contentLength =
typeof data === "string"
? Buffer.byteLength(data)
: Buffer.isBuffer(data as any)
? (data as any).byteLength
: undefined;
await uploadManager.upload({
requestDetails: {
namespaceName,
bucketName: this.bucketName,
objectName: fileName,
contentType: fileType,
...(contentLength ? { contentLength } : {}),
},
content: { stream },
});
return;
} catch (err) {
logger.error(
`Failed to upload file to OCI Object Storage ${fileName}`,
err,
);
handleStorageError(err, "upload file to OCI Object Storage ");
}
}
public async uploadFileBuffered({
fileName,
fileType,
data,
partSizeBytes,
}: UploadFileBuffered): Promise<void> {
await this.uploadFile({
fileName,
fileType,
data,
partSize: partSizeBytes,
});
}
public async uploadWithSignedUrl({
fileName,
fileType,
data,
expiresInSeconds,
partSize,
queueSize,
}: UploadWithSignedUrl): Promise<{ signedUrl: string }> {
try {
await this.uploadFile({ fileName, data, fileType, partSize, queueSize });
const signedUrl = await this.getSignedUrl(fileName, expiresInSeconds);
return { signedUrl };
} catch (err) {
logger.error(
`Failed to upload file to OCI Object Storage ${fileName}`,
err,
);
handleStorageError(
err,
"upload file to OCI Object Storage or generate signed URL",
);
}
}
public async uploadJson(path: string, body: Record<string, unknown>[]) {
try {
const { client, namespaceName } = await this.getClientAndNamespace();
const jsonString = JSON.stringify(body);
const req: objectstorage.requests.PutObjectRequest = {
namespaceName,
bucketName: this.bucketName,
objectName: path,
contentLength: Buffer.byteLength(jsonString),
putObjectBody: Readable.from([jsonString]),
contentType: "application/json",
};
await client.putObject(req);
} catch (err) {
logger.error(`Failed to upload JSON to OCI Object Storage ${path}`, err);
handleStorageError(err, "upload JSON to OCI Object Storage ");
}
}
public async download(path: string): Promise<string> {
try {
const { client, namespaceName } = await this.getClientAndNamespace();
const req: objectstorage.requests.GetObjectRequest = {
namespaceName,
bucketName: this.bucketName,
objectName: path,
};
const response = await client.getObject(req);
const bodyStream = (response as any).value as
| NodeJS.ReadableStream
| undefined;
return await this.streamToString(bodyStream);
} catch (err) {
logger.error(
`Failed to download file from OCI Object Storage ${path}`,
err,
);
handleStorageError(err, "download file from OCI Object Storage ");
}
}
public async listFiles(
prefix: string,
): Promise<{ file: string; createdAt: Date }[]> {
try {
const { client, namespaceName } = await this.getClientAndNamespace();
const req: objectstorage.requests.ListObjectsRequest = {
namespaceName,
bucketName: this.bucketName,
prefix,
};
const resp = await client.listObjects(req);
const objects = ((resp as any).listObjects?.objects ?? []) as Array<{
name?: string;
timeCreated?: Date | string;
}>;
return (
objects.flatMap((obj) =>
obj.name
? [
{
file: obj.name,
createdAt: obj.timeCreated
? new Date(obj.timeCreated as any)
: new Date(),
},
]
: [],
) ?? []
);
} catch (err) {
logger.error(
`Failed to list files from OCI Object Storage ${prefix}`,
err,
);
handleStorageError(err, "list files from OCI Object Storage ");
}
}
public async getSignedUrl(
fileName: string,
ttlSeconds: number,
asAttachment: boolean = true,
): Promise<string> {
try {
const { client, namespaceName } = await this.getClientAndNamespace();
const expiresOn = new Date(Date.now() + ttlSeconds * 1000);
const req: objectstorage.requests.CreatePreauthenticatedRequestRequest = {
namespaceName,
bucketName: this.bucketName,
createPreauthenticatedRequestDetails: {
name: `read-${fileName}-${Date.now()}`,
accessType: "ObjectRead" as any,
objectName: fileName,
timeExpires: expiresOn as any,
} as any,
};
const resp = await client.createPreauthenticatedRequest(req);
const accessUri = (resp.preauthenticatedRequest as any)
.accessUri as string;
const base = this.externalEndpoint ?? client.endpoint;
if (!base) {
throw new Error(
"Cannot build PAR URL: no externalEndpoint configured and client.endpoint is empty",
);
}
const baseUrl = new URL(base);
const parUrl = new URL(accessUri, baseUrl);
if (asAttachment) {
parUrl.searchParams.set("download", "1");
}
const url = parUrl.toString();
return url;
} catch (err) {
logger.error(
`Failed to generate presigned URL (PAR) for OCI Object Storage ${fileName}`,
err,
);
handleStorageError(err, "generate signed URL for OCI Object Storage ");
}
}
public async deleteFiles(paths: string[]): Promise<void> {
try {
const { client, namespaceName } = await this.getClientAndNamespace();
for (const p of paths) {
const req: objectstorage.requests.DeleteObjectRequest = {
namespaceName,
bucketName: this.bucketName,
objectName: p,
} as any;
await client.deleteObject(req as any);
}
} catch (err) {
logger.error(`Failed to delete files from OCI Object Storage `, {
error: err,
files: paths,
});
handleStorageError(err, "delete files from OCI Object Storage ");
}
}
public async getSignedUploadUrl(params: {
path: string;
ttlSeconds: number;
sha256Hash: string;
contentType: string;
contentLength: number;
}): Promise<string> {
const { path, ttlSeconds } = params;
try {
const { client, namespaceName } = await this.getClientAndNamespace();
const expiresOn = new Date(Date.now() + ttlSeconds * 1000);
const req: objectstorage.requests.CreatePreauthenticatedRequestRequest = {
namespaceName,
bucketName: this.bucketName,
createPreauthenticatedRequestDetails: {
name: `write-${path}-${Date.now()}`,
accessType: "ObjectWrite" as any,
objectName: path,
timeExpires: expiresOn as any,
} as any,
};
const resp = await client.createPreauthenticatedRequest(req);
const accessUri = (resp.preauthenticatedRequest as any)
.accessUri as string;
const base = this.externalEndpoint ?? client.endpoint;
if (!base) {
throw new Error(
"Cannot build PAR URL: no externalEndpoint configured and client.endpoint is empty",
);
}
const baseUrl = new URL(base);
let url = new URL(accessUri, baseUrl).toString();
return url;
} catch (err) {
logger.error(
`Failed to generate presigned upload URL (PAR) for OCI Object Storage ${path}`,
err,
);
handleStorageError(
err,
"generate presigned upload URL for OCI Object Storage ",
);
}
}
}
@@ -1,9 +1,10 @@
import { Prisma } from "@prisma/client";
import { prisma } from "../../../db";
import {
TableViewPresetTableName,
type TableViewPresetDomain,
} from "../../../domain/table-view-presets";
import { LangfuseNotFoundError } from "../../../errors";
import { LangfuseConflictError, LangfuseNotFoundError } from "../../../errors";
import {
TableViewPresetsNamesCreatorList,
TableViewPresetsNamesCreatorListSchema,
@@ -12,11 +13,44 @@ import {
type UpdateTableViewPresetsInput,
} from "./types";
const TABLE_NAME_TO_URL_MAP = <Record<TableViewPresetTableName, string>>{
[TableViewPresetTableName.Traces]: "traces",
[TableViewPresetTableName.Observations]: "observations",
[TableViewPresetTableName.Scores]: "scores",
[TableViewPresetTableName.Sessions]: "sessions",
const TABLE_NAME_TO_URL_MAP: Partial<Record<TableViewPresetTableName, string>> =
{
[TableViewPresetTableName.Traces]: "traces",
[TableViewPresetTableName.Observations]: "observations",
[TableViewPresetTableName.ObservationsEvents]: "traces",
[TableViewPresetTableName.Scores]: "scores",
[TableViewPresetTableName.Sessions]: "sessions",
[TableViewPresetTableName.Datasets]: "datasets",
[TableViewPresetTableName.Experiments]: "experiments",
[TableViewPresetTableName.ExperimentItems]: "experiments/results",
};
// The v4 table was mistakenly released under the `observations` table name,
// so we need to read legacy presets that belong to the events table under the `observations` name.
// To avoid proliferating this compatibility logic, we only apply it when reading presets for the events table,
// and we never allow it when writing (creating/updating) presets.
const getReadCompatibleTableNames = (
tableName: TableViewPresetTableName,
): TableViewPresetTableName[] =>
tableName === TableViewPresetTableName.ObservationsEvents
? [
TableViewPresetTableName.ObservationsEvents,
TableViewPresetTableName.Observations,
]
: [tableName];
const TABLE_VIEW_PRESET_NAME_CONFLICT_MESSAGE =
"Table view preset with this name already exists. Please choose a different name.";
const throwTableViewPresetConflictIfDuplicateName = (error: unknown): never => {
if (
error instanceof Prisma.PrismaClientKnownRequestError &&
error.code === "P2002"
) {
throw new LangfuseConflictError(TABLE_VIEW_PRESET_NAME_CONFLICT_MESSAGE);
}
throw error;
};
export class TableViewService {
@@ -46,11 +80,13 @@ export class TableViewService {
input: UpdateTableViewPresetsInput,
updatedBy: string,
): Promise<TableViewPresetDomain> {
const tableViewPresets = await prisma.tableViewPreset.findUnique({
const tableViewPresets = await prisma.tableViewPreset.findFirst({
where: {
id: input.id,
projectId: input.projectId,
tableName: input.tableName,
tableName: {
in: getReadCompatibleTableNames(input.tableName),
},
},
});
@@ -60,20 +96,28 @@ export class TableViewService {
);
}
const updatedTableViewPresets = await prisma.tableViewPreset.update({
where: {
id: input.id,
projectId: input.projectId,
tableName: input.tableName,
},
data: {
...input,
orderBy: input.orderBy ?? undefined,
updatedBy,
},
});
try {
const updatedTableViewPresets = await prisma.tableViewPreset.update({
where: {
id: input.id,
projectId: input.projectId,
},
data: {
name: input.name,
tableName: input.tableName,
filters: input.filters,
columnOrder: input.columnOrder,
columnVisibility: input.columnVisibility,
searchQuery: input.searchQuery,
orderBy: input.orderBy ?? undefined,
updatedBy,
},
});
return updatedTableViewPresets as unknown as TableViewPresetDomain;
return updatedTableViewPresets as unknown as TableViewPresetDomain;
} catch (error) {
return throwTableViewPresetConflictIfDuplicateName(error);
}
}
/**
@@ -83,11 +127,13 @@ export class TableViewService {
input: UpdateTableViewPresetsNameInput,
updatedBy: string,
): Promise<TableViewPresetDomain> {
const tableViewPresets = await prisma.tableViewPreset.findUnique({
const tableViewPresets = await prisma.tableViewPreset.findFirst({
where: {
id: input.id,
projectId: input.projectId,
tableName: input.tableName,
tableName: {
in: getReadCompatibleTableNames(input.tableName),
},
},
});
@@ -97,19 +143,23 @@ export class TableViewService {
);
}
const updatedTableViewPresets = await prisma.tableViewPreset.update({
where: {
id: input.id,
projectId: input.projectId,
tableName: input.tableName,
},
data: {
name: input.name,
updatedBy,
},
});
try {
const updatedTableViewPresets = await prisma.tableViewPreset.update({
where: {
id: input.id,
projectId: input.projectId,
},
data: {
name: input.name,
tableName: input.tableName,
updatedBy,
},
});
return updatedTableViewPresets as unknown as TableViewPresetDomain;
return updatedTableViewPresets as unknown as TableViewPresetDomain;
} catch (error) {
return throwTableViewPresetConflictIfDuplicateName(error);
}
}
/**
@@ -131,17 +181,20 @@ export class TableViewService {
* Gets all table view presets for a table
*/
public static async getTableViewPresetsByTableName(
tableName: string,
tableName: TableViewPresetTableName,
projectId: string,
): Promise<TableViewPresetsNamesCreatorList> {
const TableViewPresets = await prisma.tableViewPreset.findMany({
const records = await prisma.tableViewPreset.findMany({
where: {
tableName,
tableName: {
in: getReadCompatibleTableNames(tableName),
},
projectId,
},
select: {
id: true,
name: true,
tableName: true,
createdBy: true,
createdByUser: {
select: {
@@ -157,7 +210,33 @@ export class TableViewService {
},
});
return TableViewPresetsNamesCreatorListSchema.parse(TableViewPresets);
const presets = TableViewPresetsNamesCreatorListSchema.parse(records);
if (tableName === TableViewPresetTableName.ObservationsEvents) {
// Deduplicate presets that have the same name,
// preferring presets that belong to the canonical events table namespace
// over presets that belong to the legacy observations namespace.
const presetsByName = new Map<
string,
TableViewPresetsNamesCreatorList[number]
>();
for (const preset of presets) {
const existingPreset = presetsByName.get(preset.name);
if (
!existingPreset ||
(preset.tableName === TableViewPresetTableName.ObservationsEvents &&
existingPreset.tableName === TableViewPresetTableName.Observations)
) {
presetsByName.set(preset.name, preset);
}
}
return Array.from(presetsByName.values());
}
return presets;
}
/**
@@ -193,6 +272,9 @@ export class TableViewService {
projectId: string,
): Promise<string> {
const page = TABLE_NAME_TO_URL_MAP[tableName];
if (!page) {
throw new Error(`Permalinks are not supported for table ${tableName}`);
}
return `${baseUrl}/project/${projectId}/${page}?viewId=${TableViewPresetsId}`;
}
}
@@ -1,10 +1,10 @@
import z from "zod";
import { orderBy, singleFilter } from "../../..";
import { orderBy, singleFilter, TableViewPresetTableName } from "../../..";
export const CreateTableViewPresetsInput = z.object({
projectId: z.string(),
name: z.string().min(1, "View name is required"),
tableName: z.string(),
tableName: z.enum(TableViewPresetTableName),
filters: z.array(singleFilter),
columnOrder: z.array(z.string()),
columnVisibility: z.record(z.string(), z.boolean()),
@@ -19,7 +19,7 @@ export const UpdateTableViewPresetsInput = CreateTableViewPresetsInput.extend({
export const UpdateTableViewPresetsNameInput = z.object({
id: z.string(),
name: z.string(),
tableName: z.string(),
tableName: z.enum(TableViewPresetTableName),
projectId: z.string(),
});
@@ -37,6 +37,7 @@ export const TableViewPresetsNamesCreatorListSchema = z.array(
z.object({
id: z.string(),
name: z.string(),
tableName: z.enum(TableViewPresetTableName),
createdBy: z.string().nullable(),
createdByUser: z
.object({
@@ -227,6 +227,22 @@ export async function notifyBlockedEvaluatorConfigs({
return;
}
const project = await prisma.project.findUnique({
where: {
id: projectId,
},
select: {
name: true,
},
});
if (!project) {
logger.warn(
`[EVALUATOR BLOCK] Project ${projectId} not found. Skipping notifications.`,
);
return;
}
const blockedConfigs = await prisma.jobConfiguration.findMany({
where: {
projectId,
@@ -254,6 +270,7 @@ export async function notifyBlockedEvaluatorConfigs({
adminEmails.map((receiverEmail) =>
sendEvaluatorBlockedEmail({
env: emailEnv,
projectName: project.name,
evaluatorName: config.evalTemplate?.name ?? config.scoreName,
blockReason,
blockMessage,
@@ -16,6 +16,7 @@ import {
import { EvaluatorBlockReason } from "@prisma/client";
type EvaluatorBlockedEmailTemplateProps = {
projectName: string;
evaluatorName: string;
blockReason: EvaluatorBlockReason;
blockMessage: string;
@@ -104,6 +105,7 @@ const getResolutionSteps = (blockReason: EvaluatorBlockReason) => {
};
export const EvaluatorBlockedEmailTemplate = ({
projectName,
evaluatorName,
blockReason,
blockMessage,
@@ -114,8 +116,8 @@ export const EvaluatorBlockedEmailTemplate = ({
<Html>
<Head />
<Preview>
LLM evaluator &quot;{evaluatorName}&quot; paused:{" "}
{getReasonSummary(blockReason)}
LLM evaluator &quot;{evaluatorName}&quot; in project &quot;
{projectName}&quot; paused: {getReasonSummary(blockReason)}
</Preview>
<Tailwind>
<Body className="bg-background my-auto mx-auto font-sans">
@@ -135,8 +137,9 @@ export const EvaluatorBlockedEmailTemplate = ({
Evaluator Paused
</Heading>
<Text className="text-gray-700 text-sm leading-6">
The LLM evaluator &quot;{evaluatorName}&quot; was automatically
paused because {getReasonSummary(blockReason).toLowerCase()}.
The LLM evaluator &quot;{evaluatorName}&quot; in project &quot;
{projectName}&quot; was automatically paused because{" "}
{getReasonSummary(blockReason).toLowerCase()}.
</Text>
</Section>
@@ -174,7 +177,8 @@ export const EvaluatorBlockedEmailTemplate = ({
<Section>
<Text className="text-[#666666] text-[12px] leading-[24px]">
This notification was sent to {receiverEmail} regarding the
paused evaluator &quot;{evaluatorName}&quot;.
paused evaluator &quot;{evaluatorName}&quot; in project &quot;
{projectName}&quot;.
</Text>
</Section>
</Container>
@@ -17,6 +17,7 @@ export type SendEvaluatorBlockedEmailParams = {
string | undefined
>
>;
projectName: string;
evaluatorName: string;
blockReason: EvaluatorBlockReason;
blockMessage: string;
@@ -26,6 +27,7 @@ export type SendEvaluatorBlockedEmailParams = {
export const sendEvaluatorBlockedEmail = async ({
env,
projectName,
evaluatorName,
blockReason,
blockMessage,
@@ -42,9 +44,11 @@ export const sendEvaluatorBlockedEmail = async ({
try {
const mailer = createTransport(parseConnectionUrl(env.SMTP_CONNECTION_URL));
const safeEvaluatorName = sanitizeEmailSubject(evaluatorName);
const safeProjectName = sanitizeEmailSubject(projectName);
const subject = `⚠️ LLM evaluator "${safeEvaluatorName}" paused - action required`;
const html = await render(
EvaluatorBlockedEmailTemplate({
projectName: safeProjectName,
evaluatorName: safeEvaluatorName,
blockReason,
blockMessage,
@@ -19,6 +19,7 @@ import {
import { queryClickhouse } from "../repositories";
import { sessionCols } from "../tableMappings/mapSessionTable";
import { sessionsViewCols } from "../../tableDefinitions/sessionsView";
import { findUiColumnMapping } from "../../tableDefinitions";
import { parseClickhouseUTCDateTimeFormat } from "../repositories/clickhouse";
type SessionEventsBaseReturnType = {
@@ -186,10 +187,8 @@ const getSessionsTableFromEventsGeneric = async <T>(
const requiresScoresJoin =
sessionFilters.some((f) => f.clickhouseTable === "scores") ||
sessionCols.find(
(c) =>
c.uiTableName === orderBy?.column || c.uiTableId === orderBy?.column,
)?.clickhouseTableName === "scores";
findUiColumnMapping(sessionCols, orderBy?.column)?.clickhouseTableName ===
"scores";
// Build session_data CTE
const sessionsBuilder = eventsSessionsAggregation({
@@ -3,6 +3,7 @@ import { OrderByState } from "../../interfaces/orderBy";
import { sessionCols } from "../tableMappings/mapSessionTable";
import { FilterState } from "../../types";
import { sessionsViewCols } from "../../tableDefinitions/sessionsView";
import { findUiColumnMapping } from "../../tableDefinitions";
import { convertDateToClickhouseDateTime } from "../clickhouse/client";
import { measureAndReturn } from "../clickhouse/measureAndReturn";
import { DateTimeFilter, FilterList, orderByToClickhouseSql } from "../queries";
@@ -216,10 +217,8 @@ const getSessionsTableGeneric = async <T>(props: FetchSessionsTableProps) => {
const requiresScoresJoin =
tracesFilter.find((f) => f.clickhouseTable === "scores") !== undefined ||
sessionCols.find(
(c) =>
c.uiTableName === orderBy?.column || c.uiTableId === orderBy?.column,
)?.clickhouseTableName === "scores";
findUiColumnMapping(sessionCols, orderBy?.column)?.clickhouseTableName ===
"scores";
const hasMetricsFilter =
tracesFilter.find((f) =>
@@ -1,6 +1,7 @@
import { OrderByState } from "../../interfaces/orderBy";
import { tracesTableUiColumnDefinitions } from "../tableMappings";
import { tracesTableCols } from "../../tableDefinitions/tracesTable";
import { findUiColumnMapping } from "../../tableDefinitions";
import { FilterState } from "../../types";
import {
StringFilter,
@@ -269,18 +270,14 @@ async function getTracesTableGeneric(props: FetchTracesTableProps) {
const requiresScoresJoin =
tracesFilter.find((f) => f.clickhouseTable === "scores") !== undefined ||
tracesTableUiColumnDefinitions.find(
(c) =>
c.uiTableName === orderBy?.column || c.uiTableId === orderBy?.column,
)?.clickhouseTableName === "scores";
findUiColumnMapping(tracesTableUiColumnDefinitions, orderBy?.column)
?.clickhouseTableName === "scores";
const requiresObservationsJoin =
tracesFilter.find((f) => f.clickhouseTable === "observations") !==
undefined ||
tracesTableUiColumnDefinitions.find(
(c) =>
c.uiTableName === orderBy?.column || c.uiTableId === orderBy?.column,
)?.clickhouseTableName === "observations";
findUiColumnMapping(tracesTableUiColumnDefinitions, orderBy?.column)
?.clickhouseTableName === "observations";
const tracesFilterRes = tracesFilter.apply();
const scoresFilterRes = scoresFilter.apply();
@@ -1,4 +1,7 @@
import { UiColumnMappings } from "../../tableDefinitions";
import {
matchesUiColumnMapping,
UiColumnMappings,
} from "../../tableDefinitions";
import { DatasetRunItemDomain } from "../../domain/dataset-run-items";
export const datasetRunItemsTableUiColumnDefinitions: UiColumnMappings = [
@@ -52,9 +55,7 @@ export const mapDatasetRunItemFilterColumn = (
): unknown => {
const columnDef = datasetRunItemsTableUiColumnDefinitions.find(
(col) =>
col.uiTableId === column ||
col.uiTableName === column ||
col.clickhouseSelect === column,
matchesUiColumnMapping(col, column) || col.clickhouseSelect === column,
);
if (!columnDef) {
throw new Error(`Unhandled column for dataset run items filter: ${column}`);
@@ -259,6 +259,12 @@ export const eventsTableNativeUiColumnDefinitions: UiColumnMappings = [
clickhouseTableName: "events_proto",
clickhouseSelect: 'e."experiment_name"',
},
{
uiTableName: "Is Experiment Item Root Span",
uiTableId: "isExperimentItemRootSpan",
clickhouseTableName: "events_proto",
clickhouseSelect: "e.experiment_item_root_span_id = e.span_id",
},
{
uiTableName: "Available Tools",
uiTableId: "toolDefinitions",
@@ -103,7 +103,14 @@ export const dashboardColumnDefinitions: UiColumnMappings = [
clickhouseTableName: "observations",
clickhouseSelect: "mapKeys(tool_definitions)",
uiTableId: "toolNames",
uiTableName: "Tool Names",
uiTableName: "Tool Names (Available)",
aliases: ["Tool Names"],
},
{
clickhouseTableName: "observations",
clickhouseSelect: "tool_call_names",
uiTableId: "calledToolNames",
uiTableName: "Tool Names (Called)",
},
{
clickhouseTableName: "traces",

Some files were not shown because too many files have changed in this diff Show More