Sintaxis
newrelic.measure(name: string, options?: Object<{ customAttributes?: Object, start?: number|PerformanceMark, end?: number|PerformanceMark }>)Informa un evento BrowserPerformance del navegador.
Requisitos
Agente Browser Pro o Pro+SPA (v1.291 o superior)
Si está instalando el agente del browser a través de npm y creando un agente personalizado con funciones seleccionadas, debe habilitar la función
generic_eventsal crear la instanciaAgent. En el arreglofeatures, agregue lo siguiente:import { GenericEvents } from '@newrelic/browser-agent/features/generic_events';const options = {info: { ... },loader_config: { ... },init: { ... },features: [GenericEvents]}Para obtener más información, consulte la documentación de instalación del navegador npm.
Descripción
Esta API de llamada envía un eventoBrowserPerformance del navegador con su nombre definido por el usuario y atributo personalizado. Esto es útil para crear manualmente un evento como alternativa o junto con el seguimiento automático de marcas y medidas.
Parámetros
Parámetro | Descripción |
|---|---|
cadena | Requerido. Nombre o categoría de la tarea. Reportado como el atributo Evite el uso de palabras NRQL reservadas cuando nombre el atributo o valor. |
Objeto JSON | Opcional. Un objeto empleado para proporcionar configuración para el evento capturado. Todos los atributos del objeto son opcionales. Si no se define Evite el uso de palabras NRQL reservadas en el atributo personalizado. |
Valores de retorno
Este método devuelve un objeto JSON con detalles de medición. start es la hora de inicio. end es el fin del tiempo. duration es la longitud de la medida desde el inicio hasta el final. customAttributes son atributos personalizados pasados a la API de llamada de medida. El atributo personalizado devuelto no se fusiona con el atributo personalizado definido por el usuario, pero se fusiona al crear el evento BrowserPerformance.
Ejemplos
Ejemplo mínimo
const myTask = newrelic.measure('checkout')/** myTask **/{ start: 0, // page origin time was used since start was not supplied end: 1234, // performance.now() was used since end was not supplied duration: 1234, // end - start customAttributes: { } // no custom attributes were supplied}/** the browser agent buffers and later harvests the newly created BrowserPerformance event **/Uso de argumentos numéricos para la hora de inicio y/o finalización
const myTask = newrelic.measure('checkout', { start: 1234, end: 5678})/** myTask **/{ start: 1234, // options.start time was used directly end: 5678, // options.end time was used directly duration: 4444, // end - start customAttributes: { } // no custom attributes were supplied}/** the browser agent buffers and later harvests the newly created BrowserPerformance event **/Uso de argumentos de PerformanceMark
const startMark = performance.mark('my-start-mark') // startTime = 1234// laterconst endMark = performance.mark('my-end-mark') // startTime = 5678const myTask = newrelic.measure('checkout', { start: startMark, end: endMark})/** myTask **/{ start: 1234, // options.start.startTime was used since it was a BrowserPerformance entry end: 5678, // options.end.startTime was used since it was a BrowserPerformance entry duration: 4444, // end - start customAttributes: { } // no custom attributes were supplied}/** the browser agent buffers and later harvests the newly created BrowserPerformance event **/Tipos de argumentos mixtos
const startMark = performance.mark('my-start-mark') // startTime = 1234const myTask = newrelic.measure('checkout', { start: startMark, end: 5678})/** myTask **/{ start: 1234, // options.start.startTime was used since it was a BrowserPerformance entry end: 5678, // options.end time was used directly duration: 4444, // end - start customAttributes: { } // no custom attributes were supplied}/** the browser agent buffers and later harvests the newly created BrowserPerformance event **/Usando atributos personalizados
const myTask = newrelic.measure('checkout', { start: 1234, end: 5678, customAttributes: { foo: 'bar' }})/** myTask **/{ start: 1234, // options.start time was used directly end: 5678, // options.end time was used directly duration: 4444, // end - start customAttributes: { foo: 'bar' }}/** the browser agent buffers and later harvests the newly created BrowserPerformance event **/