Skip to content

Deserialization of metrics from OTLP output broken #2434

@scottgerring

Description

@scottgerring

Identified during #2432. Given this code:

    async fn test_roundtrip_example_data() -> Result<()> {
        let metrics_in = include_str!("../expected/metrics/test_u64_counter_meter.json");
        let metrics: MetricsData = serde_json::from_str(metrics_in)?;
        let metrics_out = serde_json::to_string(&metrics)?;

        println!("{:}", metrics_out);

        let metrics_in_json: Value = serde_json::from_str(metrics_in)?;
        let metrics_out_json: Value = serde_json::from_str(&metrics_out)?;

        assert_eq!(metrics_in_json, metrics_out_json);

        Ok(())
    }

And some sample data:

{
  "resourceMetrics": [
    {
      "resource": {
        "attributes": [
          {
            "key": "service.name",
            "value": {
              "stringValue": "metrics-integration-test"
            }
          }
        ]
      },
      "scopeMetrics": [
        {
          "scope": {
            "name": "test_u64_counter_meter"
          },
          "metrics": [
            {
              "name": "counter_u64",
              "sum": {
                "dataPoints": [
                  {
                    "attributes": [
                      {
                        "key": "mykey1",
                        "value": {
                          "stringValue": "myvalue1"
                        }
                      },
                      {
                        "key": "mykey2",
                        "value": {
                          "stringValue": "myvalue2"
                        }
                      }
                    ],
                    "startTimeUnixNano": "1734255506254812000",
                    "timeUnixNano": "1734255533415552000",
                    "asInt": "10"
                  }
                ],
                "aggregationTemporality": 2,
                "isMonotonic": true
              }
            }
          ]
        }
      ]
    }
  ]
}

The assertion fails:

  left: Object {"resourceMetrics": Array [Object {"resource": Object {"attributes": Array [Object {"key": String("service.name"), "value": Object {"stringValue": String("metrics-integration-test")}}]}, "scopeMetrics": Array [Object {"metrics": Array [Object {"name": String("counter_u64"), "sum": Object {"aggregationTemporality": Number(2), "dataPoints": Array [Object {"asInt": String("10"), "attributes": Array [Object {"key": String("mykey1"), "value": Object {"stringValue": String("myvalue1")}}, Object {"key": String("mykey2"), "value": Object {"stringValue": String("myvalue2")}}], "startTimeUnixNano": String("1734255506254812000"), "timeUnixNano": String("1734255533415552000")}], "isMonotonic": Bool(true)}}], "scope": Object {"name": String("test_u64_counter_meter")}}]}]}
 right: Object {"resourceMetrics": Array [Object {"resource": Object {"attributes": Array [Object {"key": String("service.name"), "value": Object {"stringValue": String("metrics-integration-test")}}], "droppedAttributesCount": Number(0)}, "schemaUrl": String(""), "scopeMetrics": Array [Object {"metrics": Array [Object {"description": String(""), "metadata": Array [], "name": String("counter_u64"), "sum": Object {"aggregationTemporality": Number(2), "dataPoints": Array [Object {"attributes": Array [Object {"key": String("mykey1"), "value": Object {"stringValue": String("myvalue1")}}, Object {"key": String("mykey2"), "value": Object {"stringValue": String("myvalue2")}}], "exemplars": Array [], "flags": Number(0), "startTimeUnixNano": String("1734255506254812000"), "timeUnixNano": String("1734255533415552000")}], "isMonotonic": Bool(true)}, "unit": String("")}], "schemaUrl": String(""), "scope": Object {"attributes": Array [], "droppedAttributesCount": Number(0), "name": String("test_u64_counter_meter"), "version": String("")}}]}]}

There's a bunch of things that are unimportant, but the asInt in dataPoints goes missing, and this is the metric value itself. Raising a separate issue as this feels like it could be a serde-and-protobuf-can-of-worms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions