패키지, 저장소 및 앱 카테고리 검색

azure_application_insights 표지
패키지 상세v5.0.1

azure_application_insights

Azure의 Application Insights 서비스와 통합하기 위한 Dart 클라이언트

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
3.1만
좋아요
49
Pub 점수
160

패키지 설치

flutter pub add azure_application_insights

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Dart 클라이언트로 Azure Application Insights와의 통합을 가능하게 하여, 여러 플랫폼에서 실행되는 Flutter 애플리케이션에서 로그, 예외 및 성능 메트릭과 같은 원격 모니터링 데이터를 수집할 수 있도록 합니다. 안드로이드, iOS, 웹, macOS, Windows, 리눅스에서 실행 중인 앱에 대한 실시간 모니터링 및 진단을 지원합니다. 이 패키지는 애플리케이션 인사이트를 Azure로 전송하는 과정을 간소화하여 디버깅, 성능 최적화, 사용자 행동 분석에 도움을 줍니다. 최소한의 구성으로 Flutter 프로젝트 내에서 원활하게 사용할 수 있도록 설계되었습니다.

사용 사례

  • 생산 환경에서 애플리케이션 성능 모니터링
  • 사용자 상호작용 및 세션 데이터 추적
  • 디버깅을 위한 예외 및 오류 캡처
  • 크래시 보고서 및 실패율 분석
  • 모바일 및 웹 앱의 실시간 관측성

주요 기능

  • 크로스 플랫폼 원격 모니터링 수집
  • 로그, 이벤트 및 예외 지원
  • Azure Application Insights 대시보드와의 통합
  • 최소한의 설정 및 구성
  • 앱 라이프사이클 이벤트의 자동 추적

적합한 대상

  • 분석용 Azure를 사용하는 Flutter 개발자
  • 크로스 플랫폼 모니터링이 필요한 팀
  • 세부 오류 추적을 필요로 하는 응용 프로그램
  • 성능 최적화에 중점을 둔 프로젝트
  • 관측성 실천을 구현하는 개발자

고려 사항

  • Azure Application Insights 리소스가 필요합니다
  • 데이터 개인정보 보호 및 준수 고려 사항
  • 앱 크기 및 성능에 미치는 잠재적 영향
  • 원격 감시 전송에 네트워크 연결에 따라 달라짐
  • 네이티브 SDK에 비해 사용자 맞춤 설정이 제한적

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Azure Application Insights

pub package

All Contributors

What?

This is a Dart library that integrates with Azure's Application Insights service. It allows you to push telemetry items into your Application Insights instance.

Why?

Application Insights is a powerful tool for understanding how your software system is operating. In the context of Flutter applications, it allows you to deeply understand user interactions, performance, and faults in your application.

Where?

Firstly, install the azure_application_insights package, then you can import it into your Dart code as follows:

import 'package:azure_application_insights/azure_application_insights.dart';

How?

The only piece of information you need to integrate with Application Insights is your connection string, which you can find inside the Azure portal. Open your Application Insights resource and look in the Overview tab.

Once you have your connection string, you can construct a TelemetryClient as follows:

final processor = BufferedProcessor(
  next: TransmissionProcessor(
    connectionString: connectionString,
    httpClient: client,
    timeout: const Duration(seconds: 10),
  ),
);

final telemetryClient = TelemetryClient(
  processor: processor,
);

This is a typical setup where telemetry items are buffered before being transmitted. Depending on your processing needs, you may have a need for more than one TelemetryClient in your application. For example, you might have one TelemetryClient that buffers telemetry items and is used for all telemetry other than errors, and a second that does not buffer and is used only to submit errors as promptly as possible. Please review the example code and API docs for alternative configurations.

Once you have a TelemetryClient, you can simply invoke the various methods to capture telemetry items:

telemetryClient.trackTrace(
  severity: Severity.information,
  message: 'Hello from Dart!',
);

You may also want to configure additional properties to be submitted with telemetry items. These can be configured in two places:

  1. On the TelemetryContext associated with your TelemetryClient. Properties in this context object will be attached to every telemetry item submitted. Moreover, you can share a TelemetryContext between multiple TelemetryClient instances if desired.
  2. Every method on TelemetryClient allows you to specify additionalProperties that will be captured only for that telemetry item. As the name suggests, these properties are in addition to those within the context.

