Skip to content

Commit

Permalink
Merge branch 'main' into self-diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb committed Jun 20, 2024
2 parents 2dbf4a6 + e0fb7fe commit 3631c8f
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 27 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ debug = 1
async-std = "1.10"
async-trait = "0.1"
bytes = "1"
criterion = "0.5"
futures-core = "0.3"
futures-executor = "0.3"
futures-util = { version = "0.3", default-features = false }
Expand All @@ -45,4 +46,4 @@ tokio-stream = "0.1.1"
tracing = { version = "0.1", default-features = false }
tracing-core = { version = "0.1", default-features = false }
tracing-subscriber = { version = "0.3", default-features = false }
url = { version = "2.2", default-features = false }
url = { version = "=2.5.0", default-features = false } #pinning the version supporting rustc 1.65
10 changes: 4 additions & 6 deletions examples/tracing-grpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ pub mod hello_world {
async fn greet() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
let tracer = global::tracer("example/client");
let span = tracer
.span_builder(String::from("Greeter/client"))
.span_builder("Greeter/client")
.with_kind(SpanKind::Client)
.with_attributes(vec![KeyValue::new("component", "grpc")])
.with_attributes([KeyValue::new("component", "grpc")])
.start(&tracer);
let cx = Context::current_with_span(span);
let mut client = GreeterClient::connect("http://[::1]:50051").await?;
Expand All @@ -75,10 +75,8 @@ async fn greet() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static
status_code.to_string()
}
};
cx.span().add_event(
"Got response!".to_string(),
vec![KeyValue::new("status", status)],
);
cx.span()
.add_event("Got response!", vec![KeyValue::new("status", status)]);

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/tracing-http-propagator/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async fn send_request(
.await?;

cx.span().add_event(
"Got response!".to_string(),
"Got response!",
vec![KeyValue::new("status", res.status().to_string())],
);

Expand Down
1 change: 0 additions & 1 deletion opentelemetry-appender-log/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ serde = { workspace = true, optional = true, features = ["std"] }
[features]
logs_level_enabled = ["opentelemetry/logs_level_enabled"]
with-serde = ["log/kv_serde", "serde"]
default = ["logs_level_enabled"]

[dev-dependencies]
opentelemetry_sdk = { path = "../opentelemetry-sdk", features = [ "testing", "logs_level_enabled" ] }
Expand Down
5 changes: 2 additions & 3 deletions opentelemetry-appender-tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ log = { workspace = true }
opentelemetry-stdout = { path = "../opentelemetry-stdout", features = ["logs"] }
opentelemetry_sdk = { path = "../opentelemetry-sdk", features = ["logs", "testing"] }
tracing-log = "0.2"
async-trait = "0.1"
criterion = "0.5.1"
async-trait = { workspace = true }
criterion = { workspace = true }

[features]
experimental_metadata_attributes = ["dep:tracing-log"]
logs_level_enabled = ["opentelemetry/logs_level_enabled"]
default = ["logs_level_enabled"]


[[bench]]
Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-otlp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ now use `.with_resource(RESOURCE::default())` to configure Resource when using
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.
- **Breaking** Correct the misspelling of "webkpi" to "webpki" in features [#1842](https://github.com/open-telemetry/opentelemetry-rust/pull/1842)
- Bump MSRV to 1.70 [#1840](https://github.com/open-telemetry/opentelemetry-rust/pull/1840)
- Fixing the OTLP HTTP/JSON exporter. [#1882](https://github.com/open-telemetry/opentelemetry-rust/pull/1882) - The exporter was broken in the
previous release.

## v0.16.0

Expand Down
9 changes: 3 additions & 6 deletions opentelemetry-otlp/examples/basic-otlp-http/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,15 @@ fn init_tracer_provider() -> Result<sdktrace::TracerProvider, TraceError> {
}

fn init_metrics() -> Result<opentelemetry_sdk::metrics::SdkMeterProvider, MetricsError> {
let provider = opentelemetry_otlp::new_pipeline()
opentelemetry_otlp::new_pipeline()
.metrics(opentelemetry_sdk::runtime::Tokio)
.with_exporter(
opentelemetry_otlp::new_exporter()
.http()
.with_endpoint("http://localhost:4318/v1/metrics"),
)
.with_resource(RESOURCE.clone())
.build();
match provider {
Ok(provider) => Ok(provider),
Err(err) => Err(err),
}
.build()
}

#[tokio::main]
Expand All @@ -85,6 +81,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
);

let meter_provider = result.unwrap();
global::set_meter_provider(meter_provider.clone());

// Opentelemetry will not provide a global API to manage the logger
// provider. Application users must manage the lifecycle of the logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,6 @@ fn span_eq(left: &Span, right: &Span) -> bool {
pub fn read_spans_from_json(file: File) -> Vec<ResourceSpans> {
let reader = std::io::BufReader::new(file);

let trace_data: TracesData = serde_json::from_reader(reader).unwrap();
let trace_data: TracesData = serde_json::from_reader(reader).expect("Failed to read json file");
trace_data.resource_spans
}
27 changes: 27 additions & 0 deletions opentelemetry-otlp/tests/integration_test/tests/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ use opentelemetry::{
trace::{TraceContextExt, Tracer},
Key, KeyValue,
};
use opentelemetry_proto::tonic::trace::v1::TracesData;
use opentelemetry_sdk::{runtime, trace as sdktrace, Resource};
use std::error::Error;
use std::fs::File;
use std::io::Write;
use std::os::unix::fs::MetadataExt;

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

TraceAsserter::new(spans.clone(), spans).assert();
}

#[test]
pub fn test_serde() {
let spans = read_spans_from_json(
File::open("./expected/traces.json").expect("Failed to read traces.json"),
);
let json = serde_json::to_string_pretty(&TracesData {
resource_spans: spans,
})
.expect("Failed to serialize spans to json");

// Write to file.
let mut file = File::create("./expected/serialized_traces.json").unwrap();
file.write_all(json.as_bytes()).unwrap();

let left = read_spans_from_json(
File::open("./expected/traces.json").expect("Failed to read traces.json"),
);
let right = read_spans_from_json(
File::open("./expected/serialized_traces.json")
.expect("Failed to read serialized_traces.json"),
);

TraceAsserter::new(left, right).assert();
}
2 changes: 1 addition & 1 deletion opentelemetry-proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ hex = { version = "0.4.3", optional = true }
tonic-build = { workspace = true }
prost-build = { workspace = true }
tempfile = "3.3.0"
serde_json = "1.0"
serde_json = { workspace = true }
22 changes: 17 additions & 5 deletions opentelemetry-proto/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,26 @@ pub(crate) mod serializers {

// AnyValue <-> KeyValue conversion
pub fn serialize_to_value<S>(value: &Option<AnyValue>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
where
S: Serializer,
{
// Serialize any_value::Value using its own implementation
// If value is None, it will be serialized as such
match value {
Some(any_value) => match &any_value.value {
Some(Value::IntValue(i)) => serialize_i64_to_string(i, serializer),
Some(Value::IntValue(i)) => {
// Attempt to create a struct to wrap the intValue
let mut state = match serializer.serialize_struct("Value", 1) {
Ok(s) => s,
Err(e) => return Err(e), // Handle the error or return it
};

// Attempt to serialize the intValue field
if let Err(e) = state.serialize_field("intValue", &i.to_string()) {
return Err(e); // Handle the error or return it
}

// Finalize the struct serialization
state.end()
},
Some(value) => value.serialize(serializer),
None => serializer.serialize_none(),
},
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] }
criterion = { workspace = true, features = ["html_reports"] }
temp-env = { workspace = true }

[target.'cfg(not(target_os = "windows"))'.dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ otel_unstable = []

[dev-dependencies]
opentelemetry_sdk = { path = "../opentelemetry-sdk", features = ["logs_level_enabled"]} # for documentation tests
criterion = { version = "0.3" }
criterion = { workspace = true }
rand = { workspace = true }

[[bench]]
Expand Down

0 comments on commit 3631c8f

Please sign in to comment.