Sintaxe
newrelic.measure(name: string, options?: Object<{ customAttributes?: Object, start?: number|PerformanceMark, end?: number|PerformanceMark }>)Relata um evento BrowserPerformance do navegador.
Requisitos
Agente Browser Pro ou Pro+SPA (v1.291 ou superior)
Se você estiver instalando o agente do browser via npm e criando um agente personalizado com recursos selecionados, você deve habilitar o recurso
generic_eventsao criar a instânciaAgent. No arrayfeatures, adicione o seguinte:import { GenericEvents } from '@newrelic/browser-agent/features/generic_events';const options = {info: { ... },loader_config: { ... },init: { ... },features: [GenericEvents]}Para obter mais informações, consulte a documentação de instalação do browser npm.
Descrição
Esta chamada de API envia um eventoBrowserPerformance do browser com seu nome definido pelo usuário e atributo personalizado. Isso é útil para criar manualmente um evento como alternativa ou junto com o rastreamento automático de marcas e medidas.
Parâmetro
Parâmetro | Descrição |
|---|---|
corda | Obrigatório. Nome ou categoria da tarefa. Relatado como o atributo Evite usar palavras NRQL reservadas ao nomear o atributo ou valor. |
Objeto JSON | Opcional. Um objeto usado para fornecer configuração para o evento capturado. Todos os atributos no objeto são opcionais. Se Evite usar palavras NRQL reservadas em atributo personalizado. |
Valores de retorno
Este método retorna um objeto JSON com detalhes de medição. start é a hora de início. end é o fim dos tempos. duration é o comprimento da medição do início ao fim. customAttributes são atributos personalizados passados para a medida chamada de API. Os atributo personalizado retornados não são mesclados com o atributo personalizado definido pelo usuário, mas são mesclados na criação do evento BrowserPerformance.
Exemplos
Exemplo 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 **/Usando argumentos numéricos para hora de início e/ou término
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 **/Usando argumentos 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 mistos
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 atributo personalizado
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 **/