playwright-opentelemetry 0.0.5 → 0.0.6
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.d.mts +2 -0
- package/dist/index.mjs +19 -9
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -4,6 +4,7 @@ import { FullConfig, FullResult, Reporter, Suite, TestCase, TestResult } from "@
|
|
|
4
4
|
interface PlaywrightOpentelemetryReporterOptions {
|
|
5
5
|
tracesEndpoint: string;
|
|
6
6
|
headers?: Record<string, string>;
|
|
7
|
+
debug?: boolean;
|
|
7
8
|
}
|
|
8
9
|
declare class PlaywrightOpentelemetryReporter implements Reporter {
|
|
9
10
|
private options;
|
|
@@ -16,6 +17,7 @@ declare class PlaywrightOpentelemetryReporter implements Reporter {
|
|
|
16
17
|
onTestBegin(_test: TestCase): void;
|
|
17
18
|
onTestEnd(test: TestCase, result: TestResult): void;
|
|
18
19
|
private processTestStep;
|
|
20
|
+
printsToStdio(): boolean;
|
|
19
21
|
}
|
|
20
22
|
//#endregion
|
|
21
23
|
export { type PlaywrightOpentelemetryReporterOptions, PlaywrightOpentelemetryReporter as default };
|
package/dist/index.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
const ATTR_CODE_FILE_PATH = "code.file.path";
|
|
5
5
|
const ATTR_CODE_LINE_NUMBER = "code.line.number";
|
|
6
6
|
const ATTR_TEST_CASE_NAME = "test.case.name";
|
|
7
|
+
const ATTR_TEST_CASE_TITLE = "test.case.title";
|
|
7
8
|
const ATTR_TEST_CASE_RESULT_STATUS = "test.case.result.status";
|
|
8
9
|
|
|
9
10
|
//#endregion
|
|
@@ -11,11 +12,12 @@ const ATTR_TEST_CASE_RESULT_STATUS = "test.case.result.status";
|
|
|
11
12
|
const TEST_SPAN_NAME = "playwright.test";
|
|
12
13
|
const TEST_STEP_SPAN_NAME = "playwright.test.step";
|
|
13
14
|
const ATTR_TEST_STEP_NAME = "test.step.name";
|
|
15
|
+
const ATTR_TEST_STEP_TITLE = "test.step.title";
|
|
14
16
|
const ATTR_TEST_STEP_CATEGORY = "test.step.category";
|
|
15
17
|
|
|
16
18
|
//#endregion
|
|
17
19
|
//#region package.json
|
|
18
|
-
var version = "0.0.
|
|
20
|
+
var version = "0.0.6";
|
|
19
21
|
|
|
20
22
|
//#endregion
|
|
21
23
|
//#region src/sender.ts
|
|
@@ -85,8 +87,10 @@ async function sendSpans(spans, options) {
|
|
|
85
87
|
const endpoint = options.tracesEndpoint;
|
|
86
88
|
const headers = options.headers || {};
|
|
87
89
|
const body = JSON.stringify(buildOtlpRequest(spans, options.playwrightVersion));
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
if (options.debug) {
|
|
91
|
+
console.log("Sending spans to", endpoint);
|
|
92
|
+
console.log("Body:", body);
|
|
93
|
+
}
|
|
90
94
|
const response = await fetch(endpoint, {
|
|
91
95
|
method: "POST",
|
|
92
96
|
body,
|
|
@@ -119,7 +123,8 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
119
123
|
await sendSpans(this.spans, {
|
|
120
124
|
tracesEndpoint: this.options.tracesEndpoint,
|
|
121
125
|
headers: this.options.headers,
|
|
122
|
-
playwrightVersion: this.playwrightVersion || "unknown"
|
|
126
|
+
playwrightVersion: this.playwrightVersion || "unknown",
|
|
127
|
+
debug: this.options.debug ?? false
|
|
123
128
|
});
|
|
124
129
|
}
|
|
125
130
|
onTestBegin(_test) {}
|
|
@@ -127,6 +132,7 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
127
132
|
const attributes = {};
|
|
128
133
|
const titlePath = test.titlePath();
|
|
129
134
|
if (titlePath.length >= 3) attributes[ATTR_TEST_CASE_NAME] = titlePath.slice(3).join(" > ");
|
|
135
|
+
attributes[ATTR_TEST_CASE_TITLE] = test.title;
|
|
130
136
|
attributes[ATTR_TEST_CASE_RESULT_STATUS] = result.status;
|
|
131
137
|
if (test.location) {
|
|
132
138
|
const { file, line } = test.location;
|
|
@@ -144,12 +150,13 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
144
150
|
status: { code: result.status === test.expectedStatus ? 1 : 2 }
|
|
145
151
|
};
|
|
146
152
|
this.spans.push(span);
|
|
147
|
-
if (result.steps && result.steps.length > 0) for (const step of result.steps) this.processTestStep(step, span.spanId, traceId);
|
|
153
|
+
if (result.steps && result.steps.length > 0) for (const step of result.steps) this.processTestStep(step, span.spanId, traceId, []);
|
|
148
154
|
}
|
|
149
|
-
processTestStep(step, parentSpanId, traceId) {
|
|
150
|
-
if (step.category !== "test.step") return;
|
|
155
|
+
processTestStep(step, parentSpanId, traceId, parentTitlePath) {
|
|
151
156
|
const attributes = {};
|
|
152
|
-
|
|
157
|
+
const currentTitlePath = [...parentTitlePath, step.title];
|
|
158
|
+
attributes[ATTR_TEST_STEP_NAME] = currentTitlePath.join(" > ");
|
|
159
|
+
attributes[ATTR_TEST_STEP_TITLE] = step.title;
|
|
153
160
|
attributes[ATTR_TEST_STEP_CATEGORY] = step.category;
|
|
154
161
|
if (step.location) {
|
|
155
162
|
const { file, line } = step.location;
|
|
@@ -167,7 +174,10 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
167
174
|
status: { code: step.error ? 2 : 1 }
|
|
168
175
|
};
|
|
169
176
|
this.spans.push(stepSpan);
|
|
170
|
-
if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(childStep, stepSpan.spanId, traceId);
|
|
177
|
+
if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(childStep, stepSpan.spanId, traceId, currentTitlePath);
|
|
178
|
+
}
|
|
179
|
+
printsToStdio() {
|
|
180
|
+
return this.options.debug ?? false;
|
|
171
181
|
}
|
|
172
182
|
};
|
|
173
183
|
function generateTraceId() {
|