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

fast-tracker-node

v1.1.1-beta.2

Published

天眼nodejs探针

Downloads

127

Readme

nodejs探针

目前支持插件:express、redis、http、axios、logging、custom(自定义)。

npmjs地址: https://www.npmjs.com/package/fast-tracker-node

探针配置

参照json:

  {
    "Enable": true,                              // 是否启用
    "Logging": {
      "Level": "ERROR",                          // logging上报的日志级别, 从低到高:debug、info、log、warn、error
      "FilePath": "logs/fast-tracker/"           // 日志存储路径
    },
    "Debug": true,                               // debug模式          
    "TenantCode": "test",                        // 租户 
    "UserCode": "test",                          // 用户 
    "ServiceName": "service1",                   // 服务名称
    "ServiceVersion": "1.0.0",                   // 服务版本
    "ServiceVersionReader": [{                   // 动态获取服务版本方式
      "ReaderType": "Environment",
      "ReaderKey": "service_version"
      },
    ],
    "TenantCode": "",                            // 租户编码
    "TenantCodeReader": [{                       // 动态获取租户编码方式
        "ReaderType": "Environment",
        "ReaderKey": "tenant_code"
      },
    ],
    "UserCode": "",                              // 用户编码
    "UserCodeReader": [{                         // 动态获取用户编码方式
        "ReaderType": "Environment",
        "ReaderKey": "user_code"
      },
    ],
    "CarrierHeader": {                           // 跨进程header key值定
      "TrackerName": "fast-tracker",             // 后端服务链路间穿透头名称
      "TraceIdName": "x-fast-trace-id"           // 前后端链路穿透TraceId头名称                                    
    },
    "CollectLayer": {
      "HTTP": {                                  // HTTP组件采集
        "Enable": true,                          // 是否采集
        "CollectBodyContent": false,             // 是否采集QueryString
        "CollectQueryString": false              // 是否采集BodyContent
      },
      "DB": {
        "Enable": true,
        "CollectParams": false
      },
      "MQ": {
        "Enable": true
      },
      "Cache": {
        "Enable": true
      },
      "RPC": {
        "Enable": true
      },
      "Log": {
        "Enable": true,
        "Level": "ERROR"
      },
      "Local": {
        "Enable": true
      },
      "Function": {
        "Enable": false,
        "ExcludeGetAndSetMethod": true,
        "ScanPackages": ["cn.com.test.fast.tracker.test","cn.com.test.fast.tracker.test1"],
        "IgnoreClasses": ["cn.com.test.fast.tracker.test.ClassA","cn.com.test.fast.tracker.test1.ClassB"],
        "IgnoreMethods": {
          "com.mypaas.fast.aaa.ClassA": ["getInfo(int.class)", "getInfo(int.class, java.util.Map)"],
          "com.mypaas.fast.aaa.ClassB": ["getList(com.mypaas.fast.aaa.Params.class)"]
        }
      }
    },
    "Filter": {
      "IgnoreEntryPaths": [],
      "IgnoreEntryFiles": [
        ".ico",
        ".js",
        ".css",
        ".woff",
        ".woff2",
        ".svg",
        ".ttf",
        ".jpg",
        ".jpeg",
        ".png",
        ".gif",
        ".bmp"
      ]
    },
    "Transport": {                // 上报配置
      "Report": {                 // 上报地址:直接上报
        "Endpoint": "[https://fast.logstore.mypaas.com/report/8ClfUEJRPC73sN99h39XYRTtYq7B3LeN027a9zrVsQDQbxlCEp9YTDfwQ2bqEvq9](https://fast.logstore.mypaas.com/report/8ClfUEJRPC73sN99h39XYRTtYq7B3LeN027a9zrVsQDQbxlCEp9YTDfwQ2bqEvq9%C2%A0)",
        "Timeout": 3,
        "Format": "json|msgpack"
      },
      "Forward": {                // 上报地址:转发
        "Endpoint": "udp://127.0.0.1:5140",
        "Timeout": 3,
        "Format": "json|msgpack"
      },
      "Local": {                  // 上报地址:本地文件
        "FilePath": "logs/fast-tracker/trace/log-.log",
        "FileSize": 10,
        "RetainedFileCount": 10
      },
      "QueueSize": 1572864,                   // 日志缓存队列大小
      "BatchSize": 1000,                      // 批次上报日志条数
      "Interval": 1000,                       // 上报间隔
      "MaxReportByte": 4096                   // 最大上报字节大小,默认4096,范围[1-32768]整数
    }
  }

探针api

1、custom 自定义组件

  // 创建实例
  const instance = FastTracker.beginSapn()
  // 【非必填】, 默认值为 CustomEvent
  instance.setComponent('ComponentName') 

  // 添加tag, 可设置多个
  instance.addTag('tagKey', 'tagValue')
  instance.addTag('tagKey_1', 'tagValue_1')

  // 添加日志
  instance.addLog("log内容")
  instance.addLog('log内容1')
  // 结束
  instance.endSpan()

2、配置信息

  // 运行时设置租户code
  FastTracker.setTenantCode('fast')
  // 运行时设置用户code
  FastTracker.setUserCode('fast')
    
  // 读取租户code
  FastTracker.getTenantCode()
  // 读取用户code
  FastTracker.getUserCode()
  // 读取所有配置信息
  FastTracker.getConfig()

3、logging 日志组件

  // 依次: debug、info、log、warn、error,受配置项 Logging.Level 影响
  FastTracker.debug('debug内容')
  FastTracker.info('info内容')
  FastTracker.log('log内容')
  FastTracker.warn('warn内容')
  FastTracker.error('error内容')

使用

1、项目引入fast-tracker-node,以npm为例

   npm i fast-tracker-node --save-dev

2、修改配置(探针启动后的配置修改,目前仅提供上述api方式)

  • 自定义配置文件, docker
  // FastTracker.json 文件内容参照上方配置json格式
  docker run --env FastTracker.ConfigPath=/etc/FastTracker.json image:tag
  • 环境变量配置, docker
  docker run -d -p 8092:3000 --name ${SERVICE1_NAME} --env-file .env ${IMG_SERVICE1}
  • .env内容如下, 以FastTracker_为前缀,多层级连接同样以_
  FastTracker_Enable=true
  FastTracker_Debug=true
  FastTracker_ServiceName=Service1
  FastTracker_TenantCode=service1

3、在node项目的启动文件中导入,如果在后续的开发中需要使用FastTracker对象,建议单独模块导出,以供后续的调用

  import FastTracker from 'fast-tracker-node'

  // 使用start方法启动探针
  FastTracker.start()

4、版本发布

  • major:代表主版本号,通常在需要提交不能向下兼容的情况下对该版本号进行升级

  • minor:代表次版本号,通常在新增功能时才对该版本号进行升级

  • patch:代表修复版本号,升级该版本号通常代表修复一些bug,但没有新增功能或者存在不向下兼容的功能

  • prerelease:带有该版本号的包通常表示在测试阶段,尚未稳定,通常不建议用户安装。 发布beta测试版本

  npm version prerelease --preid=beta
  npm publish --tag=beta