> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apitally.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Configuration

> Configure the Apitally SDK for JavaScript.

## Configuration

You can configure Apitally via a configuration object.

<CodeGroup>
  ```javascript Hono {7-12} theme={null}
  import { Hono } from "hono";
  import { useApitally } from "apitally/hono";

  const app = new Hono();

  useApitally(app, {
    clientId: "your-client-id",
    env: "dev",
    requestLogging: {
      enabled: true,
      // other parameters ...
    },
  });
  ```

  ```javascript NestJS {9-14} theme={null}
  import { NestFactory } from "@nestjs/core";
  import { useApitally } from "apitally/nestjs";
  import { AppModule } from "./app.module";

  async function bootstrap() {
    const app = await NestFactory.create(AppModule);

    await useApitally(app, {
      clientId: "your-client-id",
      env: "dev",
      requestLogging: {
        enabled: true,
        // other parameters ...
      },
    });
  }
  ```

  ```javascript Express {7-12} theme={null}
  import express from "express";
  import { useApitally } from "apitally/express";

  const app = express();

  useApitally(app, {
    clientId: "your-client-id",
    env: "dev",
    requestLogging: {
      enabled: true,
      // other parameters ...
    },
  });
  ```

  ```javascript Fastify {7-12} theme={null}
  import Fastify from "fastify";
  import { apitallyPlugin } from "apitally/fastify";

  const fastify = Fastify({ logger: true });

  await fastify.register(apitallyPlugin, {
    clientId: "your-client-id",
    env: "dev",
    requestLogging: {
      enabled: true,
      // other parameters ...
    },
  });
  ```
</CodeGroup>

See the [setup guides](/setup-guides#javascript) for more examples.

## Parameters

The following configuration parameters are available. Only `clientId` and `env` are required.

| Parameter        | Description                                                                                                       | Type     | Default |
| :--------------- | :---------------------------------------------------------------------------------------------------------------- | :------- | :------ |
| `clientId`       | Client ID for your application. Find it on the *Setup instructions* page for your app.                            | `string` |         |
| `env`            | Name of the environment, e.g. `prod` or `dev`. The environment will be automatically created if it doesn't exist. | `string` | `dev`   |
| `requestLogging` | Configuration options for request logging. See table below.                                                       | `object` |         |
| `appVersion`     | The current version of your application, e.g. `1.0.0`.                                                            | `string` |         |
| `logger`         | A custom logger instance. If not provided, a default logger is created automatically.                             | `object` |         |

The `requestLogging` parameter is an object with the following properties:

| Parameter                  | Description                                                                                                                                                                       | Type       | Default |
| :------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------- | :------ |
| `enabled`                  | Whether request logging is enabled.                                                                                                                                               | `boolean`  | `false` |
| `logQueryParams`           | Whether to include query parameters in the logs. If disabled, these will be stripped from the request URLs logged.                                                                | `boolean`  | `true`  |
| `logRequestHeaders`        | Whether to include request headers in the logs. Default masking for common sensitive headers (e.g. `Authorization`) applies.                                                      | `boolean`  | `false` |
| `logRequestBody`           | Whether to include the request body in the logs. Only JSON and text are supported, up to 50 KB.                                                                                   | `boolean`  | `false` |
| `logResponseHeaders`       | Whether to include response headers in the logs.                                                                                                                                  | `boolean`  | `true`  |
| `logResponseBody`          | Whether to include the response body in the logs. Only JSON and text are supported, up to 50 KB.                                                                                  | `boolean`  | `false` |
| `logException`             | Whether to include exception details in the logs.                                                                                                                                 | `boolean`  | `true`  |
| `captureLogs`              | Whether to capture application logs emitted during request handling.                                                                                                              | `boolean`  | `false` |
| `captureTraces`            | Whether to enable tracing with OpenTelemetry.                                                                                                                                     | `boolean`  | `false` |
| `maskQueryParams`          | Array of regular expressions for matching query parameters to mask. These are in addition to the default masking patterns.                                                        | `RegExp[]` | `[]`    |
| `maskHeaders`              | Array of regular expressions for matching headers to mask. These are in addition to the default masking patterns.                                                                 | `RegExp[]` | `[]`    |
| `maskBodyFields`           | Array of regular expressions for matching request/response body fields to mask. These are in addition to the default masking patterns.                                            | `RegExp[]` | `[]`    |
| `maskRequestBodyCallback`  | Callback function for masking the request body. Takes one parameter `request` and returns the request body as `Buffer` or `null`.                                                 | `Function` | -       |
| `maskResponseBodyCallback` | Callback function for masking the response body. Takes two parameters `request` and `response` and returns the response body as `Buffer` or `null`.                               | `Function` | -       |
| `excludePaths`             | Array of regular expressions for matching paths to exclude from logging.                                                                                                          | `RegExp[]` | `[]`    |
| `excludeCallback`          | Callback function for excluding requests from logging. Takes two parameters `request` and `response` and returns `true`, if the request should be excluded, or `false` otherwise. | `Function` | -       |
