Skip to content

@autotracer/plugin-babel-react18

Babel plugin for automatic React component tracing (Next.js, CRA, Webpack).

Build-time plugin that injects useReactTracer() into eligible React components during Babel compilation so AutoTracer can attach readable component and hook labels without manual instrumentation.

Use @autotracer/plugin-babel-react18 for build-time injection only in local development or restricted internal builds, and initialize reactTracer() before your client entry renders only in those same builds.

In restricted internal browser builds, mount @autotracer/dashboard yourself when you want the standard browser control workflow. When the Dashboard is not mounted, use the lower-level runtime control surface on globalThis.autoTracer.

Theme customization stays on the runtime side through colors. File-based theme loading is available only on the Vite plugin path through ReactTracer Theme API.

Installation

bash
# Install runtime and plugin
pnpm add @autotracer/react18
pnpm add -D @autotracer/plugin-babel-react18

# Using npm
npm install @autotracer/react18
npm install --save-dev @autotracer/plugin-babel-react18

# Using yarn
yarn add @autotracer/react18
yarn add -D @autotracer/plugin-babel-react18

If this internal browser app uses the Dashboard as its normal control surface, add it separately:

bash
pnpm add -D @autotracer/dashboard

Usage

Add the package to your Babel config:

javascript
// babel.config.js or .babelrc
{
  "plugins": [
    [
      "@autotracer/plugin-babel-react18",
      {
        "mode": "opt-out"
      }
    ]
  ]
}

Initialize the runtime separately before your client entry renders:

typescript
async function bootstrap(): Promise<void> {
  const { reactTracer, isReactTracerInitialized } = await import(
    "@autotracer/react18"
  );

  if (!isReactTracerInitialized()) {
    reactTracer({
      enabled: false,
    });
  }
}

void bootstrap();

Use the framework guide that matches your entry path when you need full bootstrap examples:

Package API

This package is consumed as a Babel plugin entry in your Babel configuration. It is not a runtime initializer.

javascript
plugins: [["@autotracer/plugin-babel-react18", options]];

Supported Option Surface

What This Package Changes

  • Injects useReactTracer() into eligible React function components
  • Labels values returned from supported hooks so trace output keeps source-level names
  • Applies mode, include, exclude, and pragma rules before instrumentation
  • Restricts instrumentation to client modules with "use client" when serverComponents is enabled
  • Seeds the initial runtime outputMode once per page load when outputMode is configured

Pragmas

Use line comments to control component-level injection.

  • // @trace enables one eligible component.
  • // @trace-disable disables one eligible component.
  • include and exclude decide the eligible set before pragma signals are applied.

For exact placement rules, precedence, and examples, see the canonical Babel pragma reference.

Released under the MIT License.