feat(core-shared/instrumentation): withSpan attaches runtime __instrumented marker

This commit is contained in:
2026-05-12 22:39:13 +02:00
parent a593962b3d
commit 9e21baf5fb
2 changed files with 15 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ import { describe, it, expect, expectTypeOf, vi } from "vitest";
import { withSpan } from "@/instrumentation/with-span";
import type { ITracer, ISpan, SpanOpts } from "@/instrumentation/tracer.interface";
import type { Instrumented } from "@/conformance/brands";
import { isInstrumented } from "@/conformance/brand-runtime";
function makeRecordingTracer() {
const calls: SpanOpts[] = [];
@@ -70,3 +71,13 @@ describe("withSpan — brand", () => {
expectTypeOf(wrapped).toMatchTypeOf<Instrumented<typeof fn>>();
});
});
describe("withSpan — runtime brand", () => {
it("attaches __instrumented as a non-enumerable property on the wrapped function", async () => {
const { tracer } = makeRecordingTracer();
const fn = async (a: number) => a + 1;
const wrapped = withSpan(tracer, { name: "test.brand", op: "use-case" }, fn);
expect(isInstrumented(wrapped)).toBe(true);
expect(Object.keys(wrapped)).not.toContain("__instrumented");
});
});