Back to Firebase Js Sdk

PerformanceTrace interface

docs-devsite/performance.performancetrace.md

12.12.16.5 KB
Original Source

Project: /docs/reference/js/_project.yaml Book: /docs/reference/_book.yaml page_type: reference

{% comment %} DO NOT EDIT THIS FILE! This is generated by the JS SDK team, and any local changes will be overwritten. Changes should be made in the source code at https://github.com/firebase/firebase-js-sdk {% endcomment %}

PerformanceTrace interface

The interface representing a Trace<!-- -->.

<b>Signature:</b>

typescript
export interface PerformanceTrace 

Methods

MethodDescription
getAttribute(attr)Retrieves the value which a custom attribute is set to.
getAttributes()Returns a map of all custom attributes of a trace instance.
getMetric(metricName)Returns the value of the custom metric by that name. If a custom metric with that name does not exist will return zero.
incrementMetric(metricName, num)Adds to the value of a custom metric. If a custom metric with the provided name does not exist, it creates one with that name and the value equal to the given number. The value will be floored down to an integer.
putAttribute(attr, value)Set a custom attribute of a trace to a certain value.
putMetric(metricName, num)Sets the value of the specified custom metric to the given number regardless of whether a metric with that name already exists on the trace instance or not. The value will be floored down to an integer.
record(startTime, duration, options)Records a trace from given parameters. This provides a direct way to use trace without a need to start/stop. This is useful for use cases in which the trace cannot directly be used (e.g. if the duration was captured before the Performance SDK was loaded).
removeAttribute(attr)Removes the specified custom attribute from a trace instance.
start()Starts the timing for the trace instance.
stop()Stops the timing of the trace instance and logs the data of the instance.

PerformanceTrace.getAttribute()

Retrieves the value which a custom attribute is set to.

<b>Signature:</b>

typescript
getAttribute(attr: string): string | undefined;

Parameters

ParameterTypeDescription
attrstringName of the custom attribute.

<b>Returns:</b>

string | undefined

PerformanceTrace.getAttributes()

Returns a map of all custom attributes of a trace instance.

<b>Signature:</b>

typescript
getAttributes(): {
        [key: string]: string;
    };

<b>Returns:</b>

{ [key: string]: string; }

PerformanceTrace.getMetric()

Returns the value of the custom metric by that name. If a custom metric with that name does not exist will return zero.

<b>Signature:</b>

typescript
getMetric(metricName: string): number;

Parameters

ParameterTypeDescription
metricNamestringName of the custom metric.

<b>Returns:</b>

number

PerformanceTrace.incrementMetric()

Adds to the value of a custom metric. If a custom metric with the provided name does not exist, it creates one with that name and the value equal to the given number. The value will be floored down to an integer.

<b>Signature:</b>

typescript
incrementMetric(metricName: string, num?: number): void;

Parameters

ParameterTypeDescription
metricNamestringThe name of the custom metric.
numnumberThe number to be added to the value of the custom metric. If not provided, it uses a default value of one.

<b>Returns:</b>

void

PerformanceTrace.putAttribute()

Set a custom attribute of a trace to a certain value.

<b>Signature:</b>

typescript
putAttribute(attr: string, value: string): void;

Parameters

ParameterTypeDescription
attrstringName of the custom attribute.
valuestringValue of the custom attribute.

<b>Returns:</b>

void

PerformanceTrace.putMetric()

Sets the value of the specified custom metric to the given number regardless of whether a metric with that name already exists on the trace instance or not. The value will be floored down to an integer.

<b>Signature:</b>

typescript
putMetric(metricName: string, num: number): void;

Parameters

ParameterTypeDescription
metricNamestringName of the custom metric.
numnumberValue to of the custom metric.

<b>Returns:</b>

void

PerformanceTrace.record()

Records a trace from given parameters. This provides a direct way to use trace without a need to start/stop. This is useful for use cases in which the trace cannot directly be used (e.g. if the duration was captured before the Performance SDK was loaded).

<b>Signature:</b>

typescript
record(startTime: number, duration: number, options?: {
        metrics?: {
            [key: string]: number;
        };
        attributes?: {
            [key: string]: string;
        };
    }): void;

Parameters

ParameterTypeDescription
startTimenumbertrace start time since epoch in millisec.
durationnumberThe duration of the trace in millisec.
options{ metrics?: { [key: string]: number; }; attributes?: { [key: string]: string; }; }An object which can optionally hold maps of custom metrics and custom attributes.

<b>Returns:</b>

void

PerformanceTrace.removeAttribute()

Removes the specified custom attribute from a trace instance.

<b>Signature:</b>

typescript
removeAttribute(attr: string): void;

Parameters

ParameterTypeDescription
attrstringName of the custom attribute.

<b>Returns:</b>

void

PerformanceTrace.start()

Starts the timing for the trace instance.

<b>Signature:</b>

typescript
start(): void;

<b>Returns:</b>

void

PerformanceTrace.stop()

Stops the timing of the trace instance and logs the data of the instance.

<b>Signature:</b>

typescript
stop(): void;

<b>Returns:</b>

void