JSPM

  • Created
  • Published
  • Downloads 2176
  • Score
    100M100P100Q131271F
  • License ISC

Diagnostics library for Node.js applications

Package Exports

  • @vtex/diagnostics-nodejs
  • @vtex/diagnostics-nodejs/dist/config/index.d.ts
  • @vtex/diagnostics-nodejs/dist/config/index.d.ts.map
  • @vtex/diagnostics-nodejs/dist/config/index.js
  • @vtex/diagnostics-nodejs/dist/config/index.js.map
  • @vtex/diagnostics-nodejs/dist/discovery/index.d.ts
  • @vtex/diagnostics-nodejs/dist/discovery/index.d.ts.map
  • @vtex/diagnostics-nodejs/dist/discovery/index.js
  • @vtex/diagnostics-nodejs/dist/discovery/index.js.map
  • @vtex/diagnostics-nodejs/dist/discovery/resource-discovery.d.ts
  • @vtex/diagnostics-nodejs/dist/discovery/resource-discovery.d.ts.map
  • @vtex/diagnostics-nodejs/dist/discovery/resource-discovery.js
  • @vtex/diagnostics-nodejs/dist/discovery/resource-discovery.js.map
  • @vtex/diagnostics-nodejs/dist/exporters/index.d.ts
  • @vtex/diagnostics-nodejs/dist/exporters/index.d.ts.map
  • @vtex/diagnostics-nodejs/dist/exporters/index.js
  • @vtex/diagnostics-nodejs/dist/exporters/index.js.map
  • @vtex/diagnostics-nodejs/dist/exporters/interface.d.ts
  • @vtex/diagnostics-nodejs/dist/exporters/interface.d.ts.map
  • @vtex/diagnostics-nodejs/dist/exporters/interface.js
  • @vtex/diagnostics-nodejs/dist/exporters/interface.js.map
  • @vtex/diagnostics-nodejs/dist/exporters/otlp.d.ts
  • @vtex/diagnostics-nodejs/dist/exporters/otlp.d.ts.map
  • @vtex/diagnostics-nodejs/dist/exporters/otlp.js
  • @vtex/diagnostics-nodejs/dist/exporters/otlp.js.map
  • @vtex/diagnostics-nodejs/dist/exporters/stdout.d.ts
  • @vtex/diagnostics-nodejs/dist/exporters/stdout.d.ts.map
  • @vtex/diagnostics-nodejs/dist/exporters/stdout.js
  • @vtex/diagnostics-nodejs/dist/exporters/stdout.js.map
  • @vtex/diagnostics-nodejs/dist/index.d.ts
  • @vtex/diagnostics-nodejs/dist/index.d.ts.map
  • @vtex/diagnostics-nodejs/dist/index.js
  • @vtex/diagnostics-nodejs/dist/index.js.map
  • @vtex/diagnostics-nodejs/dist/instrumentation/index.d.ts
  • @vtex/diagnostics-nodejs/dist/instrumentation/index.d.ts.map
  • @vtex/diagnostics-nodejs/dist/instrumentation/index.js
  • @vtex/diagnostics-nodejs/dist/instrumentation/index.js.map
  • @vtex/diagnostics-nodejs/dist/instrumentation/middlewares/core.d.ts
  • @vtex/diagnostics-nodejs/dist/instrumentation/middlewares/core.d.ts.map
  • @vtex/diagnostics-nodejs/dist/instrumentation/middlewares/core.js
  • @vtex/diagnostics-nodejs/dist/instrumentation/middlewares/core.js.map
  • @vtex/diagnostics-nodejs/dist/instrumentation/middlewares/express.d.ts
  • @vtex/diagnostics-nodejs/dist/instrumentation/middlewares/express.d.ts.map
  • @vtex/diagnostics-nodejs/dist/instrumentation/middlewares/express.js
  • @vtex/diagnostics-nodejs/dist/instrumentation/middlewares/express.js.map
  • @vtex/diagnostics-nodejs/dist/instrumentation/middlewares/fastify.d.ts
  • @vtex/diagnostics-nodejs/dist/instrumentation/middlewares/fastify.d.ts.map
  • @vtex/diagnostics-nodejs/dist/instrumentation/middlewares/fastify.js
  • @vtex/diagnostics-nodejs/dist/instrumentation/middlewares/fastify.js.map
  • @vtex/diagnostics-nodejs/dist/instrumentation/middlewares/index.d.ts
  • @vtex/diagnostics-nodejs/dist/instrumentation/middlewares/index.d.ts.map
  • @vtex/diagnostics-nodejs/dist/instrumentation/middlewares/index.js
  • @vtex/diagnostics-nodejs/dist/instrumentation/middlewares/index.js.map
  • @vtex/diagnostics-nodejs/dist/instrumentation/middlewares/koa.d.ts
  • @vtex/diagnostics-nodejs/dist/instrumentation/middlewares/koa.d.ts.map
  • @vtex/diagnostics-nodejs/dist/instrumentation/middlewares/koa.js
  • @vtex/diagnostics-nodejs/dist/instrumentation/middlewares/koa.js.map
  • @vtex/diagnostics-nodejs/dist/instrumentation/propagation/index.d.ts
  • @vtex/diagnostics-nodejs/dist/instrumentation/propagation/index.d.ts.map
  • @vtex/diagnostics-nodejs/dist/instrumentation/propagation/index.js
  • @vtex/diagnostics-nodejs/dist/instrumentation/propagation/index.js.map
  • @vtex/diagnostics-nodejs/dist/logs/client.d.ts
  • @vtex/diagnostics-nodejs/dist/logs/client.d.ts.map
  • @vtex/diagnostics-nodejs/dist/logs/client.js
  • @vtex/diagnostics-nodejs/dist/logs/client.js.map
  • @vtex/diagnostics-nodejs/dist/logs/index.d.ts
  • @vtex/diagnostics-nodejs/dist/logs/index.d.ts.map
  • @vtex/diagnostics-nodejs/dist/logs/index.js
  • @vtex/diagnostics-nodejs/dist/logs/index.js.map
  • @vtex/diagnostics-nodejs/dist/metrics/client.d.ts
  • @vtex/diagnostics-nodejs/dist/metrics/client.d.ts.map
  • @vtex/diagnostics-nodejs/dist/metrics/client.js
  • @vtex/diagnostics-nodejs/dist/metrics/client.js.map
  • @vtex/diagnostics-nodejs/dist/metrics/counter.d.ts
  • @vtex/diagnostics-nodejs/dist/metrics/counter.d.ts.map
  • @vtex/diagnostics-nodejs/dist/metrics/counter.js
  • @vtex/diagnostics-nodejs/dist/metrics/counter.js.map
  • @vtex/diagnostics-nodejs/dist/metrics/gauge.d.ts
  • @vtex/diagnostics-nodejs/dist/metrics/gauge.d.ts.map
  • @vtex/diagnostics-nodejs/dist/metrics/gauge.js
  • @vtex/diagnostics-nodejs/dist/metrics/gauge.js.map
  • @vtex/diagnostics-nodejs/dist/metrics/histogram.d.ts
  • @vtex/diagnostics-nodejs/dist/metrics/histogram.d.ts.map
  • @vtex/diagnostics-nodejs/dist/metrics/histogram.js
  • @vtex/diagnostics-nodejs/dist/metrics/histogram.js.map
  • @vtex/diagnostics-nodejs/dist/metrics/index.d.ts
  • @vtex/diagnostics-nodejs/dist/metrics/index.d.ts.map
  • @vtex/diagnostics-nodejs/dist/metrics/index.js
  • @vtex/diagnostics-nodejs/dist/metrics/index.js.map
  • @vtex/diagnostics-nodejs/dist/metrics/options.d.ts
  • @vtex/diagnostics-nodejs/dist/metrics/options.d.ts.map
  • @vtex/diagnostics-nodejs/dist/metrics/options.js
  • @vtex/diagnostics-nodejs/dist/metrics/options.js.map
  • @vtex/diagnostics-nodejs/dist/processors/index.d.ts
  • @vtex/diagnostics-nodejs/dist/processors/index.d.ts.map
  • @vtex/diagnostics-nodejs/dist/processors/index.js
  • @vtex/diagnostics-nodejs/dist/processors/index.js.map
  • @vtex/diagnostics-nodejs/dist/processors/vtexattrs/constants.d.ts
  • @vtex/diagnostics-nodejs/dist/processors/vtexattrs/constants.d.ts.map
  • @vtex/diagnostics-nodejs/dist/processors/vtexattrs/constants.js
  • @vtex/diagnostics-nodejs/dist/processors/vtexattrs/constants.js.map
  • @vtex/diagnostics-nodejs/dist/processors/vtexattrs/index.d.ts
  • @vtex/diagnostics-nodejs/dist/processors/vtexattrs/index.d.ts.map
  • @vtex/diagnostics-nodejs/dist/processors/vtexattrs/index.js
  • @vtex/diagnostics-nodejs/dist/processors/vtexattrs/index.js.map
  • @vtex/diagnostics-nodejs/dist/processors/vtexattrs/log-processor.d.ts
  • @vtex/diagnostics-nodejs/dist/processors/vtexattrs/log-processor.d.ts.map
  • @vtex/diagnostics-nodejs/dist/processors/vtexattrs/log-processor.js
  • @vtex/diagnostics-nodejs/dist/processors/vtexattrs/log-processor.js.map
  • @vtex/diagnostics-nodejs/dist/processors/vtexattrs/span-processor.d.ts
  • @vtex/diagnostics-nodejs/dist/processors/vtexattrs/span-processor.d.ts.map
  • @vtex/diagnostics-nodejs/dist/processors/vtexattrs/span-processor.js
  • @vtex/diagnostics-nodejs/dist/processors/vtexattrs/span-processor.js.map
  • @vtex/diagnostics-nodejs/dist/processors/vtexattrs/utils.d.ts
  • @vtex/diagnostics-nodejs/dist/processors/vtexattrs/utils.d.ts.map
  • @vtex/diagnostics-nodejs/dist/processors/vtexattrs/utils.js
  • @vtex/diagnostics-nodejs/dist/processors/vtexattrs/utils.js.map
  • @vtex/diagnostics-nodejs/dist/providers/account/configurable.d.ts
  • @vtex/diagnostics-nodejs/dist/providers/account/configurable.d.ts.map
  • @vtex/diagnostics-nodejs/dist/providers/account/configurable.js
  • @vtex/diagnostics-nodejs/dist/providers/account/configurable.js.map
  • @vtex/diagnostics-nodejs/dist/providers/account/file-source.d.ts
  • @vtex/diagnostics-nodejs/dist/providers/account/file-source.d.ts.map
  • @vtex/diagnostics-nodejs/dist/providers/account/file-source.js
  • @vtex/diagnostics-nodejs/dist/providers/account/file-source.js.map
  • @vtex/diagnostics-nodejs/dist/providers/account/index.d.ts
  • @vtex/diagnostics-nodejs/dist/providers/account/index.d.ts.map
  • @vtex/diagnostics-nodejs/dist/providers/account/index.js
  • @vtex/diagnostics-nodejs/dist/providers/account/index.js.map
  • @vtex/diagnostics-nodejs/dist/providers/account/provider.d.ts
  • @vtex/diagnostics-nodejs/dist/providers/account/provider.d.ts.map
  • @vtex/diagnostics-nodejs/dist/providers/account/provider.js
  • @vtex/diagnostics-nodejs/dist/providers/account/provider.js.map
  • @vtex/diagnostics-nodejs/dist/providers/account/static.d.ts
  • @vtex/diagnostics-nodejs/dist/providers/account/static.d.ts.map
  • @vtex/diagnostics-nodejs/dist/providers/account/static.js
  • @vtex/diagnostics-nodejs/dist/providers/account/static.js.map
  • @vtex/diagnostics-nodejs/dist/providers/index.d.ts
  • @vtex/diagnostics-nodejs/dist/providers/index.d.ts.map
  • @vtex/diagnostics-nodejs/dist/providers/index.js
  • @vtex/diagnostics-nodejs/dist/providers/index.js.map
  • @vtex/diagnostics-nodejs/dist/samplers/index.d.ts
  • @vtex/diagnostics-nodejs/dist/samplers/index.d.ts.map
  • @vtex/diagnostics-nodejs/dist/samplers/index.js
  • @vtex/diagnostics-nodejs/dist/samplers/index.js.map
  • @vtex/diagnostics-nodejs/dist/samplers/traces/composed.d.ts
  • @vtex/diagnostics-nodejs/dist/samplers/traces/composed.d.ts.map
  • @vtex/diagnostics-nodejs/dist/samplers/traces/composed.js
  • @vtex/diagnostics-nodejs/dist/samplers/traces/composed.js.map
  • @vtex/diagnostics-nodejs/dist/samplers/traces/debug.d.ts
  • @vtex/diagnostics-nodejs/dist/samplers/traces/debug.d.ts.map
  • @vtex/diagnostics-nodejs/dist/samplers/traces/debug.js
  • @vtex/diagnostics-nodejs/dist/samplers/traces/debug.js.map
  • @vtex/diagnostics-nodejs/dist/samplers/traces/index.d.ts
  • @vtex/diagnostics-nodejs/dist/samplers/traces/index.d.ts.map
  • @vtex/diagnostics-nodejs/dist/samplers/traces/index.js
  • @vtex/diagnostics-nodejs/dist/samplers/traces/index.js.map
  • @vtex/diagnostics-nodejs/dist/samplers/traces/metadata.d.ts
  • @vtex/diagnostics-nodejs/dist/samplers/traces/metadata.d.ts.map
  • @vtex/diagnostics-nodejs/dist/samplers/traces/metadata.js
  • @vtex/diagnostics-nodejs/dist/samplers/traces/metadata.js.map
  • @vtex/diagnostics-nodejs/dist/samplers/traces/vtex-account.d.ts
  • @vtex/diagnostics-nodejs/dist/samplers/traces/vtex-account.d.ts.map
  • @vtex/diagnostics-nodejs/dist/samplers/traces/vtex-account.js
  • @vtex/diagnostics-nodejs/dist/samplers/traces/vtex-account.js.map
  • @vtex/diagnostics-nodejs/dist/telemetry/client.d.ts
  • @vtex/diagnostics-nodejs/dist/telemetry/client.d.ts.map
  • @vtex/diagnostics-nodejs/dist/telemetry/client.js
  • @vtex/diagnostics-nodejs/dist/telemetry/client.js.map
  • @vtex/diagnostics-nodejs/dist/telemetry/index.d.ts
  • @vtex/diagnostics-nodejs/dist/telemetry/index.d.ts.map
  • @vtex/diagnostics-nodejs/dist/telemetry/index.js
  • @vtex/diagnostics-nodejs/dist/telemetry/index.js.map
  • @vtex/diagnostics-nodejs/dist/traces/baggage.d.ts
  • @vtex/diagnostics-nodejs/dist/traces/baggage.d.ts.map
  • @vtex/diagnostics-nodejs/dist/traces/baggage.js
  • @vtex/diagnostics-nodejs/dist/traces/baggage.js.map
  • @vtex/diagnostics-nodejs/dist/traces/client.d.ts
  • @vtex/diagnostics-nodejs/dist/traces/client.d.ts.map
  • @vtex/diagnostics-nodejs/dist/traces/client.js
  • @vtex/diagnostics-nodejs/dist/traces/client.js.map
  • @vtex/diagnostics-nodejs/dist/traces/config.d.ts
  • @vtex/diagnostics-nodejs/dist/traces/config.d.ts.map
  • @vtex/diagnostics-nodejs/dist/traces/config.js
  • @vtex/diagnostics-nodejs/dist/traces/config.js.map
  • @vtex/diagnostics-nodejs/dist/traces/index.d.ts
  • @vtex/diagnostics-nodejs/dist/traces/index.d.ts.map
  • @vtex/diagnostics-nodejs/dist/traces/index.js
  • @vtex/diagnostics-nodejs/dist/traces/index.js.map
  • @vtex/diagnostics-nodejs/dist/traces/span.d.ts
  • @vtex/diagnostics-nodejs/dist/traces/span.d.ts.map
  • @vtex/diagnostics-nodejs/dist/traces/span.js
  • @vtex/diagnostics-nodejs/dist/traces/span.js.map
  • @vtex/diagnostics-nodejs/dist/traces/tracer.d.ts
  • @vtex/diagnostics-nodejs/dist/traces/tracer.d.ts.map
  • @vtex/diagnostics-nodejs/dist/traces/tracer.js
  • @vtex/diagnostics-nodejs/dist/traces/tracer.js.map
  • @vtex/diagnostics-nodejs/dist/types/exporters.d.ts
  • @vtex/diagnostics-nodejs/dist/types/exporters.d.ts.map
  • @vtex/diagnostics-nodejs/dist/types/exporters.js
  • @vtex/diagnostics-nodejs/dist/types/exporters.js.map
  • @vtex/diagnostics-nodejs/dist/types/index.d.ts
  • @vtex/diagnostics-nodejs/dist/types/index.d.ts.map
  • @vtex/diagnostics-nodejs/dist/types/index.js
  • @vtex/diagnostics-nodejs/dist/types/index.js.map
  • @vtex/diagnostics-nodejs/dist/types/logs.d.ts
  • @vtex/diagnostics-nodejs/dist/types/logs.d.ts.map
  • @vtex/diagnostics-nodejs/dist/types/logs.js
  • @vtex/diagnostics-nodejs/dist/types/logs.js.map
  • @vtex/diagnostics-nodejs/dist/types/metrics.d.ts
  • @vtex/diagnostics-nodejs/dist/types/metrics.d.ts.map
  • @vtex/diagnostics-nodejs/dist/types/metrics.js
  • @vtex/diagnostics-nodejs/dist/types/metrics.js.map
  • @vtex/diagnostics-nodejs/dist/types/telemetry.d.ts
  • @vtex/diagnostics-nodejs/dist/types/telemetry.d.ts.map
  • @vtex/diagnostics-nodejs/dist/types/telemetry.js
  • @vtex/diagnostics-nodejs/dist/types/telemetry.js.map
  • @vtex/diagnostics-nodejs/dist/types/traces.d.ts
  • @vtex/diagnostics-nodejs/dist/types/traces.d.ts.map
  • @vtex/diagnostics-nodejs/dist/types/traces.js
  • @vtex/diagnostics-nodejs/dist/types/traces.js.map
  • @vtex/diagnostics-nodejs/dist/utils/index.d.ts
  • @vtex/diagnostics-nodejs/dist/utils/index.d.ts.map
  • @vtex/diagnostics-nodejs/dist/utils/index.js
  • @vtex/diagnostics-nodejs/dist/utils/index.js.map
  • @vtex/diagnostics-nodejs/dist/utils/utils.d.ts
  • @vtex/diagnostics-nodejs/dist/utils/utils.d.ts.map
  • @vtex/diagnostics-nodejs/dist/utils/utils.js
  • @vtex/diagnostics-nodejs/dist/utils/utils.js.map

