Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
"dependencies": {
Comment thread
greptile-apps[bot] marked this conversation as resolved.
"@embedly/logging": "workspace:*",
"@embedly/platforms": "workspace:*",
"@hono/otel": "^1.1.2",
"@hono/zod-validator": "^0.7.6",
"@microlabs/otel-cf-workers": "1.0.0-rc.52",
"@opentelemetry/api": "^1.9.1",
"hono": "^4.12.15",
"zod": "^4.4.1"
},
Expand All @@ -20,6 +23,6 @@
"@types/node": "catalog:",
"oxfmt": "catalog:",
"oxlint": "catalog:",
"wrangler": "^4.4.0"
"wrangler": "^4.114.0"
}
}
26 changes: 16 additions & 10 deletions apps/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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) => {
Expand All @@ -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,
Expand Down Expand Up @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 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.

Fix in Codex

} catch (cause) {
const problem = createProblem(EmbedlyErrors.PlatformFetchFailed, {
Expand Down Expand Up @@ -171,5 +177,5 @@ const app = new Hono<{ Bindings: CloudflareBindings }>()
},
);

export default app;
export default instrument(app, config);
export type AppType = typeof app;
Loading
Loading