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: {
|
|
|
|
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();
|
|
|
|
child.output().then(() => {
|
|
|
|
server.shutdown();
|
|
|
|
|
|
|
|
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();
|
|
|
|
if (body.resourceLogs) {
|
|
|
|
data.logs.push(...body.resourceLogs[0].scopeLogs[0].logRecords);
|
|
|
|
}
|
|
|
|
if (body.resourceSpans) {
|
|
|
|
data.spans.push(...body.resourceSpans[0].scopeSpans[0].spans);
|
2024-11-13 05:38:46 -05:00
|
|
|
}
|
2024-11-14 07:16:28 -05:00
|
|
|
return Response.json({ partialSuccess: {} }, { status: 200 });
|
2024-11-13 05:38:46 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|