2024-11-13 05:38:46 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
2024-11-14 07:16:28 -05:00
|
|
|
const data = {
|
|
|
|
spans: [],
|
|
|
|
logs: [],
|
|
|
|
};
|
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
|
|
|
onListen({ port }) {
|
2024-11-13 05:38:46 -05:00
|
|
|
const command = new Deno.Command(Deno.execPath(), {
|
2024-11-18 18:55:22 -05:00
|
|
|
args: ["run", "-A", "-q", "--unstable-otel", Deno.args[0]],
|
2024-11-13 05:38:46 -05:00
|
|
|
env: {
|
2024-11-25 04:45:06 -05:00
|
|
|
DENO_UNSTABLE_OTEL_DETERMINISTIC: "1",
|
2024-11-13 05:38:46 -05:00
|
|
|
OTEL_EXPORTER_OTLP_PROTOCOL: "http/json",
|
|
|
|
OTEL_EXPORTER_OTLP_ENDPOINT: `http://localhost:${port}`,
|
|
|
|
},
|
2024-11-14 07:16:28 -05:00
|
|
|
stdout: "null",
|
|
|
|
});
|
|
|
|
const child = command.spawn();
|
2024-11-25 04:45:06 -05:00
|
|
|
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));
|
|
|
|
});
|
2024-11-13 05:38:46 -05:00
|
|
|
},
|
|
|
|
async handler(req) {
|
2024-11-14 07:16:28 -05:00
|
|
|
const body = await req.json();
|
2024-11-25 04:45:06 -05:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
2024-11-14 07:16:28 -05:00
|
|
|
return Response.json({ partialSuccess: {} }, { status: 200 });
|
2024-11-13 05:38:46 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|