observable-opentelemetry
observable-opentelemetryOpenTelemetry integration for logs, metrics, and traces via OTLP
Overview
OpenTelemetry observable plugin for BSB with full OTLP (OpenTelemetry Protocol) export support. This plugin enables complete observability by exporting traces, metrics, and logs to any OpenTelemetry-compatible backend.
Key Features
- Full OpenTelemetry integration for traces, metrics, and logs
- OTLP export over HTTP and gRPC protocols
- Customizable resource attributes for service metadata
- Configurable sampling to control trace collection rates
- Efficient batch processing for data export
When to Use
Use this plugin when you need:
- Distributed tracing across microservices
- Integration with OpenTelemetry-compatible platforms (Jaeger, Zipkin, New Relic, Datadog)
- Unified observability with traces, metrics, and logs
- Industry-standard telemetry with vendor-neutral instrumentation
OpenTelemetry Ecosystem
OpenTelemetry is the industry standard for observability. It provides vendor-neutral APIs and tools for collecting distributed traces, metrics, and logs. This plugin integrates BSB seamlessly with the OpenTelemetry ecosystem.
Installation
npm install @bsb/observable-opentelemetry
Configuration
Add the plugin to your BSB configuration file:
plugins:
observables:
- plugin: "@bsb/observable-opentelemetry"
enabled: true
config:
serviceName: "my-service"
serviceVersion: "1.0.0"
endpoint: "http://localhost:4318"
export:
protocol: "http"
interval: 5000
maxBatchSize: 512
enabled:
traces: true
metrics: true
logs: true
resourceAttributes:
environment: "production"
region: "us-east-1"
samplingRate: 1.0
Configuration Options
| Option | Description | Default |
|---|---|---|
serviceName |
Name of your service | - |
serviceVersion |
Version of your service | - |
endpoint |
OTLP collector endpoint URL | http://localhost:4318 |
export.protocol |
Export protocol: "http" or "grpc" | http |
export.interval |
Export interval in milliseconds | 5000 |
export.maxBatchSize |
Maximum batch size for exports | 512 |
enabled |
Toggle traces, metrics, and logs individually | All enabled |
resourceAttributes |
Custom resource attributes (key-value pairs) | {} |
samplingRate |
Trace sampling rate (0.0 to 1.0) | 1.0 |
Usage
Once configured, the plugin automatically exports telemetry data from your BSB services. No additional code is required - simply use the standard BSB logging and metrics interfaces:
import { BSBService, BSBServiceConstructor } from "@bsb/base";
export class MyService extends BSBService {
constructor(context: BSBServiceConstructor) {
super(context);
}
async init(): Promise<void> {
// Logs are automatically exported with trace context
this.log.info("Service initialized");
// Traces are automatically propagated across service boundaries
await this.events.emitEvent("user.created", { userId: "123" });
}
}
OpenTelemetry Collector Setup
To receive telemetry data, you'll need an OpenTelemetry Collector or compatible backend:
# docker-compose.yml
version: '3'
services:
otel-collector:
image: otel/opentelemetry-collector:latest
ports:
- "4318:4318" # OTLP HTTP
- "4317:4317" # OTLP gRPC
volumes:
- ./otel-config.yaml:/etc/otel-config.yaml
command: ["--config=/etc/otel-config.yaml"]
Installation
npm i @bsb/observable-opentelemetry
Configuration
Configuration options for this plugin:
Tree view shows nested config fields and object branches.
serviceName
serviceName
string
default: "bsb-service"
serviceVersion
serviceVersion
string
optional
endpoint
endpoint
uri
default: "http://localhost:4318"
export
export
object
protocol
export.protocol
"http" | "grpc"
default: "http"
interval
export.interval
integer
default: 5000
maxBatchSize
export.maxBatchSize
integer
default: 512
enabled
enabled
object
traces
enabled.traces
boolean
default: true
metrics
enabled.metrics
boolean
default: true
logs
enabled.logs
boolean
default: true
resourceAttributes
resourceAttributes
object
default: {}
samplingRate
samplingRate
number
default: 1
Supported Features
Observable capabilities implemented by this plugin:
Logging
debug
available
info
available
warn
available
error
available
Metrics
createCounter
available
createGauge
available
createHistogram
available
incrementCounter
available
setGauge
available
observeHistogram
available
Tracing
spanStart
available
spanEnd
available
spanError
available