Skip to content

Commit

Permalink
Add express demo from oven-sh/bun#3775 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
novaluke committed Jan 30, 2024
1 parent 37d6907 commit b5c1c8c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
17 changes: 16 additions & 1 deletion app.ts
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
console.log("Hello via Bun!");
import express from "express";

const PORT = parseInt(process.env.PORT || "8080");
const app = express();

function getRandomNumber(min: number, max: number) {
return Math.floor(Math.random() * (max - min) + min);
}

app.get("/rolldice", (req, res) => {
res.send(getRandomNumber(1, 6).toString());
});

app.listen(PORT, () => {
console.log(`Listening for requests on http://localhost:${PORT}`);
});
Binary file modified bun.lockb
Binary file not shown.
18 changes: 18 additions & 0 deletions instrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Require dependencies
import { NodeSDK } from "@opentelemetry/sdk-node";
import { ConsoleSpanExporter } from "@opentelemetry/sdk-trace-node";
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
import {
PeriodicExportingMetricReader,
ConsoleMetricExporter,
} from "@opentelemetry/sdk-metrics";

const sdk = new NodeSDK({
traceExporter: new ConsoleSpanExporter(),
metricReader: new PeriodicExportingMetricReader({
exporter: new ConsoleMetricExporter(),
}),
instrumentations: [getNodeAutoInstrumentations()],
});

sdk.start();
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@
"name": "otel-auto-bun-repro",
"module": "app.ts",
"type": "module",
"scripts": {
"start": "bun run --preload ./instrumentation.ts ./app.ts"
},
"devDependencies": {
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"@opentelemetry/auto-instrumentations-node": "^0.41.0",
"@opentelemetry/sdk-metrics": "^1.21.0",
"@opentelemetry/sdk-node": "^0.48.0",
"@opentelemetry/sdk-trace-node": "^1.21.0",
"express": "^4.18.2"
}
}
}

0 comments on commit b5c1c8c

Please sign in to comment.