Here are examples of both:

final telemetryClient = ...;

// 1. Properties associated with the TelemetryClient will be attached to
// all telemetry items submitted via that client.
telemetryClient.context
    // These built-in helpers simply set the pre-defined properties
    // Application Insights provides.
    ..applicationVersion = 'my version'
    ..device.type = 'Android';
    // But you can also set whatever property name you like.
    ..properties['environmentName'] = 'dev';

// 2. Additional properties can be bundled with individual telemetry items.
telemetryClient.traceTrace(
    severity: Severity.information,
    message: 'An example',
    additionalProperties: <String, Object>{
        'answer': 42,
    },
);

Of course, you can leverage whatever data sources and third party libraries make sense in order to populate properties. Typically you would use a package like device_info_plus to obtain information on the device and fill in the appropriate properties on the context.

Flutter Integration

To submit crashes in Flutter applications as telemetry, follow the following recipe:

void main() {
    // You probably don't want to always run with crash reporting because it interferes with the normal
    // debug/development experience. Here we use kReleaseMode to only enable crash reporting for release builds, but
    // you can use whatever criteria and mechanism you like.
    if (kReleaseMode) {
        runWithCrashReporting(codeToExecute: run);
    } else {
        run();
    }
}

void run() => runApp(MyApp());

Future<void> runWithCrashReporting({
  required VoidCallback codeToExecute,
}) async {
  // Hook into Flutter error handling.
  FlutterError.onError = (details) => submitErrorAsTelemetry(
        isFatal: true,
        error: details.exception,
        trace: details.stack,
      );

  // Run the code to execute in a zone and handle all errors within.
  runZonedGuarded(
    codeToExecute,
    (error, trace) => submitErrorAsTelemetry(
      isFatal: true,
      error: error,
      trace: trace,
    ),
  );
}

Future<void> submitErrorAsTelemetry({
  required bool isFatal,
  required Object error,
  required StackTrace trace,
}) async {
  debugPrint('reporting ${isFatal ? 'fatal' : 'non-fatal'} error: $error');
  debugPrint('$trace');

  try {
    // Get your TelemetryClient instance here, perhaps by DI or some other mechanism.
    final telemetryClient = ...;

    // Get any additional properties for the crash report here, such as device information.
    final errorProperties = ...;

    // Write an error telemetry item.
    telemetryClient.trackError(
      error: error,
      stackTrace: trace,
      severity: isFatal ? Severity.critical : Severity.error,
      additionalProperties: errorProperties,
    );

    if (isFatal) {
      await telemetryClient.flush();
    }
  } on Object catch (e, t) {
    // We print synchronously here to ensure the output is written in the case we force exit.
    debugPrintSynchronously('Sending error telemetry failed: $e\r\n$t');
    debugPrintSynchronously('Original error: $error');
  } finally {
    if (isFatal && kReleaseMode) {
      debugPrintSynchronously('Forcing exit');
    }
  }
}
HTTP Middleware

Whilst you can certainly use TelemetryClient.trackDependency to track HTTP requests yourself, you can save time by using the TelemetryHttpClient HTTP client. This class will automatically time requests and forward on the details of completed requests to a given TelemetryClient as dependency telemetry items.

Typical usage looks like this:

final telemetryHttpClient = TelemetryHttpClient(
  telemetryClient: telemetryClient,
  inner: Client(),
);

// This request will be captured as a dependency telemetry item.
await telemetryHttpClient.get('https://kent-boogaart.com/');

The TelemetryHttpClient could be one piece in a long chain of HTTP middleware - it is composable.

Who?

Thanks goes to these wonderful people (emoji key):

Kent Boogaart
Kent Boogaart

💻 ⚠️ 📖 💡
Daniel Luz
Daniel Luz

💻
Robert Sandberg
Robert Sandberg

💻
Robson Silva
Robson Silva

💻
Michael Gugler
Michael Gugler

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

카테고리

의존성

의존성 목록 5 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.