Skip to content

Commit a8d4cde

Browse files
authored
Remove unnecessary string allocations from examples (open-telemetry#777)
1 parent a474268 commit a8d4cde

File tree

10 files changed

+21
-21
lines changed

10 files changed

+21
-21
lines changed

examples/basic-otlp-http/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
4040
let span = cx.span();
4141
span.set_attribute(LEMONS_KEY.string("five"));
4242

43-
span.add_event("Sub span event".to_string(), vec![]);
43+
span.add_event("Sub span event", vec![]);
4444
});
4545
});
4646

examples/basic-otlp-with-selector/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
142142
let span = cx.span();
143143
span.set_attribute(LEMONS_KEY.string("five"));
144144

145-
span.add_event("Sub span event".to_string(), vec![]);
145+
span.add_event("Sub span event", vec![]);
146146

147147
histogram.record(1.3);
148148
});

examples/basic-otlp/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
125125
let span = cx.span();
126126
span.set_attribute(LEMONS_KEY.string("five"));
127127

128-
span.add_event("Sub span event".to_string(), vec![]);
128+
span.add_event("Sub span event", vec![]);
129129

130130
histogram.record(1.3);
131131
});

examples/basic/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
9191
let span = cx.span();
9292
span.set_attribute(LEMONS_KEY.string("five"));
9393

94-
span.add_event("Sub span event".to_string(), vec![]);
94+
span.add_event("Sub span event", vec![]);
9595

9696
histogram.record(1.3);
9797
});

examples/dynatrace/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
170170
let span = cx.span();
171171
span.set_attribute(LEMONS_KEY.string("five"));
172172

173-
span.add_event("Sub span event".to_string(), vec![]);
173+
span.add_event("Sub span event", vec![]);
174174

175175
histogram.record(1.3);
176176
});

examples/external-otlp-grpcio-async-std/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use opentelemetry::{
1414
trace::{TraceContextExt, Tracer},
1515
Key,
1616
};
17-
use url::Url;
1817
use opentelemetry_otlp::WithExportConfig;
18+
use url::Url;
1919

2020
use std::{
2121
collections::HashMap,
@@ -67,7 +67,7 @@ fn init_tracer() -> Result<sdktrace::Tracer, TraceError> {
6767
.grpcio()
6868
.with_endpoint(grpcio_endpoint)
6969
.with_headers(headers)
70-
.with_tls(true)
70+
.with_tls(true),
7171
)
7272
.install_batch(opentelemetry::runtime::AsyncStd)
7373
}
@@ -96,7 +96,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
9696
let span = cx.span();
9797
span.set_attribute(LEMONS_KEY.string("five"));
9898

99-
span.add_event("Sub span event".to_string(), vec![]);
99+
span.add_event("Sub span event", vec![]);
100100
});
101101
});
102102

examples/external-otlp-tonic-tokio/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
9595
let span = cx.span();
9696
span.set_attribute(LEMONS_KEY.string("five"));
9797

98-
span.add_event("Sub span event".to_string(), vec![]);
98+
span.add_event("Sub span event", vec![]);
9999
});
100100
});
101101

examples/http/src/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async fn handle(req: Request<Body>) -> Result<Response<Body>, Infallible> {
1717
propagator.extract(&HeaderExtractor(req.headers()))
1818
});
1919
let mut span = global::tracer("example/server").start_with_context("hello", &parent_cx);
20-
span.add_event("handling this...".to_string(), Vec::new());
20+
span.add_event("handling this...", Vec::new());
2121

2222
Ok(Response::new("Hello, World!".into()))
2323
}

opentelemetry-api/src/trace/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ pub fn mark_span_as_active<T: crate::trace::Span + Send + Sync + 'static>(span:
326326
/// fn my_other_function() {
327327
/// // call methods on the current span from
328328
/// get_active_span(|span| {
329-
/// span.add_event("An event!".to_string(), vec![KeyValue::new("happened", true)]);
329+
/// span.add_event("An event!", vec![KeyValue::new("happened", true)]);
330330
/// })
331331
/// }
332332
/// ```

opentelemetry-sdk/src/trace/span.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,9 @@ mod tests {
309309
#[test]
310310
fn add_event() {
311311
let mut span = create_span();
312-
let name = "some_event".to_string();
312+
let name = "some_event";
313313
let attributes = vec![KeyValue::new("k", "v")];
314-
span.add_event(name.clone(), attributes.clone());
314+
span.add_event(name, attributes.clone());
315315
span.with_data(|data| {
316316
if let Some(event) = data.events.iter().next() {
317317
assert_eq!(event.name, name);
@@ -325,10 +325,10 @@ mod tests {
325325
#[test]
326326
fn add_event_with_timestamp() {
327327
let mut span = create_span();
328-
let name = "some_event".to_string();
328+
let name = "some_event";
329329
let attributes = vec![KeyValue::new("k", "v")];
330330
let timestamp = opentelemetry_api::time::now();
331-
span.add_event_with_timestamp(name.clone(), timestamp, attributes.clone());
331+
span.add_event_with_timestamp(name, timestamp, attributes.clone());
332332
span.with_data(|data| {
333333
if let Some(event) = data.events.iter().next() {
334334
assert_eq!(event.timestamp, timestamp);
@@ -411,8 +411,8 @@ mod tests {
411411
#[test]
412412
fn update_name() {
413413
let mut span = create_span();
414-
let name = "new_name".to_string();
415-
span.update_name(name.clone());
414+
let name = "new_name";
415+
span.update_name(name);
416416
span.with_data(|data| {
417417
assert_eq!(data.name, name);
418418
});
@@ -453,17 +453,17 @@ mod tests {
453453
let mut span = create_span();
454454
let initial = span.with_data(|data| data.clone()).unwrap();
455455
span.end();
456-
span.add_event("some_event".to_string(), vec![KeyValue::new("k", "v")]);
456+
span.add_event("some_event", vec![KeyValue::new("k", "v")]);
457457
span.add_event_with_timestamp(
458-
"some_event".to_string(),
458+
"some_event",
459459
opentelemetry_api::time::now(),
460460
vec![KeyValue::new("k", "v")],
461461
);
462462
let err = std::io::Error::from(std::io::ErrorKind::Other);
463463
span.record_error(&err);
464464
span.set_attribute(KeyValue::new("k", "v"));
465465
span.set_status(Status::error("ERROR"));
466-
span.update_name("new_name".to_string());
466+
span.update_name("new_name");
467467
span.with_data(|data| {
468468
assert_eq!(data.events, initial.events);
469469
assert_eq!(data.attributes, initial.attributes);
@@ -563,7 +563,7 @@ mod tests {
563563
let tracer = provider.tracer("test");
564564

565565
let mut span = tracer.start("test_span");
566-
span.add_event("test_event".to_string(), vec![]);
566+
span.add_event("test_event", vec![]);
567567
span.set_status(Status::error(""));
568568

569569
let exported_data = span.exported_data();

0 commit comments

Comments
 (0)