Send logs from your app

Learn how to send logs from your applications to Hive using the SDK

Published: 1/15/2025

Beyond CLI execution, you can send logs directly from your production applications to Hive for real-time monitoring and observability. This tutorial shows you how to integrate the Hive SDK into your applications to capture execution logs automatically.

Installation

First, install the Hive SDK in your project:

pnpm add @forgehive/hive-sdk

Or with npm:

npm install @forgehive/hive-sdk

Getting Your API Credentials

Before using the SDK, you need to obtain API credentials from the Hive dashboard:

1. Create API Keys in the Dashboard

  1. Visit forgehive.dev
  2. Log in to your account or create a new account
  3. Navigate to Dashboard → Settings
  4. In the API Keys section, click Create
  5. Enter a descriptive name for your API key (e.g., "Production API")
  6. Click Create

2. Copy Your Credentials

After creating the API key, you'll see:

  • API Key: A public identifier for your application
  • API Secret: A private secret (keep this secure!)

Environment Setup

Configure your environment variables with your API credentials:

HIVE_API_KEY=your_api_key_here
HIVE_API_SECRET=your_api_secret_here
HIVE_HOST=https://your-hive-instance.com

Basic Usage

Creating a Hive Log Client

Start by importing and creating a Hive log client for your project:

import { createHiveLogClient } from '@forgehive/hive-sdk'

const hiveLogger = createHiveLogClient('My Application Name')

The project name helps organize your logs within the Hive dashboard.

Quick Integration Example

Here's a practical example showing how to integrate Hive logging with task execution:

// Using safeRun pattern with automatic logging
const [res, error, record] = await getPrice.safeRun({ ticker: 'AAPL' })

await hiveLogger.sendLog('stocks:getPrice', record)

This pattern is particularly useful when working with tasks that return execution records, as it captures the complete execution context automatically.

Complete Documentation

For comprehensive documentation including all available methods, configuration options, and advanced usage patterns, visit the complete package documentation:

📚 Full Hive SDK Documentation on npm

The npm documentation covers:

  • Complete API reference
  • Advanced configuration options
  • Error handling patterns
  • Integration examples
  • TypeScript definitions