Skip to content

feat: observability layer#370

Merged
gregorydemay merged 17 commits intomainfrom
gdemay/XC-287-observability
Feb 25, 2025
Merged

feat: observability layer#370
gregorydemay merged 17 commits intomainfrom
gdemay/XC-287-observability

Conversation

@gregorydemay
Copy link
Contributor

@gregorydemay gregorydemay commented Feb 14, 2025

Follow-up on #364 to add a new observability layer to take care of logging and metrics. Unfortunately, tower_http::trace cannot be used in a canister environment because it measures call latency with Instant::now. The proposed layer, while inspired by tower_http::trace, is also simpler because it does not have to deal with streaming responses.

@gregorydemay gregorydemay marked this pull request as ready for review February 14, 2025 16:37
@gregorydemay gregorydemay requested a review from a team as a code owner February 14, 2025 16:37
Copy link
Contributor

@lpahlavi lpahlavi left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @gregorydemay! A few nits regarding mostly the documentation, but otherwise looks good! Had to wrap my head a bit around the number of generics but the end result is quite cool.

Copy link
Contributor Author

@gregorydemay gregorydemay left a comment

Choose a reason for hiding this comment

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

Thanks @lpahlavi for the review! Should be ready for another round.

Copy link
Contributor Author

@gregorydemay gregorydemay left a comment

Choose a reason for hiding this comment

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

Thanks @ninegua for the review! Should also be ready for a 2nd round

Copy link
Contributor

@lpahlavi lpahlavi left a comment

Choose a reason for hiding this comment

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

Thanks again for this PR @gregorydemay LGTM!

@gregorydemay gregorydemay merged commit bd02c54 into main Feb 25, 2025
10 checks passed
@gregorydemay gregorydemay deleted the gdemay/XC-287-observability branch February 25, 2025 08:29
gregorydemay added a commit that referenced this pull request Feb 28, 2025
Follow-up on #370 and #364 to add a conversion layer between request and
responses so that the caller only has to deal with types from the Rust
[`http`](https://crates.io/crates/http) crate. This has several
advantages from the caller's point of view:

1. Can re-use existing types like `Request::builder` or `StatusCode`.
2. Requests are automatically sanitized and canonicalized (e.g. header
names are validated and lower cased).
3. Can re-use existing middlewares, like from the
`[tower-http`](https://crates.io/crates/tower-http) crate, since many of
them require a client that uses the
[`http`](https://crates.io/crates/http) crate.
gregorydemay added a commit that referenced this pull request Mar 7, 2025
Follow-up on #370, #364, and #374 to add a conversion layer between
request and responses to handle [JSON
RPC](https://www.jsonrpc.org/specification) over HTTP.

Concretely:
1. Refactor existing infrastructure to handle errors explicitly, instead
of having to downcast `BoxError`. This is beneficial since errors may
happen at different layers and they all need to be handled by the above
observability layer, e.g., add the corresponding metric in case the
response has a non successful status.
2. Refactor existing infrastructure to transform request and response to
use a single `Convert` trait to convert one type into another with some
potential error.
3. Add a layer for `http::Request` and `http::Response` to transform
their body into a JSON RPC type. This uses the above `Convert` trait.
This conversion layer is behind a feature flag (`json`) since it
requires `serde_json` to handle the serialization/deserialization
4. Add a new layer to filter out non-successful HTTP responses.
@gregorydemay gregorydemay mentioned this pull request Mar 7, 2025
gregorydemay added a commit that referenced this pull request Mar 11, 2025
Follow-up on #370, #364, #374, and #375 to automatically retry requests
by doubling its `max_response_bytes` when the response was too big.
gregorydemay added a commit to dfinity/canhttp that referenced this pull request Jul 9, 2025
Follow-up on dfinity/evm-rpc-canister#364 to add a new observability layer to take care of
logging and metrics. Unfortunately,
[`tower_http::trace`](https://docs.rs/tower-http/latest/tower_http/trace/index.html)
cannot be used in a canister environment because it measures call
latency with `Instant::now`. The proposed layer, while inspired by
[`tower_http::trace`](https://docs.rs/tower-http/latest/tower_http/trace/index.html),
is also simpler because it does not have to deal with streaming
responses.

---------

Co-authored-by: Louis Pahlavi <louis.pahlavi@gmail.com>
gregorydemay added a commit to dfinity/canhttp that referenced this pull request Jul 9, 2025
Follow-up on dfinity/evm-rpc-canister#370 and dfinity/evm-rpc-canister#364 to add a conversion layer between request and
responses so that the caller only has to deal with types from the Rust
[`http`](https://crates.io/crates/http) crate. This has several
advantages from the caller's point of view:

1. Can re-use existing types like `Request::builder` or `StatusCode`.
2. Requests are automatically sanitized and canonicalized (e.g. header
names are validated and lower cased).
3. Can re-use existing middlewares, like from the
`[tower-http`](https://crates.io/crates/tower-http) crate, since many of
them require a client that uses the
[`http`](https://crates.io/crates/http) crate.
gregorydemay added a commit to dfinity/canhttp that referenced this pull request Jul 9, 2025
Follow-up on dfinity/evm-rpc-canister#370, dfinity/evm-rpc-canister#364, and dfinity/evm-rpc-canister#374 to add a conversion layer between
request and responses to handle [JSON
RPC](https://www.jsonrpc.org/specification) over HTTP.

Concretely:
1. Refactor existing infrastructure to handle errors explicitly, instead
of having to downcast `BoxError`. This is beneficial since errors may
happen at different layers and they all need to be handled by the above
observability layer, e.g., add the corresponding metric in case the
response has a non successful status.
2. Refactor existing infrastructure to transform request and response to
use a single `Convert` trait to convert one type into another with some
potential error.
3. Add a layer for `http::Request` and `http::Response` to transform
their body into a JSON RPC type. This uses the above `Convert` trait.
This conversion layer is behind a feature flag (`json`) since it
requires `serde_json` to handle the serialization/deserialization
4. Add a new layer to filter out non-successful HTTP responses.
gregorydemay added a commit to dfinity/canhttp that referenced this pull request Jul 9, 2025
Follow-up on dfinity/evm-rpc-canister#370, dfinity/evm-rpc-canister#364, dfinity/evm-rpc-canister#374, and dfinity/evm-rpc-canister#375 to automatically retry requests
by doubling its `max_response_bytes` when the response was too big.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants