構文
newrelic.measure(name: string, options?: Object<{ customAttributes?: Object, start?: number|PerformanceMark, end?: number|PerformanceMark }>)ブラウザの BrowserPerformance イベントを報告します。
要件
Browser Pro または Pro+SPA エージェント (v1.291 以上)
npm 経由で Browser エージェントをインストールし、選択した機能を使用してカスタム エージェントを構築する場合は、
Agentインスタンスの作成時にgeneric_events機能を有効にする必要があります。features配列に以下を追加します。import { GenericEvents } from '@newrelic/browser-agent/features/generic_events';const options = {info: { ... },loader_config: { ... },init: { ... },features: [GenericEvents]}詳細については、 npm ブラウザのインストールに関するドキュメントを参照してください。
説明
このAPIコールは、ユーザーが定義した名前とカスタム アトリビュートを含むブラウザBrowserPerformanceイベントを送信します。 これは、代替手段として、または自動マークおよび測定追跡と並行してイベントを手動で作成する場合に便利です。
パラメーター
パラメータ | 説明 |
|---|---|
ストリング | 必須。タスクの名前またはカテゴリ。 予約したNRQLの単語 を属性や値の名前に使うのは避けましょう。 |
JSONオブジェクト | オプション。キャプチャしたイベントの設定を提供するために使用されるオブジェクト。 オブジェクト内のすべての属性はオプションです。
カスタムアトリビュートでは、 NRQLの予約語を使用しないでください。 |
戻り値
このメソッドは、測定の詳細を含む JSON オブジェクトを返します。 startは開始時刻です。endは終了時刻です。duration開始から終了までの測定の長さです。customAttributesは、メジャーAPIコールに渡されるカスタム アトリビュートです。 返されたカスタムアトリビュート はユーザー定義のカスタムアトリビュートとマージされませんが、 BrowserPerformanceイベントの作成時にマージされます。
例
最小限の例
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 **/開始時刻および/または終了時刻に数値引数を使用する
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 **/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 **/混合引数タイプ
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 **/カスタム属性の使用
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 **/