|
1 | 1 | import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi"; |
2 | 2 | import { serve } from "@hono/node-server"; |
3 | 3 | import { createNodeWebSocket } from "@hono/node-ws"; |
| 4 | +import { httpInstrumentationMiddleware } from "@hono/otel"; |
4 | 5 | import { getUserTodoStore } from "./todo"; |
5 | 6 | import { cors } from "hono/cors"; |
6 | 7 | import { assert } from "tsafe/assert"; |
7 | | -import { bootstrapAuth, getUser, getUser_ws } from "./auth"; |
| 8 | +import { bootstrapAuth, getUser, getUser_ws } from "./auth"; |
| 9 | +import { setupTracing } from "./telemetry"; |
| 10 | + |
| 11 | +setupTracing(); |
8 | 12 |
|
9 | 13 | (async function main() { |
10 | 14 | const issuerUri = (() => { |
@@ -32,21 +36,26 @@ import { bootstrapAuth, getUser, getUser_ws } from "./auth"; |
32 | 36 | const app = new OpenAPIHono(); |
33 | 37 |
|
34 | 38 | app.use("*", cors()); |
| 39 | + app.use( |
| 40 | + "*", |
| 41 | + httpInstrumentationMiddleware({ serviceName: "todo-rest-api" }) |
| 42 | + ); |
35 | 43 |
|
36 | 44 | const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app }); |
37 | 45 |
|
38 | 46 | app.get( |
39 | 47 | "/ws", |
40 | 48 | upgradeWebSocket(async c => { |
41 | | - |
42 | 49 | const user = await getUser_ws({ req: c.req }); |
43 | 50 |
|
44 | 51 | return { |
45 | 52 | onOpen: (_event, ws) => { |
46 | 53 | ws.send(`Hello ${user.name}`); |
47 | 54 | }, |
48 | 55 | onMessage(event, ws) { |
49 | | - ws.send(`I'm not very smart, all I can do is repeat what you say: "${event.data}"`); |
| 56 | + ws.send( |
| 57 | + `I'm not very smart, all I can do is repeat what you say: "${event.data}"` |
| 58 | + ); |
50 | 59 | } |
51 | 60 | }; |
52 | 61 | }) |
|
0 commit comments