Readme

OpenTelemetry Diagnostics Library for Node.js

A Node.js library that simplifies telemetry collection using OpenTelemetry, providing unified interfaces for metrics, logs, and traces with easy-to-use instrumentation setups for popular libraries.

Installation

npm install @vtex/diagnostics-nodejs

Quick Start

Here's how to set up basic telemetry with instrumentation for an Express application:

const { NewTelemetryClient, Exporters, Instrumentation } = require('@vtex/diagnostics-nodejs');

async function main() {
  // 1. Initialize the telemetry client. This MUST be done before importing Express.
  const telemetryClient = await NewTelemetryClient(
    'my-client-name', // Name of the client/app instance
    'my-service-name' // Name of the service
  );

  // 2. Create the traces client, passing the desired instrumentations.
  const tracesClient = await telemetryClient.newTracesClient({
    exporter: Exporters.CreateExporter(Exporters.CreateTracesExporterConfig({ endpoint: 'localhost:4317' }), 'otlp'),
    instrumentations: Instrumentation.CommonInstrumentations.express(), // <-- Instrumentation bundle for Express
  });

  // 3. Create clients for logs and metrics as needed
  const logsClient = await telemetryClient.newLogsClient({ /* ... */ });
  const metricsClient = await telemetryClient.newMetricsClient({ /* ... */ });
  
  // 4. Now, it's safe to import Express and other instrumented modules.
  const express = require('express');
  const app = express();
  
  app.get('/hello', (req, res) => {
    // This request is automatically traced.
    logsClient.info('Hello endpoint was called');
    res.json({ message: 'Hello World!' });
  });

  app.listen(3000, () => console.log('Server running on port 3000'));

  // Graceful shutdown
  process.on('SIGTERM', async () => {
    await tracesClient.shutdown();
  });
}

