1 | /**
|
2 | * @license
|
3 | * Copyright 2017 Google LLC
|
4 | *
|
5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
6 | * you may not use this file except in compliance with the License.
|
7 | * You may obtain a copy of the License at
|
8 | *
|
9 | * http://www.apache.org/licenses/LICENSE-2.0
|
10 | *
|
11 | * Unless required by applicable law or agreed to in writing, software
|
12 | * distributed under the License is distributed on an "AS IS" BASIS,
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 | * See the License for the specific language governing permissions and
|
15 | * limitations under the License.
|
16 | */
|
17 |
|
18 | export interface FirebasePerformance {
|
19 | /**
|
20 | * Creates an uninitialized instance of trace and returns it.
|
21 | *
|
22 | * @param traceName The name of trace instance.
|
23 | * @return The trace instance.
|
24 | */
|
25 | trace(traceName: string): PerformanceTrace;
|
26 |
|
27 | /**
|
28 | * Controls the logging of automatic traces and HTTP/S network monitoring.
|
29 | */
|
30 | instrumentationEnabled: boolean;
|
31 | /**
|
32 | * Controls the logging of custom traces.
|
33 | */
|
34 | dataCollectionEnabled: boolean;
|
35 | }
|
36 |
|
37 | export interface PerformanceTrace {
|
38 | /**
|
39 | * Starts the timing for the trace instance.
|
40 | */
|
41 | start(): void;
|
42 | /**
|
43 | * Stops the timing of the trace instance and logs the data of the instance.
|
44 | */
|
45 | stop(): void;
|
46 | /**
|
47 | * Records a trace from given parameters. This provides a direct way to use trace without a need to
|
48 | * start/stop. This is useful for use cases in which the trace cannot directly be used
|
49 | * (e.g. if the duration was captured before the Performance SDK was loaded).
|
50 | *
|
51 | * @param startTime trace start time since epoch in millisec.
|
52 | * @param duration The duration of the trace in millisec.
|
53 | * @param options An object which can optionally hold maps of custom metrics and
|
54 | * custom attributes.
|
55 | */
|
56 | record(
|
57 | startTime: number,
|
58 | duration: number,
|
59 | options?: {
|
60 | metrics?: { [key: string]: number };
|
61 | attributes?: { [key: string]: string };
|
62 | }
|
63 | ): void;
|
64 | /**
|
65 | * Adds to the value of a custom metric. If a custom metric with the provided name does not
|
66 | * exist, it creates one with that name and the value equal to the given number. The value will be floored down to an
|
67 | * integer.
|
68 | *
|
69 | * @param metricName The name of the custom metric.
|
70 | * @param num The number to be added to the value of the custom metric. If not provided, it
|
71 | * uses a default value of one.
|
72 | */
|
73 | incrementMetric(metricName: string, num?: number): void;
|
74 | /**
|
75 | * Sets the value of the specified custom metric to the given number regardless of whether
|
76 | * a metric with that name already exists on the trace instance or not. The value will be floored down to an
|
77 | * integer.
|
78 | *
|
79 | * @param metricName Name of the custom metric.
|
80 | * @param num Value to of the custom metric.
|
81 | */
|
82 | putMetric(metricName: string, num: number): void;
|
83 | /**
|
84 | * Returns the value of the custom metric by that name. If a custom metric with that name does
|
85 | * not exist will return zero.
|
86 | *
|
87 | * @param metricName Name of the custom metric.
|
88 | */
|
89 | getMetric(metricName: string): number;
|
90 | /**
|
91 | * Set a custom attribute of a trace to a certain value.
|
92 | *
|
93 | * @param attr Name of the custom attribute.
|
94 | * @param value Value of the custom attribute.
|
95 | */
|
96 | putAttribute(attr: string, value: string): void;
|
97 | /**
|
98 | * Retrieves the value which a custom attribute is set to.
|
99 | *
|
100 | * @param attr Name of the custom attribute.
|
101 | */
|
102 | getAttribute(attr: string): string | undefined;
|
103 | /**
|
104 | * Removes the specified custom attribute from a trace instance.
|
105 | *
|
106 | * @param attr Name of the custom attribute.
|
107 | */
|
108 | removeAttribute(attr: string): void;
|
109 | /**
|
110 | * Returns a map of all custom attributes of a trace instance.
|
111 | */
|
112 | getAttributes(): { [key: string]: string };
|
113 | }
|
114 |
|
115 | declare module '@firebase/component' {
|
116 | interface NameServiceMapping {
|
117 | 'performance-compat': FirebasePerformance;
|
118 | }
|
119 | }
|