opentelemetry-cpp icon indicating copy to clipboard operation
opentelemetry-cpp copied to clipboard

Asynchronous metric instruments ignoring attributes

Open duncanpo opened this issue 1 year ago • 1 comments

Describe your environment I am using Windows, and building with Visual Studio 2019

Steps to reproduce This issue can be reproduced by making some small changes to the "metrics_simple" example. Replace the file examples/common/metrics_foo_library/foo_library.cc with the attached version. The new file simply add some random attributes in the call to observe in the callback function. Build the example and run.

What is the expected behavior? I expect to see some random attributes in the output

What is the actual behavior? Attributes is always empty in the output

Additional context This issue seems to be introduced from commit cf5cdaa foo_library.cc.txt

duncanpo avatar Feb 23 '24 16:02 duncanpo

I should clarify, you can simply run the observable_counter part of the example as that is the only relevant part: metrics_ostream_example.exe observable_counter

duncanpo avatar Feb 23 '24 18:02 duncanpo

@duncanpo I am sure I am doing something wrong, as multiple people have reported it. I just used the attached foo_library, and can see the attributes getting generated:

./metrics_ostream_example observable_counter
{
  scope name    : ostream_metric_example
  schema url    :
  version       : 1.2.0
  start time    : Mon Feb 26 22:34:42 2024
  end time      : Mon Feb 26 22:34:43 2024
  instrument name       : ostream_metric_example_observable_counter
  description   :
  unit          :
  type          : SumPointData
  value         : 4.1
  attributes            :
        key2: value2
        key3: value3
  resources     :
        service.name: unknown_service
        telemetry.sdk.language: cpp
        telemetry.sdk.name: opentelemetry
        telemetry.sdk.version: 1.13.0
}
{
  scope name    : ostream_metric_example
  schema url    :
  version       : 1.2.0
  start time    : Mon Feb 26 22:34:42 2024
  end time      : Mon Feb 26 22:34:44 2024
  instrument name       : ostream_metric_example_observable_counter
  description   :
  unit          :
  type          : SumPointData
  value         : 4.1
  attributes            :
        key2: value2
        key3: value3
  type          : SumPointData
  value         : 5.2
  attributes            :
        key2: value2
        key4: value4
  resources     :
        service.name: unknown_service
        telemetry.sdk.language: cpp
        telemetry.sdk.name: opentelemetry
        telemetry.sdk.version: 1.13.0
}

Any idea what is expected here?

lalitb avatar Feb 26 '24 22:02 lalitb

Ah please ignore - the telemetry.sdk.version is 1.13.0 in my output above, seems somehow old sdk is getting used for me. Let me check further.

lalitb avatar Feb 26 '24 23:02 lalitb

@lalitb, this is what I see when I am running from commit cf5cdaa

{ scope name : ostream_metric_example schema url : version : 1.2.0 start time : Tue Feb 27 02:46:55 2024 end time : Tue Feb 27 02:47:04 2024 instrument name : ostream_metric_example_observable_counter description : unit : type : SumPointData value : 30 attributes : resources : service.name: unknown_service telemetry.sdk.language: cpp telemetry.sdk.name: opentelemetry telemetry.sdk.version: 1.13.0 } { scope name : ostream_metric_example schema url : version : 1.2.0 start time : Tue Feb 27 02:46:55 2024 end time : Tue Feb 27 02:47:05 2024 instrument name : ostream_metric_example_observable_counter description : unit : type : SumPointData value : 33.1 attributes : resources : service.name: unknown_service telemetry.sdk.language: cpp telemetry.sdk.name: opentelemetry telemetry.sdk.version: 1.13.0 }

duncanpo avatar Feb 27 '24 02:02 duncanpo

And what I see running out of commit d32f960

{ scope name : ostream_metric_example schema url : version : 1.2.0 start time : Tue Feb 27 03:20:08 2024 end time : Tue Feb 27 03:20:08 2024 instrument name : ostream_metric_example_observable_counter description : unit : type : SumPointData value : 2.1 attributes : key3: value3 key4: value4 resources : service.name: unknown_service telemetry.sdk.language: cpp telemetry.sdk.name: opentelemetry telemetry.sdk.version: 1.13.0 }

duncanpo avatar Feb 27 '24 03:02 duncanpo