fix(api): link bot and worker traces - #95
Conversation
|
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
embedly-docs | a0d8b65 | Commit Preview URL Branch Preview URL |
Jul 24 2026, 05:43 AM |
|
@greptile review |
Greptile SummaryThis PR instruments the API Worker with
Confidence Score: 4/5Safe to merge after restoring Reddit credential forwarding; the OTEL wiring itself is correct. The OTEL instrumentation changes are sound — trace context propagation, span ID logging, and the fail-fast OTEL_ENDPOINT guard all work as intended. However, REDDIT_CLIENT_ID and REDDIT_CLIENT_SECRET are no longer forwarded to p.fetch(), and the Reddit platform's fetchAccessToken hard-throws when those values are absent, so every Reddit scrape will return a 500 after this lands. apps/api/src/index.ts — the p.fetch() call and apps/api/worker-configuration.d.ts — the regenerated bindings both need Reddit credentials restored. Important Files Changed
Sequence DiagramsequenceDiagram
participant Bot
participant API as API Worker (instrument wrapper)
participant Hono as Hono + httpInstrumentationMiddleware
participant OTLPExporter as OTLP Collector (OTEL_ENDPOINT)
participant CF as Cloudflare Logs
Bot->>API: "POST /platforms/scrape traceparent: 00-{traceId}-{spanId}-01"
Note over API: instrument() reads traceparent,creates child span in same trace
API->>Hono: next() — span now active
Hono->>Hono: "spanContext = trace.getActiveSpan().spanContext()"
Hono->>Hono: "logContext.trace_id = spanContext.traceId logContext.span_id = spanContext.spanId"
Hono-->>CF: console.info(formatLog(..., logContext))
API-->>OTLPExporter: export spans (traceId shared with bot)
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
apps/api/src/index.ts:109-112
**Reddit credentials silently dropped from platform fetch**
`REDDIT_CLIENT_ID` and `REDDIT_CLIENT_SECRET` were removed from the `p.fetch()` call here. The Reddit platform's `fetchAccessToken` function throws `{ code: 500, message: "Reddit credentials are not configured" }` when either credential is absent (`reddit.ts` lines 13–18), so every Reddit scrape request will fail with a 500 after this change. This removal appears to be a side-effect of regenerating `worker-configuration.d.ts` without the deployed secrets — TypeScript would then flag `c.env.REDDIT_CLIENT_ID` as unknown, prompting their removal. The secrets and their wiring both need to be restored.
Reviews (4): Last reviewed commit: "fix(api): sync worker bindings" | Re-trigger Greptile |
Greptile SummaryThis PR instruments the API Cloudflare Worker with
Confidence Score: 4/5Safe to merge — the instrumentation wiring is correct and the API's request-handling logic is unchanged. The trace propagation approach is sound: instrument() correctly picks up the incoming traceparent and httpInstrumentationMiddleware creates a child HTTP span, so trace.getActiveSpan()?.spanContext() in the route handler reliably returns the correlated IDs. Disabling native CF traces while keeping log export is the right call. The one gap is that OTEL_ENDPOINT is referenced as a non-optional binding but is not wired up in wrangler.jsonc or the generated type file — if the secret is missing in a deployment, span export will fail silently with no compile-time or startup warning. apps/api/src/index.ts — the manual Bindings type extension for OTEL_ENDPOINT and the absence of that secret from wrangler.jsonc / worker-configuration.d.ts is the only area worth a second look before deploying to a new environment. Important Files Changed
Sequence DiagramsequenceDiagram
participant Bot
participant API Worker (instrument wrapper)
participant Hono httpInstrumentationMiddleware
participant Route Handler
participant OTEL Collector
Bot->>API Worker (instrument wrapper): HTTP request + traceparent header
Note over API Worker (instrument wrapper): instrument() extracts traceparent,<br/>propagates W3C trace context,<br/>creates root span as child of bot's span
API Worker (instrument wrapper)->>Hono httpInstrumentationMiddleware: fetch(request, env, ctx)
Note over Hono httpInstrumentationMiddleware: Creates HTTP child span<br/>under propagated root span
Hono httpInstrumentationMiddleware->>Route Handler: next()
Route Handler->>Route Handler: trace.getActiveSpan()?.spanContext()<br/>→ writes trace_id + span_id to log
Route Handler-->>Hono httpInstrumentationMiddleware: response
Hono httpInstrumentationMiddleware-->>API Worker (instrument wrapper): response + span end
API Worker (instrument wrapper)-->>Bot: HTTP response
API Worker (instrument wrapper)->>OTEL Collector: export spans to env.OTEL_ENDPOINT
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
apps/api/src/index.ts:23-28
`OTEL_ENDPOINT` not declared in `wrangler.jsonc` and absent from the generated `CloudflareBindings`
`OTEL_ENDPOINT` is typed as a required `string`, but there is no `vars` or `secrets` entry for it in `wrangler.jsonc`, and `worker-configuration.d.ts` does not include it. If the secret has not been added via `wrangler secret put OTEL_ENDPOINT`, `env.OTEL_ENDPOINT` will be `undefined` at runtime. The `@microlabs/otel-cf-workers` OTLP exporter will then be initialised with `url: undefined`, causing all span exports to fail silently — no traces will reach the collector, but the API itself will continue serving requests. Consider documenting the required `wrangler secret put` step and re-running `cf-typegen` after adding the secret so the binding appears in `CloudflareBindings` rather than needing a manual type extension.
Reviews (2): Last reviewed commit: "fix(api): harden tracing config" | Re-trigger Greptile |
| try { | ||
| raw = await p.fetch(id, { | ||
| EMBED_USER_AGENT: c.env.EMBED_USER_AGENT, | ||
| REDDIT_CLIENT_ID: c.env.REDDIT_CLIENT_ID, | ||
| REDDIT_CLIENT_SECRET: c.env.REDDIT_CLIENT_SECRET, | ||
| }); |
There was a problem hiding this comment.
Reddit credentials silently dropped from platform fetch
REDDIT_CLIENT_ID and REDDIT_CLIENT_SECRET were removed from the p.fetch() call here. The Reddit platform's fetchAccessToken function throws { code: 500, message: "Reddit credentials are not configured" } when either credential is absent (reddit.ts lines 13–18), so every Reddit scrape request will fail with a 500 after this change. This removal appears to be a side-effect of regenerating worker-configuration.d.ts without the deployed secrets — TypeScript would then flag c.env.REDDIT_CLIENT_ID as unknown, prompting their removal. The secrets and their wiring both need to be restored.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/api/src/index.ts
Line: 109-112
Comment:
**Reddit credentials silently dropped from platform fetch**
`REDDIT_CLIENT_ID` and `REDDIT_CLIENT_SECRET` were removed from the `p.fetch()` call here. The Reddit platform's `fetchAccessToken` function throws `{ code: 500, message: "Reddit credentials are not configured" }` when either credential is absent (`reddit.ts` lines 13–18), so every Reddit scrape request will fail with a 500 after this change. This removal appears to be a side-effect of regenerating `worker-configuration.d.ts` without the deployed secrets — TypeScript would then flag `c.env.REDDIT_CLIENT_ID` as unknown, prompting their removal. The secrets and their wiring both need to be restored.
How can I resolve this? If you propose a fix, please make it concise.
Summary
@microlabs/otel-cf-workersand Hono OTEL middlewareRoot cause
Cloudflare's native Worker tracing creates a new trace ID instead of accepting trace context propagated from services outside Cloudflare. The bot already injects
traceparent, but the API trace was disconnected and Cloudflare's metadata trace ID did not match the application log trace ID.