Skip to content

Commit

Permalink
Merge pull request #3 from robert-northmind/fix_faro_auth_issue
Browse files Browse the repository at this point in the history
Fix missing auth logic and broken example app
  • Loading branch information
NasarTarique authored Jul 30, 2024
2 parents dbf05b8 + b4e168a commit 57cef32
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 126 deletions.
6 changes: 6 additions & 0 deletions packages/rum_sdk/example/.env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Make a copy of this file and name it `.env`
# (NOTE: Do not commit the `.env` file)

# Then fill it in with data from the `Faro configs` section in Grafana Cloud.
FARO_API_KEY=""
FARO_COLLECTOR_URL=""
130 changes: 57 additions & 73 deletions packages/rum_sdk/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,30 @@ void main() async {
WidgetsFlutterBinding.ensureInitialized();
HttpOverrides.global = RumHttpOverrides(HttpOverrides.current);
await dotenv.load(fileName: ".env");
RumFlutter().transports.add(
OfflineTransport(maxCacheDuration: const Duration(days: 3))
);
await RumFlutter().runApp( optionsConfiguration:
RumConfig(
appName: "example_app",
appVersion: "2.0.1",
appEnv: "Test",
apiKey: "api_key",
anrTracking: true,
cpuUsageVitals: true,
collectorUrl: "http://10.0.2.2:8027/collect",
enableCrashReporting: true,
memoryUsageVitals: true,
refreshRateVitals: true,
fetchVitalsInterval: const Duration(seconds: 30),
),
appRunner: () async {
runApp( DefaultAssetBundle(bundle: RumAssetBundle(), child: const RumUserInteractionWidget(child: MyApp()))
);
}
);
RumFlutter()
.transports
.add(OfflineTransport(maxCacheDuration: const Duration(days: 3)));
await RumFlutter().runApp(
optionsConfiguration: RumConfig(
appName: "example_app",
appVersion: "2.0.1",
appEnv: "Test",
apiKey: dotenv.env['FARO_API_KEY'] ?? '',
anrTracking: true,
cpuUsageVitals: true,
collectorUrl: dotenv.env['FARO_COLLECTOR_URL'] ?? '',
enableCrashReporting: true,
memoryUsageVitals: true,
refreshRateVitals: true,
fetchVitalsInterval: const Duration(seconds: 30),
),
appRunner: () async {
runApp(DefaultAssetBundle(
bundle: RumAssetBundle(),
child: const RumUserInteractionWidget(child: MyApp())));
});
}



class MyApp extends StatefulWidget {
const MyApp({super.key});

Expand All @@ -51,68 +49,58 @@ class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
setState(() {
});
setState(() {});
}




@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorObservers: [RumNavigationObserver()],
initialRoute: '/',
routes: {
'/home': (context) => const HomePage(),
'/features': (context) => const FeaturesPage()
},
home: Scaffold(
appBar: AppBar(
title: const Text('RUM Test App'),
),
body:
const HomePage()
)
);
navigatorObservers: [RumNavigationObserver()],
initialRoute: '/',
routes: {
'/home': (context) => const HomePage(),
'/features': (context) => const FeaturesPage()
},
home: Scaffold(
appBar: AppBar(
title: const Text('RUM Test App'),
),
body: const HomePage()));
}
}

class HomePage extends StatefulWidget{
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);

@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage>{

class _HomePageState extends State<HomePage> {
@override
void initState() {
super.initState();
}

@override
Widget build(BuildContext context){
Widget build(BuildContext context) {
return Center(
child:Column(
mainAxisAlignment: MainAxisAlignment.center, // Center vertically
crossAxisAlignment: CrossAxisAlignment.center, // Center horizontally
children: [
const Image(image: AssetImage("assets/AppHomeImage.png"),),
child: Column(
mainAxisAlignment: MainAxisAlignment.center, // Center vertically
crossAxisAlignment:
CrossAxisAlignment.center, // Center horizontally
children: [
// const Image(image: AssetImage("assets/AppHomeImage.png"),),
ElevatedButton(
child: const Text("Change Route"),
onPressed:(){
Navigator.pushNamed(context,'/features');
}
),
]
)
);
onPressed: () {
Navigator.pushNamed(context, '/features');
}),
]));
}

}

class _FeaturesPageState extends State<FeaturesPage> {

@override
void initState() {
super.initState();
Expand All @@ -129,7 +117,6 @@ class _FeaturesPageState extends State<FeaturesPage> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [

ElevatedButton(
onPressed: () async {
final response = await http.post(
Expand Down Expand Up @@ -161,33 +148,30 @@ class _FeaturesPageState extends State<FeaturesPage> {
),
ElevatedButton(
onPressed: () async {
final response = await http
.get(Uri.parse('http://10.0.2.2:4000/failpath/'));
final response =
await http.get(Uri.parse('http://10.0.2.2:4000/failpath/'));
},
child: const Text('HTTP GET Request - fail'),
),

ElevatedButton(
onPressed: () {
RumFlutter().pushLog("Custom Log",level: "warn");
RumFlutter().pushLog("Custom Log", level: "warn");
},
child: const Text('Custom Warn Log'),
),

ElevatedButton(
onPressed: () {
RumFlutter().pushMeasurement({'customvalue': 1}, "custom_measurement");
RumFlutter()
.pushMeasurement({'customvalue': 1}, "custom_measurement");
},
child: const Text('Custom Measurement'),
),

ElevatedButton(
onPressed: () {
RumFlutter().pushEvent("custom_event");
},
child: const Text('Custom Event'),
),

ElevatedButton(
onPressed: () {
setState(() {
Expand All @@ -199,21 +183,21 @@ class _FeaturesPageState extends State<FeaturesPage> {
ElevatedButton(
onPressed: () {
setState(() {
double a = 0/0;
double a = 0 / 0;
throw Exception("This is an Exception!");
});
},
child: Text('Exception'),
),
ElevatedButton(
onPressed: () async {
RumFlutter().markEventStart("event1","event1_duration");
RumFlutter().markEventStart("event1", "event1_duration");
},
child: const Text('Mark Event Start'),
),
ElevatedButton(
onPressed: () async {
RumFlutter().markEventEnd("event1","event1_duration");
RumFlutter().markEventEnd("event1", "event1_duration");
},
child: const Text('Mark Event End'),
),
Expand Down
7 changes: 3 additions & 4 deletions packages/rum_sdk/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: rum_sdk_example
description: Demonstrates how to use the rum_sdk plugin.
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
publish_to: "none" # Remove this line if you wish to publish to pub.dev

environment:
sdk: '>=2.19.6 <3.0.0'
sdk: ">=2.19.6 <3.0.0"

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
Expand All @@ -21,8 +21,7 @@ dependencies:
offline_transport:
path: ../../offline_transport
flutter_dotenv: ^5.1.0
# path: ../../rum_dart

# path: ../../rum_dart

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
Expand Down
Loading

0 comments on commit 57cef32

Please sign in to comment.