Skip to content
Merged
Changes from 1 commit
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
30 changes: 0 additions & 30 deletions services/gastown/src/gastown.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ import { townAuthMiddleware } from './middleware/town-auth.middleware';
import { orgAuthMiddleware } from './middleware/org-auth.middleware';
import { adminAuditMiddleware } from './middleware/admin-audit.middleware';
import { timingMiddleware, instrumented } from './middleware/analytics.middleware';
import { logger } from './util/log.util';
import { useWorkersLogger } from 'workers-tagged-logger';
import type { MiddlewareHandler } from 'hono';
import { handleGetTownConfig, handleUpdateTownConfig } from './handlers/town-config.handler';
Expand Down Expand Up @@ -173,35 +172,6 @@ app.use('*', timingMiddleware);
// Cast needed: workers-tagged-logger@1.0.0 was built against an older Hono.
app.use('*', useWorkersLogger('gastown-worker') as unknown as MiddlewareHandler);

// ── Request logging ─────────────────────────────────────────────────────
// Extract IDs from the URL path directly — c.req.param() only works
// after Hono has matched a route, which hasn't happened yet in a
// wildcard middleware.
// Matches /orgs/:orgId, /towns/:townId, /rigs/:rigId, /agents/:agentId
// in any combination that appears in our route patterns.
const RE_ORG = /\/orgs\/(?<orgId>[^/]+)/;
const RE_TOWN = /\/towns\/(?<townId>[^/]+)/;
const RE_RIG = /\/rigs\/(?<rigId>[^/]+)/;
const RE_AGENT = /\/agents\/(?<agentId>[^/]+)/;

app.use('*', async (c, next) => {
const method = c.req.method;
const path = c.req.path;
// Tag with route params immediately so all downstream logs (auth,
// handlers, DO calls) inherit them. Auth-derived tags (userId, orgId)
// are set by kiloAuthMiddleware and orgAuthMiddleware when they run.
logger.setTags({
orgId: RE_ORG.exec(path)?.groups?.orgId,
townId: RE_TOWN.exec(path)?.groups?.townId,
rigId: RE_RIG.exec(path)?.groups?.rigId,
agentId: RE_AGENT.exec(path)?.groups?.agentId,
});
Comment on lines -193 to -198
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It'd still be nice to set tags on requests, but maybe we can do it in a way more structured way like:

app.use('/api/towns/:townId', async (c, next) => {
  logger.setTags({ townId: c.req.param('townId' })
  await next()
})

logger.info(`--> ${method} ${path}`);
await next();
const elapsed = Math.round(performance.now() - (c.get('requestStartTime') ?? 0));
logger.info(`<-- ${method} ${path} ${c.res.status}`, { durationMs: elapsed });
});

// ── CORS ────────────────────────────────────────────────────────────────
// Allow browser requests from the main Kilo app. In development, allow
// localhost origins for the Next.js dev server.
Expand Down