@grafana/faro-web-sdk (英语)
Faro是一个SDK,它可以仪器前端JavaScript应用程序来收集遥测并转发到 格拉法纳合金 (应用代理接收器集成启用).
格拉法纳 合金可以发送此数据到任何一种 罗基 或者说 临时。 。 。 .
开始吧
见 快速启动网络应用程序。 。 。 .
或者,您可以使用库的CDN版本. 见 使用 cdn 库 详细介绍如何这样做.
仪器
- 控制台 - 捕获已登录到的信件
console全球对象。 仅warn, (中文(简体) ),info财务报告和审定财务报表error默认水平. - 错误 - 抓取未处理的顶级例外
- 网络活性 -- -- 获取网络活性指标
- 会话 - 发送会话启动事件
- 视图 - 发送已更改的视图事件
- 导航 - 捕捉软导航并报告其URL变化和持续时间
- 挫折感 - 为每次愤怒点击、死亡点击和错误点击发送事件,但不为普通点击发送事件
默认启用导航仪表 。 要禁用,请通过 trackNavigation: false 改为
getWebInstrumentations() 提供自定义仪器时,或提供自定义 instrumentations 没有阵列
NavigationInstrumentation。 。 。 .
元数据
- 浏览器 - 抓取浏览器元数据:名称,版本等
- os - 从用户代理中获取 OS 名称和版本解析
- 页面 - 抓取当前 URL
- 视图 - 网络 SDK 执行 a
default视图元值a
运输
- 控制台 - 日志事件到全局
console - 获取 - 从 HTTP 发送事件到后端
示例
基本设置, 将自动报告错误和网络动态 :
import { initializeFaro } from '@grafana/faro-web-sdk';
const faro = initializeFaro({
url: 'https://agent.myapp/collect',
apiKey: 'secret',
app: {
name: 'frontend',
version: '1.0.0',
},
});
// send a log message
faro.api.pushLog(['hello world']);
// will be captured
throw new Error('oh no');
// push error manually
faro.api.pushError(new Error('oh no'));
通过OTel追踪和浏览器控制台抓取:
import { ConsoleInstrumentation, getWebInstrumentations, initializeFaro } from '@grafana/faro-web-sdk';
import { TracingInstrumentation } from '@grafana/faro-web-tracing';
const faro = initializeFaro({
url: 'https://agent.myapp/collect',
apiKey: 'secret',
instrumentations: [...getWebInstrumentations({ captureConsole: true }), new TracingInstrumentation()],
app: {
name: 'frontend',
version: '1.0.0',
},
});
// start a span
faro.api
.getOTEL()
?.trace.getTracer('frontend')
.startActiveSpan('hello world', (span) => {
// send a log message
faro.api.pushLog(['hello world']);
span.end();
});
// will be captured
throw new Error('oh no');