-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.tsx
61 lines (57 loc) · 1.43 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Span, trace } from "@opentelemetry/api";
import { useState } from "react";
import "./App.css";
import { provider } from "./loadInstrumentation";
const tracer = trace.getTracer("app-tracer");
function App() {
const [error, setError] = useState<string | null>(null);
const onSubmit = async () => {
tracer.startActiveSpan(
"complex_flow_with_two_requests",
async (span: Span) => {
try {
const characterRequest = fetch(
"https://rickandmortyapi.com/api/character",
{
method: "GET",
}
);
await characterRequest;
const episodesRequest = fetch(
"https://rickandmortyapi.com/api/episode",
{
method: "GET",
}
);
await episodesRequest;
} catch (e) {
setError("Something bad happened");
console.log(e);
}
span.end();
provider.forceFlush();
}
);
};
return (
<>
<h1>Demo lost context in async</h1>
<div className="card">
<button
className="button"
onClick={async () => {
await onSubmit();
}}
>
Test
</button>
<p>
Check the console's network tab. The parent ids should be set to the
root span.
</p>
{error && <p>{error}</p>}
</div>
</>
);
}
export default App;