open-index/open-npm huggingface dataset:
npm package: @meistrari/llm-observability
Description: Structured observability for LLM requests — OpenTelemetry metrics + Pino logging.
Latest version: 1.0.7

# llm-observability

Structured observability for LLM requests — OpenTelemetry metrics + Pino logging.

## Install

```bash
bun add @meistrari/llm-observability
```

## Usage

```ts
import { recordSuccess, recordError } from '@meistrari/llm-observability'

// Record a successful LLM call
recordSuccess({
    attributes: { provider: 'openai', model: 'gpt-4' },
    metrics: {
        duration: 1200,
        cost: 0.03,
        totalTokens: 500,
        promptTokens: 400,
        completionTokens: 100,
    },
}, 'Chat completion succeeded')

// Record a failed LLM call
recordError({
    attributes: { provider: 'anthropic', model: 'claude-3' },
    metrics: { duration: 5000 },
    error: {
        errorType: 'rate_limit',
        httpStatus: 429,
        retriable: true,
        reason: 'Too many requests',
    },
}, 'Chat completion failed')
```

## API

### `recordSuccess(params, message)`

Records a successful LLM request: increments request counter, logs via Pino, records metric histograms.

| Parameter | Type | Description |
|-----------|------|-------------|
| `params.attributes` | `Record<string, any>` | Custom attributes (e.g. provider, model) |
| `params.metrics` | `MetricValues` | Metric values to record |
| `message` | `string` | Log message |

### `recordError(params, message)`

Records a failed LLM request: increments request + error counters, logs error, optionally records duration.

| Parameter | Type | Description |
|-----------|------|-------------|
| `params.attributes` | `Record<string, any>` | Custom attributes |
| `params.metrics` | `{ duration?: number }` | Optional duration |
| `params.error` | `ErrorMetadata` | Error details |
| `message` | `string` | Log message |

### `MetricValues`

| Field | Type |
|-------|------|
| `duration` | `number?` |
| `cost` | `number?` |
| `totalTokens` | `number?` |
| `promptTokens` | `number?` |
| `completionTokens` | `number?` |
| `reasoningTokens` | `number?` |
| `pages` | `number?` |

### `ErrorMetadata`

| Field | Type |
|-------|------|
| `errorType` | `string?` |
| `errorMessage` | `string?` |
| `retriable` | `boolean?` |
| `reason` | `string?` |
| `httpStatus` | `number?` |

## Metrics Emitted

| Metric Name | Type | Description |
|-------------|------|-------------|
| `llm.request.count` | Counter | Total requests (success + error) |
| `llm.error.count` | Counter | Failed requests |
| `llm.request.duration` | Histogram | Request duration |
| `llm.cost.total` | Histogram | Cost per request |
| `llm.tokens.total` | Histogram | Total tokens |
| `llm.tokens.prompt` | Histogram | Prompt tokens |
| `llm.tokens.completion` | Histogram | Completion tokens |
| `llm.tokens.reasoning` | Histogram | Reasoning tokens |
| `llm.pages.total` | Histogram | Pages processed |
npm package: @meistrari/logger
Description: @meistrari/logger
Latest version: 2.1.5

@meistrari/logger

---

## Add environment variables

This library **requires** 3 environment variables: `SERVICE_NAME`, `SERVICE_VERSION` and `ENVIRONMENT`. Without any of them, it will throw an error and crash the application.

### `SERVICE_NAME`

`SERVICE_NAME` is a slug-friendly value that represents the name of the service

Use `-` as word divider. Example: use `tela-api` instead of `tela_api`

### `ENVIRONMENT`

`ENVIRONMENT` should be one of `development`, `staging`, `forninho` or `production`, any other value will crash the application. Also, this is case sensitive.

When using `ENVIRONMENT=development`, the logger will output pretty-printed logs to the console.

### `SERVICE_VERSION`

`SERVICE_VERSION` should change based on the deployed version. This is accomplished with a custom deploy workflow that generates the version for each build. The version is commonly the result of `git rev-parse --short HEAD`, which returns the short version of the `HEAD` commit

If your application doesn't have a deploy pipeline yet but you want to instrument it anyway, we recommend using `unknown` as the value for this variable