2024-11-13 05:38:46 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
2024-11-18 18:55:22 -05:00
|
|
|
import { trace } from "npm:@opentelemetry/api@1.9.0";
|
|
|
|
import "jsr:@deno/otel@0.0.2/register";
|
|
|
|
|
|
|
|
const tracer = trace.getTracer("example-tracer");
|
|
|
|
|
2024-11-13 05:38:46 -05:00
|
|
|
async function inner() {
|
2024-11-18 18:55:22 -05:00
|
|
|
await tracer.startActiveSpan("inner span", async (span) => {
|
|
|
|
console.log("log 1");
|
|
|
|
await 1;
|
|
|
|
console.log("log 2");
|
|
|
|
span.end();
|
|
|
|
});
|
2024-11-13 05:38:46 -05:00
|
|
|
}
|
|
|
|
|
2024-11-14 07:16:28 -05:00
|
|
|
const server = Deno.serve({
|
2024-11-13 05:38:46 -05:00
|
|
|
port: 0,
|
2024-11-14 07:16:28 -05:00
|
|
|
async onListen({ port }) {
|
|
|
|
try {
|
|
|
|
await fetch(`http://localhost:${port}`);
|
|
|
|
} finally {
|
|
|
|
server.shutdown();
|
|
|
|
}
|
2024-11-13 05:38:46 -05:00
|
|
|
},
|
|
|
|
handler: async (_req) => {
|
2024-11-18 18:55:22 -05:00
|
|
|
return await tracer.startActiveSpan("outer span", async (span) => {
|
|
|
|
await inner();
|
|
|
|
const resp = new Response(null, { status: 200 });
|
|
|
|
span.end();
|
|
|
|
return resp;
|
|
|
|
});
|
2024-11-13 05:38:46 -05:00
|
|
|
},
|
|
|
|
});
|