main().catch(console.error);

How Automatic Instrumentation Works (Important!)

Automatic instrumentation in OpenTelemetry works by monkey-patching modules like http, express, or axios when they are loaded via require().

This means the telemetry client and its instrumentations MUST be initialized before you require any module you want to trace.

Correct Initialization Order

  1. require('@vtex/diagnostics-nodejs')
  2. NewTelemetryClient()
  3. telemetryClient.newTracesClient({ instrumentations: [...] })
  4. require('express')
  5. require('axios')
  6. require('./my-other-modules-that-use-axios')

If you import express or axios before initializing the TracesClient, their methods will not be patched, and no automatic traces will be generated.

Instrumentation Setup

This library provides pre-configured instrumentation bundles for common frameworks. You must choose the bundle that matches your stack and pass it to the TracesClient configuration.

const { Instrumentation } = require('@vtex/diagnostics-nodejs');

// Choose ONE of the following bundles:
const myInstrumentations = Instrumentation.CommonInstrumentations.express(); // For Express.js
const myInstrumentations = Instrumentation.CommonInstrumentations.fastify(); // For Fastify
const myInstrumentations = Instrumentation.CommonInstrumentations.koa();     // For Koa
const myInstrumentations = Instrumentation.CommonInstrumentations.nestjs();  // For NestJS
const myInstrumentations = Instrumentation.CommonInstrumentations.minimal(); // Basic HTTP/Net only

