open-index/open-npm huggingface dataset:
npm package: @protobuf-ts-toolkit/metadata
Description: Metadata interceptor for gRPC: supports static, sync, and async metadata with streaming support
Author: smnbbrv
Latest version: 1.0.1

# @protobuf-ts-toolkit/metadata

Interceptor for adding metadata to gRPC calls. Supports static values, sync functions, and async functions with proper streaming support.

## Installation

```bash
npm install @protobuf-ts-toolkit/metadata
```

## Usage

### Static Metadata

```typescript
import { createMetadataInterceptor } from '@protobuf-ts-toolkit/metadata';

const interceptor = createMetadataInterceptor({
  metadata: { 'x-api-key': 'key123' }
});
```

### Dynamic Metadata (Sync)

```typescript
const interceptor = createMetadataInterceptor({
  metadata: () => ({
    'x-request-id': crypto.randomUUID()
  })
});
```

### Async Metadata

```typescript
const interceptor = createMetadataInterceptor({
  metadata: async () => ({
    'authorization': `Bearer ${await getAccessToken()}`
  })
});
```

### Multiple Headers

```typescript
const interceptor = createMetadataInterceptor({
  metadata: async ({ method }) => ({
    'authorization': `Bearer ${await getAccessToken()}`,
    'x-csrf-token': await getCsrfToken(),
    'x-method': method.name
  })
});
```

### Filter by Call Type

```typescript
const interceptor = createMetadataInterceptor({
  metadata: async () => ({
    'authorization': `Bearer ${await generateOneTimeToken()}`
  }),
  callTypes: ['clientStreaming', 'duplex']
});
```

## Configuration

```typescript
interface MetadataInterceptorConfig {
  // Metadata to add - static object, sync function, or async function
  metadata: MetadataProvider;

  // Optional: filter which call types to intercept
  // Default: all call types
  callTypes?: ('unary' | 'serverStreaming' | 'clientStreaming' | 'duplex')[];
}

type MetadataProvider =
  | RpcMetadata
  | ((context: MetadataContext) => RpcMetadata)
  | ((context: MetadataContext) => Promise<RpcMetadata>);

interface MetadataContext {
  callType: 'unary' | 'serverStreaming' | 'clientStreaming' | 'duplex';
  method: MethodInfo;
}
```

## How It Works

For streaming calls, the interceptor buffers outgoing messages while waiting for async metadata to resolve. Once resolved, buffered messages are flushed to the actual stream.
npm package: @protobuf-ts-toolkit/opentelemetry
Description: OpenTelemetry interceptor for gRPC calls with protobuf-ts
Author: smnbbrv
Latest version: 1.0.1

# @protobuf-ts-toolkit/opentelemetry

OpenTelemetry tracing interceptor for protobuf-ts gRPC clients.

## Installation

```bash
npm install @protobuf-ts-toolkit/opentelemetry @opentelemetry/api
```

## Usage

```typescript
import { GrpcWebFetchTransport } from '@protobuf-ts/grpcweb-transport';
import { createOtelInterceptor } from '@protobuf-ts-toolkit/opentelemetry';

const transport = new GrpcWebFetchTransport({
  baseUrl: 'https://api.example.com',
  interceptors: [createOtelInterceptor()],
});
```

### Custom Tracer Name

```typescript
const otelInterceptor = createOtelInterceptor({
  tracerName: 'my-service-client',
});
```

### Custom Span Names

```typescript
const otelInterceptor = createOtelInterceptor({
  spanNameFormatter: (method, callType) =>
    `${callType}:${method.service.typeName}/${method.name}`,
});
```

## Features

- Creates spans for all gRPC call types (unary, server streaming, client streaming, duplex)
- Sets semantic convention attributes:
  - `rpc.system`: "grpc"
  - `rpc.service`: Service type name
  - `rpc.method`: Full method path
  - `rpc.grpc.status_code`: Response status code
- Automatically propagates trace context via W3C Trace Context headers
- Sets span status based on call success/failure

## Configuration

```typescript
interface OtelConfig {
  // Tracer name (default: '@protobuf-ts-toolkit/opentelemetry')
  tracerName?: string;

  // Custom span name formatter (default: 'grpc.{service}/{method}')
  spanNameFormatter?: (method: MethodInfo, callType: string) => string;
}
```