Skip to content

common::MakeAttributes creates garbled output for std::string #2651

@t-b

Description

@t-b

Describe your environment
OS: Debian bookworm
GCC: 12.2.0
Version: 054b0dc ([RELEASE] Release opentelemetry-cpp version 1.15.0 (#2639), 2024-04-21), also present in 1.11.0.

Steps to reproduce

  • Download patch to ostream test 0001-Show-error-with-garbled-output.zip
  • unzip 0001-Show-error-with-garbled-output.patch.zip
  • git am 0001-Show-error-with-garbled-output.patch
  • cmake -S . -B build -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_SHARED_LIBS=ON -DWITH_OTLP_GRPC=ON -DWITH_OTLP_HTTP=ON -DWITH_ABSEIL=ON -DWITH_BENCHMARK=OFF -DCMAKE_CXX_STANDARD=17
  • cmake --build build --target ostream_log_test && ctest --test-dir build -R IntegrationTestWithEventId --verbose

Outputs:

... 539: { 539: timestamp : 0 539: observed_timestamp : 1714407256398793342 539: severity_num : 5 539: severity_text : DEBUG 539: body : Hello {key1} {key2} 539: resource : 539: service.name: unknown_service 539: telemetry.sdk.version: 1.15.0 539: telemetry.sdk.name: opentelemetry 539: telemetry.sdk.language: cpp 539: attributes : 539: key2: �fA�U 539: 539: ��A����abcd 539: key1: 123 539: event_id : 12345678 539: event_name : test_event_id 539: trace_id : 00000000000000000000000000000000 539: span_id : 0000000000000000 539: trace_flags : 00 539: scope : 539: name : opentelelemtry_library 539: version : 1.15.0 539: schema_url : https://opentelemetry.io/schemas/1.11.0 539: attributes : 539: scope.attr.key: 123 539: } ... 

If I use the SimpleLogRecordProcessor there is no garbled output. And if I pass in a const char* via someString.c_str() and use the batched processor I also get garbled output.

What is the expected behavior?
That the strings I sent are outputted properly.

What is the actual behavior?
Garbled output.

Additional context
Add any other context about the problem here.

I would also be interested to know if the bug is limited to the ostream exporter or also applies to other exporters, we want tot use otlp with grpc and http in production.

This looks like a lifetime issue with regarding common::AttributeValue.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdo-not-staleissue:blockingThis issue is preventing other fixespriority:p1Issues that are blockingtriage/acceptedIndicates an issue or PR is ready to be actively worked on.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions