atatus_tracking_http_client 1.0.4
atatus_tracking_http_client: ^1.0.4 copied to clipboard
A wrapping implementation of HttpClient for tracking resources with Atatus
example/lib/main.dart
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
// This product includes software developed at Atatus (https://www.atatus.com/).
// Copyright 2026 Atatus, Inc.
import 'dart:io';
import 'package:atatus_common_test/atatus_common_test.dart';
import 'package:atatus_flutter_plugin/atatus_flutter_plugin.dart';
import 'package:atatus_tracking_http_client/atatus_tracking_http_client.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'scenario_config.dart';
import 'scenario_select_screen.dart';
// This file sets up a different application for testing auto instrumentation
// Using the widgets in this library by themselves won't send any RUM events
// but, by utilizing this entry point instead, we can test that
// auto-instrumentation added to an existing app gives us the expected results.
TestingConfiguration? testingConfiguration;
class ClientListener extends AtatusTrackingHttpClientListener {
@override
void requestStarted(
{required Object resourceKey,
required HttpClientRequest request,
required Map<String, Object?> userAttributes}) {
if (kDebugMode) {
print('($resourceKey) Request started');
}
}
@override
void responseFinished(
{required Object resourceKey,
required HttpClientResponse response,
required Map<String, Object?> userAttributes,
Object? error}) {
if (kDebugMode) {
print('($resourceKey) Request finished');
}
}
}
Future<void> main() async {
final merge = kIsWeb ? <String, String>{} : Platform.environment;
await dotenv.load(mergeWith: merge);
var licenseKey = dotenv.get('ATATUS_CLIENT_TOKEN', fallback: '');
String? customEndpoint = dotenv.maybeGet('ATATUS_CUSTOM_ENDPOINT');
if (testingConfiguration != null) {
if (testingConfiguration!.customEndpoint != null) {
customEndpoint = testingConfiguration!.customEndpoint;
}
if (testingConfiguration!.licenseKey != null) {
licenseKey = testingConfiguration!.licenseKey!;
}
}
final firstPartyHosts = ['atatus.com'];
if (testingConfiguration != null) {
firstPartyHosts.addAll(testingConfiguration!.firstPartyHosts);
}
AtatusSdk.instance.sdkVerbosity = CoreLoggerLevel.debug;
final configuration = AtatusConfiguration(
licenseKey: licenseKey,
env: dotenv.get('ATATUS_ENV', fallback: ''),
appName: 'atatus_tracking_http_client_example',
site: AtatusSite.ATATUS,
uploadFrequency: UploadFrequency.frequent,
batchSize: BatchSize.small,
nativeCrashReportEnabled: true,
firstPartyHosts: firstPartyHosts,
loggingConfiguration: AtatusLoggingConfiguration(
customEndpoint: customEndpoint,
),
rumConfiguration:
AtatusRumConfiguration(
detectLongTasks: false,
traceSampleRate: 100,
customEndpoint: customEndpoint,
));
if (testingConfiguration != null) {
// Add clear text if we're running an actual test.
configuration.additionalConfig['_atatus.needsClearTextHttp'] = true;
}
if (RumAutoInstrumentationScenarioConfig.instance.enableIoHttpTracking) {
configuration.enableHttpTracking(
clientListener: ClientListener(),
);
}
await AtatusSdk.runApp(configuration, TrackingConsent.granted, () async {
// User for testing baggage headers
AtatusSdk.instance.setUserInfo(id: 'integration_test_user');
AtatusSdk.instance.setAccountInfo(id: 'integration_test_account');
runApp(const AtatusAutoIntegrationTestApp());
});
}
class AtatusAutoIntegrationTestApp extends StatelessWidget {
const AtatusAutoIntegrationTestApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final navObserver = AtatusNavigationObserver(atatusSdk: AtatusSdk.instance);
return AtatusNavigationObserverProvider(
navObserver: navObserver,
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
navigatorObservers: [
navObserver,
],
home: const ScenarioSelectScreen()),
);
}
}