Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/iii-hq/sdk/llms.txt

Use this file to discover all available pages before exploring further.

The OtelConfig type configures OpenTelemetry integration for distributed tracing, metrics, and logs.

Type Definition

interface OtelConfig {
  enabled?: boolean
  serviceName?: string
  serviceVersion?: string
  serviceNamespace?: string
  serviceInstanceId?: string
  engineWsUrl?: string
  instrumentations?: Instrumentation[]
  metricsEnabled?: boolean
  metricsExportIntervalMs?: number
  fetchInstrumentationEnabled?: boolean
  reconnectionConfig?: Partial<ReconnectionConfig>
}

Fields

Default Configuration

const DEFAULT_OTEL_CONFIG = {
  enabled: true,
  serviceName: 'iii-node',
  serviceVersion: 'unknown',
  engineWsUrl: 'ws://localhost:49134',
  metricsEnabled: true,
  metricsExportIntervalMs: 60000,
  fetchInstrumentationEnabled: true,
}

Usage Examples

Basic Telemetry Setup

import { init } from '@iii/sdk'

const iii = init('ws://localhost:49134', {
  otel: {
    serviceName: 'my-api',
    serviceVersion: '1.0.0',
    serviceNamespace: 'production'
  }
})

Disable Telemetry

const iii = init('ws://localhost:49134', {
  otel: {
    enabled: false
  }
})

Custom Metrics Interval

const iii = init('ws://localhost:49134', {
  otel: {
    metricsEnabled: true,
    metricsExportIntervalMs: 30000  // 30 seconds
  }
})

With Custom Instrumentation (TypeScript)

import { init } from '@iii/sdk'
import { PrismaInstrumentation } from '@prisma/instrumentation'
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'

const iii = init('ws://localhost:49134', {
  otel: {
    serviceName: 'my-api',
    instrumentations: [
      new PrismaInstrumentation(),
      new HttpInstrumentation()
    ]
  }
})

Disable HTTP Auto-Instrumentation

const iii = init('ws://localhost:49134', {
  otel: {
    fetchInstrumentationEnabled: false
  }
})

Full Configuration

import { init } from '@iii/sdk'

const iii = init('ws://localhost:49134', {
  otel: {
    enabled: true,
    serviceName: 'my-api',
    serviceVersion: '1.0.0',
    serviceNamespace: 'production',
    serviceInstanceId: 'instance-1',
    instrumentations: [],
    metricsEnabled: true,
    metricsExportIntervalMs: 60000,
    fetchInstrumentationEnabled: true,
    reconnectionConfig: {
      initialDelayMs: 1000,
      maxDelayMs: 30000,
      backoffMultiplier: 2,
      jitterFactor: 0.3,
      maxRetries: -1
    }
  }
})

Environment Variables

OpenTelemetry configuration can be controlled via environment variables:
  • OTEL_ENABLED - Enable/disable OTel (true/false/0/1/yes/no/on/off)
  • OTEL_SERVICE_NAME - Service name
  • SERVICE_VERSION - Service version
  • SERVICE_NAMESPACE - Service namespace
  • SERVICE_INSTANCE_ID - Service instance ID
  • III_BRIDGE_URL - Engine WebSocket URL
  • OTEL_METRICS_ENABLED - Enable/disable metrics
Example:
export OTEL_SERVICE_NAME=my-api
export SERVICE_VERSION=1.0.0
export SERVICE_NAMESPACE=production
export OTEL_METRICS_ENABLED=true

Observability Features

Distributed Tracing

All function invocations are automatically traced with W3C trace context propagation:
  • Parent-child span relationships across workers
  • Automatic trace ID and span ID generation
  • Baggage propagation for custom context

Metrics

Automatic metrics collection:
  • Function invocation count
  • Function duration
  • Error rate
  • Active invocations
  • Worker status

Logs

Structured logging with trace correlation:
  • All logs include trace ID and span ID
  • Automatic severity level detection
  • Resource attributes (service name, version, etc.)

Best Practices

  1. Always set service metadata: Provide meaningful serviceName, serviceVersion, and serviceNamespace
  2. Use environment variables: Configure via env vars for easier deployment
  3. Production monitoring: Keep telemetry enabled in production for observability
  4. Custom instrumentation: Add framework-specific instrumentations (Prisma, Express, etc.)
  5. Metrics tuning: Adjust export interval based on traffic volume

Build docs developers (and LLMs) love