Skip to content

Latest commit

 

History

History

README.md

Demonstrating Application-Level Transparency in OpenTelemetry Tracing for Hono.js + Bun

A comprehensive example showcasing how to achieve application-level transparency in OTel tracing using @waitingliou/tsc-otel-instrumentation - automatic, non-invasive OpenTelemetry instrumentation for your Hono.js project running on Bun runtime.

demo

Project Purpose

Primary Goals

  • Show how to achieve clean business logic without manual instrumentation
  • Provide a complete example of @waitingliou/tsc-otel-instrumentation integration
  • Demonstrate basic observability stack (traces + logs)

Who Is This For?

  • Developers learning OpenTelemetry and automatic instrumentation
  • Teams, Organizations seeking non-invasive tracing approaches

Technology Stack

Core Technologies

Component Technology Version Purpose
Web Framework Hono.js 4.8+ Lightweight, fast web framework
Runtime Bun Latest JavaScript/TypeScript runtime (for execution)
Language TypeScript 5.0+ Type-safe development
Compiler TypeScript Compiler (tsc) 5.0+ ⚠️ Required for compilation
Instrumentation @waitingliou/tsc-otel-instrumentation 1.1.7+ Automatic class method tracing
Observability OpenTelemetry Latest Distributed tracing standard
Trace Backend Grafana Cloud Tempo Cloud Trace storage and visualization

⚠️ Important: Must Use TypeScript Compiler

Why not Bun's transpiler?

@waitingliou/tsc-otel-instrumentation is a TypeScript compiler plugin that hooks into tsc's AST transformation pipeline. Bun's TypeScript transpiler (written in Zig for speed) doesn't support TypeScript's plugin system.

Build pipeline:

Source TypeScript → tsc (with ts-patch) → Instrumented JavaScript → Bun runtime
                      ↑
                tsc-otel-instrumentation
                AST transformation

Use tsc to compile, then Bun to run.

Project Architecture

This example follows Clean Architecture principles to demonstrate real-world usage:

Architecture Layers

┌────────────────────────────────────────┐
│  Controllers (HTTP Handlers)           │
│  - Handle requests/responses           │
└─────────────┬──────────────────────────┘
              │ Dependency Injection
┌─────────────▼──────────────────────────┐
│  Use Cases (Business Logic Services)   │  ← Automatically instrumented
│  - UserService, NotificationService    │
└─────────────┬──────────────────────────┘
              │ Interfaces (Ports)
┌─────────────▼──────────────────────────┐
│  Repositories (Data Access)            │  ← Automatically instrumented
│  - UserRepository, SocialLinkRepo      │
└────────────────────────────────────────┘

Quick Start

Prerequisites

Installation

# Install dependencies
bun install

Environment Configuration

Create .env file:

# Application Configuration
NODE_ENV=production
PORT=3002

# OpenTelemetry - Get from Grafana Cloud → Connections → OTLP
OTEL_EXPORTER_OTLP_ENDPOINT=...
OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic <your-base64-token>"

# Grafana Cloud Credentials (for logs if using Loki)
GRAFANA_HOST=https://logs-prod-XXX.grafana.net
GRAFANA_USERNAME=123456
GRAFANA_CLOUD_TOKEN=glc_xxxxxxxxxxxxxxxxxxxxx

How to get credentials:

  1. Visit grafana.com and sign up
  2. Navigate to ConnectionsAdd new connection
  3. Select OpenTelemetry (OTLP) for traces
  4. Select Loki for logs
  5. Copy credentials to .env

Build and Run

# Step 1: Compile TypeScript with tsc (applies instrumentation)
bun run build

# Step 2: Run the compiled JavaScript with Bun
bun run start:bun

# Or for development with hot reload
bun run dev

Server starts at http://localhost:3002

Additional Resources

Learn More About @waitingliou/tsc-otel-instrumentation

Related Documentation

Happy tracing! 🎉

Achieve application-level transparency in your TypeScript projects with zero code pollution.