Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
RazvanRotari opened this issue Jul 2, 2024 · 1 comment · Fixed by #1906
Closed

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

RazvanRotari opened this issue Jul 2, 2024 · 1 comment · Fixed by #1906
Labels
bug Something isn't working triage:todo Needs to be traiged.

Comments

@RazvanRotari
Copy link
Contributor

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
            },
          ]
        },
      ]
    }
  ]
}
@Dav1dde
Copy link

Dav1dde commented Jul 9, 2024

Can confirm a Span produced from the opentelemetry-proto Python library with an integer attribute fails to parse with the crate:

    protobuf_span = Span(
        trace_id=bytes.fromhex("89143b0763095bd9c9955e8175d1fb24"),
        span_id=bytes.fromhex("f0b809703e783d00"),
        parent_span_id=bytes.fromhex("f0f0f0abcdef1234"),
        name="my 3rd protobuf OTel span",
        start_time_unix_nano=int(start.timestamp() * 1e9),
        end_time_unix_nano=int(end.timestamp() * 1e9),
        attributes=[
            KeyValue(
                key="sentry.exclusive_time_nano",
                value=AnyValue(int_value=int(duration.total_seconds() * 1e9)),
            ),
        ],
    )
    scope_spans = ScopeSpans(spans=[protobuf_span])
    resource_spans = ResourceSpans(scope_spans=[scope_spans])
    traces_data = TracesData(resource_spans=[resource_spans])
    protobuf_payload = traces_data.SerializeToString()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage:todo Needs to be traiged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants