Skip to content

feat(agent,runtime): gzip OTLP posts + auto-wire agent generations + eslint fixes - #162

Merged
prisis merged 4 commits into
alphafrom
feat/framework-otlp-followups
Jul 22, 2026
Merged

prisis merged 4 commits into
alphafrom
feat/framework-otlp-followups

Conversation

@prisis

@prisis prisis commented Jul 22, 2026 •

Copy link
Copy Markdown
Member

Follow-up to the merged #160 (OTLP generation spans), completing items 8, 9, and the eslint pass from the "do 1 to 10" gap-closure:

  • gzip OTLP posts (item 9) — otlpSink gzips bodies past 1 KB (Content-Encoding: gzip, via CompressionStream); tiny single-span posts stay plain.
  • Auto-wire agent generations (item 8) — the compiled agent workflow auto-appends otlpTelemetry when LUNORA_OTLP_ENDPOINT is injected (the platform), so a deployed agent emits gen_ai.* spans with no app wiring. No-op locally / when telemetry is explicitly disabled; privacy-safe (structural metadata only).
  • eslint fixes — feat(agent,ai): emit AI generation spans over OTLP #160 merged with eslint findings that only the alpha TS-6 pin surfaces (the detached observer's promise/always-return, exports-last, jsdoc nits, a nested ternary, a chained assignment). Fixed here; no behavior change.

Test plan

@lunora/agent + @lunora/runtime tsc clean, agent telemetry suite green, @lunora/ai/@lunora/runtime unchanged behavior. eslint clean on the changed files.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • OTLP generation telemetry is now automatically enabled when an endpoint is configured, while respecting explicit telemetry settings.
    • Large telemetry payloads are compressed to improve transmission efficiency.
  • Bug Fixes

    • Improved telemetry reporting for successful and failed model or tool operations.
    • Prevented background telemetry processing from causing unhandled errors.
  • Documentation

    • Clarified telemetry integration and RAG context documentation.

prisis and others added 2 commits July 22, 2026 08:04
…emetry

- @lunora/runtime: otlpSink gzips OTLP bodies past 1 KB (Content-Encoding:
  gzip, via CompressionStream) — tiny single-span posts stay plain.
- @lunora/agent: the compiled workflow auto-appends an otlpTelemetry
  integration when LUNORA_OTLP_ENDPOINT is injected (the platform), so a
  deployed agent emits gen_ai.* generation spans with no app wiring.
  Byte-identical no-op locally or when telemetry is explicitly disabled;
  privacy-safe (structural metadata only unless recordInputs/Outputs).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0197KjhmBDB3PXAc6TXiPqZ9
eslint (which only runs on alpha, TS-6 pinned) flagged real issues the
tsc/vitest gate missed: the agent otlpTelemetry detached observer tripped
promise/always-return + no-confusing-void-expression (rewritten as a
named async `observe().catch(...)`), plus exports-last / jsdoc-link /
jsdoc-indentation nits; a nested ternary + needless cast in the workflow
auto-wire; a chained assignment in define-rag; and jsdoc description/link
nits in runtime + rag types. No behavior change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0197KjhmBDB3PXAc6TXiPqZ9
@netlify

netlify Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for lunorash ready!

Name Link
🔨 Latest commit c595fc7
🔍 Latest deploy log https://app.netlify.com/projects/lunorash/deploys/6a606779a28cc90008d4fb4a
😎 Deploy Preview https://deploy-preview-162--lunorash.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • packages/agent/__tests__/telemetry/otlp.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1765a296-bae9-4e7b-9412-da95703b5e3a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

The workflow now auto-configures OTLP telemetry from environment variables. Span settlement and attribute encoding are centralized, OTLP payloads can be gzipped above a threshold, and minor RAG implementation and documentation cleanup is included.

Changes

OTLP telemetry integration

