|
| 1 | +/** |
| 2 | + * Public types snapshot from the Firebase JS SDK (@firebase/performance). |
| 3 | + * |
| 4 | + * Source: firebase-js-sdk `node_modules/@firebase/performance/dist/src/index.d.ts` |
| 5 | + * and `node_modules/@firebase/performance/dist/src/public_types.d.ts` |
| 6 | + * Modality: modular (tree-shakeable) API only |
| 7 | + * |
| 8 | + * This file is the reference snapshot used to detect API drift between the |
| 9 | + * firebase-js-sdk and the @react-native-firebase/perf modular API. |
| 10 | + * |
| 11 | + * When a new version of the firebase-js-sdk ships with type changes, update |
| 12 | + * this file with the new public modular types from @firebase/performance. |
| 13 | + */ |
| 14 | + |
| 15 | +import { FirebaseApp } from '@firebase/app'; |
| 16 | + |
| 17 | +/** |
| 18 | + * Defines configuration options for the Performance Monitoring SDK. |
| 19 | + * |
| 20 | + * @public |
| 21 | + */ |
| 22 | +export interface PerformanceSettings { |
| 23 | + /** Whether to collect custom events. */ |
| 24 | + dataCollectionEnabled?: boolean; |
| 25 | + /** Whether to collect out of the box events. */ |
| 26 | + instrumentationEnabled?: boolean; |
| 27 | +} |
| 28 | + |
| 29 | +/** |
| 30 | + * The Firebase Performance Monitoring service interface. |
| 31 | + * |
| 32 | + * @public |
| 33 | + */ |
| 34 | +export interface FirebasePerformance { |
| 35 | + /** |
| 36 | + * The {@link @firebase/app#FirebaseApp} this `FirebasePerformance` instance is associated with. |
| 37 | + */ |
| 38 | + app: FirebaseApp; |
| 39 | + /** |
| 40 | + * Controls the logging of automatic traces and HTTP/S network monitoring. |
| 41 | + */ |
| 42 | + instrumentationEnabled: boolean; |
| 43 | + /** |
| 44 | + * Controls the logging of custom traces. |
| 45 | + */ |
| 46 | + dataCollectionEnabled: boolean; |
| 47 | +} |
| 48 | + |
| 49 | +/** |
| 50 | + * The interface representing a `Trace`. |
| 51 | + * |
| 52 | + * @public |
| 53 | + */ |
| 54 | +export interface PerformanceTrace { |
| 55 | + /** |
| 56 | + * Starts the timing for the trace instance. |
| 57 | + */ |
| 58 | + start(): void; |
| 59 | + /** |
| 60 | + * Stops the timing of the trace instance and logs the data of the instance. |
| 61 | + */ |
| 62 | + stop(): void; |
| 63 | + /** |
| 64 | + * Records a trace from given parameters. This provides a direct way to use trace without a need to |
| 65 | + * start/stop. This is useful for use cases in which the trace cannot directly be used |
| 66 | + * (e.g. if the duration was captured before the Performance SDK was loaded). |
| 67 | + * |
| 68 | + * @param startTime - trace start time since epoch in millisec. |
| 69 | + * @param duration - The duration of the trace in millisec. |
| 70 | + * @param options - An object which can optionally hold maps of custom metrics and |
| 71 | + * custom attributes. |
| 72 | + */ |
| 73 | + record( |
| 74 | + startTime: number, |
| 75 | + duration: number, |
| 76 | + options?: { |
| 77 | + metrics?: { |
| 78 | + [key: string]: number; |
| 79 | + }; |
| 80 | + attributes?: { |
| 81 | + [key: string]: string; |
| 82 | + }; |
| 83 | + }, |
| 84 | + ): void; |
| 85 | + /** |
| 86 | + * Adds to the value of a custom metric. If a custom metric with the provided name does not |
| 87 | + * exist, it creates one with that name and the value equal to the given number. The value will be floored down to an |
| 88 | + * integer. |
| 89 | + * |
| 90 | + * @param metricName - The name of the custom metric. |
| 91 | + * @param num - The number to be added to the value of the custom metric. If not provided, it |
| 92 | + * uses a default value of one. |
| 93 | + */ |
| 94 | + incrementMetric(metricName: string, num?: number): void; |
| 95 | + /** |
| 96 | + * Sets the value of the specified custom metric to the given number regardless of whether |
| 97 | + * a metric with that name already exists on the trace instance or not. The value will be floored down to an |
| 98 | + * integer. |
| 99 | + * |
| 100 | + * @param metricName - Name of the custom metric. |
| 101 | + * @param num - Value to of the custom metric. |
| 102 | + */ |
| 103 | + putMetric(metricName: string, num: number): void; |
| 104 | + /** |
| 105 | + * Returns the value of the custom metric by that name. If a custom metric with that name does |
| 106 | + * not exist will return zero. |
| 107 | + * |
| 108 | + * @param metricName - Name of the custom metric. |
| 109 | + */ |
| 110 | + getMetric(metricName: string): number; |
| 111 | + /** |
| 112 | + * Set a custom attribute of a trace to a certain value. |
| 113 | + * |
| 114 | + * @param attr - Name of the custom attribute. |
| 115 | + * @param value - Value of the custom attribute. |
| 116 | + */ |
| 117 | + putAttribute(attr: string, value: string): void; |
| 118 | + /** |
| 119 | + * Retrieves the value which a custom attribute is set to. |
| 120 | + * |
| 121 | + * @param attr - Name of the custom attribute. |
| 122 | + */ |
| 123 | + getAttribute(attr: string): string | undefined; |
| 124 | + /** |
| 125 | + * Removes the specified custom attribute from a trace instance. |
| 126 | + * |
| 127 | + * @param attr - Name of the custom attribute. |
| 128 | + */ |
| 129 | + removeAttribute(attr: string): void; |
| 130 | + /** |
| 131 | + * Returns a map of all custom attributes of a trace instance. |
| 132 | + */ |
| 133 | + getAttributes(): { |
| 134 | + [key: string]: string; |
| 135 | + }; |
| 136 | +} |
| 137 | + |
| 138 | +/** |
| 139 | + * Returns a {@link FirebasePerformance} instance for the given app. |
| 140 | + * @param app - The {@link @firebase/app#FirebaseApp} to use. |
| 141 | + * @public |
| 142 | + */ |
| 143 | +export declare function getPerformance(app?: FirebaseApp): FirebasePerformance; |
| 144 | + |
| 145 | +/** |
| 146 | + * Returns a {@link FirebasePerformance} instance for the given app. Can only be called once. |
| 147 | + * @param app - The {@link @firebase/app#FirebaseApp} to use. |
| 148 | + * @param settings - Optional settings for the {@link FirebasePerformance} instance. |
| 149 | + * @public |
| 150 | + */ |
| 151 | +export declare function initializePerformance( |
| 152 | + app: FirebaseApp, |
| 153 | + settings?: PerformanceSettings, |
| 154 | +): FirebasePerformance; |
| 155 | + |
| 156 | +/** |
| 157 | + * Returns a new `PerformanceTrace` instance. |
| 158 | + * @param performance - The {@link FirebasePerformance} instance to use. |
| 159 | + * @param name - The name of the trace. |
| 160 | + * @public |
| 161 | + */ |
| 162 | +export declare function trace(performance: FirebasePerformance, name: string): PerformanceTrace; |
0 commit comments