Skip to content

Commit e327b08

Browse files
feat(sandbox): add exception event button (#326)
Co-authored-by: David Luna <david.luna@elastic.co>
1 parent 31297d1 commit e327b08

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

β€Žsandbox/src/app/actions.tsβ€Ž

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ export function createActions(tracer: Tracer, logger: Logger) {
6363
}
6464
};
6565

66+
// ── Event actions ────────────────────────────────────────────────────────────
67+
68+
const exceptionEvent = () => {
69+
setTimeout(() => {
70+
throw new Error(
71+
'Demo exception event β€” captured by ErrorsInstrumentation',
72+
);
73+
}, 0);
74+
};
75+
6676
const navigation = () => {
6777
const routes = [
6878
'/home',
@@ -159,5 +169,6 @@ export function createActions(tracer: Tracer, logger: Logger) {
159169
logInfo,
160170
logWarn,
161171
logError,
172+
exceptionEvent,
162173
};
163174
}

β€Žsandbox/src/app/components/ActionsPanel.tsxβ€Ž

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,22 @@ export function ActionsPanel({ ready, act, sessionId }: ActionsPanelProps) {
121121
</button>
122122
</div>
123123
</article>
124+
125+
<article>
126+
<header>
127+
<strong>Events</strong>
128+
</header>
129+
<div className="btn-grid">
130+
<button
131+
type="button"
132+
disabled={!ready}
133+
onClick={() => act('exceptionEvent')}
134+
className="btn-err"
135+
>
136+
πŸ’₯ Exception
137+
</button>
138+
</div>
139+
</article>
124140
</>
125141
);
126142
}

β€Žsandbox/src/otel.tsβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Tracer } from '@opentelemetry/api';
44
import { trace } from '@opentelemetry/api';
55
import type { Logger } from '@opentelemetry/api-logs';
66
import { logs } from '@opentelemetry/api-logs';
7+
import { ErrorsInstrumentation } from '@opentelemetry/browser-instrumentation/experimental/errors';
78
import { NavigationTimingInstrumentation } from '@opentelemetry/browser-instrumentation/experimental/navigation-timing';
89
import { ResourceTimingInstrumentation } from '@opentelemetry/browser-instrumentation/experimental/resource-timing';
910
import { UserActionInstrumentation } from '@opentelemetry/browser-instrumentation/experimental/user-action';
@@ -128,6 +129,7 @@ export async function initOtel(
128129
// ── Auto-instrumentations ───────────────────────────────────────────────────
129130
registerInstrumentations({
130131
instrumentations: [
132+
new ErrorsInstrumentation(),
131133
new NavigationTimingInstrumentation(),
132134
new ResourceTimingInstrumentation({
133135
ignoreUrls: [config.tracesUrl, config.logsUrl],

0 commit comments

Comments
Β (0)