-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathApp.js
57 lines (51 loc) · 1.44 KB
/
App.js
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
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Tracer, ExplicitContext, BatchRecorder, jsonEncoder, Annotation } from 'zipkin';
import wrapFetch from 'zipkin-instrumentation-fetch';
import { HttpLogger } from 'zipkin-transport-http';
const { JSON_V2 } = jsonEncoder;
const zipkinBaseUrl = 'http://localhost:9411';
const tracer = new Tracer({
ctxImpl: new ExplicitContext(),
recorder: new BatchRecorder({
logger: new HttpLogger({
endpoint: `${zipkinBaseUrl}/api/v2/spans`,
jsonEncoder: JSON_V2,
fetch,
}),
}),
localServiceName: 'react-native',
});
export default class App extends React.Component {
state = {
person: 'Not loaded',
tracer,
fetch: wrapFetch(fetch, {tracer, remoteServiceName: 'starwars'}),
};
componentWillMount() {
const randomNumber = Math.floor(Math.random() * 10) + 1;
this.state.tracer.local('pay-me', () =>
this.state.fetch("https://swapi.co/api/people/" + randomNumber)
.then(response => response.json())
.then(person => this.setState({
person: person.name,
})
).catch(e => console.error(e))
);
}
render() {
return (
<View style={styles.container}>
<Text>{this.state.person}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});