Skip to content

Commit 897291a

Browse files
authored
Merge pull request #44 from frigus02/update-opentelemetry
Update to opentelemetry 0.17
2 parents 0c19cf5 + a503ee2 commit 897291a

File tree

8 files changed

+25
-59
lines changed

8 files changed

+25
-59
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
- Upgrade to `v0.17.0` of `opentelemetry`.
11+
1012
## [0.18.0] - 2021-09-12
1113

1214
- Add support for metrics.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ bytes = "1"
3636
chrono = "0.4"
3737
http = "0.2"
3838
once_cell = "1"
39-
opentelemetry = "0.16"
40-
opentelemetry-http = "0.5"
41-
opentelemetry-semantic-conventions = "0.8"
39+
opentelemetry = "0.17"
40+
opentelemetry-http = "0.6"
41+
opentelemetry-semantic-conventions = "0.9"
4242
reqwest = { version = "0.11", default-features = false, features = ["blocking"], optional = true }
4343
serde = { version = "1", features = ["derive"] }
4444
serde_json = "1"
@@ -50,7 +50,7 @@ async-std = { version = "1.9.0", features = ["attributes"] }
5050
backtrace = "0.3.60"
5151
doc-comment = "0.3.3"
5252
env_logger = "0.9.0"
53-
opentelemetry = { version = "0.16", features = ["rt-tokio"] }
53+
opentelemetry = { version = "0.17", features = ["rt-tokio"] }
5454
opentelemetry-application-insights = { path = ".", features = ["reqwest-client", "reqwest-blocking-client"] }
5555
rand = "0.8.4"
5656
surf = "2.2.0"

examples/attributes.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn main() {
3838
])),
3939
)
4040
.build_simple();
41-
let client_tracer = client_provider.tracer("example-attributes", None);
41+
let client_tracer = client_provider.tracer("example-attributes");
4242

4343
let server_provider = opentelemetry_application_insights::new_pipeline(instrumentation_key)
4444
.with_client(reqwest::blocking::Client::new())
@@ -49,7 +49,7 @@ fn main() {
4949
])),
5050
)
5151
.build_simple();
52-
let server_tracer = server_provider.tracer("example-attributes", None);
52+
let server_tracer = server_provider.tracer("example-attributes");
5353

