1.6.6 • Published 1 year ago

fusion-plugin-introspect v1.6.6

Weekly downloads
13
License
MIT
Repository
github
Last release
1 year ago

fusion-plugin-introspect

Collects runtime metadata to aid debugging


Table of contents


Usage

import App from 'fusion-core';
import introspect from 'fusion-plugin-introspect';

const store = {
  storeSync(data) {
    // Log to stdout and collect data via log-entries, papertrail or similar
    console.log(JSON.stringify(data));
  }
  async store(data, {myMetricsService}) {
    // This is called once the app finishes collecting data
    // We can obtain an arbitrary data storage service (`myMetricsService`) from the DI container
    myMetricsService.emit('node-version', data.meta.nodeVersion);
  }
}

export default () => {
  const app = new App('<h1>Hello world</h1>', v => v);
  app.register(
    introspect(app, {
      deps: {myMetricsService: SomeServiceToken},
      store: !__DEV__ ? store : undefined,
    })
  )
}

Data schema

The data that is passed to store and storeSync follows this schema:

{
  version: string,
  server: [{
    timestamp: number,
    dependencies: [{name: string, stack: string, dependencies: [string]}],
    enhanced: [{name: string}],
  }],
  browser: [{
    timestamp: number,
    dependencies: [{name: string, stack: string, dependencies: [string]}],
    enhanced: [{name: string}],
  }],
  runtime: {
    timestamp: number,
    pid: number,
    nodeVersion: string,
    npmVersion: string,
    yarnVersion: string,
    lockFileType: string,
    dependencies: {[string]: string},
    devDependencies: {[string]: string},
    varNames: [string],
    vars: {[string]: string},
  }
}
  • version - Data schema version
  • server.timestamp - When server-side DI graph data was collected. Note that this may differ from other timestamps
  • server.dependencies - A list of tokens and their respective creation stack traces and dependencies
  • server.enhanced - A list of token names that have been enhanced

  • browser.timestamp - When client-side DI graph data was collected. Note that this may differ from other timestamps

  • browser.dependencies - A list of tokens and their respective creation stack traces and dependencies
  • browser.enhanced - A list of token names that have been enhanced

  • runtime.timestamp - When DI graph data was collected. Note that this may differ from other timestamps

  • runtime.pid - The process ID
  • runtime.nodeVersion - Node version
  • runtime.npmVersion - NPM version
  • runtime.yarnVersion - Yarn version
  • runtime.lockFileType - Either npm, yarn or none
  • runtime.lockFile - The contents of the lock file
  • dependencies - The dependencies field in package.json
  • devDependencies - The devDependencies field in package.json
  • varNames - A list of all defined env var names (but not their values)
  • vars - A map of env vars, filtered by the env option

Flow types

export type IntrospectionSchema = {
  version: string,
  server: Array<Dependencies>,
  browser: Array<Dependencies>,
  runtime: Metadata,
};
export type Dependencies = {
  timestamp: number,
  dependencies: Array<Dependency>,
  enhanced: Array<{name: string}>,
};
export type Dependency = {
  name: string,
  stack: string,
  dependencies: Array<string>,
};
export type Metadata = {
  timestamp: number,
  pid: number,
  nodeVersion: string,
  npmVersion: string,
  yarnVersion: string,
  lockFileType: string,
  dependencies: {[string]: string},
  devDependencies: {[string]: string},
  varNames: Array<string>,
  vars: {[string]: string},
};

API

Registration API

introspect
import introspect from 'fusion-plugin-introspect';

app.register(introspect(app, {store, env}));
  • introspect: (app, {store, env}) => FusionPlugin<void, void> - creates a Fusion plugin
    • app: FusionApp - a Fusion app instance. Usually obtained from fusion-react or fusion-apollo.
    • store: {store, storeSync} - a storage mechanism. Defaults to fsStore
      • store: (data, deps) => Promise<void> - called when all runtime data is collected successfully
        • data: Object - An object that conforms to the introspection data schema
        • deps: Object - A map of dependencies. You can inject a service to consume the data.
      • storeSync: data => void - called at startup time just in case the app crashes before data collection completes. Must not contain asynchronous code. See also the "Using 'uncaughtException' correctly" section in the Node docs. Note that storeSync does not receive a deps argument because the DI graph may not be resolvable.
    • env: ?Array<string> - A list of env var names to be collected. Do not collect env vars that contain secrets or other sensitive data. Defaults to [].

Storage

fsStore
import {fsStore} from 'fusion-plugin-introspect';
  • fsStore: {store, storeSync} - A storage mechanism that saves data to .fusion/fusion-stats.json
    • store: data => Promise<void> - called when all runtime data is collected successfully. Saves data to a file
    • storeSync: (data) => void - called at startup time just in case the app crashes before data collection completes. Saves data to a file synchronously
1.6.6

1 year ago

1.6.4

1 year ago

1.6.5

1 year ago

1.6.3

1 year ago

1.6.2

1 year ago

1.6.1

1 year ago

1.6.0

1 year ago

1.5.12

2 years ago

1.5.11

2 years ago

1.5.10

2 years ago

1.5.9

2 years ago

1.5.8

2 years ago

1.5.7

2 years ago

1.5.6

2 years ago

1.5.5

2 years ago

1.5.4

2 years ago

1.5.3

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.2.10

5 years ago

0.2.9

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.1-0

5 years ago

0.1.1

6 years ago

0.1.0

6 years ago