Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ramgdev committed Feb 29, 2024
1 parent d460bda commit da76734
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions opentelemetry-otlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ futures-core = { workspace = true }
opentelemetry = { version = "0.22", default-features = false, path = "../opentelemetry" }
opentelemetry_sdk = { version = "0.22", default-features = false, path = "../opentelemetry-sdk" }
opentelemetry-http = { version = "0.11", path = "../opentelemetry-http", optional = true }
opentelemetry-proto = { version = "0.5", path = "../opentelemetry-proto", default-features = false, features=["with-serde"] }
opentelemetry-proto = { version = "0.5", path = "../opentelemetry-proto", default-features = false }
opentelemetry-semantic-conventions = { version = "0.14", path = "../opentelemetry-semantic-conventions" }

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

# test
integration-testing = ["tonic", "prost", "tokio/full", "trace"]
24 changes: 14 additions & 10 deletions opentelemetry-otlp/src/exporter/http/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,26 @@ impl SpanExporter for OtlpHttpClient {
#[cfg(any(feature = "http-proto", feature = "http-json"))]
fn build_body(spans: Vec<SpanData>) -> TraceResult<(Vec<u8>, &'static str)> {
use opentelemetry_proto::tonic::collector::trace::v1::ExportTraceServiceRequest;
use prost::Message;

use crate::{exporter::default_protocol, Protocol};

let req = ExportTraceServiceRequest {
resource_spans: spans.into_iter().map(Into::into).collect(),
};
let buf;
let ctype;
#[cfg(all(feature = "http-proto", not(feature = "http-json")))]{
use prost::Message;
buf = req.encode_to_vec();
ctype = "application/x-protobuf";
}
#[cfg(all(feature = "http-json", not(feature = "http-proto")))]{
let json_struct = serde_json::to_string_pretty(&req).unwrap();
buf = json_struct.into();
ctype = "application/json";
}
match default_protocol() {
Protocol::HttpJson => {
let json_struct = serde_json::to_string_pretty(&req).unwrap();
buf = json_struct.into();
ctype = "application/json";
},
_ => {
buf = req.encode_to_vec();
ctype = "application/x-protobuf";
},
};
Ok((buf, ctype))
}

Expand Down

0 comments on commit da76734

Please sign in to comment.