Opik TS - Interactive Setup Tool
The Opik TS is an interactive command-line tool that streamlines the process of adding Opik observability to your Node.js and TypeScript applications. It automatically detects your project setup, installs dependencies, and configures tracing for your LLM integrations.
Features
Section titled “Features”- 🔍 Smart Detection: Automatically detects your project setup (package manager, TypeScript configuration, existing integrations)
- 📦 Package Management: Supports npm, yarn, pnpm, and bun
- ⚙️ Environment Configuration: Creates or updates
.envfiles with proper Opik configuration
Getting Started
Section titled “Getting Started”Basic Usage
Section titled “Basic Usage”Run the CLI in your project directory:
npx opik-ts configureThe CLI will guide you through:
- Project Detection: Identifies your package manager and project structure
- Dependency Installation: Installs Opik SDK and integration packages
- Environment Setup: Configures API keys and environment variables
- Code Generation: Sets up Opik client in your root project folder
- Formatting: Optionally applies Prettier formatting
Requirements
Section titled “Requirements”- Node.js: Version 18.17.0 or higher
- Package Manager: npm, yarn, pnpm, or bun
- Supported Project Types:
- Node.js applications
- TypeScript projects
- Express/Fastify APIs
CLI Options
Section titled “CLI Options”The CLI supports several command-line options for customization:
| Option | Type | Default | Description | Environment Variable |
|---|---|---|---|---|
--help |
boolean | - | Display help information | - |
--version |
boolean | - | Show version number | - |
--debug |
boolean | false |
Enable verbose logging for troubleshooting | OPIK_TS_DEBUG |
--default |
boolean | true |
Use default options for all prompts (non-interactive) | OPIK_TS_DEFAULT |
--force-install |
boolean | false |
Force package installation even if peer dependency checks fail | OPIK_TS_FORCE_INSTALL |
--install-dir |
string | current directory | Specify custom installation directory | OPIK_TS_INSTALL_DIR |
--use-local |
boolean | false |
Skip deployment selection and configure for local development | OPIK_TS_USE_LOCAL |
Examples
Section titled “Examples”Verbose debugging mode:
npx opik-ts configure --debugNon-interactive mode with defaults:
npx opik-ts configure --defaultInstall in a specific directory:
npx opik-ts configure --install-dir=./my-appForce installation (skip peer dependency checks):
npx opik-ts configure --force-installLocal development setup:
npx opik-ts configure --use-localThis will skip the deployment selection step and automatically configure your environment for local development (localhost:5173).
Environment Configuration
Section titled “Environment Configuration”The CLI automatically creates or updates your .env file with the necessary configuration:
# Opik Configuration
OPIK_API_KEY=your-api-key-here
OPIK_URL_OVERRIDE=https://www.comet.com/opik/api
OPIK_PROJECT_NAME=default
OPIK_WORKSPACE=defaultTroubleshooting
Section titled “Troubleshooting”Permission Errors
Section titled “Permission Errors”If you encounter permission errors during installation:
# Use --force-install to bypass peer dependency checks
npx opik-ts configure --force-installPackage Manager Issues
Section titled “Package Manager Issues”If the CLI fails to detect your package manager:
- Ensure you have a
package.jsonin your project directory - Try running the CLI with debug mode:
npx opik-ts configure --debug - Manually specify your package manager by selecting it from the prompts
Environment Variable Setup
Section titled “Environment Variable Setup”If environment variables aren't being set correctly:
- Check that
.envfile was created in your project root - Ensure your application loads environment variables (e.g., using
dotenv) - Restart your development server after running the CLI
Integration Not Working
Section titled “Integration Not Working”If traces aren't appearing in Opik:
- Verify your
OPIK_API_KEYis correct - Check that
OPIK_URL_OVERRIDEpoints to the right endpoint - Ensure you're calling
flush()before your application exits:TypeScript await trackedClient.flush();
Debug Mode
Section titled “Debug Mode”Enable verbose logging to troubleshoot issues:
npx opik-ts configure --debugThis will show detailed information about:
- Project detection results
- Package installation steps
- File modifications
- Configuration changes
CI/CD Integration
Section titled “CI/CD Integration”For automated deployments, use the non-interactive mode:
# In your CI/CD pipeline
npx opik-ts configure --default --force-installSet environment variables beforehand:
export OPIK_API_KEY="your-api-key"
export OPENAI_API_KEY="your-openai-key"
npx opik-ts configure --defaultNext Steps
Section titled “Next Steps”After running the CLI:
- Start Your Application: Run your application and make LLM calls to see traces in Opik
- Explore Traces: Visit the Opik dashboard to view your traces
- Add Custom Spans: Learn about manual tracing for custom instrumentation
- Set Up Evaluation: Configure evaluation metrics for your LLM outputs
- Production Monitoring: Set up production monitoring for your application