Layer / File(s) Summary
Workflow OTLP auto-configuration
packages/agent/src/workflow.ts
Creates a runtime agent with an OTLP integration when configured and uses it for loop, regular generation, and streaming generation.
Span settlement and attributes
packages/agent/src/telemetry/otlp.ts
Centralizes promise settlement emission, prevents detached observer rejections, and encodes non-nullish attributes with JSON serialization for objects and arrays.
Compressed OTLP transport
packages/runtime/src/observability-sinks.ts
Gzips serialized OTLP payloads above the threshold and sets the corresponding content-encoding header.
RAG implementation and documentation cleanup
packages/ai/src/rag/define-rag.ts, packages/ai/src/rag/types.ts
Splits embedding-model resolution into separate assignment and binding steps and adjusts RAG documentation formatting.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant WorkflowHandler
  participant RuntimeAgent
  participant AgentLoop
  participant OTLPIntegration
  participant OTLPHTTP
  WorkflowHandler->>RuntimeAgent: Configure from OTLP environment variables
  WorkflowHandler->>AgentLoop: Run with RuntimeAgent
  AgentLoop->>OTLPIntegration: Observe generation or tool settlement
  OTLPIntegration->>OTLPHTTP: Send serialized payload, optionally gzipped
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the changes and test plan, but it omits required template sections like Summary, Linked issues, Checklist, Notes, and CLA. Add the missing template sections, especially Summary, Linked issues, Checklist, Notes for reviewers, and the CLA statement.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is specific, conventional, and matches the main OTLP gzip and auto-wiring changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/framework-otlp-followups

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for confirming the Contributor License Agreement! 🙏

@codspeed

codspeed Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 11.2%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 26 untouched benchmarks
⏩ 134 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ with shardKey: explicit shard selection 1.6 ms 1.4 ms +11.2%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing feat/framework-otlp-followups (c595fc7) with alpha (4c7f0cb)2

Open in CodSpeed

Footnotes

  1. 134 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on alpha (837b8ec) during the generation of this report, so 4c7f0cb was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

… span)

The detached observer wrapped `emit()` inside the try, so a throw from
`emit` on the SUCCESS path (e.g. JSON.stringify on a circular recorded
input/output) was mis-caught and recorded a successful call as an error
span. Extract a shared `observeSettled(promise, onSettle)` helper that
guards only the `await` — a success-path throw now propagates to the
detached `.catch` (no span) instead of a wrong error span — and dedupes
the two near-identical observer blocks.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0197KjhmBDB3PXAc6TXiPqZ9

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/runtime/src/observability-sinks.ts`:
- Around line 264-270: Update the gzip threshold check in the observability
export flow to measure the serialized JSON payload in UTF-8 bytes rather than
UTF-16 code units. Replace the json.length comparison with the byteLength of new
TextEncoder().encode(json), while preserving the existing gzip and fetch
branches.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 98dd711b-c57e-4c15-9e82-dc48cce937e8

📥 Commits

Reviewing files that changed from the base of the PR and between 837b8ec and f120e0b.

📒 Files selected for processing (5)
  • packages/agent/src/telemetry/otlp.ts
  • packages/agent/src/workflow.ts
  • packages/ai/src/rag/define-rag.ts
  • packages/ai/src/rag/types.ts
  • packages/runtime/src/observability-sinks.ts

Comment on lines +264 to +270
const json = JSON.stringify(body);
// `.catch` swallows any rejection so a failed export can never reject
// into the dispatch path.
const sent = fetch(url, { body: JSON.stringify(body), headers, method: "POST" }).catch(() => {
// Network error / non-OK response — intentionally ignored.
const sent = (
json.length < OTLP_GZIP_THRESHOLD
? fetch(url, { body: json, headers, method: "POST" })
: gzipEncode(json).then((gz) => fetch(url, { body: gz, headers: { ...headers, "content-encoding": "gzip" }, method: "POST" }))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Map the file structure and inspect the relevant area
ast-grep outline packages/runtime/src/observability-sinks.ts --view expanded || true
printf '\n--- lines around the target ---\n'
sed -n '220,320p' packages/runtime/src/observability-sinks.ts
printf '\n--- search for threshold/helper usage ---\n'
rg -n "OTLP_GZIP_THRESHOLD|TextEncoder|gzipEncode|content-encoding|json.length" packages/runtime/src/observability-sinks.ts packages/runtime/src -S

Repository: anolilab/lunora

Length of output: 9206


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Check how byte length is computed elsewhere in the repo and whether TextEncoder is assumed available
rg -n "new TextEncoder\(|TextEncoder\.|byteLength" packages/runtime/src packages -S

Repository: anolilab/lunora

Length of output: 9984


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Verify the environment exposes the relevant web APIs in TypeScript typings used by the repo, without executing repo code.
node - <<'JS'
const names = ['TextEncoder', 'CompressionStream', 'Blob', 'Response', 'fetch'];
for (const name of names) {
  console.log(name, typeof globalThis[name]);
}
JS

Repository: anolilab/lunora

Length of output: 248


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the runtime TypeScript sources for any explicit byte-length helper or threshold comments.
sed -n '1,220p' packages/runtime/src/observability-sinks.ts

Repository: anolilab/lunora

Length of output: 10016


Measure the gzip cutoff in UTF-8 bytes. json.length counts UTF-16 code units, so non-ASCII payloads can stay under the 1 KiB threshold while exceeding it on the wire; use new TextEncoder().encode(json).byteLength here.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/runtime/src/observability-sinks.ts` around lines 264 - 270, Update
the gzip threshold check in the observability export flow to measure the
serialized JSON payload in UTF-8 bytes rather than UTF-16 code units. Replace
the json.length comparison with the byteLength of new
TextEncoder().encode(json), while preserving the existing gzip and fetch
branches.