// --- Then, pass it in the config ---
const tracesClient = await telemetryClient.newTracesClient({
  exporter: myExporter,
  instrumentations: myInstrumentations, // <-- Here
});

Adding Community Instrumentations

You can easily add more instrumentations from the OpenTelemetry ecosystem to the array. This is the recommended way to trace database calls, message queues, and other interactions. Remember to initialize them before requiring the target modules.

const { MongoDBInstrumentation } = require('@opentelemetry/instrumentation-mongodb');
const { RedisInstrumentation } = require('@opentelemetry/instrumentation-redis');

const tracesClient = await telemetryClient.newTracesClient({
  exporter: myExporter,
  instrumentations: [
    ...Instrumentation.CommonInstrumentations.express(), // Keep the default bundle
    new MongoDBInstrumentation(),
    new RedisInstrumentation(),
  ],
});

Manual Tracing

Manually create spans to add detail to your traces.

// Start a manual span
const span = tracesClient.startSpan('my-operation');

try {
  // Your business logic
  span.setAttributes({ 
    'my.attribute': 'value',
    'operation.type': 'data-processing'
  });
  
  // Record an event
  span.addEvent('processing-started', { 'items.count': 100 });
  
} catch (error) {
  span.recordException(error);
  span.setStatus({ code: 2, message: error.message }); // 2 = ERROR
  throw error;
} finally {
  span.end();
}

