@mark1russell7/otel-ts 0.8.5 → 0.8.7
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/README.md +46 -0
- package/dist/error-record.d.ts +127 -0
- package/dist/error-record.d.ts.map +1 -0
- package/dist/error-record.js +227 -0
- package/dist/error-record.js.map +1 -0
- package/dist/error-view.d.ts +91 -0
- package/dist/error-view.d.ts.map +1 -0
- package/dist/error-view.js +339 -0
- package/dist/error-view.js.map +1 -0
- package/dist/init.js +7 -2
- package/dist/init.js.map +1 -1
- package/package.json +10 -1
- package/src/error-record.ts +306 -0
- package/src/error-view.ts +387 -0
- package/src/init.ts +8 -2
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The entry `@mark1russell7/otel-ts/error-view`: one view of an error record, as a custom element with no framework.
|
|
3
|
+
*
|
|
4
|
+
* The element shows the record of `@mark1russell7/otel-ts/error`:
|
|
5
|
+
* - the message in plain words, the procedure and the time;
|
|
6
|
+
* - the actions: retry, copy the whole record, report it, and open its trace;
|
|
7
|
+
* - the details: each id, the context keys and the cause chain.
|
|
8
|
+
*
|
|
9
|
+
* The element does no network call. Retry and report are events: the page decides what they do. Copy writes the
|
|
10
|
+
* text of `errorRecordText()` to the clipboard. The trace link comes from the attribute `trace-url`, a template with
|
|
11
|
+
* `{traceId}` and `{spanId}`.
|
|
12
|
+
*
|
|
13
|
+
* The import registers nothing. Call `defineErrorView()` one time, or register `ErrorViewElement` with a name of
|
|
14
|
+
* your own.
|
|
15
|
+
*
|
|
16
|
+
* Colors follow the `color-scheme` of the page, with `light-dark()`. A page sets the custom properties
|
|
17
|
+
* `--otel-error-*` to use its own colors.
|
|
18
|
+
*
|
|
19
|
+
* @packageDocumentation
|
|
20
|
+
*/
|
|
21
|
+
import { errorRecordText, redactErrorRecord, type ErrorRecord } from "./error-record.js";
|
|
22
|
+
|
|
23
|
+
/** The default name of the element */
|
|
24
|
+
export const ERROR_VIEW_TAG = "otel-error";
|
|
25
|
+
|
|
26
|
+
/** The detail of the event `otel-error-retry` */
|
|
27
|
+
export interface ErrorRetryDetail {
|
|
28
|
+
readonly record: ErrorRecord;
|
|
29
|
+
/** Keep the retry button busy until the promise settles */
|
|
30
|
+
waitUntil(promise: PromiseLike<unknown>): void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The detail of the events `otel-error-report` and `otel-error-copy` */
|
|
34
|
+
export interface ErrorTextDetail {
|
|
35
|
+
readonly record: ErrorRecord;
|
|
36
|
+
/** The text of `errorRecordText(record)` */
|
|
37
|
+
readonly text: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The detail of the event `otel-error-copy` */
|
|
41
|
+
export interface ErrorCopyDetail extends ErrorTextDetail {
|
|
42
|
+
/** True when the clipboard took the text. Else the view opens the details with the text selected. */
|
|
43
|
+
readonly copied: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
declare global {
|
|
47
|
+
interface HTMLElementEventMap {
|
|
48
|
+
"otel-error-retry": CustomEvent<ErrorRetryDetail>;
|
|
49
|
+
"otel-error-report": CustomEvent<ErrorTextDetail>;
|
|
50
|
+
"otel-error-copy": CustomEvent<ErrorCopyDetail>;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The link of a trace from a template, for example `https://grafana.example/explore?trace={traceId}`. It gives
|
|
56
|
+
* undefined with no trace id, and for a link that is not `http:` or `https:`.
|
|
57
|
+
*/
|
|
58
|
+
export function traceLink(template: string | null | undefined, record: ErrorRecord, base?: string): string | undefined {
|
|
59
|
+
if (!template || record.traceId === undefined) return undefined;
|
|
60
|
+
const href = template
|
|
61
|
+
.replaceAll("{traceId}", encodeURIComponent(record.traceId))
|
|
62
|
+
.replaceAll("{spanId}", encodeURIComponent(record.spanId ?? ""));
|
|
63
|
+
try {
|
|
64
|
+
const url = base === undefined ? new URL(href) : new URL(href, base);
|
|
65
|
+
return url.protocol === "https:" || url.protocol === "http:" ? url.href : undefined;
|
|
66
|
+
} catch {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const STYLE = `
|
|
72
|
+
:host {
|
|
73
|
+
--_bg: var(--otel-error-bg, light-dark(#fff7f7, #241417));
|
|
74
|
+
--_ink: var(--otel-error-ink, light-dark(#1b1d24, #f1e9ea));
|
|
75
|
+
--_muted: var(--otel-error-muted, light-dark(#5b5f6b, #b9adb0));
|
|
76
|
+
--_rule: var(--otel-error-rule, light-dark(#efc9cb, #57323a));
|
|
77
|
+
--_accent: var(--otel-error-accent, light-dark(#b3261e, #ff8a85));
|
|
78
|
+
--_accent-ink: var(--otel-error-accent-ink, light-dark(#ffffff, #23090b));
|
|
79
|
+
--_focus: var(--otel-error-focus, light-dark(#2346c4, #93abff));
|
|
80
|
+
--_mono: var(--otel-error-mono, ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace);
|
|
81
|
+
display: block;
|
|
82
|
+
container-type: inline-size;
|
|
83
|
+
font: inherit;
|
|
84
|
+
color: var(--_ink);
|
|
85
|
+
}
|
|
86
|
+
:host([hidden]) { display: none; }
|
|
87
|
+
.box {
|
|
88
|
+
background: var(--_bg);
|
|
89
|
+
border: 1px solid var(--_rule);
|
|
90
|
+
border-inline-start: 4px solid var(--_accent);
|
|
91
|
+
border-radius: var(--otel-error-radius, 8px);
|
|
92
|
+
padding: 14px 16px;
|
|
93
|
+
display: grid;
|
|
94
|
+
gap: 10px;
|
|
95
|
+
}
|
|
96
|
+
.head { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; }
|
|
97
|
+
.icon { width: 22px; height: 22px; color: var(--_accent); flex: none; margin-top: 1px; }
|
|
98
|
+
.title { margin: 0; font-size: 1rem; font-weight: 650; line-height: 1.35; overflow-wrap: anywhere; }
|
|
99
|
+
.meta { margin: 2px 0 0; color: var(--_muted); font-size: 0.875rem; overflow-wrap: anywhere; }
|
|
100
|
+
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
|
|
101
|
+
button, a.trace {
|
|
102
|
+
font: inherit; font-size: 0.875rem; line-height: 1.2;
|
|
103
|
+
min-height: 36px; padding: 8px 14px; border-radius: 6px;
|
|
104
|
+
border: 1px solid var(--_rule); background: transparent; color: var(--_ink);
|
|
105
|
+
cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
|
|
106
|
+
}
|
|
107
|
+
button.primary { background: var(--_accent); border-color: var(--_accent); color: var(--_accent-ink); font-weight: 600; }
|
|
108
|
+
button:hover, a.trace:hover { border-color: var(--_accent); }
|
|
109
|
+
button:focus-visible, a.trace:focus-visible, summary:focus-visible, textarea:focus-visible { outline: 2px solid var(--_focus); outline-offset: 2px; }
|
|
110
|
+
button[aria-disabled="true"] { opacity: 0.6; cursor: progress; }
|
|
111
|
+
.status { margin: 0; min-height: 1.2em; font-size: 0.8125rem; color: var(--_muted); }
|
|
112
|
+
.status:empty { display: none; }
|
|
113
|
+
details { border-top: 1px solid var(--_rule); padding-top: 8px; }
|
|
114
|
+
summary { cursor: pointer; font-size: 0.875rem; color: var(--_muted); width: fit-content; border-radius: 4px; }
|
|
115
|
+
dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 10px 0 0; font-size: 0.8125rem; }
|
|
116
|
+
dt { color: var(--_muted); }
|
|
117
|
+
dd { margin: 0; font-family: var(--_mono); overflow-wrap: anywhere; }
|
|
118
|
+
ol { margin: 10px 0 0; padding-inline-start: 20px; font-size: 0.8125rem; display: grid; gap: 4px; }
|
|
119
|
+
ol .via { color: var(--_muted); }
|
|
120
|
+
textarea {
|
|
121
|
+
width: 100%; box-sizing: border-box; margin-top: 10px; min-height: 8em; resize: vertical;
|
|
122
|
+
font: 0.75rem/1.4 var(--_mono); color: var(--_ink); background: transparent;
|
|
123
|
+
border: 1px solid var(--_rule); border-radius: 6px; padding: 8px;
|
|
124
|
+
}
|
|
125
|
+
@container (max-width: 420px) {
|
|
126
|
+
dl { grid-template-columns: 1fr; gap: 0; }
|
|
127
|
+
dd { margin-bottom: 6px; }
|
|
128
|
+
.actions > * { flex: 1 1 auto; justify-content: center; }
|
|
129
|
+
}
|
|
130
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
131
|
+
button, a.trace { transition: border-color 120ms ease; }
|
|
132
|
+
}
|
|
133
|
+
`;
|
|
134
|
+
|
|
135
|
+
const ICON =
|
|
136
|
+
'<svg class="icon" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9.5"/><path d="M12 7.5v5.5"/><path d="M12 16.5h.01"/></svg>';
|
|
137
|
+
|
|
138
|
+
/** A local time for people, with the ISO text as its title */
|
|
139
|
+
function timeText(at: string): string {
|
|
140
|
+
const date = new Date(at);
|
|
141
|
+
if (Number.isNaN(date.getTime())) return at;
|
|
142
|
+
return date.toLocaleTimeString(undefined, { hour: "2-digit", minute: "2-digit", second: "2-digit" });
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** The base class: `HTMLElement` in a browser, a stand-in in Node.js, so that an import on a server does not throw */
|
|
146
|
+
const ElementBase: typeof HTMLElement = (globalThis as { HTMLElement?: typeof HTMLElement }).HTMLElement ?? (class {} as unknown as typeof HTMLElement);
|
|
147
|
+
|
|
148
|
+
/** The element of one error record. Set `record` to show it. */
|
|
149
|
+
export class ErrorViewElement extends ElementBase {
|
|
150
|
+
static get observedAttributes(): string[] {
|
|
151
|
+
return ["trace-url", "trace-target", "retry", "report", "summary", "open"];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
#record: ErrorRecord | undefined;
|
|
155
|
+
#busy = false;
|
|
156
|
+
#status = "";
|
|
157
|
+
readonly #root: ShadowRoot;
|
|
158
|
+
|
|
159
|
+
constructor() {
|
|
160
|
+
super();
|
|
161
|
+
this.#root = this.attachShadow({ mode: "open" });
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** The record that the element shows */
|
|
165
|
+
get record(): ErrorRecord | undefined {
|
|
166
|
+
return this.#record;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** The setter keeps the redacted copy of the record (`redactErrorRecord`), so the view, the copy and the report hold no secret. */
|
|
170
|
+
set record(record: ErrorRecord | undefined) {
|
|
171
|
+
this.#record = record === undefined ? undefined : redactErrorRecord(record);
|
|
172
|
+
this.#busy = false;
|
|
173
|
+
this.#status = "";
|
|
174
|
+
this.#render();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** The text of the record, as the copy action gives it */
|
|
178
|
+
get text(): string {
|
|
179
|
+
return this.#record ? errorRecordText(this.#record) : "";
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
connectedCallback(): void {
|
|
183
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "alert");
|
|
184
|
+
this.#render();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
attributeChangedCallback(): void {
|
|
188
|
+
this.#render();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Copy the text of the record. It gives true when the clipboard took it. */
|
|
192
|
+
async copy(): Promise<boolean> {
|
|
193
|
+
const record = this.#record;
|
|
194
|
+
if (!record) return false;
|
|
195
|
+
const text = errorRecordText(record);
|
|
196
|
+
let copied = false;
|
|
197
|
+
try {
|
|
198
|
+
await navigator.clipboard.writeText(text);
|
|
199
|
+
copied = true;
|
|
200
|
+
} catch {
|
|
201
|
+
copied = false;
|
|
202
|
+
}
|
|
203
|
+
this.#setStatus(copied ? "The details are on the clipboard." : "The clipboard is not available. Select the text below and copy it.");
|
|
204
|
+
if (!copied) this.#showText();
|
|
205
|
+
this.dispatchEvent(new CustomEvent<ErrorCopyDetail>("otel-error-copy", { detail: { record, text, copied }, bubbles: true, composed: true }));
|
|
206
|
+
return copied;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
#setStatus(text: string): void {
|
|
210
|
+
this.#status = text;
|
|
211
|
+
const status = this.#root.querySelector(".status");
|
|
212
|
+
if (status) status.textContent = text;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
#showText(): void {
|
|
216
|
+
const details = this.#root.querySelector("details");
|
|
217
|
+
const area = this.#root.querySelector("textarea");
|
|
218
|
+
if (details) details.open = true;
|
|
219
|
+
if (area) {
|
|
220
|
+
area.hidden = false;
|
|
221
|
+
area.focus();
|
|
222
|
+
area.select();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
#retry(): void {
|
|
227
|
+
const record = this.#record;
|
|
228
|
+
if (!record || this.#busy) return;
|
|
229
|
+
let wait: PromiseLike<unknown> | undefined;
|
|
230
|
+
this.dispatchEvent(
|
|
231
|
+
new CustomEvent<ErrorRetryDetail>("otel-error-retry", {
|
|
232
|
+
detail: { record, waitUntil: (promise) => void (wait = promise) },
|
|
233
|
+
bubbles: true,
|
|
234
|
+
composed: true,
|
|
235
|
+
}),
|
|
236
|
+
);
|
|
237
|
+
if (!wait) return;
|
|
238
|
+
this.#busy = true;
|
|
239
|
+
this.#render();
|
|
240
|
+
const settle = (): void => {
|
|
241
|
+
// A new record during the retry already cleared the busy state
|
|
242
|
+
if (this.#record !== record) return;
|
|
243
|
+
this.#busy = false;
|
|
244
|
+
this.#render();
|
|
245
|
+
};
|
|
246
|
+
wait.then(settle, settle);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
#report(): void {
|
|
250
|
+
const record = this.#record;
|
|
251
|
+
if (!record) return;
|
|
252
|
+
this.dispatchEvent(
|
|
253
|
+
new CustomEvent<ErrorTextDetail>("otel-error-report", { detail: { record, text: errorRecordText(record) }, bubbles: true, composed: true }),
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
#render(): void {
|
|
258
|
+
const root = this.#root;
|
|
259
|
+
const record = this.#record;
|
|
260
|
+
const wasOpen = root.querySelector("details")?.open ?? this.hasAttribute("open");
|
|
261
|
+
// A render keeps the focus on the same action, so a keyboard user does not lose the place
|
|
262
|
+
const focused = (root.activeElement as HTMLElement | null)?.dataset?.["action"];
|
|
263
|
+
root.replaceChildren();
|
|
264
|
+
const style = document.createElement("style");
|
|
265
|
+
style.textContent = STYLE;
|
|
266
|
+
root.append(style);
|
|
267
|
+
if (!record) return;
|
|
268
|
+
|
|
269
|
+
const make = <K extends keyof HTMLElementTagNameMap>(tag: K, props: Partial<HTMLElementTagNameMap[K]> = {}, ...children: (Node | string)[]): HTMLElementTagNameMap[K] => {
|
|
270
|
+
const node = Object.assign(document.createElement(tag), props);
|
|
271
|
+
node.append(...children);
|
|
272
|
+
return node;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
const box = make("div", { className: "box" });
|
|
276
|
+
box.setAttribute("part", "box");
|
|
277
|
+
|
|
278
|
+
const head = make("div", { className: "head" });
|
|
279
|
+
const icon = document.createElement("template");
|
|
280
|
+
icon.innerHTML = ICON;
|
|
281
|
+
const summary = this.getAttribute("summary");
|
|
282
|
+
const meta: string[] = [];
|
|
283
|
+
if (summary) meta.push(record.message);
|
|
284
|
+
if (record.procedure) meta.push(record.procedure.name);
|
|
285
|
+
meta.push(timeText(record.at));
|
|
286
|
+
if (record.code) meta.push(record.code);
|
|
287
|
+
head.append(
|
|
288
|
+
icon.content,
|
|
289
|
+
make("div", {}, make("p", { className: "title", textContent: summary || record.message || record.name }), make("p", { className: "meta", textContent: meta.join(" · ") })),
|
|
290
|
+
);
|
|
291
|
+
box.append(head);
|
|
292
|
+
|
|
293
|
+
const actions = make("div", { className: "actions" });
|
|
294
|
+
if (this.hasAttribute("retry")) {
|
|
295
|
+
const retry = make("button", { type: "button", className: "primary", textContent: this.#busy ? "Retrying…" : "Retry" });
|
|
296
|
+
if (this.#busy) retry.setAttribute("aria-disabled", "true");
|
|
297
|
+
retry.dataset["action"] = "retry";
|
|
298
|
+
retry.addEventListener("click", () => this.#retry());
|
|
299
|
+
actions.append(retry);
|
|
300
|
+
}
|
|
301
|
+
const copy = make("button", { type: "button", textContent: "Copy details" });
|
|
302
|
+
copy.dataset["action"] = "copy";
|
|
303
|
+
copy.addEventListener("click", () => void this.copy());
|
|
304
|
+
actions.append(copy);
|
|
305
|
+
if (this.hasAttribute("report")) {
|
|
306
|
+
const report = make("button", { type: "button", textContent: this.getAttribute("report") || "Report" });
|
|
307
|
+
report.dataset["action"] = "report";
|
|
308
|
+
report.addEventListener("click", () => this.#report());
|
|
309
|
+
actions.append(report);
|
|
310
|
+
}
|
|
311
|
+
const href = traceLink(this.getAttribute("trace-url"), record, document.baseURI);
|
|
312
|
+
if (href) {
|
|
313
|
+
// The default opens the trace in a new tab. `trace-target="_self"` opens it in the page, for example a view of the page.
|
|
314
|
+
const target = this.getAttribute("trace-target") || "_blank";
|
|
315
|
+
const link = make("a", { className: "trace", href, textContent: "Open the trace" });
|
|
316
|
+
if (target !== "_self") Object.assign(link, { target, rel: "noopener noreferrer" });
|
|
317
|
+
link.dataset["action"] = "trace";
|
|
318
|
+
actions.append(link);
|
|
319
|
+
}
|
|
320
|
+
box.append(actions);
|
|
321
|
+
|
|
322
|
+
const status = make("p", { className: "status", textContent: this.#status });
|
|
323
|
+
status.setAttribute("role", "status");
|
|
324
|
+
box.append(status);
|
|
325
|
+
|
|
326
|
+
const rows: [string, string | undefined][] = [
|
|
327
|
+
["Trace", record.traceId],
|
|
328
|
+
["Span", record.spanId],
|
|
329
|
+
["Procedure", record.procedure?.name],
|
|
330
|
+
["Input digest", record.procedure?.inputDigest],
|
|
331
|
+
...Object.entries(record.context),
|
|
332
|
+
...Object.entries(record.attributes ?? {}).map(([key, value]): [string, string] => [key, String(value)]),
|
|
333
|
+
["Time", record.at],
|
|
334
|
+
["Record", record.id],
|
|
335
|
+
];
|
|
336
|
+
const list = make("dl");
|
|
337
|
+
for (const [label, value] of rows) if (value !== undefined && value !== "") list.append(make("dt", { textContent: label }), make("dd", { textContent: value }));
|
|
338
|
+
const details = make("details", { open: wasOpen }, make("summary", { textContent: "Details" }), list);
|
|
339
|
+
if (record.causes.length > 1) {
|
|
340
|
+
const causes = make("ol");
|
|
341
|
+
causes.setAttribute("aria-label", "The causes");
|
|
342
|
+
for (const cause of record.causes.slice(1)) causes.append(make("li", {}, `${cause.name}: ${cause.message}`, make("span", { className: "via", textContent: cause.via ? ` (${cause.via})` : "" })));
|
|
343
|
+
details.append(causes);
|
|
344
|
+
}
|
|
345
|
+
const area = make("textarea", { readOnly: true, hidden: true, value: errorRecordText(record) });
|
|
346
|
+
area.setAttribute("aria-label", "The details as text");
|
|
347
|
+
details.append(area);
|
|
348
|
+
box.append(details);
|
|
349
|
+
root.append(box);
|
|
350
|
+
if (focused) root.querySelector<HTMLElement>(`[data-action="${focused}"]`)?.focus();
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** Register the element under `name`, one time. A second call with the same name does nothing. */
|
|
355
|
+
export function defineErrorView(name: string = ERROR_VIEW_TAG): void {
|
|
356
|
+
if (!customElements.get(name)) customElements.define(name, class extends ErrorViewElement {});
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** The options of `errorView()` */
|
|
360
|
+
export interface ErrorViewOptions {
|
|
361
|
+
/** Show a retry button */
|
|
362
|
+
readonly retry?: boolean;
|
|
363
|
+
/** Show a report button, with this label (default: Report) */
|
|
364
|
+
readonly report?: boolean | string;
|
|
365
|
+
/** The template of the trace link */
|
|
366
|
+
readonly traceUrl?: string;
|
|
367
|
+
/** Where the trace link opens. Default: `_blank`. */
|
|
368
|
+
readonly traceTarget?: string;
|
|
369
|
+
/** A headline in plain words. The message of the record then goes in the line below it. */
|
|
370
|
+
readonly summary?: string;
|
|
371
|
+
/** The name of the element. Default: `ERROR_VIEW_TAG`. */
|
|
372
|
+
readonly tag?: string;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** Make an element for `record`. It registers the element first, when it is not registered. */
|
|
376
|
+
export function errorView(record: ErrorRecord, options: ErrorViewOptions = {}): ErrorViewElement {
|
|
377
|
+
const tag = options.tag ?? ERROR_VIEW_TAG;
|
|
378
|
+
defineErrorView(tag);
|
|
379
|
+
const element = document.createElement(tag) as ErrorViewElement;
|
|
380
|
+
if (options.retry) element.setAttribute("retry", "");
|
|
381
|
+
if (options.report) element.setAttribute("report", options.report === true ? "" : options.report);
|
|
382
|
+
if (options.traceUrl) element.setAttribute("trace-url", options.traceUrl);
|
|
383
|
+
if (options.traceTarget) element.setAttribute("trace-target", options.traceTarget);
|
|
384
|
+
if (options.summary) element.setAttribute("summary", options.summary);
|
|
385
|
+
element.record = record;
|
|
386
|
+
return element;
|
|
387
|
+
}
|
package/src/init.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { context, propagation, trace } from "@opentelemetry/api";
|
|
1
|
+
import { context, logs, propagation, trace } from "@opentelemetry/api";
|
|
2
2
|
import { MeterProvider } from "@opentelemetry/sdk-metrics";
|
|
3
3
|
import { LoggerProvider } from "@opentelemetry/sdk-logs";
|
|
4
4
|
import type { FlushCause, OtelTsConfig, OtelTsInstance, ResolvedConfig } from "./types.js";
|
|
@@ -117,7 +117,7 @@ type Provider = { forceFlush(): Promise<void>; shutdown(): Promise<void> };
|
|
|
117
117
|
*/
|
|
118
118
|
function releaseContext(releaseRegistration: (() => void) | undefined): void {
|
|
119
119
|
if (!releaseRegistration) return;
|
|
120
|
-
for (const api of [trace, propagation, context]) api.disable();
|
|
120
|
+
for (const api of [trace, propagation, context, logs]) api.disable();
|
|
121
121
|
releaseRegistration();
|
|
122
122
|
}
|
|
123
123
|
|
|
@@ -160,6 +160,12 @@ function startInstance(
|
|
|
160
160
|
|
|
161
161
|
providers.push(loggerProvider);
|
|
162
162
|
|
|
163
|
+
// The owner of the globals also registers its logger provider, so a library
|
|
164
|
+
// that logs through the API (for example reportError of /error) reaches it
|
|
165
|
+
if (releaseRegistration && resolved.logs) {
|
|
166
|
+
logs.setGlobalLoggerProvider(loggerProvider);
|
|
167
|
+
}
|
|
168
|
+
|
|
163
169
|
// After the tracing, so Faro reads the context of otel-ts
|
|
164
170
|
if (faroUrl) {
|
|
165
171
|
setupFaro(resolved, faroUrl);
|