Source: Path instructions

Move `afterEach` inside the describe (require-top-level-describe) and hoist
the fixed 32-hex trace id to a single `no-secrets`-disabled const (a fake
test id, not a credential) reused across assertions.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0197KjhmBDB3PXAc6TXiPqZ9
@prisis
prisis merged commit cef9855 into alpha Jul 22, 2026
41 checks passed
@prisis
prisis deleted the feat/framework-otlp-followups branch July 22, 2026 08:25
prisis added a commit that referenced this pull request Jul 28, 2026
…, otp reset

From better-auth-ui #173, #162, #211 and #337, checked against our code.

The password minimum was hard-coded to 8, which is a guess at the server's
rule: too low and the user is told 'too short' only after a round-trip, too
high and we refuse passwords the server would take. It is config now, meant
to be matched to emailAndPassword, and every password field routes through
it. <PasswordStrength> shows the rules as a checklist rather than a bar,
because a bar says a password is unacceptable without saying what to change.

The providers dropped the field. AuthUIConfig.password existed and
resolveContext honoured it, but all five rebuilt their config object
field-by-field and omitted it — so a configured policy was unreachable and
the checklist always showed the default. Regression test added.

Username availability now uses /is-username-available, which better-auth
exposed all along: a taken name surfaced only as a failed sign-up. It is
debounced and drops out-of-order answers, and reports 'unknown' rather than
'taken' on failure so it can never block a sign-up the server would allow.

Forgot-password can use the emailOTP endpoints. An app that recovers by code
got 'Reset password isn't enabled' from /request-password-reset, which names
neither cause nor fix.

Sign-up seeds email/name from the link, and the invitation bounce now carries
the invited address — retyping it is how an invitee ends up creating a
different account the invitation doesn't match. Passwords are never
prefilled: an allow-list, because a password in a query string lands in
history, referrers and logs.

Also organization.showSlug, and the last-used badge now covers email and
magic-link — better-auth records those too, so badging only social buttons
made the feature invisible for the commonest route.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using our GitHub Discussions tab for questions.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 9, 2026

This branch was previously deployed

1 inactive deployment
benchmarks — c595fc7a Deployed Jul 22, 2026 by prisis via Benchmarks #834
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant