Skip to content

fix(embed-filter): zero-dep /metrics + access log (weown-fleet#150) - #325

Draft
ncimino wants to merge 1 commit into
mainfrom
fix/150-embed-filter-obs
Draft

ncimino wants to merge 1 commit into
mainfrom
fix/150-embed-filter-obs

Conversation

@ncimino

@ncimino ncimino commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements the embed-filter slice of weown-fleet#150 without breaking the zero-npm / no-secrets shape of this process.

  • GET /metrics — hand-rolled Prom histogram embed_filter_request_duration_seconds and counter embed_filter_requests_total, labels status + tenant (embed id from /api/embed/<id>/…)
  • Structured JSON access log per request (request_id, method, path, status, duration_ms, tenant, optional traceparent)
  • traceparent left on the upstream hop (passthrough); x-request-id echoed (generated if absent)
  • /healthz and /metrics are local and not metered as chat traffic
  • PostHog deliberately out of scope here (this container holds no secrets)

Test

node anythingllm-docker/template/embed-filter/test.js — obs group + full suite (30 assertion groups) pass after; helpers//metrics absent before.

Notes

Agent merges OFF. Prefer forge CI. Seat: ai-grok.

…n-fleet#150)

Hand-rolled Prometheus histogram and request counter labeled by status and
tenant (embed id), structured JSON access lines with a request id, and
traceparent left on the upstream proxy hop. Keeps the zero-npm / no-secrets
shape of embed-filter; PostHog stays out of this process.

Test: embed-filter/test.js obs group fails before (no /metrics, no helpers)
and passes after. Suite: 30 assertion groups.
Copilot AI balanced review requested due to automatic review settings October 26, 2026 06:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unbounded client-controlled metric labels threaten proxy availability, and request accounting and correlation remain incomplete.

3 open issues
What changed in this PR

Adds zero-dependency observability to the AnythingLLM embed proxy in both the deployment template and beta site, preserving its no-secrets design.

Changes:

  • Adds Prometheus request counters and duration histograms, excluding health and metrics requests.
  • Adds structured access logs and request IDs while retaining trace-header passthrough.
  • Adds observability assertions and documents the feature in the template changelog.
File Description
anythingllm-docker/​template/​embed-filter/​test.js Adds metrics, endpoint, and request-ID assertions.
anythingllm-docker/​template/​embed-filter/​server.js Implements metrics and structured request logging.
anythingllm-docker/​template/​CHANGELOG.md.jinja Documents observability features and scope.
anythingllm-docker/​sites/​beta-weown-chat/​embed-filter/​test.js Mirrors observability assertions for the beta site.
anythingllm-docker/​sites/​beta-weown-chat/​embed-filter/​server.js Applies observability changes to the beta deployment.

Review effort: Balanced

Comment on lines +83 to +85
if (!row) {
row = { count: 0, sum: 0, buckets: DURATION_BUCKETS.map(() => 0) };
metrics.duration.set(key, row);
try { res.setHeader('x-request-id', requestId); } catch (_) { /* headers may already be on the way */ }
// Meter the hot path only (not health/metrics scrapes).
const meter = pathname !== '/healthz' && pathname !== '/metrics';
res.on('finish', () => {
Comment on lines +348 to 349
attachObs(req, res, target.pathname);
const headers = { ...req.headers };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants