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

[Bug]: Fail to deserialize JSON request from opentelemetry-js

Open RazvanRotari opened this issue 7 months ago • 0 comments

What happened?

I'm writing my own collector using the structs from opentelemetry-proto crate, and observed that requests from opentelemetry-js in JSON format cannot be deserialized using serde because they use a number instead of a string in the intValue field of AnyValue.

invalid type: integer `5893`, expected a string at line 1 column 1216

One affected field is resourceSpans::scopeSpans::spans::attributes::key == 'http.response_content_length'

{
                  "key": "http.response_content_length",
                  "value": {
                    "intValue": 5893
                  }
                },

The deserialization from string happens here: https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry-proto/src/proto.rs#L106

The JSON Mapping guide from protobuf says that int64 should be encoded as a string, but either numbers or strings are accepted..

API Version

opentelemetry-proto 0.6.0

SDK Version

N/A

What Exporter(s) are you seeing the problem on?

No response

Relevant log output

Request from `frontend-web` service in opentelemetry-demo
{
  "resourceSpans": [
    {
      "resource": {
        "attributes": [
          {
            "key": "service.name",
            "value": {
              "stringValue": "frontend-web"
            }
          },
          {
            "key": "telemetry.sdk.language",
            "value": {
              "stringValue": "webjs"
            }
          },
          {
            "key": "telemetry.sdk.name",
            "value": {
              "stringValue": "opentelemetry"
            }
          },
          {
            "key": "telemetry.sdk.version",
            "value": {
              "stringValue": "1.24.1"
            }
          },
          {
            "key": "process.runtime.name",
            "value": {
              "stringValue": "browser"
            }
          },
          {
            "key": "process.runtime.description",
            "value": {
              "stringValue": "Web Browser"
            }
          },
          {
            "key": "process.runtime.version",
            "value": {
              "stringValue": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/120.0.6099.28 Safari/537.36"
            }
          }
        ],
        "droppedAttributesCount": 0
      },
      "scopeSpans": [
        {
          "scope": {
            "name": "@opentelemetry/instrumentation-document-load",
            "version": "0.38.0"
          },
          "spans": [
            {
              "traceId": "66c78e2721e8c66c7bcfb5cdc7d62aa2",
              "spanId": "daeaa114dfead3cb",
              "parentSpanId": "c33dd183922cb954",
              "name": "documentFetch",
              "kind": 1,
              "startTimeUnixNano": "1719910708138899903",
              "endTimeUnixNano": "1719910708154599903",
              "attributes": [
                {
                  "key": "session.id",
                  "value": {
                    "stringValue": "43b5e140-cedd-4b54-834a-f6d258816cd2"
                  }
                },
                {
                  "key": "http.url",
                  "value": {
                    "stringValue": "http://frontend-proxy:8080/"
                  }
                },
                {
                  "key": "http.response_content_length",
                  "value": {
                    "intValue": 5893
                  }
                },
                {
                  "key": "http.response_content_length_uncompressed",
                  "value": {
                    "intValue": 74421
                  }
                }
              ],
              "droppedAttributesCount": 0,
              "events": [],
              "droppedEventsCount": 0,
              "status": {
                "code": 0
              },
              "links": [],
              "droppedLinksCount": 0
            },
          ]
        },
      ]
    }
  ]
}

RazvanRotari avatar Jul 02 '24 09:07 RazvanRotari