OpenTelemetry SDK
    Preparing search index...

    Module @opentelemetry/exporter-logs-otlp-http

    OpenTelemetry Collector Logs Exporter for web and node with HTTP

    NPM Published Version Apache License

    Note: This is an experimental package under active development. New releases may include breaking changes.

    This module provides a logs-exporter for OTLP (http/json) using protocol version v1.7.0.

    npm install --save @opentelemetry/exporter-logs-otlp-http
    

    This exporter uses the shared HTTP options documented in @opentelemetry/otlp-exporter-base. That includes url, headers, timeoutMillis, concurrencyLimit, and Node.js options such as compression, keepAlive, httpAgentOptions, and userAgent.

    To see documentation and sample code for the traces exporter, as well as instructions for using TLS, visit the Collector Trace Exporter for web and node. To see documentation and sample code for the metric exporter, see the exporter-metrics-otlp-grpc package

    The OTLPLogExporter in Web expects the endpoint to end in /v1/logs.

    import { SeverityNumber } from '@opentelemetry/api-logs';
    import {
    LoggerProvider,
    BatchLogRecordProcessor,
    } from '@opentelemetry/sdk-logs';
    import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http';

    // exporter options. see all options in OTLPExporterConfigBase
    const collectorOptions = {
    url: '<opentelemetry-collector-url>', // url is optional and can be omitted - default is http://localhost:4318/v1/logs
    headers: {}, // an optional object containing custom headers to be sent with each request
    concurrencyLimit: 1, // an optional limit on pending requests
    };
    const logExporter = new OTLPLogExporter(collectorOptions);
    const loggerProvider = new LoggerProvider({
    processors: [new BatchLogRecordProcessor({ exporter: logExporter })]
    });

    const logger = loggerProvider.getLogger('default', '1.0.0');
    // Emit a log
    logger.emit({
    severityNumber: SeverityNumber.INFO,
    severityText: 'info',
    body: 'this is a log body',
    attributes: { 'log.type': 'custom' },
    });
    import {