@appland/appmap-agent-js

中文文档
14.2.0发布于 2023/08/16MITES Module近 30 天下载 1885

appmap-agent-js is a JavaScript recording agent for the AppMap framework.

此软件包已被标记为弃用

This package has been deprecated. Please use appmap-node instead

原始使用文档
文档目录13 节
  1. Introduction
  2. Installation and setup
  3. Requirements
  4. Installation
  5. Configuration
  6. Recording AppMaps
  7. Recording test cases:
  8. Recording Node.js processes with remote recording:
  9. Recording Node.js processes from start to finish
  10. Viewing AppMaps
  11. Frequently used parameters
  12. Example
  13. Next steps

Getting started with appmap-agent-js

appmap-agent-js is a JavaScript recording agent for the AppMap framework.

Introduction

appmap-agent-js records AppMaps from Node.js processes when they run. There are several strategies for recording AppMaps:

  1. Record test cases. At the moment, we support jest and mocha.
  2. Record Node.js processes using start/stop controls via http calls to web endpoints. These are implemented by the AppMap agent to let users control the recording remotely.
  3. Record Node.js processes from start to finish.

Installation and setup

Requirements

Supported platforms:

  • Mainstream os: Linux distros, macOS, and Windows.
  • Node.js: any up-to-date major versions that is not in end-of-life -- ie: 16, 18, and 19.
  • Express.js: 4.
  • git is highly recommended.
  • mocha >= 8.0.0 is required for recording AppMaps from test cases (earlier versions do not support required root hooks).
  • jest >= 25, older version might also work but have not been tested.

Please open a new GitHub ticket if your application does not satisfy the criteria or if you experience any problems with the agent.

Installation

Run this command in your Node.js project folder (where package.json is located):

npx @appland/appmap install

You will be guided through a series of steps for installing and configuring the agent.

Alternatively, the agent can be directly installed as a normal npm package:

npm install --save-dev @appland/appmap-agent-js

To use remote recording, and view and interact with recorded AppMaps, we recommend installing the AppMap extension for popular code editors:

Configuration

The agent will read configuration options from a file named appmap.yml. If this file does not exist a default one will be created. Note that the install command creates a suitable appmap.yml file by scanning the project directories. We recommend that you review any generated appmap.yml file and confirm your application name and a list of directories that will be recorded.

For projects with JavaScript source maps: add paths to sources to be recorded. For example:

name: MyApp
packages:
  - path: src/server/controllers
  - path: src/server/data
  - path: src/server/lib
  - path: src/server/models
  - path: src/server/routes

For projects without JavaScript source maps: include build folders. For example:

name: MyApp
packages:
  - path: dist/controllers
  - path: dist/data
  - path: dist/lib
  - path: dist/models
  - path: dist/routes

If you aren't sure which option to take, start with both source and build folders and optimize the appmap.yml file later.

Recording AppMaps

Once appmap.yml is configured for your project, you're ready to record AppMaps.

Recording test cases:

  1. Validate that the tests run prior to recording AppMaps.
  2. Prefix your test command with npx appmap-agent-js -- For example:
npx appmap-agent-js -- mocha 'test/**/*.ts'

npm run test does not work, only direct invocation of testing frameworks are currently supported 3. appmap-agent-js will run the tests. When the tests are complete, the AppMaps will be stored in the default output directory tmp/appmap/(mocha|jest).

Recording Node.js processes with remote recording:

  1. Prefix your node command with npx appmap-agent-js --recorder=remote --. For example:
npx appmap-agent-js --recorder=remote -- node app/main.js --param1 hello --param2=world
  1. appmap-agent-js will start the app and inject itself in its http stack. It will listen for remote recording requests on all http ports of the application.
  2. Start the remote recording:
  3. Interact with your application or service to exercise code included in appmap.yml
  4. Stop the recording and save the new AppMap to disk.

Recording Node.js processes from start to finish

  1. Prefix your node command with npx appmap-agent-js --recorder=process --. For example:
npx appmap-agent-js --recorder=process -- node app/main.js --arg1 val1 --arg2=val2
  1. When the node process exits, a single AppMap will be stored in tmp/appmap/process.

Viewing AppMaps

Recorded AppMap are saved as .appmap.json files in the project folders (default location: tmp/appmap).

Follow the documentation for your IDE to open the recorded .appmap.json files:

Frequently used parameters

The most frequently used appmap-agent-js parameters are:

  • --recorder=[mocha|jest|remote|process]: process recorder
    • default recorder is inferred from the starting command:
      • mocha if the the command contains mocha
      • jest if the command contains jest
      • process in all other cases
    • mocha and jest recorders record AppMaps from test cases automatically
    • remote recorder has to be started and stopped manually with http requests
    • process recorder records entire processes automatically, from start to finish
      • Warning: AppMaps recorded with the process recorder can be excessively large and noisy.
  • --command="_start command_": alternate method of specifying the app- or tests-starting command, wrapped in quotes
  • --log-level=[debug|info|warning|error]: defaults to info
  • --log-file=_file_: location of log file, defaults to stderr
  • --appmap-dir=_directory_: location of recorded AppMap files, default is tmp/appmap.

Example

npx appmap-agent-js --recorder=mocha --command='mocha "test/**/*.ts"' --log-level=error

Next steps

版本与发布记录

@appland/appmap-agent-js 共发布 171 个版本,首次发布于 2021/03/30;过去 12 个月发布了 0 个版本。

版本发布日期距今
14.2.0latest2023/08/163 年前
14.1.02023/08/143 年前
14.0.02023/08/053 年前
13.9.22023/08/053 年前
13.9.12023/07/293 年前
13.9.02023/05/163 年前

关于 @appland/appmap-agent-js 的常见问题

@appland/appmap-agent-js 是什么?

appmap-agent-js is a JavaScript recording agent for the AppMap framework.注意:该包已被作者标记为弃用——This package has been deprecated. Please use appmap-node instead

如何安装 @appland/appmap-agent-js?

在项目目录运行 npm install @appland/appmap-agent-js,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 appmap-agent-js,可以用 npx appmap-agent-js 直接运行。

@appland/appmap-agent-js 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/appland__appmap-agent-js 是否存在。

@appland/appmap-agent-js 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@appland/appmap-agent-js 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js 16.x.x || 17.x.x || 18.x.x || 19.x.x。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@appland/appmap-agent-js 可以商用吗?

@appland/appmap-agent-js 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@appland/appmap-agent-js 的下载量有多少?

根据 npm 官方下载统计,@appland/appmap-agent-js 在 2026/10/07 – 2026/11/05 这 30 天内被下载 1,885 次,日均约 63 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@appland/appmap-agent-js 还在维护吗?

最新版本 14.2.0 发布于 2023/08/16(3 年前);至今共发布 171 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/03/30。作者已将其标记为弃用,新项目建议寻找替代方案。