> ## 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.

<CodeGroup>
  ```javascript Express {8-12} theme={null}
  import "apitally/express/register";

  import express from "express";
  import { useApitally } from "apitally";

  const app = express();

  useApitally(app, {
    writeToken: "your-write-token",
    env: "dev",
    // other parameters ...
  });
  ```

  ```javascript Fastify {6-10} theme={null}
  import Fastify from "fastify";
  import { useApitally } from "apitally";

  const app = Fastify();

  useApitally(app, {
    writeToken: "your-write-token",
    env: "dev",
    // other parameters ...
  });
  ```

  ```javascript Hono {6-10} theme={null}
  import { Hono } from "hono";
  import { useApitally } from "apitally";

  const app = new Hono();

  useApitally(app, {
    writeToken: "your-write-token",
    env: "dev",
    // other parameters ...
  });
  ```
</CodeGroup>

## Parameters

### General

#### `writeToken`

Write token for your application in the format `apt_...`. Find it on the *Setup instructions* page for your app. Required unless the `APITALLY_WRITE_TOKEN` environment variable is set.

#### `env`

Name of the environment, for example `prod` or `dev`. Can also be set via the `APITALLY_ENV` environment variable. The environment is created automatically if it does not exist. Defaults to `dev`.

#### `appVersion`

The current version of your application, for example `1.0.0`.

#### `disabled`

Boolean. Whether to disable the SDK. Truthy `APITALLY_DISABLED` or `OTEL_SDK_DISABLED` environment variables also disable it. Defaults to `false`.

### Data capture

#### `captureLogs`

Boolean. Whether to capture application logs from `console` and supported logging integrations. Only logs associated with captured requests are exported. Defaults to `true`.

#### `captureRequestHeaders`

Boolean. Whether to capture request headers. Default masking applies to common sensitive headers such as `Authorization`. Defaults to `false`.

#### `captureRequestBody`

Boolean. Whether to capture the request body. Only JSON and text bodies up to 50 KB are supported. Defaults to `false`.

#### `captureResponseHeaders`

Boolean. Whether to capture response headers. Defaults to `true`.

#### `captureResponseBody`

Boolean. Whether to capture the response body. Only JSON and text bodies up to 50 KB are supported. Defaults to `false`.

### Masking

#### `maskQueryParams`

Array of regular expressions for matching query parameters to mask. These are applied in addition to the default masking patterns. Defaults to `[]`.

```javascript theme={null}
maskQueryParams: [/^api_key$/i, /^token$/i],
```

#### `maskHeaders`

Array of regular expressions for matching headers to mask. These are applied in addition to the default masking patterns. Defaults to `[]`.

```javascript theme={null}
maskHeaders: [/^X-Api-Key$/i, /^X-Internal-/i],
```

#### `maskBodyFields`

Array of regular expressions for matching request and response body fields to mask. These are applied in addition to the default masking patterns. Defaults to `[]`.

```javascript theme={null}
maskBodyFields: [/^credit_card$/i, /^account_id$/i],
```

#### `maskRequestBody`

Callback for masking the request body. It receives the body as a [`Buffer`](https://nodejs.org/api/buffer.html#class-buffer) and the request [`ReadableSpan`](https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_sdk-trace-base.ReadableSpan.html), and returns the masked body as a [`Buffer`](https://nodejs.org/api/buffer.html#class-buffer) or `null`.

See example [here](/sdk-reference/javascript/v1/masking#body-masking-callbacks).

#### `maskResponseBody`

Callback for masking the response body. It receives the body as a [`Buffer`](https://nodejs.org/api/buffer.html#class-buffer) and the request [`ReadableSpan`](https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_sdk-trace-base.ReadableSpan.html), and returns the masked body as a [`Buffer`](https://nodejs.org/api/buffer.html#class-buffer) or `null`.

See example [here](/sdk-reference/javascript/v1/masking#body-masking-callbacks).

#### `maskLogRecord`

Callback for masking application logs. It receives an OpenTelemetry [`ReadWriteLogRecord`](https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_sdk-logs.ReadWriteLogRecord.html) and returns the same record after masking, or `null` or `undefined` to drop it.

See example [here](/sdk-reference/javascript/v1/masking#log-record-masking-callback).

### Sampling

#### `sampleRate`

Fraction of requests to capture as request logs and traces, from `0.0` to `1.0`. Metrics are not sampled. Defaults to `1.0`.

#### `sampleOnRequest`

Callback for adjusting sampling when a request starts. It receives the request [`ReadableSpan`](https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_sdk-trace-base.ReadableSpan.html) and returns a probability, a boolean, or `undefined` to use `sampleRate`.

See example [here](/sdk-reference/javascript/v1/sampling#custom-sampling).

#### `sampleOnResponse`

Callback for adjusting sampling when a response is ready. It receives the ended request [`ReadableSpan`](https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_sdk-trace-base.ReadableSpan.html) and returns a probability, a boolean, or `undefined` to preserve the existing decision.

See example [here](/sdk-reference/javascript/v1/sampling#custom-sampling).

#### `excludePaths`

Array of regular expressions for matching paths to exclude from request logs and traces. Excluded requests are still included in metrics. Defaults to `[]`.

```javascript theme={null}
excludePaths: [/^\/admin\/$/, /\/internal\//],
```
