OpenTelemetryJS Can’t sending LogRecord to Collector (wrong wireType = 1 for field TraceId)

I managed to have trace_id and span_id in the winston log:

{"level":"info","message":"foobar","span_id":"04f3b62138ee6786","trace_flags":"01","trace_id":"23da183fc69e3bbb3bfbcdbda4fb0ab3"}

but when I tried to send the log to OpenTelemetry Collector, it kept saying that

{"stack":"OTLPExporterError: Bad Requestn    at IncomingMessage.<anonymous> (/app/node_modules/@opentelemetry/otlp-exporter-base/build/src/platform/node/util.js:108:39)n    at IncomingMessage.emit (node:events:530:35)n    at endReadableNT (node:internal/streams/readable:1696:12)n    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)","message":"Bad Request","name":"OTLPExporterError","data":"bu0003u0012+proto: wrong wireType = 1 for field TraceId","code":"400"}

my code is here

const oapi = require('@opentelemetry/api');

const opentelemetry = require("@opentelemetry/sdk-node");
const logsAPI = require('@opentelemetry/api-logs');
const {
    LoggerProvider,
    SimpleLogRecordProcessor,
    ConsoleLogRecordExporter,
    BatchLogRecordProcessor,
} = require('@opentelemetry/sdk-logs');
const {
    PeriodicExportingMetricReader,
    ConsoleMetricExporter,
} = require('@opentelemetry/sdk-metrics');
const { PrometheusExporter } = require("@opentelemetry/exporter-prometheus");
const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-proto')
const { AsyncHooksContextManager } = require('@opentelemetry/context-async-hooks');

const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-proto');
const { OTLPLogExporter } = require('@opentelemetry/exporter-logs-otlp-proto');
const {
    getNodeAutoInstrumentations,
} = require("@opentelemetry/auto-instrumentations-node");
const { diag, DiagConsoleLogger, DiagLogLevel, } = require('@opentelemetry/api');

diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);
oapi.context.setGlobalContextManager(new AsyncHooksContextManager());

const JaegerGRPCOLTPUrl = 'http://otel-collector:4318/v1/traces';

const exporterOption = {
    url: JaegerGRPCOLTPUrl,
    concurrencyLimit: 1,
}
const traceExporter = new OTLPTraceExporter(exporterOption)

const metricReader = null;
// const metricReader = new PeriodicExportingMetricReader({
//   exporter: new OTLPMetricExporter({
//     url: JaegerGRPCOLTPUrl,
//   }),
// })

// To start a logger, you first need to initialize the Logger provider.
const loggerProvider = new LoggerProvider();
// Add a processor to export log record
loggerProvider.addLogRecordProcessor(
    new SimpleLogRecordProcessor(new OTLPLogExporter(exporterOption))
);
loggerProvider.addLogRecordProcessor(
    new SimpleLogRecordProcessor(new ConsoleLogRecordExporter())
);

logsAPI.logs.setGlobalLoggerProvider(loggerProvider);

let instrumentationList = getNodeAutoInstrumentations({
    '@opentelemetry/instrumentation-mongodb': {
        enabled: true,
        enhancedDatabaseReporting: true,
    },
})

// for (var i in instrumentationList) {
//   instrumentationList[i].setLoggerProvider(loggerProvider);
// }

const sdk = new opentelemetry.NodeSDK({
    // Optional - if omitted, the tracing SDK will be initialized from environment variables
    traceExporter: traceExporter,
    // Optional - If omitted, the metrics SDK will not be initialized
    metricReader: metricReader,
    // Optional - you can use the metapackage or load each instrumentation individually
    instrumentations: [instrumentationList],
});

sdk.start();

const winston = require('winston');
const tracer = oapi.trace.getTracer(
    'global-tracer',
    'v1.0.0',
);

const logger = winston.createLogger({
    level: 'debug',
    levels: winston.config.cli.levels,
    transports: [new winston.transports.Console()],
})

const span = tracer.startSpan('abc');
oapi.context.with(oapi.trace.setSpan(oapi.context.active(), span), () => {
    logger.info('foobar');
});

span.end();

and docker-compose:
otel-collector: image: otel/opentelemetry-collector:0.99.0 command: ["--config=/etc/otelcol-contrib/config.yaml"] container_name: otel-collector volumes: - ./otel-collector-config.yaml:/etc/otelcol-contrib/config.yaml ports: - 1888:1888 # pprof extension - 8888:8888 # Prometheus metrics exposed by the Collector - 8889:8889 # Prometheus exporter metrics - 13133:13133 # health_check extension - 4319:4317 # OTLP gRPC receiver - 4320:4318 # OTLP http receiver - 55679:55679 # zpages extension

my simplest otel config looks like this:
`
receivers:
nop:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318

processors:
batch:

exporters:
debug:
verbosity: detailed

otlp/jaeger:
endpoint: jaeger:4317
tls:
insecure: true

`

I expect that the request to otel-collector should be 200 and the log should be something like:
Span #0 Trace ID : f42436b7165138ee501737645d749036 Parent ID : ID : 3adb2919955383dc Name : GET

New contributor

Viet Ký Quoc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật