firebase_functions.alerts.performance_fn module

Cloud functions to handle Firebase Performance Monitoring events from Firebase Alerts.

Classes

PerformanceEvent

class firebase_functions.alerts.performance_fn.PerformanceEvent(specversion: str, id: str, source: str, type: str, time: datetime, data: T, subject: str | None, alert_type: str, app_id: str)

Bases: CloudEvent[FirebaseAlertData[T]]

A custom CloudEvent for billing Firebase Alerts.

alert_type: str

The type of the alerts that got triggered.

app_id: str

The Firebase App ID that's associated with the alert.

ThresholdAlertPayload

class firebase_functions.alerts.performance_fn.ThresholdAlertPayload(event_name: str, event_type: str, metric_type: str, num_samples: int, threshold_value: float, threshold_unit: str, violation_value: float | int, violation_unit: str, investigate_uri: str, condition_percentile: float | int | None = None, app_version: str | None = None)

Bases: object

The internal payload object for a performance threshold alert. Payload is wrapped inside a FirebaseAlertData object.

app_version: str | None = None

The app version this alert was triggered for, can be omitted if the alert is for a network request (because the alert was checked against data from all versions of app) or a web app (where the app is versionless).

condition_percentile: float | int | None = None

The percentile of the alert condition, can be 0 if percentile is not applicable to the alert condition and omitted; range: [1, 100].

event_name: str

Name of the trace or network request this alert is for (e.g. my_custom_trace, firebase.com/api/123).

event_type: str

The resource type this alert is for (i.e. trace, network request, screen rendering, etc.).

investigate_uri: str

The link to Firebase Console to investigate more into this alert.

metric_type: str

The metric type this alert is for (i.e. success rate, response time, duration, etc.).

num_samples: int

The number of events checked for this alert condition.

threshold_unit: str

The unit for the alert threshold (e.g. "percent", "seconds").

threshold_value: float

The threshold value of the alert condition without units (e.g. "75", "2.1").

violation_unit: str

The unit for the violation value (e.g. "percent", "seconds").

violation_value: float | int

The value that violated the alert condition (e.g. "76.5", "3").

Functions

on_threshold_alert_published

firebase_functions.alerts.performance_fn.on_threshold_alert_published(**kwargs) Callable[[Callable[[PerformanceEvent[ThresholdAlertPayload]], None]], Callable[[PerformanceEvent[ThresholdAlertPayload]], None]]

Event handler which runs every time a threshold alert is received.

Example:

import firebase_functions.alerts.performance_fn as performance_fn

@performance_fn.on_threshold_alert_published()
def example(alert: performance_fn.PerformanceThresholdAlertEvent) -> None:
    print(alert)
Parameters:

**kwargs (as firebase_functions.options.PerformanceOptions) -- Options.

Return type:

typing.Callable [ [ firebase_functions.alerts.performance_fn.PerformanceThresholdAlertEvent ], None ] A function that takes a PerformanceThresholdAlertEvent and returns None.

Constants

OnThresholdAlertPublishedCallable

firebase_functions.alerts.performance_fn.OnThresholdAlertPublishedCallable

The type of the callable for 'on_threshold_alert_published' functions.

alias of Callable[[PerformanceEvent[ThresholdAlertPayload]], None]

PerformanceThresholdAlertEvent

firebase_functions.alerts.performance_fn.PerformanceThresholdAlertEvent

The type of the event for 'on_threshold_alert_published' functions.

alias of PerformanceEvent[ThresholdAlertPayload]