mirror of
https://github.com/denoland/deno.git
synced 2024-12-30 02:59:11 -05:00
8ea95c34b5
Add basic trace to Deno.serve. Also updates a bit of the testing infra to make it easier to deal with.
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
const data = {
|
|
spans: [],
|
|
logs: [],
|
|
};
|
|
|
|
const server = Deno.serve(
|
|
{
|
|
port: 0,
|
|
onListen({ port }) {
|
|
const command = new Deno.Command(Deno.execPath(), {
|
|
args: ["run", "-A", "-q", "--unstable-otel", Deno.args[0]],
|
|
env: {
|
|
DENO_UNSTABLE_OTEL_DETERMINISTIC: "1",
|
|
OTEL_EXPORTER_OTLP_PROTOCOL: "http/json",
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: `http://localhost:${port}`,
|
|
},
|
|
stdout: "null",
|
|
});
|
|
const child = command.spawn();
|
|
child.output()
|
|
.then(() => server.shutdown())
|
|
.then(() => {
|
|
data.logs.sort((a, b) =>
|
|
Number(
|
|
BigInt(a.observedTimeUnixNano) - BigInt(b.observedTimeUnixNano),
|
|
)
|
|
);
|
|
data.spans.sort((a, b) =>
|
|
Number(BigInt(`0x${a.spanId}`) - BigInt(`0x${b.spanId}`))
|
|
);
|
|
console.log(JSON.stringify(data, null, 2));
|
|
});
|
|
},
|
|
async handler(req) {
|
|
const body = await req.json();
|
|
body.resourceLogs?.forEach((rLogs) => {
|
|
rLogs.scopeLogs.forEach((sLogs) => {
|
|
data.logs.push(...sLogs.logRecords);
|
|
});
|
|
});
|
|
body.resourceSpans?.forEach((rSpans) => {
|
|
rSpans.scopeSpans.forEach((sSpans) => {
|
|
data.spans.push(...sSpans.spans);
|
|
});
|
|
});
|
|
return Response.json({ partialSuccess: {} }, { status: 200 });
|
|
},
|
|
},
|
|
);
|