Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3191d5d

Browse files
authoredJun 19, 2024··
Merge branch 'main' into main
2 parents 9bd6162 + e0fb7fe commit 3191d5d

File tree

6 files changed

+52
-13
lines changed

6 files changed

+52
-13
lines changed
 

‎examples/tracing-grpc/src/client.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ pub mod hello_world {
5050
async fn greet() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
5151
let tracer = global::tracer("example/client");
5252
let span = tracer
53-
.span_builder(String::from("Greeter/client"))
53+
.span_builder("Greeter/client")
5454
.with_kind(SpanKind::Client)
55-
.with_attributes(vec![KeyValue::new("component", "grpc")])
55+
.with_attributes([KeyValue::new("component", "grpc")])
5656
.start(&tracer);
5757
let cx = Context::current_with_span(span);
5858
let mut client = GreeterClient::connect("http://[::1]:50051").await?;
@@ -75,10 +75,8 @@ async fn greet() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static
7575
status_code.to_string()
7676
}
7777
};
78-
cx.span().add_event(
79-
"Got response!".to_string(),
80-
vec![KeyValue::new("status", status)],
81-
);
78+
cx.span()
79+
.add_event("Got response!", vec![KeyValue::new("status", status)]);
8280

8381
Ok(())
8482
}

‎examples/tracing-http-propagator/src/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async fn send_request(
4141
.await?;
4242

4343
cx.span().add_event(
44-
"Got response!".to_string(),
44+
"Got response!",
4545
vec![KeyValue::new("status", res.status().to_string())],
4646
);
4747

‎opentelemetry-otlp/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ now use `.with_resource(RESOURCE::default())` to configure Resource when using
1616
These methods would also no longer set the global tracer provider. It would now be the responsibility of users to set it by calling `global::set_tracer_provider(tracer_provider.clone());`. Refer to the [basic-otlp](https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry-otlp/examples/basic-otlp/src/main.rs) and [basic-otlp-http](https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs) examples on how to initialize OTLP Trace Exporter.
1717
- **Breaking** Correct the misspelling of "webkpi" to "webpki" in features [#1842](https://github.com/open-telemetry/opentelemetry-rust/pull/1842)
1818
- Bump MSRV to 1.70 [#1840](https://github.com/open-telemetry/opentelemetry-rust/pull/1840)
19+
- Fixing the OTLP HTTP/JSON exporter. [#1882](https://github.com/open-telemetry/opentelemetry-rust/pull/1882) - The exporter was broken in the
20+
previous release.
1921

2022
## v0.16.0
2123

‎opentelemetry-otlp/tests/integration_test/src/trace_asserter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,6 @@ fn span_eq(left: &Span, right: &Span) -> bool {
216216
pub fn read_spans_from_json(file: File) -> Vec<ResourceSpans> {
217217
let reader = std::io::BufReader::new(file);
218218

219-
let trace_data: TracesData = serde_json::from_reader(reader).unwrap();
219+
let trace_data: TracesData = serde_json::from_reader(reader).expect("Failed to read json file");
220220
trace_data.resource_spans
221221
}

‎opentelemetry-otlp/tests/integration_test/tests/traces.rs

+27
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ use opentelemetry::{
88
trace::{TraceContextExt, Tracer},
99
Key, KeyValue,
1010
};
11+
use opentelemetry_proto::tonic::trace::v1::TracesData;
1112
use opentelemetry_sdk::{runtime, trace as sdktrace, Resource};
1213
use std::error::Error;
1314
use std::fs::File;
15+
use std::io::Write;
1416
use std::os::unix::fs::MetadataExt;
1517

1618
fn init_tracer_provider() -> Result<sdktrace::TracerProvider, TraceError> {
@@ -83,3 +85,28 @@ pub fn test_assert_span_eq() {
8385

8486
TraceAsserter::new(spans.clone(), spans).assert();
8587
}
88+
89+
#[test]
90+
pub fn test_serde() {
91+
let spans = read_spans_from_json(
92+
File::open("./expected/traces.json").expect("Failed to read traces.json"),
93+
);
94+
let json = serde_json::to_string_pretty(&TracesData {
95+
resource_spans: spans,
96+
})
97+
.expect("Failed to serialize spans to json");
98+
99+
// Write to file.
100+
let mut file = File::create("./expected/serialized_traces.json").unwrap();
101+
file.write_all(json.as_bytes()).unwrap();
102+
103+
let left = read_spans_from_json(
104+
File::open("./expected/traces.json").expect("Failed to read traces.json"),
105+
);
106+
let right = read_spans_from_json(
107+
File::open("./expected/serialized_traces.json")
108+
.expect("Failed to read serialized_traces.json"),
109+
);
110+
111+
TraceAsserter::new(left, right).assert();
112+
}

‎opentelemetry-proto/src/proto.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,26 @@ pub(crate) mod serializers {
4646

4747
// AnyValue <-> KeyValue conversion
4848
pub fn serialize_to_value<S>(value: &Option<AnyValue>, serializer: S) -> Result<S::Ok, S::Error>
49-
where
50-
S: Serializer,
49+
where
50+
S: Serializer,
5151
{
52-
// Serialize any_value::Value using its own implementation
53-
// If value is None, it will be serialized as such
5452
match value {
5553
Some(any_value) => match &any_value.value {
56-
Some(Value::IntValue(i)) => serialize_i64_to_string(i, serializer),
54+
Some(Value::IntValue(i)) => {
55+
// Attempt to create a struct to wrap the intValue
56+
let mut state = match serializer.serialize_struct("Value", 1) {
57+
Ok(s) => s,
58+
Err(e) => return Err(e), // Handle the error or return it
59+
};
60+
61+
// Attempt to serialize the intValue field
62+
if let Err(e) = state.serialize_field("intValue", &i.to_string()) {
63+
return Err(e); // Handle the error or return it
64+
}
65+
66+
// Finalize the struct serialization
67+
state.end()
68+
},
5769
Some(value) => value.serialize(serializer),
5870
None => serializer.serialize_none(),
5971
},

0 commit comments

Comments
 (0)
Please sign in to comment.