Last active
February 22, 2025 06:16
-
-
Save up1/f0c267da5087ace024ef2d4964da7501 to your computer and use it in GitHub Desktop.
DEno 2.2 :: OpenTelemetry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$deno --version | |
deno 2.2.1 (stable, release, aarch64-apple-darwin) | |
v8 13.4.114.9-rusty | |
typescript 5.7.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
lgtm: | |
image: grafana/otel-lgtm | |
ports: | |
- 3000:3000 | |
- 4317:4317 | |
- 4318:4318 | |
service1: | |
build: ./service1 | |
ports: | |
- 8000:8000 | |
environment: | |
- OTEL_DENO=true | |
- OTEL_SERVICE_NAME=service1 | |
- OTEL_EXPORTER_OTLP_INSECURE=true | |
- OTEL_EXPORTER_OTLP_ENDPOINT=http://lgtm:4318 | |
- OTEL_PROPAGATORS=b3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM denoland/deno:2.2.1 | |
WORKDIR /app | |
COPY . . | |
RUN deno cache main.ts | |
EXPOSE 8000 | |
CMD ["deno", "run", "--allow-net", "--unstable-otel", "server.ts"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { trace } from "npm:@opentelemetry/[email protected]"; | |
const tracer = trace.getTracer("example-tracer"); | |
Deno.serve(async (req) => { | |
console.log("Received request for", req.url); | |
// Call internal function | |
await doWork(); | |
// Call external api with fetch | |
const response = await fetch("http://service2:8000"); | |
const body = new Uint8Array(await response.arrayBuffer()); | |
if (!response.ok) { | |
return new Response("Error fetching data", { status: response.status }); | |
} | |
const text = new TextDecoder().decode(body); | |
return new Response("Hello world deno" + text); | |
}); | |
// Internal function with custom trace span | |
async function doWork() { | |
return tracer.startActiveSpan("doWork", async (span) => { | |
span.setAttribute("key", "value"); | |
await new Promise((resolve) => setTimeout(resolve, 1000)); | |
span.end(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment