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.
Parameters
metricName: string
The name of the custom metric.
Optional num: number
The number to be added to the value of the custom metric. If not provided, it
uses a default value of one.
Returns void
putAttribute
putAttribute
(
attr
:
string
,
value
:
string): void
Set a custom attribute of a trace to a certain value.
Parameters
attr: string
Name of the custom attribute.
value: string
Value of the custom attribute.
Returns void
putMetric
putMetric
(
metricName
:
string
,
num
:
number): void
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.
Parameters
metricName: string
Name of the custom metric.
num: number
Value to of the custom metric.
Returns void
record
record
(
startTime
:
number
,
duration
:
number
,
options
?
:
{
attributes
?: {};
metrics
?: {} }): void
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).
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2022-07-27 UTC."],[],[],null,["# Trace | JavaScript SDK\n\n- [firebase](/docs/reference/js/v8/firebase).\n- [performance](/docs/reference/js/v8/firebase.performance).\n- Trace\n==================================================================================================================\n\nIndex\n-----\n\n### Methods\n\n- [getAttribute](/docs/reference/js/v8/firebase.performance.Trace#getattribute)\n- [getAttributes](/docs/reference/js/v8/firebase.performance.Trace#getattributes)\n- [getMetric](/docs/reference/js/v8/firebase.performance.Trace#getmetric)\n- [incrementMetric](/docs/reference/js/v8/firebase.performance.Trace#incrementmetric)\n- [putAttribute](/docs/reference/js/v8/firebase.performance.Trace#putattribute)\n- [putMetric](/docs/reference/js/v8/firebase.performance.Trace#putmetric)\n- [record](/docs/reference/js/v8/firebase.performance.Trace#record)\n- [removeAttribute](/docs/reference/js/v8/firebase.performance.Trace#removeattribute)\n- [start](/docs/reference/js/v8/firebase.performance.Trace#start)\n- [stop](/docs/reference/js/v8/firebase.performance.Trace#stop)\n\nMethods\n-------\n\n### getAttribute\n\n- getAttribute ( attr : string ) : string \\| undefined\n- Retrieves the value that the custom attribute is set to.\n\n #### Parameters\n\n -\n\n ##### attr: string\n\n Name of the custom attribute.\n\n #### Returns string \\| undefined\n\n### getAttributes\n\n- getAttributes ( ) : {}\n- Returns a map of all custom attributes of a [`trace`](/docs/reference/js/v8/firebase.performance.Trace)\n instance.\n\n #### Returns {}\n\n -\n\n ##### \\[key: string\\]: string\n\n### getMetric\n\n- getMetric ( metricName : string ) : number\n- Returns the value of the custom metric by that name. If a custom metric with that name does\n not exist returns zero.\n\n #### Parameters\n\n -\n\n ##### metricName: string\n\n Name of the custom metric.\n\n #### Returns number\n\n### incrementMetric\n\n- incrementMetric ( metricName : string , num ? : number ) : void\n- Adds to the value of a custom metric. If a custom metric with the provided name does not\n exist, it creates one with that name and the value equal to the given number.\n\n #### Parameters\n\n -\n\n ##### metricName: string\n\n The name of the custom metric.\n -\n\n ##### Optional num: number\n\n The number to be added to the value of the custom metric. If not provided, it\n uses a default value of one.\n\n #### Returns void\n\n### putAttribute\n\n- putAttribute ( attr : string , value : string ) : void\n- Set a custom attribute of a [`trace`](/docs/reference/js/v8/firebase.performance.Trace) to a certain value.\n\n #### Parameters\n\n -\n\n ##### attr: string\n\n Name of the custom attribute.\n -\n\n ##### value: string\n\n Value of the custom attribute.\n\n #### Returns void\n\n### putMetric\n\n- putMetric ( metricName : string , num : number ) : void\n- Sets the value of the specified custom metric to the given number regardless of whether\n a metric with that name already exists on the [`trace`](/docs/reference/js/v8/firebase.performance.Trace)\n instance or not.\n\n #### Parameters\n\n -\n\n ##### metricName: string\n\n Name of the custom metric.\n -\n\n ##### num: number\n\n Value to of the custom metric.\n\n #### Returns void\n\n### record\n\n- record ( startTime : number , duration : number , options ? : { attributes ?: {} ; metrics ?: {} } ) : void\n- Records a [`trace`](/docs/reference/js/v8/firebase.performance.Trace) from given parameters. This provides a\n direct way to use [`trace`](/docs/reference/js/v8/firebase.performance.Trace) without a need to start/stop.\n This is useful for use cases in which the [`trace`](/docs/reference/js/v8/firebase.performance.Trace) cannot\n directly be used (e.g. if the duration was captured before the Performance SDK was loaded).\n\n #### Parameters\n\n -\n\n ##### startTime: number\n\n Trace start time since epoch in millisec.\n -\n\n ##### duration: number\n\n The duraction of the trace in millisec.\n -\n\n ##### Optional options: { attributes?: {}; metrics?: {} }\n\n An object which can optionally hold maps of custom metrics and\n custom attributes.\n -\n\n ##### Optional attributes?: {}\n\n -\n\n ##### \\[key: string\\]: string\n\n -\n\n ##### Optional metrics?: {}\n\n -\n\n ##### \\[key: string\\]: number\n\n #### Returns void\n\n### removeAttribute\n\n- removeAttribute ( attr : string ) : void\n- Removes the specified custom attribute from a [`trace`](/docs/reference/js/v8/firebase.performance.Trace)\n instance.\n\n #### Parameters\n\n -\n\n ##### attr: string\n\n Name of the custom attribute.\n\n #### Returns void\n\n### start\n\n- start ( ) : void\n- Starts the timing for the [`trace`](/docs/reference/js/v8/firebase.performance.Trace) instance.\n\n #### Returns void\n\n### stop\n\n- stop ( ) : void\n- Stops the timing of the [`trace`](/docs/reference/js/v8/firebase.performance.Trace) instance and logs the\n data of the instance.\n\n #### Returns void"]]
Retrieves the value that the custom attribute is set to.