Skip to content

Conversation

@fbs
Copy link
Contributor

@fbs fbs commented Apr 29, 2025

This PR builds on #22957.

Once that is accepted I'll rebase this onto that. Opening this to show how the content-type handling from #22957 fits in.
This PR 'starts at' otel-proto: support json serialization

Summary

This adds JSON Protobuf encoding support to the open telemetry source. The PR has two main parts:

  1. adding JSON support to the types used. The implementation mostly stolen from opentelemetry-rust.
  2. selecting the right encoding for both request and reply based on the content-type header.

Change Type

  • Bug fix
  • New feature
  • Non-functional (chore, refactoring, docs)
  • Performance

Is this a breaking change?

  • Yes
  • No

How did you test this PR?

Both sending actual logs as well as with test cases

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.
  • No. A maintainer will apply the "no-changelog" label to this PR.

Notes

  • Please read our Vector contributor resources.
  • Do not hesitate to use @vectordotdev/vector to reach out to us regarding this PR.
  • The CI checks run only after we manually approve them.
    • We recommend adding a pre-push hook, please see this template.
    • Alternatively, we recommend running the following locally before pushing to the remote branch:
      • cargo fmt --all
      • cargo clippy --workspace --all-targets -- -D warnings
      • cargo nextest run --workspace (alternatively, you can run cargo test --all)
      • ./scripts/check_changelog_fragments.sh
  • After a review is requested, please avoid force pushes to help us review incrementally.
    • Feel free to push as many commits as you want. They will be squashed into one before merging.
    • For example, you can run git merge origin master and git push.
  • If this PR introduces changes Vector dependencies (modifies Cargo.lock), please
    run cargo vdev build licenses to regenerate the license inventory and commit the changes (if any). More details here.

References

#22940

TODO

[] make sure traces and metrics have a test

@fbs fbs requested a review from a team as a code owner April 29, 2025 22:38
@github-actions github-actions bot added the domain: sources Anything related to the Vector's sources label Apr 29, 2025
@@ -1,9 +1,100 @@
use std::io::Error;

// NOTE: Serde related attributes are copied from https://github.com/open-telemetry/opentelemetry-rust/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an issue wrt the CLA and licenses?

I initially started on an implementation and its ended up very similar (don't think tonic and serde offer an alternative way). Figured that copying it is easier as it makes it easier to sync if otel changes

Copy link
Contributor

@thomasqueirozb thomasqueirozb Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that if this file is copied from the elsewhere then their license needs to be pasted in there

@pront pront self-assigned this May 8, 2025
@pront pront force-pushed the master branch 4 times, most recently from 1720078 to ffe54be Compare July 10, 2025 15:43
@pront
Copy link
Member

pront commented Jul 11, 2025

Hi @fbs, I was going over open PRs. Are you still motivated to contribute this?

@pront pront added the meta: awaiting author Pull requests that are awaiting their author. label Jul 11, 2025
@fbs
Copy link
Contributor Author

fbs commented Jul 12, 2025

hi @pront , yes sorry for the delay. Not a lot of spare time these days.

I think this is good to go in once #22957 is in. I'm updating that one now

fbs added 11 commits July 12, 2025 13:42
This will allow us to support json in a later stage, as the content type
of the reply must match what the client used in the request.

This also improves error messages a bit, as its now a 415 instead of a
500. A 500 internal server error is quite confusing when debugging.
There is no error with the server, its the client sending the wrong
request.
This tests the expected behaviour of the Open Telemetry source wrt error
handling. Currently vector mostly sends 500 Internal Server errors,
which isnt that helpful when debugging. It also means some retryable
errors are not retried.

The source implementation is done in the next step, so all tests fail.
Reject and recover indicates that the current filter didn't match but
that others might[1]. This means reject is not the appropriate tool for
handling e.g. deserialization errors.

This commit migrates from rejection to returning the reply directly, and
at the same time updates it to the new status codes to make sure it
passes the new tests.

This change also makes it possible to support `application/json` in the
future. The `content-type` of the reply must match that of the request,
and as we now have access to the request headers we can make sure they
match.

[1]: seanmonstar/warp#388 (comment)
Opentelemtry allows both binary protobuf as well as JSON protobuf when
using the HTTP transport. This commit adds support.

The implementation is basically stolen from opentelemetry-rust[1], so all
go credits to them.

[1]: https://github.com/open-telemetry/opentelemetry-rust
This adds the ability to serialize, part of, Status to JSON.
The main usecase is to support Opentelemetry with HTTP/JSON and is thus
tailored to that.
As otel doesn't currently use 'detailed' that is skipped.
Seems like both are allowed, so we need to support it
@github-actions github-actions bot removed the meta: awaiting author Pull requests that are awaiting their author. label Jul 12, 2025
@thomasqueirozb
Copy link
Contributor

Hi @fbs I'll make this a draft and we can re-open it once the dependent PR gets merged

@thomasqueirozb thomasqueirozb marked this pull request as draft November 17, 2025 19:34
@pront
Copy link
Member

pront commented Nov 17, 2025

Note that protobuf codecs now have new options and we also provide native OTLP support (otlp codecs).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: sources Anything related to the Vector's sources

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants