-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathApp.jsx
86 lines (73 loc) · 2.32 KB
/
App.jsx
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import React from 'react';
import {BrowserRouter, Link, Route} from 'react-router-dom';
import {SeverityLevel} from '@microsoft/applicationinsights-web';
import './App.css';
import { getAppInsights } from './TelemetryService';
import TelemetryProvider from './telemetry-provider';
const Home = () => (
<div>
<h2>Home Page</h2>
</div>
);
const About = () => (
<div>
<h2>About Page</h2>
</div>
);
const Header = () => (
<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/about">About</Link>
</li>
</ul>
);
const App = () => {
let appInsights = null;
function trackException() {
appInsights.trackException({ error: new Error('some error'), severityLevel: SeverityLevel.Error });
}
function trackTrace() {
appInsights.trackTrace({ message: 'some trace', severityLevel: SeverityLevel.Information });
}
function trackEvent() {
appInsights.trackEvent({ name: 'some event' });
}
function throwError() {
let foo = {
field: { bar: 'value' }
};
// This will crash the app; the error will show up in the Azure Portal
return foo.fielld.bar;
}
function ajaxRequest() {
let xhr = new XMLHttpRequest();
xhr.open('GET', 'https://httpbin.org/status/200');
xhr.send();
}
function fetchRequest() {
fetch('https://httpbin.org/status/200');
}
return (
<BrowserRouter>
<TelemetryProvider instrumentationKey="INSTRUMENTATION_KEY" after={() => { appInsights = getAppInsights() }}>
<div >
<Header />
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
</div>
<div className="App">
<button onClick={trackException}>Track Exception</button>
<button onClick={trackEvent}>Track Event</button>
<button onClick={trackTrace}>Track Trace</button>
<button onClick={throwError}>Autocollect an Error</button>
<button onClick={ajaxRequest}>Autocollect a Dependency (XMLHttpRequest)</button>
<button onClick={fetchRequest}>Autocollect a dependency (Fetch)</button>
</div>
</TelemetryProvider>
</BrowserRouter>
);
};
export default App;