Skip to content

Validate tonic can be used in blocking scenarios/non-tokio context #2402

Closed
@cijothomas

Description

Pre-req to #2386 which proposes to change default to use dedicated thread, and then make blocking calls to networking libraries.

However, tonic requires a tokio runtime to function.
But, based on our testing, it is seen that tonic client captures/stores the tokio runtime at creation time, and subsequently, gRPC methods can be called from non-tokio context as well (i.e from the normal std::thread)
See #2142 (comment)

Have done some tests to validate this behavior in separate repo:
https://github.com/cijothomas/async-explore/blob/main/src/client-no-tokio.rs

This issue is opened to validate that the above is valid, and add integration tests to validate it, and also add doc comments/examples/readme as relevant.

An example content in readme/doc:
When using OTLP with gRPC/tonic, provider(tracer/meter/logger) creation must be done in a tokio runtime, which is required for tonic for function. If your app uses tokio::main, then no further action required. Otherwise, ensure providers are created inside a tokio runtime.
Example: https://github.com/open-telemetry/opentelemetry-rust/tree/main/opentelemetry-otlp/examples/basic-otlp#basic-otlp-exporter-example

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions