1.0.2 • Published 7 months ago
@bluealba-public/opentelemetry-tracer v1.0.2
OpenTelemetry Tracer
Overview
OpenTelemetry Tracer provides a robust tracing utility built on OpenTelemetry, enabling seamless instrumentation of asynchronous operations in your application. It supports auto-instrumentation and custom tracer configuration to effectively monitor performance and troubleshoot issues.
Installation
Install the package from npm:
npm install @bluealba-public/opentelemetry-tracerUsage
Initialize tracing in your application by importing and calling the initTracing function:
import { initTracing } from '@bluealba-public/opentelemetry-tracer';
const tracing = initTracing({
enabled: true,
url: process.env.TRACE_URL,
serviceName: 'your-service-name'
});
// Wrap asynchronous operations with tracing
const tracedOperation = tracing.withTracing('operation-span', async () => {
// ... your code ...
});For Fastify Applications >5.x
For Fastify applications, use the provided Fastify plugin to automatically trace incoming requests and responses:
npm install @autotelic/fastify-opentelemetryimport fastify from 'fastify';
import fastifyOpenTelemetry from '@autotelic/fastify-opentelemetry';
const app = fastify();
app.register(fastifyOpenTelemetry);
// ... existing code ...Configuration
Customize the tracer with the following options:
- enabled: Toggle tracing on or off.
- url: Specify the OTLP trace exporter endpoint.
- serviceName: Name your service for trace identification.
- logger: (Optional) Custom logger for additional logging.
- instrumentations: (Optional) List of instrumentations to enable.