autotel-vitest 0.4.40 → 0.4.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/reporter.d.cts +0 -1
- package/dist/reporter.d.cts.map +1 -1
- package/dist/reporter.d.ts +0 -1
- package/dist/reporter.d.ts.map +1 -1
- package/package.json +4 -4
- package/skills/autotel-vitest/SKILL.md +24 -13
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["TestSpanCollector","SimpleSpanProcessor","otelTrace","otelContext","SpanStatusCode","base"],"sources":["../src/fixture.ts","../src/index.ts"],"sourcesContent":["import {\n getTracer,\n getAutotelTracerProvider,\n context as otelContext,\n otelTrace,\n SpanStatusCode,\n} from 'autotel';\nimport { TestSpanCollector } from 'autotel/test-span-collector';\nimport { SimpleSpanProcessor } from 'autotel/processors';\n\nconst TRACER_NAME = 'vitest-tests';\nconst TRACER_VERSION = '0.1.0';\n\nlet collector: TestSpanCollector | null = null;\n\ninterface TracerProviderWithProcessor {\n addSpanProcessor(processor: unknown): void;\n}\n\nfunction ensureCollector(): TestSpanCollector {\n if (!collector) {\n collector = new TestSpanCollector();\n const provider = getAutotelTracerProvider();\n if ('addSpanProcessor' in provider) {\n (provider as TracerProviderWithProcessor).addSpanProcessor(\n new SimpleSpanProcessor(collector),\n );\n }\n }\n return collector;\n}\n\nexport type OtelFixtureFn = (\n args: {
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["TestSpanCollector","SimpleSpanProcessor","otelTrace","otelContext","SpanStatusCode","base"],"sources":["../src/fixture.ts","../src/index.ts"],"sourcesContent":["import {\n getTracer,\n getAutotelTracerProvider,\n context as otelContext,\n otelTrace,\n SpanStatusCode,\n} from 'autotel';\nimport { TestSpanCollector } from 'autotel/test-span-collector';\nimport { SimpleSpanProcessor } from 'autotel/processors';\n\nconst TRACER_NAME = 'vitest-tests';\nconst TRACER_VERSION = '0.1.0';\n\nlet collector: TestSpanCollector | null = null;\n\ninterface TracerProviderWithProcessor {\n addSpanProcessor(processor: unknown): void;\n}\n\nfunction ensureCollector(): TestSpanCollector {\n if (!collector) {\n collector = new TestSpanCollector();\n const provider = getAutotelTracerProvider();\n if ('addSpanProcessor' in provider) {\n (provider as TracerProviderWithProcessor).addSpanProcessor(\n new SimpleSpanProcessor(collector),\n );\n }\n }\n return collector;\n}\n\nexport type OtelFixtureFn = (\n args: {\n task: {\n name: string;\n file?: { name: string };\n suite?: { name: string };\n meta: Record<string, unknown>;\n };\n },\n use: (span: unknown) => Promise<void>,\n) => Promise<void>;\n\nexport const otelTestSpanFixture: [OtelFixtureFn, { auto: true }] = [\n async (\n {\n task,\n }: {\n task: {\n name: string;\n file?: { name: string };\n suite?: { name: string };\n meta: Record<string, unknown>;\n };\n },\n use: (span: unknown) => Promise<void>,\n ) => {\n ensureCollector();\n const tracer = getTracer(TRACER_NAME, TRACER_VERSION);\n const span = tracer.startSpan(`test:${task.name}`, {\n attributes: {\n 'test.name': task.name,\n 'test.file': task.file?.name ?? '',\n 'test.suite': task.suite?.name ?? '',\n },\n });\n const ctx = otelTrace.setSpan(otelContext.active(), span);\n try {\n await otelContext.with(ctx, () => use(span));\n } catch (error) {\n span.setStatus({ code: SpanStatusCode.ERROR });\n span.recordException(\n error instanceof Error ? error : new Error(String(error)),\n );\n throw error;\n } finally {\n span.end();\n const traceId = span.spanContext().traceId;\n const rootSpanId = span.spanContext().spanId;\n const spans = collector!.drainTrace(traceId, rootSpanId);\n if (spans.length > 0) {\n (task.meta as Record<string, unknown>).otelSpans = spans;\n }\n }\n },\n { auto: true },\n];\n","/**\n * autotel-vitest\n *\n * Vitest fixture that creates one OTel span per test so all autotel-instrumented\n * code executed during a test automatically creates child spans under it;\n * making every test run filterable in your OTLP backend.\n *\n * @example\n * // vitest.config.ts: globalSetup calls init({ service: 'unit-tests' })\n * // In spec:\n * import { test, expect } from 'autotel-vitest';\n * test('creates user', async () => {\n * await userService.createUser({ email: 'test@example.com' });\n * // All trace()/span() calls become children of the test span\n * });\n */\n\nimport { test as base } from 'vitest';\nimport { otelTestSpanFixture } from './fixture';\n\nexport const test = base.extend({\n _otelTestSpan: otelTestSpanFixture as never,\n});\n\nexport {\n expect,\n describe,\n beforeEach,\n afterEach,\n beforeAll,\n afterAll,\n} from 'vitest';\n\n// Re-export all autotel/testing utilities\nexport {\n createTraceCollector,\n assertTraceCreated,\n assertTraceSucceeded,\n assertTraceFailed,\n assertNoErrors,\n assertTraceDuration,\n waitForTrace,\n getTraceDuration,\n createMockLogger,\n type TraceCollector,\n type TestSpan,\n type LogCollector,\n type LogEntry,\n} from 'autotel/testing';\n\n// Re-export trace context helpers for DX convenience\nexport {\n getTraceContext,\n resolveTraceUrl,\n isTracing,\n enrichWithTraceContext,\n} from 'autotel';\n\nexport type { OtelTraceContext } from 'autotel';\n"],"mappings":";;;;;;;AAUA,MAAM,cAAc;AACpB,MAAM,iBAAiB;AAEvB,IAAI,YAAsC;AAM1C,SAAS,kBAAqC;CAC5C,IAAI,CAAC,WAAW;EACd,YAAY,IAAIA,4BAAAA,kBAAkB;EAClC,MAAM,YAAA,GAAA,QAAA,yBAAA,CAAoC;EAC1C,IAAI,sBAAsB,UACxB,SAA0C,iBACxC,IAAIC,mBAAAA,oBAAoB,SAAS,CACnC;CAEJ;CACA,OAAO;AACT;;;;;;;;;;;;;;;;;;;ACVA,MAAa,OAAOI,OAAAA,KAAK,OAAO,EAC9B,eAAe,CDwBf,OACE,EACE,QASF,QACG;CACH,gBAAgB;CAEhB,MAAM,QAAA,GAAA,QAAA,UAAA,CADmB,aAAa,cACpB,CAAC,CAAC,UAAU,QAAQ,KAAK,QAAQ,EACjD,YAAY;EACV,aAAa,KAAK;EAClB,aAAa,KAAK,MAAM,QAAQ;EAChC,cAAc,KAAK,OAAO,QAAQ;CACpC,EACF,CAAC;CACD,MAAM,MAAMH,QAAAA,UAAU,QAAQC,QAAAA,QAAY,OAAO,GAAG,IAAI;CACxD,IAAI;EACF,MAAMA,QAAAA,QAAY,KAAK,WAAW,IAAI,IAAI,CAAC;CAC7C,SAAS,OAAO;EACd,KAAK,UAAU,EAAE,MAAMC,QAAAA,eAAe,MAAM,CAAC;EAC7C,KAAK,gBACH,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC,CAC1D;EACA,MAAM;CACR,UAAU;EACR,KAAK,IAAI;EACT,MAAM,UAAU,KAAK,YAAY,CAAC,CAAC;EACnC,MAAM,aAAa,KAAK,YAAY,CAAC,CAAC;EACtC,MAAM,QAAQ,UAAW,WAAW,SAAS,UAAU;EACvD,IAAI,MAAM,SAAS,GACjB,KAAM,KAAiC,YAAY;CAEvD;AACF,GACA,EAAE,MAAM,KAAK,CCjEE,EACjB,CAAC"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect } from "vitest";
|
|
2
2
|
import { LogCollector, LogEntry, TestSpan, TraceCollector, assertNoErrors, assertTraceCreated, assertTraceDuration, assertTraceFailed, assertTraceSucceeded, createMockLogger, createTraceCollector, getTraceDuration, waitForTrace } from "autotel/testing";
|
|
3
3
|
import { OtelTraceContext, enrichWithTraceContext, getTraceContext, isTracing, resolveTraceUrl } from "autotel";
|
|
4
|
-
|
|
5
4
|
//#region src/index.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* autotel-vitest
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;cAoBa,uBAAI,QAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect } from "vitest";
|
|
2
2
|
import { OtelTraceContext, enrichWithTraceContext, getTraceContext, isTracing, resolveTraceUrl } from "autotel";
|
|
3
3
|
import { LogCollector, LogEntry, TestSpan, TraceCollector, assertNoErrors, assertTraceCreated, assertTraceDuration, assertTraceFailed, assertTraceSucceeded, createMockLogger, createTraceCollector, getTraceDuration, waitForTrace } from "autotel/testing";
|
|
4
|
-
|
|
5
4
|
//#region src/index.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* autotel-vitest
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;cAoBa,uBAAI,QAAA"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["otelContext","base"],"sources":["../src/fixture.ts","../src/index.ts"],"sourcesContent":["import {\n getTracer,\n getAutotelTracerProvider,\n context as otelContext,\n otelTrace,\n SpanStatusCode,\n} from 'autotel';\nimport { TestSpanCollector } from 'autotel/test-span-collector';\nimport { SimpleSpanProcessor } from 'autotel/processors';\n\nconst TRACER_NAME = 'vitest-tests';\nconst TRACER_VERSION = '0.1.0';\n\nlet collector: TestSpanCollector | null = null;\n\ninterface TracerProviderWithProcessor {\n addSpanProcessor(processor: unknown): void;\n}\n\nfunction ensureCollector(): TestSpanCollector {\n if (!collector) {\n collector = new TestSpanCollector();\n const provider = getAutotelTracerProvider();\n if ('addSpanProcessor' in provider) {\n (provider as TracerProviderWithProcessor).addSpanProcessor(\n new SimpleSpanProcessor(collector),\n );\n }\n }\n return collector;\n}\n\nexport type OtelFixtureFn = (\n args: {
|
|
1
|
+
{"version":3,"file":"index.js","names":["otelContext","base"],"sources":["../src/fixture.ts","../src/index.ts"],"sourcesContent":["import {\n getTracer,\n getAutotelTracerProvider,\n context as otelContext,\n otelTrace,\n SpanStatusCode,\n} from 'autotel';\nimport { TestSpanCollector } from 'autotel/test-span-collector';\nimport { SimpleSpanProcessor } from 'autotel/processors';\n\nconst TRACER_NAME = 'vitest-tests';\nconst TRACER_VERSION = '0.1.0';\n\nlet collector: TestSpanCollector | null = null;\n\ninterface TracerProviderWithProcessor {\n addSpanProcessor(processor: unknown): void;\n}\n\nfunction ensureCollector(): TestSpanCollector {\n if (!collector) {\n collector = new TestSpanCollector();\n const provider = getAutotelTracerProvider();\n if ('addSpanProcessor' in provider) {\n (provider as TracerProviderWithProcessor).addSpanProcessor(\n new SimpleSpanProcessor(collector),\n );\n }\n }\n return collector;\n}\n\nexport type OtelFixtureFn = (\n args: {\n task: {\n name: string;\n file?: { name: string };\n suite?: { name: string };\n meta: Record<string, unknown>;\n };\n },\n use: (span: unknown) => Promise<void>,\n) => Promise<void>;\n\nexport const otelTestSpanFixture: [OtelFixtureFn, { auto: true }] = [\n async (\n {\n task,\n }: {\n task: {\n name: string;\n file?: { name: string };\n suite?: { name: string };\n meta: Record<string, unknown>;\n };\n },\n use: (span: unknown) => Promise<void>,\n ) => {\n ensureCollector();\n const tracer = getTracer(TRACER_NAME, TRACER_VERSION);\n const span = tracer.startSpan(`test:${task.name}`, {\n attributes: {\n 'test.name': task.name,\n 'test.file': task.file?.name ?? '',\n 'test.suite': task.suite?.name ?? '',\n },\n });\n const ctx = otelTrace.setSpan(otelContext.active(), span);\n try {\n await otelContext.with(ctx, () => use(span));\n } catch (error) {\n span.setStatus({ code: SpanStatusCode.ERROR });\n span.recordException(\n error instanceof Error ? error : new Error(String(error)),\n );\n throw error;\n } finally {\n span.end();\n const traceId = span.spanContext().traceId;\n const rootSpanId = span.spanContext().spanId;\n const spans = collector!.drainTrace(traceId, rootSpanId);\n if (spans.length > 0) {\n (task.meta as Record<string, unknown>).otelSpans = spans;\n }\n }\n },\n { auto: true },\n];\n","/**\n * autotel-vitest\n *\n * Vitest fixture that creates one OTel span per test so all autotel-instrumented\n * code executed during a test automatically creates child spans under it;\n * making every test run filterable in your OTLP backend.\n *\n * @example\n * // vitest.config.ts: globalSetup calls init({ service: 'unit-tests' })\n * // In spec:\n * import { test, expect } from 'autotel-vitest';\n * test('creates user', async () => {\n * await userService.createUser({ email: 'test@example.com' });\n * // All trace()/span() calls become children of the test span\n * });\n */\n\nimport { test as base } from 'vitest';\nimport { otelTestSpanFixture } from './fixture';\n\nexport const test = base.extend({\n _otelTestSpan: otelTestSpanFixture as never,\n});\n\nexport {\n expect,\n describe,\n beforeEach,\n afterEach,\n beforeAll,\n afterAll,\n} from 'vitest';\n\n// Re-export all autotel/testing utilities\nexport {\n createTraceCollector,\n assertTraceCreated,\n assertTraceSucceeded,\n assertTraceFailed,\n assertNoErrors,\n assertTraceDuration,\n waitForTrace,\n getTraceDuration,\n createMockLogger,\n type TraceCollector,\n type TestSpan,\n type LogCollector,\n type LogEntry,\n} from 'autotel/testing';\n\n// Re-export trace context helpers for DX convenience\nexport {\n getTraceContext,\n resolveTraceUrl,\n isTracing,\n enrichWithTraceContext,\n} from 'autotel';\n\nexport type { OtelTraceContext } from 'autotel';\n"],"mappings":";;;;;;AAUA,MAAM,cAAc;AACpB,MAAM,iBAAiB;AAEvB,IAAI,YAAsC;AAM1C,SAAS,kBAAqC;CAC5C,IAAI,CAAC,WAAW;EACd,YAAY,IAAI,kBAAkB;EAClC,MAAM,WAAW,yBAAyB;EAC1C,IAAI,sBAAsB,UACxB,SAA0C,iBACxC,IAAI,oBAAoB,SAAS,CACnC;CAEJ;CACA,OAAO;AACT;;;;;;;;;;;;;;;;;;;ACVA,MAAa,OAAOC,OAAK,OAAO,EAC9B,eAAe,CDwBf,OACE,EACE,QASF,QACG;CACH,gBAAgB;CAEhB,MAAM,OADS,UAAU,aAAa,cACpB,CAAC,CAAC,UAAU,QAAQ,KAAK,QAAQ,EACjD,YAAY;EACV,aAAa,KAAK;EAClB,aAAa,KAAK,MAAM,QAAQ;EAChC,cAAc,KAAK,OAAO,QAAQ;CACpC,EACF,CAAC;CACD,MAAM,MAAM,UAAU,QAAQD,QAAY,OAAO,GAAG,IAAI;CACxD,IAAI;EACF,MAAMA,QAAY,KAAK,WAAW,IAAI,IAAI,CAAC;CAC7C,SAAS,OAAO;EACd,KAAK,UAAU,EAAE,MAAM,eAAe,MAAM,CAAC;EAC7C,KAAK,gBACH,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC,CAC1D;EACA,MAAM;CACR,UAAU;EACR,KAAK,IAAI;EACT,MAAM,UAAU,KAAK,YAAY,CAAC,CAAC;EACnC,MAAM,aAAa,KAAK,YAAY,CAAC,CAAC;EACtC,MAAM,QAAQ,UAAW,WAAW,SAAS,UAAU;EACvD,IAAI,MAAM,SAAS,GACjB,KAAM,KAAiC,YAAY;CAEvD;AACF,GACA,EAAE,MAAM,KAAK,CCjEE,EACjB,CAAC"}
|
package/dist/reporter.d.cts
CHANGED
package/dist/reporter.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reporter.d.cts","names":[],"sources":["../src/reporter.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"reporter.d.cts","names":[],"sources":["../src/reporter.ts"],"mappings":";;;;;;cAyCM,wBAAwB;UACpB;UACA;EAER,gBAAgB,UAAU;EAa1B,iBAAiB,UAAU;EAiB3B,iBAAiB,WAAW;EAY5B,kBAAkB,WAAW;EAY7B,gBAAgB,YAAY"}
|
package/dist/reporter.d.ts
CHANGED
package/dist/reporter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reporter.d.ts","names":[],"sources":["../src/reporter.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"reporter.d.ts","names":[],"sources":["../src/reporter.ts"],"mappings":";;;;;;cAyCM,wBAAwB;UACpB;UACA;EAER,gBAAgB,UAAU;EAa1B,iBAAiB,UAAU;EAiB3B,iBAAiB,WAAW;EAY5B,kBAAkB,WAAW;EAY7B,gBAAgB,YAAY"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autotel-vitest",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.41",
|
|
4
4
|
"description": "Vitest fixture for OpenTelemetry: one span per test so all instrumented code is filterable by test run",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"skills"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"autotel": "
|
|
28
|
+
"autotel": "5.0.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"vitest": ">=4.1.10"
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@types/node": "^26.1.
|
|
40
|
-
"tsdown": "^0.22.
|
|
39
|
+
"@types/node": "^26.1.1",
|
|
40
|
+
"tsdown": "^0.22.12",
|
|
41
41
|
"typescript": "^6.0.3",
|
|
42
42
|
"vitest": "^4.1.10"
|
|
43
43
|
},
|
|
@@ -17,7 +17,7 @@ pnpm add autotel autotel-vitest
|
|
|
17
17
|
pnpm add -D vitest
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
### 2. globalSetup.ts
|
|
20
|
+
### 2. globalSetup.ts: call init() before tests run
|
|
21
21
|
|
|
22
22
|
```typescript
|
|
23
23
|
// globalSetup.ts
|
|
@@ -26,12 +26,12 @@ import { init } from 'autotel';
|
|
|
26
26
|
export default function globalSetup() {
|
|
27
27
|
init({
|
|
28
28
|
service: 'unit-tests',
|
|
29
|
-
endpoint: 'http://localhost:4318',
|
|
29
|
+
endpoint: 'http://localhost:4318', // Your OTLP collector
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
### 3. vitest.config.ts
|
|
34
|
+
### 3. vitest.config.ts: register globalSetup
|
|
35
35
|
|
|
36
36
|
```typescript
|
|
37
37
|
// vitest.config.ts
|
|
@@ -56,7 +56,7 @@ test('creates user', async () => {
|
|
|
56
56
|
});
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
The fixture is `auto: true
|
|
59
|
+
The fixture is `auto: true`. Every test gets a parent span automatically with no extra code.
|
|
60
60
|
|
|
61
61
|
## Configuration / Core Patterns
|
|
62
62
|
|
|
@@ -64,9 +64,9 @@ The fixture is `auto: true` — every test gets a parent span automatically with
|
|
|
64
64
|
|
|
65
65
|
Each test span is named `test:${task.name}` and carries these attributes automatically:
|
|
66
66
|
|
|
67
|
-
- `test.name
|
|
68
|
-
- `test.file
|
|
69
|
-
- `test.suite
|
|
67
|
+
- `test.name`: the test name string
|
|
68
|
+
- `test.file`: file path from `task.file.name`
|
|
69
|
+
- `test.suite`: suite name from `task.suite.name` (if in a describe block)
|
|
70
70
|
|
|
71
71
|
If a test throws, the span is marked `ERROR` and records the exception.
|
|
72
72
|
|
|
@@ -87,6 +87,7 @@ export default defineConfig({
|
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
Reporter creates:
|
|
90
|
+
|
|
90
91
|
- `test:<name>` spans for each test case
|
|
91
92
|
- `suite:<name>` spans for each describe block
|
|
92
93
|
|
|
@@ -117,7 +118,12 @@ test('traces user creation', async () => {
|
|
|
117
118
|
### Trace context helpers (re-exported from autotel)
|
|
118
119
|
|
|
119
120
|
```typescript
|
|
120
|
-
import {
|
|
121
|
+
import {
|
|
122
|
+
getTraceContext,
|
|
123
|
+
resolveTraceUrl,
|
|
124
|
+
isTracing,
|
|
125
|
+
enrichWithTraceContext,
|
|
126
|
+
} from 'autotel-vitest';
|
|
121
127
|
```
|
|
122
128
|
|
|
123
129
|
### Cross-process tracing (test → HTTP server)
|
|
@@ -139,9 +145,10 @@ test('traces across HTTP', async () => {
|
|
|
139
145
|
|
|
140
146
|
## Common Mistakes
|
|
141
147
|
|
|
142
|
-
### HIGH
|
|
148
|
+
### HIGH: Importing test from vitest instead of autotel-vitest
|
|
143
149
|
|
|
144
150
|
Wrong:
|
|
151
|
+
|
|
145
152
|
```typescript
|
|
146
153
|
import { test } from 'vitest'; // base test — no OTel fixture
|
|
147
154
|
|
|
@@ -152,21 +159,24 @@ test('creates user', async () => {
|
|
|
152
159
|
```
|
|
153
160
|
|
|
154
161
|
Correct:
|
|
162
|
+
|
|
155
163
|
```typescript
|
|
156
164
|
import { test } from 'autotel-vitest'; // extended test with auto fixture
|
|
157
165
|
```
|
|
158
166
|
|
|
159
167
|
Explanation: Only the extended `test` from `autotel-vitest` has the `_otelTestSpan` fixture registered. Using the base `vitest` `test` means no parent context is active and child spans appear as disconnected traces.
|
|
160
168
|
|
|
161
|
-
### HIGH
|
|
169
|
+
### HIGH: Not calling init() in globalSetup
|
|
162
170
|
|
|
163
171
|
Wrong:
|
|
172
|
+
|
|
164
173
|
```typescript
|
|
165
174
|
// vitest.config.ts — no globalSetup
|
|
166
175
|
// Spans are created but never exported (no tracer provider configured)
|
|
167
176
|
```
|
|
168
177
|
|
|
169
178
|
Correct:
|
|
179
|
+
|
|
170
180
|
```typescript
|
|
171
181
|
// globalSetup.ts
|
|
172
182
|
import { init } from 'autotel';
|
|
@@ -177,9 +187,10 @@ export default function globalSetup() {
|
|
|
177
187
|
|
|
178
188
|
Explanation: `init()` must run in `globalSetup` (not in a `beforeAll` or test file) so the provider is available before any worker process starts executing tests.
|
|
179
189
|
|
|
180
|
-
### MEDIUM
|
|
190
|
+
### MEDIUM: Adding the reporter without globalSetup
|
|
181
191
|
|
|
182
192
|
Wrong:
|
|
193
|
+
|
|
183
194
|
```typescript
|
|
184
195
|
// vitest.config.ts
|
|
185
196
|
export default defineConfig({
|
|
@@ -194,9 +205,9 @@ Correct: Always pair the reporter with `globalSetup` that calls `init()`.
|
|
|
194
205
|
|
|
195
206
|
Explanation: The reporter runs in the Vitest runner process and calls `getTracer()`. If `init()` was never called, there is no configured tracer provider and spans silently go nowhere.
|
|
196
207
|
|
|
197
|
-
### MEDIUM
|
|
208
|
+
### MEDIUM: Calling describe/beforeEach from vitest directly when using autotel-vitest
|
|
198
209
|
|
|
199
|
-
These are safe to mix
|
|
210
|
+
These are safe to mix. `autotel-vitest` re-exports `describe`, `beforeEach`, `afterEach`, `beforeAll`, `afterAll` directly from `vitest`, so you can import everything from one place:
|
|
200
211
|
|
|
201
212
|
```typescript
|
|
202
213
|
import { test, expect, describe, beforeEach } from 'autotel-vitest';
|