-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
105 lines (97 loc) · 2.38 KB
/
App.tsx
File metadata and controls
105 lines (97 loc) · 2.38 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* Sample React Native App - SigNoz OpenTelemetry Test
*/
import { useTracer } from './hooks/tracing';
import {
StatusBar,
StyleSheet,
useColorScheme,
View,
Text,
TouchableOpacity,
} from 'react-native';
import {
SafeAreaProvider,
useSafeAreaInsets,
} from 'react-native-safe-area-context';
import { useState } from 'react';
function App() {
const isDarkMode = useColorScheme() === 'dark';
const { loaded: tracerLoaded } = useTracer();
return (
<SafeAreaProvider>
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
<AppContent tracerLoaded={tracerLoaded} />
</SafeAreaProvider>
);
}
function AppContent({ tracerLoaded }: { tracerLoaded: boolean }) {
const safeAreaInsets = useSafeAreaInsets();
const [response, setResponse] = useState<string>('');
const makeTestRequest = async () => {
try {
const res = await fetch('https://jsonplaceholder.typicode.com/todos/1');
const data = await res.json();
setResponse(JSON.stringify(data, null, 2));
} catch (err: any) {
setResponse(`Error: ${err.message}`);
}
};
return (
<View style={[styles.container, { paddingTop: safeAreaInsets.top + 20 }]}>
<Text style={styles.title}>SigNoz OTel Test</Text>
<Text style={styles.status}>
Tracer: {tracerLoaded ? 'Ready' : 'Loading...'}
</Text>
<TouchableOpacity style={styles.button} onPress={makeTestRequest}>
<Text style={styles.buttonText}>Make Test Request</Text>
</TouchableOpacity>
{response ? (
<View style={styles.responseBox}>
<Text style={styles.responseText}>{response}</Text>
</View>
) : null}
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
backgroundColor: '#f5f5f5',
padding: 20,
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 10,
},
status: {
fontSize: 16,
marginBottom: 20,
color: '#666',
},
button: {
backgroundColor: '#e2632d',
paddingHorizontal: 24,
paddingVertical: 12,
borderRadius: 8,
},
buttonText: {
color: '#fff',
fontSize: 16,
fontWeight: '600',
},
responseBox: {
marginTop: 20,
padding: 12,
backgroundColor: '#fff',
borderRadius: 8,
width: '100%',
},
responseText: {
fontFamily: 'monospace',
fontSize: 12,
},
});
export default App;