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 .env.local.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
OIDC_ISSUER_URI=https://cloud-iam.oidc-spa.dev/realms/oidc-spa
OIDC_AUDIENCE=account
PORT=8080
PORT=8080
MODE=prod
OTEL_ENABLED=false
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 25
- uses: bahmutov/npm-install@v1
- run: yarn build
#- run: yarn test
Expand Down Expand Up @@ -42,6 +44,8 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 25
- uses: softprops/action-gh-release@v1
with:
name: Release v${{ needs.check_if_version_upgraded.outputs.to_version }}
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# build environment
FROM node:18-alpine3.17 as build
FROM node:25-alpine as build
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
COPY . .
RUN yarn build

# production environment
FROM node:20-alpine3.19
FROM node:25-alpine
COPY --from=build /app/dist .
ENTRYPOINT sh -c "node ."
ENTRYPOINT sh -c "node ."
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@
"dependencies": {
"@hono/node-server": "^1.11.1",
"@hono/node-ws": "^1.0.3",
"@hono/otel": "^1.1.2",
"@hono/zod-openapi": "^0.13.0",
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/exporter-trace-otlp-http": "^0.53.0",
"@opentelemetry/sdk-metrics": "^1.26.0",
"@opentelemetry/sdk-node": "^0.53.0",
"@opentelemetry/sdk-trace-node": "^1.26.0",
"hono": "^4.11.1",
"oidc-spa": "^10.0.0",
"tsafe": "^1.8.12",
Expand Down
15 changes: 12 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
import { serve } from "@hono/node-server";
import { createNodeWebSocket } from "@hono/node-ws";
import { httpInstrumentationMiddleware } from "@hono/otel";
import { getUserTodoStore } from "./todo";
import { cors } from "hono/cors";
import { assert } from "tsafe/assert";
import { bootstrapAuth, getUser, getUser_ws } from "./auth";
import { bootstrapAuth, getUser, getUser_ws } from "./auth";
import { setupTracing } from "./telemetry";

setupTracing();

(async function main() {
const issuerUri = (() => {
Expand Down Expand Up @@ -32,21 +36,26 @@ import { bootstrapAuth, getUser, getUser_ws } from "./auth";
const app = new OpenAPIHono();

app.use("*", cors());
app.use(
"*",
httpInstrumentationMiddleware({ serviceName: "todo-rest-api" })
);

const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app });

app.get(
"/ws",
upgradeWebSocket(async c => {

const user = await getUser_ws({ req: c.req });

return {
onOpen: (_event, ws) => {
ws.send(`Hello ${user.name}`);
},
onMessage(event, ws) {
ws.send(`I'm not very smart, all I can do is repeat what you say: "${event.data}"`);
ws.send(
`I'm not very smart, all I can do is repeat what you say: "${event.data}"`
);
}
};
})
Expand Down
21 changes: 21 additions & 0 deletions src/telemetry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { NodeSDK } from "@opentelemetry/sdk-node";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
import { ConsoleSpanExporter } from "@opentelemetry/sdk-trace-node";

export function setupTracing() {
const sdk = new NodeSDK({
serviceName: "todo-rest-api",
traceExporter:
process.env.MODE === "dev"
? new ConsoleSpanExporter()
: new OTLPTraceExporter()
});

console.log(
process.env.MODE === "dev"
? "Using ConsoleSpanExporter for tracing"
: "Using OTLPTraceExporter for tracing"
);

sdk.start();
}
Loading
Loading