@whatap-npm/browser-nuxt
v0.1.0
Published
WhaTap Browser Agent Nuxt plugin: component, app and SSR errors, route templates, page navigation timing
Readme
@whatap-npm/browser-nuxt
WhaTap 브라우저 에이전트의 Nuxt 3 플러그인입니다. Vue 플러그인의 기능(컴포넌트 스택, 에러 단계, 라우트 템플릿, 막힌 이동, Pinia)에 Nuxt 의 앱 에러, 서버 렌더 에러, 청크 실패, 페이지 데이터까지 기다린 이동 시간을 더합니다.
설치
npm install @whatap-npm/browser-nuxtpeer 의존성은 nuxt 3.8 이상, vue 3.3 이상입니다. 이 패키지는 nuxt 를 import 하지 않습니다. 보내는 에러와 이벤트에는 metaFramework: nuxt 가 붙습니다.
설정
코어 스크립트를 nuxt.config.ts 의 head 에 넣고, 클라이언트 플러그인 하나를 만듭니다.
// nuxt.config.ts
export default defineNuxtConfig({
app: {
head: {
script: [
{ innerHTML: "window.WhatapBrowserAgent = { config: { projectAccessKey: 'your-key', pcode: 12345, sampleRate: 100 } };" },
{ src: 'https://repo.whatap-browser-agent.io/rum/prod/v2/whatap-browser-agent.js' },
],
},
},
});// plugins/whatap.client.ts
import { whatapNuxt } from '@whatap-npm/browser-nuxt';
export default defineNuxtPlugin((nuxtApp) => {
whatapNuxt(nuxtApp, { trackComponents: ['ProductGrid'] });
});수집되는 것
| 무엇 | 어디서 받나 | 레코드 |
| --- | --- | --- |
| 컴포넌트 에러 | 루트 컴포넌트가 부르는 vue:error 훅 | Vue 플러그인과 같다. source 는 에러 단계(setup function, render function 등) |
| 앱 에러 | app:error 훅. 플러그인 초기화 에러, showError, 치명 에러 | source: app:error, handled: false, statusCode, fatal |
| 서버 렌더 에러 | 첫 화면의 payload.error | source: ssr, origin: server, statusCode |
| 청크 실패 | app:chunkError 훅 | source: chunk, errorKind: chunk_load |
| 라우트 템플릿 | vue-router | /products/:id |
| 막힌 이동 | vue-router afterEach | router.navigation-failure aborted|cancelled |
| 이동 시간 | 첫 beforeEach 부터 page:finish 까지 | router.navigation <템플릿>, kind: page, routeMs(가드와 라우트 청크), pageMs(페이지 Suspense, useAsyncData) |
| Pinia | @pinia/nuxt 가 있으면 자동 | 액션 에러. piniaTiming: true 면 액션 시간 |
| 컴포넌트 렌더 시간 | trackComponents | component.render <이름> |
| useAsyncData, useFetch 시간 | 자동(asyncDataTiming: false 로 끔) | nuxt.asyncdata <키>, 10초 동안 키와 화면별로 calls, failures, totalMs, avgMs, maxMs, slowCalls. 서버가 이미 가져와 payload 로 채운 호출은 세지 않는다 |
| 하이드레이션 불일치 자리 | hydrationMismatchDetails 와 빌드 플래그 | component.hydration-mismatch <컴포넌트>, mismatch(node, text, children, class, style, attribute), element, componentTrace(안쪽부터 다섯) |
Nuxt 는 app.config.errorHandler 를 하이드레이션 동안만 자기 것으로 두고 지우므로 이 플러그인은 감싸지 않고 훅을 씁니다. vue:error 로 보고한 에러가 app:error 로 다시 오거나 showError 가 감싼 cause 로 와도 한 건만 남깁니다.
같은 페이지 컴포넌트를 다시 쓰는 이동(쿼리만 바뀜)은 page:finish 가 오지 않아, 다음 이동이 시작될 때 routeMs 까지만 보냅니다.
옵션
| 옵션 | 기본 | 뜻 |
| --- | --- | --- |
| attachProps | false | 에러 컴포넌트의 원시값 props 를 싣는다 |
| attachRouteParams | false | 라우트 파라미터를 route.<키> 로 싣는다 |
| routeNameSource | template | name 이면 라우트 name 을 이름으로 쓴다 |
| reportDuplicatedNavigation | false | 같은 위치로 다시 간 이동도 보낸다 |
| pageTiming | true | 이동 시간을 보낸다 |
| pinia | true | $pinia 가 있으면 액션 에러를 보고한다 |
| piniaTiming | false | 액션 시간도 보낸다 |
| trackComponents | false | 렌더 시간을 잴 컴포넌트 이름 목록 |
| asyncDataTiming | true | useAsyncData, useFetch 키별 요청 시간을 보낸다 |
| hydrationMismatchDetails | false | 하이드레이션 불일치 자리를 보낸다. 배포 빌드는 nuxt.config 의 vite.define 에 __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: true 를 둔 앱만 Vue 가 알려 준다. app.config.warnHandler 를 감싼다 |
useAsyncData, useFetch 시간은 Nuxt 가 진행 중인 요청을 두는 내부 객체(nuxtApp._asyncDataPromises)를 감싸 잽니다. 키가 곧 집계 단위라 `product-${id}` 처럼 값이 들어간 키는 값마다 따로 셉니다. 같은 종류의 요청은 같은 키를 쓰는 편이 보기 좋습니다. useFetch 에 키를 주지 않으면 Nuxt 가 URL 과 옵션으로 만든 해시가 키가 됩니다.
수집되지 않는 것
- 하이드레이션 불일치는 Vue 가
console.error로 알리고 에러를 던지지 않아 코어가 콘솔 에러로만 받습니다. - 서버에서만 난 에러(첫 화면이 에러 페이지가 아닌 경우)는 브라우저에 오지 않습니다.
