OpenTelemetry instrumentation for firebase_analytics

License OpenTelemetry Specification

otel_firebase_analytics is an OpenTelemetry instrumentation for firebase_analytics that easily adds standard observability to applications that use firebase_analytics. This package depends on dartastic_opentelemetry_api.

This package can be used with any OTel backend because it's compliant with the OpenTelemetry Specification.

This package supports Android, iOS, macOS and Web, for versions of firebase_analytics that support those platforms. It is WASM-ready.

This Apache-2.0 package is professionally maintained and supported with 💙 by Michael Bushe, Dart and Flutter Maintainer at OpenTelemetry and the creator of dartastic_opentelemetry and dartastic_opentelemetry_api. This package is professionally supported by Dartastic.io.


Dartastic.io: AI Code Healing and Real User Monitoring for Flutter

See what your users experience. Find problems with Flutter apps in production. Fix them with AI.

Dartastic.io brings AI code healing, real user monitoring, and OpenTelemetry observability together in one platform built for Dart and Flutter. (Patents pending)

Dartastic AI answering "Why did crashes jump after the last release?" over a Flutter App Health dashboard

Dartastic AI — From Production Problems to Code Fixes

Dartastic AI analyzes production telemetry alongside your application source code to diagnose problems and propose fixes.

  • Investigate production issues using crashes, errors, traces, metrics, and real user telemetry.
  • Find the offending code by connecting observed problems with your application's source in Dartastic Pub or your source code repos.
  • Generate code patches that address the underlying problems.
  • Create actionable issues in your issue tracker, complete with findings and the proposed code patch.

Dartastic RUM — See What Your Users See

Understand how people actually experience your Flutter application.

  • Replay user sessions in the Dartastic Observatory session player.
  • Choose your replay fidelity, from privacy-preserving widget outlines to pixel-level reproductions of the user experience.
  • Investigate real user problems using session replay and production observability data.

Dartastic RUM Session Replay

Dartastic Observatory — Observability Built for Flutter

A complete observability backend where Flutter and Dart are first-class citizens.

  • Flutter-specific dashboards for application performance, health, and reliability.
  • Alerts and notifications through email, Slack, and PagerDuty.
  • Dartastic Cloud Observatory — Start with a 30-day free trial on isolated, shared infrastructure, as low as $39/mo.
  • Dartastic Hosted Observatory — Run the observability stack in a private managed environment, sized from Mini to Enterprise XL.
  • Dartastic Self-Hosted Observatory — The whole platform inside your own network. Your keys, your cluster, with nothing leaving your perimeter.

Dartastic Native OTel Runtime — Native OpenTelemetry Performance

Collect production telemetry without burdening Flutter's main isolate.

  • Native OpenTelemetry runtime that moves telemetry processing off the main isolate.
  • Native crash reporting for problems that Dart can't catch.
  • Widget performance diagnostics to identify janky widgets.
  • On-device PII filtering before sensitive data leaves your application.
  • Source-level error diagnostics powered by the Dartastic Symbolizer API.
  • Platform-native metrics for iOS, Android, and Linux, including iOS MetricKit and Android Vitals.
  • OpenTelemetry compatibility — Send telemetry to Dartastic Observatory or any OpenTelemetry platform.

Dartastic Labs — OpenTelemetry Integrations

Instrument more of your application without writing everything yourself.

  • 650+ open-source integrations for Dart and Flutter libraries and services, including Dio, Shelf, Logger, Anthropic, AWS, Azure, and Stripe. Look for otel_* on pub.dev.

More Dartastic Tools

Dartastic Pub

A private Dart package registry for sharing packages and plugins with your team, partners, and customers.

Dartastic Symbolizer

Turn production errors into lines of source code through a web API, while keeping your source code artifacts private.

Professional Support and Training

Dartastic.io offers commercial support for the open-source dartastic_opentelemetry and dartastic_opentelemetry_api packages and the complete Dartastic product suite.

  • Professional support with available around-the-clock coverage and response times under four hours on qualifying plans.
  • OpenTelemetry training for teams instrumenting Dart, Flutter, mobile, and web applications.

Open Standards. No Mandatory Backend.

The Dartastic OpenTelemetry API and SDK are open source and standards-based. You can use them independently of Dartastic's commercial services and send telemetry to any compatible OpenTelemetry backend.

Dartastic's commercial products add native performance, advanced diagnostics, session replay, AI-assisted remediation, and managed observability services.

Explore Dartastic.io


OpenTelemetry instrumentation for package:firebase_analytics, built on the Dartastic OpenTelemetry SDK.

Every Firebase Analytics call becomes an OTel span — so analytics activity (add-to-cart, screen views, set user) appears alongside your HTTP/Firestore/GraphQL spans in the same trace.

import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:otel_firebase_analytics/otel_firebase_analytics.dart';

final analytics = FirebaseAnalytics.instance;

await analytics.tracedLogEvent(
  name: 'add_to_cart',
  parameters: {'item_id': 'SKU-123', 'value': 9.99, 'quantity': 2},
);

await analytics.tracedLogScreenView(
  screenName: 'CartPage',
  screenClass: 'CartPage',
);

await analytics.tracedSetUserId(id: user.uid);
await analytics.tracedSetUserProperty(name: 'subscription', value: 'premium');

If you call analytics from inside a span (typical in a Flutter checkout flow), the analytics span nests as a child:

HTTP POST /checkout            ←— OTel HTTP span
  ├─ firestore set orders/...  ←— Firestore span
  └─ analytics add_to_cart     ←— this package's span

Span shape

  • Span name: analytics <event_name> (e.g. analytics add_to_cart, analytics screen_view, analytics set_user_id)
  • Span kind: CLIENT
  • Attributes:
    • analytics.system = firebase_analytics
    • analytics.event.name = <event name>
    • analytics.parameters.<key> = <value> — flat fan-out of the parameters map. Values are coerced to String / int / double / bool (OTel attribute types); others are toString'd.
    • On tracedLogScreenView: analytics.screen.name, analytics.screen.class
    • On tracedSetUserId: enduser.id (OTel semconv)
    • On tracedSetUserProperty: analytics.user_property.name, analytics.user_property.value
  • Span status: Error only if the underlying analytics call throws (typically it doesn't — Firebase Analytics is fire-and-forget on most platforms).

Lower-level helper

await tracedAnalyticsCall<void>(
  eventName: 'add_to_cart',
  parameters: {'value': 9.99},
  invoke: () => myCustomAnalytics.send(...),
);

The extension methods are thin wrappers over this. Use it if you're routing through a custom analytics backend or want to test the span shape without a real FirebaseAnalytics.

Self-recursion guard

await runWithoutFirebaseAnalyticsInstrumentationAsync(() async {
  await analytics.tracedLogEvent(name: 'quiet');
});

Inside the helper's zone the traced* methods become transparent passthroughs.

Caveats

  • Firebase Analytics events have a hard limit of 25 parameters per event; this wrapper doesn't enforce that — the underlying Firebase call will if you exceed it. The span captures whatever you passed.
  • The wrapper calls OTel.tracerProvider().getTracer(...) on each invocation — OTel.initialize() must have run first.
  • Parameter values that aren't String/int/double/bool are toString'd into the attribute. OTel attributes don't accept nested maps/lists.

License

Apache 2.0 — see LICENSE.

Libraries

otel_firebase_analytics
OpenTelemetry instrumentation for package:firebase_analytics.