summaryrefslogtreecommitdiff
path: root/tests/specs/cli/otel_basic/main.ts
diff options
context:
space:
mode:
authorsnek <snek@deno.com>2024-11-14 13:16:28 +0100
committerGitHub <noreply@github.com>2024-11-14 12:16:28 +0000
commit4e899d48cffa95617266dd8f9aef54603a87ad82 (patch)
treeec667f58ccb4126ecad38bc4600d9dd8dc372ca5 /tests/specs/cli/otel_basic/main.ts
parentcb107a762fb903973e0d0c2e4481baf2c0bc13b8 (diff)
fix: otel resiliency (#26857)
Improving the breadth of collected data, and ensuring that the collected data is more likely to be successfully reported. - Use `log` crate in more places - Hook up `log` crate to otel - Switch to process-wide otel processors - Handle places that use `process::exit` Also adds a more robust testing framework, with a deterministic tracing setting. Refs: https://github.com/denoland/deno/issues/26852
Diffstat (limited to 'tests/specs/cli/otel_basic/main.ts')
-rw-r--r--tests/specs/cli/otel_basic/main.ts80
1 files changed, 21 insertions, 59 deletions
diff --git a/tests/specs/cli/otel_basic/main.ts b/tests/specs/cli/otel_basic/main.ts
index 66ef5c79c..6c49462a0 100644
--- a/tests/specs/cli/otel_basic/main.ts
+++ b/tests/specs/cli/otel_basic/main.ts
@@ -1,76 +1,38 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
-import { assert, assertEquals } from "@std/assert";
-import { TextLineStream } from "@std/streams/text-line-stream";
+const data = {
+ spans: [],
+ logs: [],
+};
-const logs = [];
-const spans = [];
-let child: Deno.ChildProcess;
-
-Deno.serve(
+const server = Deno.serve(
{
port: 0,
- async onListen({ port }) {
+ onListen({ port }) {
const command = new Deno.Command(Deno.execPath(), {
- args: ["run", "-A", "--unstable-otel", "child.ts"],
+ args: ["run", "-A", "--unstable-otel", Deno.args[0]],
env: {
OTEL_EXPORTER_OTLP_PROTOCOL: "http/json",
OTEL_EXPORTER_OTLP_ENDPOINT: `http://localhost:${port}`,
- OTEL_BSP_SCHEDULE_DELAY: "10",
- OTEL_BLRP_SCHEDULE_DELAY: "10",
},
- stdin: "piped",
- stdout: "piped",
- stderr: "inherit",
+ stdout: "null",
+ });
+ const child = command.spawn();
+ child.output().then(() => {
+ server.shutdown();
+
+ console.log(JSON.stringify(data, null, 2));
});
- child = command.spawn();
- const lines = child.stdout
- .pipeThrough(new TextDecoderStream())
- .pipeThrough(new TextLineStream())
- .getReader();
- const line = await lines.read();
- await fetch(`http://localhost:${line.value}/`);
},
async handler(req) {
- try {
- const body = await req.json();
- if (body.resourceLogs) {
- logs.push(...body.resourceLogs[0].scopeLogs[0].logRecords);
- }
- if (body.resourceSpans) {
- spans.push(...body.resourceSpans[0].scopeSpans[0].spans);
- }
-
- if (logs.length > 2 && spans.length > 1) {
- child.kill();
-
- const inner = spans.find((s) => s.name === "inner span");
- const outer = spans.find((s) => s.name === "outer span");
-
- assertEquals(inner.traceId, outer.traceId);
- assertEquals(inner.parentSpanId, outer.spanId);
-
- assertEquals(logs[1].body.stringValue, "log 1\n");
- assertEquals(logs[1].traceId, inner.traceId);
- assertEquals(logs[1].spanId, inner.spanId);
-
- assertEquals(logs[2].body.stringValue, "log 2\n");
- assertEquals(logs[2].traceId, inner.traceId);
- assertEquals(logs[2].spanId, inner.spanId);
-
- console.log("processed");
- Deno.exit(0);
- }
-
- return Response.json({ partialSuccess: {} }, { status: 200 });
- } catch (e) {
- console.error(e);
- Deno.exit(1);
+ 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);
}
+ return Response.json({ partialSuccess: {} }, { status: 200 });
},
},
);
-
-setTimeout(() => {
- assert(false, "test did not finish in time");
-}, 10e3);