5454
// An HTTP client make a request
5555
let span = client_tracer
@@ -74,9 +74,8 @@ fn main() {
7474
KeyValue::new("net.peer.ip", "10.1.2.3"),
7575
KeyValue::new("http.target", "/hello/world?name=marry"),
7676
KeyValue::new("http.status_code", "200"),
77-
])
78-
.with_parent_context(cx);
79-
let span = server_tracer.build(builder);
77+
]);
78+
let span = server_tracer.build_with_context(builder, &cx);
8079
server_tracer.with_span(span, |_cx| {
8180
log();
8281
exception();

examples/opentelemetry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ async fn spawn_child_process(process_name: &str) {
5555
async fn run_in_child_process() {
5656
let tracer = global::tracer("run_in_child_process");
5757
let mut span = tracer.start("run_in_child_process");
58-
span.add_event("leaf fn".into(), vec![]);
58+
span.add_event("leaf fn", vec![]);
5959
sleep(Duration::from_millis(50)).await
6060
}
6161

src/convert.rs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
11
use crate::models::Properties;
22
use chrono::{DateTime, SecondsFormat, Utc};
3-
use opentelemetry::{
4-
sdk::{trace::EvictedHashMap, Resource},
5-
trace::{SpanId, TraceId},
6-
};
3+
use opentelemetry::sdk::{trace::EvictedHashMap, Resource};
74
use std::time::{Duration, SystemTime};
85

9-
pub(crate) fn trace_id_to_string(trace_id: TraceId) -> String {
10-
format!("{:032x}", trace_id.to_u128())
11-
}
12-
13-
pub(crate) fn span_id_to_string(span_id: SpanId) -> String {
14-
format!("{:016x}", span_id.to_u64())
15-
}
16-
176
pub(crate) fn duration_to_string(duration: Duration) -> String {
187
let micros = duration.as_micros();
198
let s = micros / 1_000_000 % 60;
@@ -55,20 +44,6 @@ mod tests {
5544
use super::*;
5645
use test_case::test_case;
5746

58-
#[test_case(TraceId::invalid(), "00000000000000000000000000000000" ; "zero")]
59-
#[test_case(TraceId::from_u128(314), "0000000000000000000000000000013a" ; "some number")]
60-
#[test_case(TraceId::from_u128(u128::MAX), "ffffffffffffffffffffffffffffffff" ; "max")]
61-
fn trace_id(id: TraceId, expected: &'static str) {
62-
assert_eq!(expected.to_string(), trace_id_to_string(id));
63-
}
64-
65-
#[test_case(SpanId::invalid(), "0000000000000000" ; "zero")]
66-
#[test_case(SpanId::from_u64(314), "000000000000013a" ; "some number")]
67-
#[test_case(SpanId::from_u64(u64::MAX), "ffffffffffffffff" ; "max")]
68-
fn span_id(id: SpanId, expected: &'static str) {
69-
assert_eq!(expected.to_string(), span_id_to_string(id));
70-
}
71-
7247
#[test_case(Duration::from_micros(123456789123), "1.10:17:36.789123" ; "all")]
7348
fn duration(duration: Duration, expected: &'static str) {
7449
assert_eq!(expected.to_string(), duration_to_string(duration));

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,10 @@ where
430430
/// that.
431431
pub fn install_simple(self) -> sdk::trace::Tracer {
432432
let trace_provider = self.build_simple();
433-
let tracer = trace_provider.tracer(
433+
let tracer = trace_provider.versioned_tracer(
434434
"opentelemetry-application-insights",
435435
Some(env!("CARGO_PKG_VERSION")),
436+
None,
436437
);
437438
let _previous_provider = global::set_tracer_provider(trace_provider);
438439
tracer
@@ -444,9 +445,10 @@ where
444445
/// that.
445446
pub fn install_batch<R: TraceRuntime>(self, runtime: R) -> sdk::trace::Tracer {
446447
let trace_provider = self.build_batch(runtime);
447-
let tracer = trace_provider.tracer(
448+
let tracer = trace_provider.versioned_tracer(
448449
"opentelemetry-application-insights",
449450
Some(env!("CARGO_PKG_VERSION")),
451+
None,
450452
);
451453
let _previous_provider = global::set_tracer_provider(trace_provider);
452454
tracer

src/tags.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use crate::{
2-
convert::{span_id_to_string, trace_id_to_string},
3-
models::context_tag_keys::{self as tags, Tags, TAG_KEY_LOOKUP},
4-
};
1+
use crate::models::context_tag_keys::{self as tags, Tags, TAG_KEY_LOOKUP};
52
#[cfg(feature = "metrics")]
63
use opentelemetry::sdk::export::metrics::Record;
74
use opentelemetry::{
@@ -20,15 +17,9 @@ pub(crate) fn get_tags_for_span(span: &SpanData) -> Tags {
2017
};
2118

2219
// Set the operation id and operation parent id.
23-
tags.insert(
24-
tags::OPERATION_ID,
25-
trace_id_to_string(span.span_context.trace_id()),
26-
);
27-
if span.parent_span_id != SpanId::invalid() {
28-
tags.insert(
29-
tags::OPERATION_PARENT_ID,
30-
span_id_to_string(span.parent_span_id),
31-
);
20+
tags.insert(tags::OPERATION_ID, span.span_context.trace_id().to_string());
21+
if span.parent_span_id != SpanId::INVALID {
22+
tags.insert(tags::OPERATION_PARENT_ID, span.parent_span_id.to_string());
3223
}
3324

3425
// Ensure the name of the operation is `METHOD /the/route/path`.
@@ -48,13 +39,10 @@ pub(crate) fn get_tags_for_span(span: &SpanData) -> Tags {
4839

4940
pub(crate) fn get_tags_for_event(span: &SpanData) -> Tags {
5041
let mut tags = Tags::new();
51-
tags.insert(
52-
tags::OPERATION_ID,
53-
trace_id_to_string(span.span_context.trace_id()),
54-
);
42+
tags.insert(tags::OPERATION_ID, span.span_context.trace_id().to_string());
5543
tags.insert(
5644
tags::OPERATION_PARENT_ID,
57-
span_id_to_string(span.span_context.span_id()),
45+
span.span_context.span_id().to_string(),
5846
);
5947
tags
6048
}

src/trace.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
convert::{attrs_to_properties, duration_to_string, span_id_to_string, time_to_string},
2+
convert::{attrs_to_properties, duration_to_string, time_to_string},
33
models::{
44
Data, Envelope, ExceptionData, ExceptionDetails, LimitedLenString1024, MessageData,
55
Properties, RemoteDependencyData, RequestData,
@@ -96,7 +96,7 @@ impl From<&SpanData> for RequestData {
9696
fn from(span: &SpanData) -> RequestData {
9797
let mut data = RequestData {
9898
ver: 2,
99-
id: span_id_to_string(span.span_context.span_id()).into(),
99+
id: span.span_context.span_id().to_string().into(),
100100
name: Some(LimitedLenString1024::from(span.name.clone()))
101101
.filter(|x| !x.as_ref().is_empty()),
102102
duration: duration_to_string(
@@ -158,7 +158,7 @@ impl From<&SpanData> for RemoteDependencyData {
158158
fn from(span: &SpanData) -> RemoteDependencyData {
159159
let mut data = RemoteDependencyData {
160160
ver: 2,
161-
id: Some(span_id_to_string(span.span_context.span_id()).into()),
161+
id: Some(span.span_context.span_id().to_string().into()),
162162
name: span.name.clone().into(),
163163
duration: duration_to_string(
164164
span.end_time

0 commit comments

Comments
 (0)