-
Notifications
You must be signed in to change notification settings - Fork 3
fix(api): link bot and worker traces #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,10 @@ import { | |
| getRequestId, | ||
| } from "@embedly/logging"; | ||
| import { Platforms } from "@embedly/platforms"; | ||
| import { httpInstrumentationMiddleware } from "@hono/otel"; | ||
| import { zValidator } from "@hono/zod-validator"; | ||
| import { instrument, type ResolveConfigFn } from "@microlabs/otel-cf-workers"; | ||
| import { trace } from "@opentelemetry/api"; | ||
| import { Hono } from "hono"; | ||
| import { bearerAuth } from "hono/bearer-auth"; | ||
| import { cors } from "hono/cors"; | ||
|
|
@@ -18,14 +21,17 @@ import { version } from "../package.json"; | |
|
|
||
| type ScrapeResponse = Awaited<ReturnType<(typeof Platforms)[keyof typeof Platforms]["transform"]>>; | ||
|
|
||
| function getTraceId(request: Request) { | ||
| const traceparent = request.headers.get("traceparent"); | ||
| const traceId = traceparent?.split("-")[1]; | ||
| if (!traceId || !/^[a-f0-9]{32}$/.test(traceId)) return undefined; | ||
| return traceId; | ||
| } | ||
| const config: ResolveConfigFn<CloudflareBindings> = (env) => { | ||
| if (!env.OTEL_ENDPOINT) throw new Error("OTEL_ENDPOINT is required."); | ||
|
|
||
| return { | ||
| exporter: { url: env.OTEL_ENDPOINT }, | ||
| service: { name: "embedly-api", version }, | ||
| }; | ||
| }; | ||
|
|
||
| const app = new Hono<{ Bindings: CloudflareBindings }>() | ||
| .use("*", httpInstrumentationMiddleware()) | ||
| .use(cors()) | ||
| .use(prettyJSON()) | ||
| .get("/health", (c) => { | ||
|
|
@@ -45,9 +51,11 @@ const app = new Hono<{ Bindings: CloudflareBindings }>() | |
| const startedAt = Date.now(); | ||
| const { id, platform, force } = c.req.valid("json"); | ||
| const requestId = getRequestId(c.req.raw); | ||
| const spanContext = trace.getActiveSpan()?.spanContext(); | ||
| const logContext: Record<string, unknown> = { | ||
| request_id: requestId, | ||
| trace_id: getTraceId(c.req.raw), | ||
| trace_id: spanContext?.traceId, | ||
| span_id: spanContext?.spanId, | ||
| source: c.req.header("X-Embedly-Source") ?? "api", | ||
| platform, | ||
| post_id: id, | ||
|
|
@@ -101,8 +109,6 @@ const app = new Hono<{ Bindings: CloudflareBindings }>() | |
| 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, | ||
| }); | ||
|
Comment on lines
109
to
112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Prompt To Fix With AIThis 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. |
||
| } catch (cause) { | ||
| const problem = createProblem(EmbedlyErrors.PlatformFetchFailed, { | ||
|
|
@@ -171,5 +177,5 @@ const app = new Hono<{ Bindings: CloudflareBindings }>() | |
| }, | ||
| ); | ||
|
|
||
| export default app; | ||
| export default instrument(app, config); | ||
| export type AppType = typeof app; | ||
Uh oh!
There was an error while loading. Please reload this page.