# registerLogRocketInstrumentation

Initializes LogRocket instrumentation with Workleap's default settings.

# Reference

registerLogRocketInstrumentation(appId, options?: { rootHostname, privateFieldNames, privateQueryParameterNames })

# Parameters

  • appId: The LogRocket application id.
  • options: An optional object literal of predefined options.

# Returns

Nothing

# Predefined options

The registerLogRocketInstrumentation(appId, options?: {}) function also accepts a few predefined options 👇

# rootHostname

  • Type: string
  • Default: workleap.com

A root hostname to track sessions across subdomains.

import { registerLogRocketInstrumentation } from "@workleap/logrocket";

registerLogRocketInstrumentation("my-app-id", {
    rootHostname: "an-host.com"
});

# privateFieldNames

  • Type: string[]
  • Default: undefined

Names of additional fields to exclude from session replays. These fields will be removed from network requests, responses using a fuzzy-matching algorithm.

import { registerLogRocketInstrumentation } from "@workleap/logrocket";

registerLogRocketInstrumentation("my-app-id", {
    privateFieldNames: ["a-custom-field"]
});

To view the default private fields, have a look at the registerLogRocketInstrumentation.ts file on GitHub.

# privateQueryParameterNames

  • Type: string[]
  • Default: undefined

Names of additional fields to exclude from session replays. These fields will be removed from query parameters using a fuzzy-matching algorithm.

import { registerLogRocketInstrumentation } from "@workleap/logrocket";

registerLogRocketInstrumentation("my-app-id", {
    privateQueryParameterNames: ["a-custom-param"]
});

To view the default private query parameters, have a look at the registerLogRocketInstrumentation.ts file on GitHub.

# verbose

  • Type: boolean
  • Default: false

If no loggers are configured, verbose mode will automatically send logs to the console. In some cases, enabling verbose mode also produces additional debug information.

import { registerLogRocketInstrumentation } from "@workleap/logrocket";

registerLogRocketInstrumentation("my-app-id", {
    verbose: true
});

# loggers

  • Type: RootLogger[]
  • Default: undefined

The logger instances that will output messages.

import { registerLogRocketInstrumentation, LogRocketLogger } from "@workleap/logrocket";
import { BrowserConsoleLogger, LogLevel } from "@workleap/logging";

registerLogRocketInstrumentation("my-app-id", {
    loggers: [new BrowserConsoleLogger(), new LogRocketLogger({ logLevel: LogLevel.information })]
});

# Configuration transformers

The predefined options are useful to quickly customize the default configuration of the LogRocket SDK, but only covers a subset of the options. If you need full control over the configuration, you can provide configuration transformer functions through the transformers option of the registerLogRocketInstrumentation function. Remember, no locked in ❤️✌️.

To view the default configuration of registerLogRocketInstrumentation, have a look at the registerLogRocketInstrumentation.ts file on GitHub.

# transformers

  • Type: ((options: LogRocketSdkOptions, context: LogRocketSdkOptionsTransformer) => LogRocketSdkOptions)[]
  • Default: []
transformer(options: LogRocketSdkOptions, context: LogRocketSdkOptionsTransformer) => LogRocketSdkOptions;
import { registerLogRocketInstrumentation, type LogRocketSdkOptionsTransformer } from "@workleap/logrocket";

const disableConsoleLogging: LogRocketSdkOptionsTransformer = config => {
    config.console = ...(config.console || {});
    config.console.isEnabled = false;

    return config;
};

registerLogRocketInstrumentation("my-app-id", {
    transformers: [disableConsoleLogging]
});

# Execution context

Generic transformers can use the context argument to gather additional information about their execution context:

transformer.js
import type { LogRocketSdkOptionsTransformer } from "@workleap/logrocket";

const disableConsoleLogging: LogRocketSdkOptionsTransformer = (config, context) => {
    if (!context.verbose) {
        config.console = ...(config.console || {});
        config.shouldDebugLog = false;

        context.logger.debug("Disabling LogRocket SDK debug logs.");
    }

    return config;
}
  • verbose: boolean
  • logger: Logger