Metrics Example

To create metrics, use the option functions (WithDescription, WithUnit, WithBuckets) for configuration.

const { Metrics } = require('@vtex/diagnostics-nodejs');
const { WithDescription, WithUnit, WithBuckets } = Metrics;

// Create a counter
const requestCounter = metricsClient.createCounter('http_requests_total', [
  WithDescription('Total HTTP requests processed'),
  WithUnit('1')
]);

// Create a histogram with custom buckets
const responseTimeHistogram = metricsClient.createHistogram('response_time_seconds', [
  WithDescription('HTTP response time'),
  WithUnit('s'),
  WithBuckets([0.01, 0.05, 0.1, 0.5, 1, 5])
]);

// Usage
requestCounter.add(1, { method: 'GET', route: '/api/users' });
responseTimeHistogram.record(0.25, { method: 'POST', status: '200' });

Logging Example

// Log with different levels and structured attributes
logsClient.info('Application started', { 
  version: '1.0.0',
  environment: 'production',
});

logsClient.warn('Resource usage high', { 
  cpu: 0.85,
  memory: 0.72,
});

try {
  throw new Error('Database connection failed');
} catch (err) {
  logsClient.error('Operation failed', { 
    error: err.message,
    operation: 'database_connect'
  });
}

gRPC Configuration

