@@ -57,17 +57,33 @@ fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
57
57
Ok (())
58
58
}
59
59
```
60
+
61
+ ## Options
62
+
63
+ Multiple gRPC transport layers are available. [ ` tonic ` ] ( https://crates.io/crates/tonic ) is the default gRPC transport
64
+ layer and is enabled by default. [ ` grpcio ` ] ( https://crates.io/crates/grpcio ) is optional.
65
+
66
+ | gRPC transport layer | [ hyperium/tonic] ( https://github.com/hyperium/tonic ) | [ tikv/grpc-rs] ( https://github.com/tikv/grpc-rs ) |
67
+ | ---| ---| ---|
68
+ | Feature | --features=default | --features=grpc-sys |
69
+ | gRPC library | [ ` tonic ` ] ( https://crates.io/crates/tonic ) | [ ` grpcio ` ] ( https://crates.io/crates/grpcio ) |
70
+ | Transport | [ hyperium/hyper] ( https://github.com/hyperium/hyper ) (Rust) | [ grpc/grpc] ( https://github.com/grpc/grpc ) (C++ binding) |
71
+ | TLS support | yes | yes |
72
+ | TLS library | rustls | OpenSSL |
73
+ | TLS optional | yes | yes |
74
+ | Supported .proto generator | [ ` prost ` ] ( https://crates.io/crates/prost ) | [ ` prost ` ] ( https://crates.io/crates/prost ) , [ ` protobuf ` ] ( https://crates.io/crates/protobuf ) |
75
+
60
76
## Performance
61
77
62
78
For optimal performance, a batch exporter is recommended as the simple
63
- exporter will export each span synchronously on drop. You can enable the
64
- [ ` tokio ` ] or [ ` async-std ` ] features to have a batch exporter configured for
65
- you automatically for either executor when you install the pipeline.
79
+ exporter will export each span synchronously on drop. Enable a runtime
80
+ to have a batch exporter configured automatically for either executor
81
+ when using the pipeline.
66
82
67
83
``` toml
68
84
[dependencies ]
69
- opentelemetry = { version = " *" , features = [" tokio " ] }
70
- opentelemetry-otlp = " *"
85
+ opentelemetry = { version = " *" , features = [" async-std " ] }
86
+ opentelemetry-otlp = { version = " *" , features = [ " grpc-sys " ] }
71
87
```
72
88
73
89
[ `tokio` ] : https://tokio.rs
@@ -83,25 +99,31 @@ Example showing how to override all configuration options. See the
83
99
``` rust
84
100
use opentelemetry :: {KeyValue , Tracer };
85
101
use opentelemetry :: sdk :: {trace, IdGenerator , Resource , Sampler };
86
- use opentelemetry_otlp :: {Compression , Credentials , Protocol };
102
+ use opentelemetry_otlp :: {Protocol };
87
103
use std :: time :: Duration ;
104
+ use tonic :: {
105
+ metadata :: * ,
106
+ transport :: {Certificate , ClientTlsConfig },
107
+ };
88
108
89
109
fn main () -> Result <(), Box <dyn std :: error :: Error + Send + Sync + 'static >> {
90
- let headers = vec! [(" X-Custom" . to_string (), " Custom-Value" . to_string ())]
91
- . into_iter ()
92
- . collect ();
110
+ let cert = std :: fs :: read_to_string (" ca.pem" )? ;
111
+
112
+ let mut map = MetadataMap :: with_capacity (3 );
113
+
114
+ map . insert (" x-host" , " example.com" . parse (). unwrap ());
115
+ map . insert (" x-number" , " 123" . parse (). unwrap ());
116
+ map . insert_bin (" trace-proto-bin" , MetadataValue :: from_bytes (b " [binary data]" ));
93
117
94
118
let (tracer , _uninstall ) = opentelemetry_otlp :: new_pipeline ()
95
119
. with_endpoint (" localhost:55680" )
96
120
. with_protocol (Protocol :: Grpc )
97
- . with_headers (headers )
98
- . with_compression (Compression :: Gzip )
121
+ . with_metadata (map )
99
122
. with_timeout (Duration :: from_secs (3 ))
100
- . with_completion_queue_count (2 )
101
- . with_credentials (Credentials {
102
- cert : " tls.cert" . to_string (),
103
- key : " tls.key" . to_string (),
104
- })
123
+ . with_tls_config (ClientTlsConfig :: new ()
124
+ . ca_certificate (Certificate :: from_pem (& cert ))
125
+ . domain_name (" example.com" . to_string ())
126
+ )
105
127
. with_trace_config (
106
128
trace :: config ()
107
129
. with_default_sampler (Sampler :: AlwaysOn )
@@ -120,16 +142,3 @@ fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
120
142
Ok (())
121
143
}
122
144
```
123
-
124
- ## Feature flags
125
-
126
- By default ` opentelemetry-otlp ` uses ` boringssl ` for grpc crypto. You can switch
127
- this to use ` openssl ` by enabling the ` openssl ` feature:
128
-
129
- ``` toml
130
- [dependencies ]
131
- opentelemetry-otlp = { version = " *" , features = [" openssl" ] }
132
- ```
133
-
134
- If you would like to use a vendored ` openssl ` version, use the ` openssl-vendored ` feature.
135
- For more info, see https://github.com/tikv/grpc-rs#feature-openssl-and-openssl-vendored.
0 commit comments