npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cloudcare/dataflux-rum-miniapp-logs

v1.0.4

Published

DataFlux RUM 小程序 端数据指标监控

Downloads

8

Readme

DataFlux Miniapp Logs SDK

简介

小程序主动发送不同等级的日志数据(对应的source:browser_log 指标类型日志数据)到DataFlux

功能简介

  • 自定义日志数据采集,通过 sdk 接入客户端应用中,针对不同场景采集不同日志数据。
  • 可以自动收集应用端的错误信息(包括网络错误,console 错误,以及 js 错误)上报到 DataFlux。
  • 自定义错误等级(debug,critical,error,info,warn),自定义 Logger 对象,以及自定义 log 字段
  • 可以自动收集RUM相关数据,关联 RUM 业务场景

开始使用

前置条件

datakit 通过datakit日志采集 API 发送日志数据到 DataFlux 平台

引入 SDK 可通过NPM,CDN的方式引入 SDK 到应用中,初始化后,可以存放到全局变量中,方便其他页面引用

支持的浏览器 支持微信,百度,支付宝,头条大部分小程序端

npm 引入

//#ifndef H5 || APP-PLUS || APP-NVUE || APP-PLUS-NVUE
const { datafluxRum } = require('@cloudcare/dataflux-rum-miniapp-logs')
// 初始化 Rum
datafluxRum.init({
	datakitOrigin: '<DATAKIT ORIGIN>'
  service: 'minapp',
})
//#endif

CDN 下载文件本地方式引入(下载地址)

//#ifndef H5 || APP-PLUS || APP-NVUE || APP-PLUS-NVUE
const { datafluxRum } = require('@cloudcare/dataflux-rum-miniapp-logs')
// 初始化 Rum
datafluxRum.init({
	datakitOrigin: '<DATAKIT ORIGIN>'
  service: 'miniapp',
})
//#endif

配置

初始化参数

| 参数 | 类型 | 是否必须 | 默认值 | 描述 | | --------------------- | ------- | -------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | datakitOrigin | String | 是 | | datakit 数据上报 Origin 注释: 协议(包括://),域名(或IP地址)[和端口号] 例如:https://www.datakit.com, http://100.20.34.3:8088 | | site | String | 是(公网dataway上报方式 必填) | | (SDK 版本要求 >= 1.0.4 )公网 DataWay 对应站点的域名 注释: 协议(包括://),域名(或IP地址)[和端口号] 例如:https://www.datakit.com, http://100.20.34.3:8088 | | clientToken | String | 是 (公网dataway 必填) | | (SDK 版本要求 >= 1.0.4 )公网 DataWay 上报所需的客户端 token,在观测云控制台创建应用时生成 | | service | String | 否 | browser | 日志 service 名称 | | env | String | 否 | | web 应用当前环境, 如 prod:线上环境;gray:灰度环境;pre:预发布环境 common:日常环境;local:本地环境; | | version | String | 否 | | web 应用的版本号 | | sampleRate | Number | 否 | 100 | 指标数据收集百分比: 100表示全收集,0表示不收集 | | forwardErrorsToLogs | Boolean | 否 | true | 设置为false 表示停止采集 console.error、 js、以及网络错误上报到 DataFlux 日志数据中 |

使用

SDK 在应用中初始化后,通过暴露的 SDK API 可以自定义配置日志数据

logger.debug | info | warn | error | critical (message: string, messageContext = Context)

NPM

import { datafluxLogs } from '@cloudcare/dataflux-rum-miniapp-logs'

datafluxLogs.logger.info('Button clicked', { name: 'buttonName', id: 123 })

返回数据结构

{
    "service": "miniapp",
    "session": {
        "id": "c549c2b8-4955-4f74-b7f8-a5f42fc6e79b"
    },
    "type": "logger",
    "_dd": {
        "sdk_name": "miniapp LOG SDK",
        "sdk_version": "1.0.0",
        "env": "",
        "version": ""
    },
    "device": {
        "platform_version": "8.0.5",
        "model": "iPhone 6/7/8 Plus",
        "app_framework_version":"2.23.3",
        "os": "OS",
        "os_version": "10.14.6",
        "os_version_major": "10",
        "screen_size": "414*736",
        "network_type": "3g",
        "divice": "devtools"
    },
    "user": {},
    "date": 1621321916756,
    "view": {
        "referrer": "",
        "name": "pages/index/index",
        "id": "5dce64f4-8d6d-411a-af84-c41653ccd94a"
    },
    "application": {
        "id": "app_idxxxxxx"
    },
    "message": "XHR error get http://testing-ft2x-api.cloudcare.cn/api/v1/workspace/xxx",
    "status": "error",
    "error": {
        "source": "network",
        "stack": "Failed to load"
    },
    "resource": {
        "method": "get",
        "status": 0,
        "status_group": 0,
        "url": "http://testing-ft2x-api.cloudcare.cn/api/v1/workspace/xxx",
        "url_host": "testing-ft2x-api.cloudcare.cn",
        "url_path": "/api/v1/workspace/xxx",
        "url_path_group": "/api/?/workspace/xxx"
    }
}

Status 参数

初始化 SDk 后,可以使用提供log API,定义不同类型的状态

log (message: string, messageContext: Context, status? = 'debug' | 'info' | 'warning' | 'error' | 'critical')

使用

import { datafluxLogs } from '@cloudcare/dataflux-rum-miniapp-logs'

datafluxLogs.logger.log(<MESSAGE>,<JSON_ATTRIBUTES>,<STATUS>);

参数说明

| 参数 | 描述 | | ------------------- | ------------------------------------------------------------------- | | <MESSAGE> | Dataflux 日志中的 message 字段 | | <JSON_ATTRIBUTES> | 描述 message 的额外数据,是一个 json 对象 | | <STATUS> | 日志的等级,可选值:debug, info, warning, error, critical |