This library exclusively uses gRPC to export OTLP data for better performance.

  • Never use http:// or https:// prefixes in gRPC endpoints.
  • Port 4317 is the standard for insecure gRPC (local development).
  • Port 443 automatically enables TLS for secure connections.
// Local Development
const config = Exporters.CreateTracesExporterConfig({
  endpoint: 'localhost:4317'
});

// Production with TLS
const config = Exporters.CreateTracesExporterConfig({
  endpoint: 'telemetry.your-domain.com:443'
});

Advanced Configuration

Resource Discovery

Customize resource attributes for all telemetry signals.

const telemetryClient = await NewTelemetryClient('my-service', 'my-service', {
  additionalAttrs: {
    'service.instance.id': process.env.HOSTNAME,
  },
  envMappings: [
    { envVar: 'REGION', attributeName: 'cloud.region' },
  ],
  disableCloudDetect: false,
  disableK8sDetect: false,
});

Sampling

Provide a custom sampling strategy for traces.

const { Samplers, Providers } = require('@vtex/diagnostics-nodejs');

const accountProvider = Providers.AccountProvider.newStaticProvider({
  defaultRate: 0.1, // 10%
  accounts: {
    'my-special-account': 1.0 // 100%
  }
});

const tracesClient = await telemetryClient.newTracesClient({
  exporter: myExporter,
  instrumentations: myInstrumentations,
  sampler: Samplers.TracesSamplers.newVtexAccountSampler(accountProvider),
});