Skip to content

Commit da76734

Browse files
committed
address review comments
1 parent d460bda commit da76734

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

opentelemetry-otlp/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ futures-core = { workspace = true }
3131
opentelemetry = { version = "0.22", default-features = false, path = "../opentelemetry" }
3232
opentelemetry_sdk = { version = "0.22", default-features = false, path = "../opentelemetry-sdk" }
3333
opentelemetry-http = { version = "0.11", path = "../opentelemetry-http", optional = true }
34-
opentelemetry-proto = { version = "0.5", path = "../opentelemetry-proto", default-features = false, features=["with-serde"] }
34+
opentelemetry-proto = { version = "0.5", path = "../opentelemetry-proto", default-features = false }
3535
opentelemetry-semantic-conventions = { version = "0.14", path = "../opentelemetry-semantic-conventions" }
3636

3737
prost = { workspace = true, optional = true }
@@ -75,7 +75,7 @@ reqwest-blocking-client = ["reqwest/blocking", "opentelemetry-http/reqwest"]
7575
reqwest-client = ["reqwest", "opentelemetry-http/reqwest"]
7676
reqwest-rustls = ["reqwest", "reqwest/rustls-tls-native-roots"]
7777
# http json
78-
http-json = ["serde_json", "prost", "opentelemetry-http", "opentelemetry-proto/gen-tonic-messages", "http", "trace", "metrics"]
78+
http-json = ["serde_json", "prost", "opentelemetry-http", "opentelemetry-proto/gen-tonic-messages", "opentelemetry-proto/with-serde", "http", "trace", "metrics"]
7979

8080
# test
8181
integration-testing = ["tonic", "prost", "tokio/full", "trace"]

opentelemetry-otlp/src/exporter/http/trace.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,26 @@ impl SpanExporter for OtlpHttpClient {
7171
#[cfg(any(feature = "http-proto", feature = "http-json"))]
7272
fn build_body(spans: Vec<SpanData>) -> TraceResult<(Vec<u8>, &'static str)> {
7373
use opentelemetry_proto::tonic::collector::trace::v1::ExportTraceServiceRequest;
74+
use prost::Message;
75+
76+
use crate::{exporter::default_protocol, Protocol};
7477

7578
let req = ExportTraceServiceRequest {
7679
resource_spans: spans.into_iter().map(Into::into).collect(),
7780
};
7881
let buf;
7982
let ctype;
80-
#[cfg(all(feature = "http-proto", not(feature = "http-json")))]{
81-
use prost::Message;
82-
buf = req.encode_to_vec();
83-
ctype = "application/x-protobuf";
84-
}
85-
#[cfg(all(feature = "http-json", not(feature = "http-proto")))]{
86-
let json_struct = serde_json::to_string_pretty(&req).unwrap();
87-
buf = json_struct.into();
88-
ctype = "application/json";
89-
}
83+
match default_protocol() {
84+
Protocol::HttpJson => {
85+
let json_struct = serde_json::to_string_pretty(&req).unwrap();
86+
buf = json_struct.into();
87+
ctype = "application/json";
88+
},
89+
_ => {
90+
buf = req.encode_to_vec();
91+
ctype = "application/x-protobuf";
92+
},
93+
};
9094
Ok((buf, ctype))
9195
}
9296

0 commit comments

Comments
 (0)