Skip to content

Instrumentation Files Guide

This guide explains the observability instrumentation setup following SigNoz’s TypeScript documentation.

instrumentation.cjs (Single Implementation)

Section titled “instrumentation.cjs (Single Implementation)”

Purpose: JavaScript implementation following SigNoz’s exact documentation pattern
When to use: All environments (development, production, Docker)
How to use:

Terminal window
# For development (assuming you have a CJS-based entrypoint)
node --require ./instrumentation.cjs your-app.js
# For production (in package.json scripts)
"start": "NODE_OPTIONS='--import ./instrumentation.cjs' astro dev"

Features:

  • ✅ Follows SigNoz documentation exactly
  • ✅ Production-ready and development-friendly
  • ✅ Environment variable based configuration
  • ✅ Automatic fallback to console export for development
  • ✅ Proper resource configuration and graceful shutdown

Purpose: Additional observability utilities and helpers

  • astro-integration.ts: Astro middleware for request tracing
  • api-instrumentation.ts: Wrapper functions for API routes
  • node-metrics.ts: Custom business metrics
  • src/utils/logger.ts: Main structured logger with trace correlation

Use the JavaScript implementation with environment variables:

Terminal window
# Set SigNoz configuration
export OTEL_EXPORTER_OTLP_ENDPOINT="https://ingest.us.signoz.cloud:443"
export OTEL_EXPORTER_OTLP_HEADERS="signoz-ingestion-key=your-key"
export OTEL_SERVICE_NAME="erp-unlocked-backend"
# Run with tracing (as configured in package.json)
npm start

Use console export for local testing:

Terminal window
export OTEL_CONSOLE_EXPORT=true
export ENABLE_OBSERVABILITY=true
# Run normally - traces will appear in console
npm run dev

Follow SigNoz’s no-code approach:

Terminal window
export OTEL_TRACES_EXPORTER="otlp"
export OTEL_EXPORTER_OTLP_ENDPOINT="https://ingest.us.signoz.cloud:443"
export OTEL_NODE_RESOURCE_DETECTORS="env,host,os"
export OTEL_SERVICE_NAME="erp-unlocked-backend"
export OTEL_EXPORTER_OTLP_HEADERS="signoz-ingestion-key=your-key"
export NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register"
npm start

For production deployment:

  • Compile TypeScript: npx tsc
  • The compiled instrumentation.js will be used in production
  • TypeScript provides better development experience and type safety
  1. Check environment variables are set correctly
  2. Verify SigNoz endpoint and ingestion key
  3. Enable console export for debugging: OTEL_CONSOLE_EXPORT=true
  • The instrumentation has minimal performance impact
  • Metrics collection is optional and can be disabled
  • Console export should only be used in development
  • src/lib/observability/node-tracer.ts - REMOVED (was redundant)
  • src/lib/observability/node-logger.ts - REMOVED (replaced by src/utils/logger.ts)
  • tracing.js - REMOVED (redundant with CJS version)
  • Single instrumentation.cjs file following SigNoz documentation
  • Environment variables updated to SigNoz standards
  • SIGNOZ_OTLP_ENDPOINT → OTEL_EXPORTER_OTLP_ENDPOINT
  • SIGNOZ_API_KEY → Include in OTEL_EXPORTER_OTLP_HEADERS
  • Added OTEL_TRACES_EXPORTER=otlp
  • Added OTEL_NODE_RESOURCE_DETECTORS=env,host,os

Purpose: SigNoz-compatible logging using Pino following SigNoz Pino documentation.

Key Features:

  • Pino Transport: Uses pino-opentelemetry-transport for SigNoz integration
  • Development Mode: Pretty printing for local development
  • Production Mode: JSON structured logs sent to SigNoz
  • Trace Correlation: Automatic correlation with OpenTelemetry traces
  • Environment Detection: Fallback for browser environments

Usage:

import { logger } from '@/utils/logger';
// Structured logging with metadata
logger.info('Order processed', {
orderId: '123',
amount: 99.99,
customerId: 'cust-456',
});
// Error logging with full context
logger.error('Payment failed', error, {
orderId: '456',
paymentMethod: 'credit_card',
});

Environment Variables:

  • ENABLE_SIGNOZ_LOGS: Enable SigNoz transport (default: true in production)
  • LOG_LEVEL: Set log level (debug, info, warn, error)
  • OTEL_SERVICE_NAME: Service name for log correlation
  • OTEL_EXPORTER_OTLP_LOGS_ENDPOINT: SigNoz logs endpoint

Python Logging (pdf_processor_service/app/utils/logging.py)

Section titled “Python Logging (pdf_processor_service/app/utils/logging.py)”

Purpose: SigNoz-compatible structured logging with OpenTelemetry correlation.

Key Features:

  • Structured JSON: SigNoz-compatible JSON formatting
  • OpenTelemetry Correlation: Automatic trace and span ID correlation
  • Service Context: Automatic service metadata injection
  • Flexible Configuration: Environment-based configuration

Usage:

from app.utils.logging import logger, structured_logger
# Basic logging with context
logger.info("PDF processing started", extra={
"document_id": "doc-123",
"file_size": 2048576
})
# Structured logging
structured_logger.info(
"pdf_extraction_completed",
document_id="doc-123",
processing_time=5.2,
orders_extracted=15
)
  • Single Implementation: ✅ instrumentation.cjs only
  • Production & Development Ready: ✅ Works in all environments
  • SigNoz Aligned: ✅ Follows official JavaScript documentation
  • TypeScript Support: ✅ Astro/Vite handles module loading
  • Backwards Compatible: ✅ Legacy environment variables still work
  • Logging Integration: ✅ SigNoz-compatible logging for Node.js (Pino) and Python