Skip to content

Commit 5f7a564

Browse files
authored
Merge branch 'main' into trace-set-resource
2 parents 34f5e97 + e699233 commit 5f7a564

File tree

43 files changed

+584
-536
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+584
-536
lines changed

.cspell.json

+7
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
"Cijo",
3333
"clippy",
3434
"codecov",
35+
"datapoint",
3536
"deque",
3637
"Dirkjan",
38+
"EPYC",
3739
"hasher",
3840
"isahc",
3941
"Isobel",
@@ -43,6 +45,9 @@
4345
"Lalit",
4446
"LIBCLANG",
4547
"msrv",
48+
"mykey",
49+
"myvalue",
50+
"nocapture",
4651
"Ochtman",
4752
"opentelemetry",
4853
"OTLP",
@@ -53,8 +58,10 @@
5358
"runtimes",
5459
"rustc",
5560
"shoppingcart",
61+
"struct",
5662
"Tescher",
5763
"tracerprovider",
64+
"updown",
5865
"Zhongyang",
5966
"zipkin"
6067
],

.github/workflows/ci.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,8 @@ jobs:
110110
- uses: dtolnay/rust-toolchain@1.65.0
111111
- name: Patch dependencies versions # some dependencies bump MSRV without major version bump
112112
run: bash ./scripts/patch_dependencies.sh
113-
- name: Run tests
114-
run: cargo --version &&
115-
cargo test --manifest-path=opentelemetry/Cargo.toml --features trace,metrics,testing &&
116-
cargo test --manifest-path=opentelemetry-zipkin/Cargo.toml
113+
- name: Check MSRV for all crates
114+
run: bash ./scripts/msrv.sh
117115
cargo-deny:
118116
runs-on: ubuntu-latest # This uses the step `EmbarkStudios/cargo-deny-action@v1` which is only supported on Linux
119117
continue-on-error: true # Prevent sudden announcement of a new advisory from failing ci

CONTRIBUTING.md

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ You can provide the protocol compiler protoc path programmatically (only works w
3737
export PROTOC=$(which protoc)
3838
```
3939

40+
It is recommended to use "3.15" or newer of protoc, as some of the proto
41+
definitions include "optional" fields, that are not supported in older versions,
42+
resulting in errors as shown
43+
[here](https://github.com/open-telemetry/opentelemetry-proto/issues/451).
44+
4045
Prerequisites to build the protocol compiler protoc from source
4146

4247
- [protoc](https://github.com/protocolbuffers/protobuf)

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ debug = 1
1919
async-std = "1.10"
2020
async-trait = "0.1"
2121
bytes = "1"
22-
env_logger = { version = "0.10", default-features = false } # env_logger requires a newer MSRV
2322
futures-core = "0.3"
2423
futures-executor = "0.3"
2524
futures-util = { version = "0.3", default-features = false }

examples/metrics-advanced/src/main.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use opentelemetry::global;
2-
use opentelemetry::metrics::Unit;
32
use opentelemetry::Key;
43
use opentelemetry::KeyValue;
54
use opentelemetry_sdk::metrics::{
@@ -15,7 +14,7 @@ fn init_meter_provider() -> opentelemetry_sdk::metrics::SdkMeterProvider {
1514
Some(
1615
Stream::new()
1716
.name("my_histogram_renamed")
18-
.unit(Unit::new("milliseconds")),
17+
.unit("milliseconds"),
1918
)
2019
} else {
2120
None
@@ -76,7 +75,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
7675
// using view.
7776
let histogram = meter
7877
.f64_histogram("my_histogram")
79-
.with_unit(Unit::new("ms"))
78+
.with_unit("ms")
8079
.with_description("My histogram example description")
8180
.init();
8281

@@ -114,7 +113,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
114113
// use a custom set of boundaries, and min/max values will not be recorded.
115114
let histogram2 = meter
116115
.f64_histogram("my_second_histogram")
117-
.with_unit(Unit::new("ms"))
116+
.with_unit("ms")
118117
.with_description("My histogram example description")
119118
.init();
120119

examples/metrics-basic/src/main.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use opentelemetry::global;
2-
use opentelemetry::metrics::Unit;
32
use opentelemetry::KeyValue;
43
use opentelemetry_sdk::metrics::{PeriodicReader, SdkMeterProvider};
54
use opentelemetry_sdk::{runtime, Resource};
@@ -47,7 +46,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
4746
let _observable_counter = meter
4847
.u64_observable_counter("my_observable_counter")
4948
.with_description("My observable counter example description")
50-
.with_unit(Unit::new("myunit"))
49+
.with_unit("myunit")
5150
.with_callback(|observer| {
5251
observer.observe(
5352
100,
@@ -75,7 +74,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
7574
let _observable_up_down_counter = meter
7675
.i64_observable_up_down_counter("my_observable_updown_counter")
7776
.with_description("My observable updown counter example description")
78-
.with_unit(Unit::new("myunit"))
77+
.with_unit("myunit")
7978
.with_callback(|observer| {
8079
observer.observe(
8180
100,
@@ -108,7 +107,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
108107
let gauge = meter
109108
.f64_gauge("my_gauge")
110109
.with_description("A gauge set to 1.0")
111-
.with_unit(Unit::new("myunit"))
110+
.with_unit("myunit")
112111
.init();
113112

114113
gauge.record(
@@ -123,7 +122,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
123122
let _observable_gauge = meter
124123
.f64_observable_gauge("my_observable_gauge")
125124
.with_description("An observable gauge set to 1.0")
126-
.with_unit(Unit::new("myunit"))
125+
.with_unit("myunit")
127126
.with_callback(|observer| {
128127
observer.observe(
129128
1.0,

examples/tracing-jaeger/src/main.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use opentelemetry_semantic_conventions::resource::SERVICE_NAME;
1010

1111
use std::error::Error;
1212

13-
fn init_tracer() -> Result<opentelemetry_sdk::trace::Tracer, TraceError> {
13+
fn init_tracer_provider() -> Result<opentelemetry_sdk::trace::TracerProvider, TraceError> {
1414
opentelemetry_otlp::new_pipeline()
1515
.tracing()
1616
.with_exporter(
@@ -29,7 +29,8 @@ fn init_tracer() -> Result<opentelemetry_sdk::trace::Tracer, TraceError> {
2929

3030
#[tokio::main]
3131
async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
32-
let _tracer = init_tracer().expect("Failed to initialize tracer.");
32+
let tracer_provider = init_tracer_provider().expect("Failed to initialize tracer provider.");
33+
global::set_tracer_provider(tracer_provider.clone());
3334

3435
let tracer = global::tracer("tracing-jaeger");
3536
tracer.in_span("main-operation", |cx| {

opentelemetry-appender-tracing/benches/logs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
| noop_layer_disabled | 12 ns |
1111
| noop_layer_enabled | 25 ns |
1212
| ot_layer_disabled | 19 ns |
13-
| ot_layer_enabled | 446 ns |
13+
| ot_layer_enabled | 371 ns |
1414
*/
1515

1616
use async_trait::async_trait;

opentelemetry-appender-tracing/src/layer.rs

+39-40
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ use tracing_subscriber::Layer;
1111
const INSTRUMENTATION_LIBRARY_NAME: &str = "opentelemetry-appender-tracing";
1212

1313
/// Visitor to record the fields from the event record.
14-
#[derive(Default)]
15-
struct EventVisitor {
16-
log_record_attributes: Vec<(Key, AnyValue)>,
17-
log_record_body: Option<AnyValue>,
14+
struct EventVisitor<'a, LR: LogRecord> {
15+
log_record: &'a mut LR,
1816
}
1917

2018
/// Logs from the log crate have duplicated attributes that we removed here.
@@ -37,59 +35,61 @@ fn get_filename(filepath: &str) -> &str {
3735
filepath
3836
}
3937

40-
impl EventVisitor {
38+
impl<'a, LR: LogRecord> EventVisitor<'a, LR> {
39+
fn new(log_record: &'a mut LR) -> Self {
40+
EventVisitor { log_record }
41+
}
4142
fn visit_metadata(&mut self, meta: &Metadata) {
42-
self.log_record_attributes
43-
.push(("name".into(), meta.name().into()));
43+
self.log_record
44+
.add_attribute(Key::new("name"), AnyValue::from(meta.name()));
4445

4546
#[cfg(feature = "experimental_metadata_attributes")]
4647
self.visit_experimental_metadata(meta);
4748
}
4849

4950
#[cfg(feature = "experimental_metadata_attributes")]
5051
fn visit_experimental_metadata(&mut self, meta: &Metadata) {
51-
self.log_record_attributes
52-
.push(("log.target".into(), meta.target().to_owned().into()));
52+
self.log_record.add_attribute(
53+
Key::new("log.target"),
54+
AnyValue::from(meta.target().to_owned()),
55+
);
5356

5457
if let Some(module_path) = meta.module_path() {
55-
self.log_record_attributes
56-
.push(("code.namespace".into(), module_path.to_owned().into()));
58+
self.log_record.add_attribute(
59+
Key::new("code.namespace"),
60+
AnyValue::from(module_path.to_owned()),
61+
);
5762
}
5863

5964
if let Some(filepath) = meta.file() {
60-
self.log_record_attributes
61-
.push(("code.filepath".into(), filepath.to_owned().into()));
62-
self.log_record_attributes.push((
63-
"code.filename".into(),
64-
get_filename(filepath).to_owned().into(),
65-
));
65+
self.log_record.add_attribute(
66+
Key::new("code.filepath"),
67+
AnyValue::from(filepath.to_owned()),
68+
);
69+
self.log_record.add_attribute(
70+
Key::new("code.filename"),
71+
AnyValue::from(get_filename(filepath).to_owned()),
72+
);
6673
}
6774

6875
if let Some(line) = meta.line() {
69-
self.log_record_attributes
70-
.push(("code.lineno".into(), line.into()));
71-
}
72-
}
73-
74-
fn push_to_otel_log_record<LR: LogRecord>(self, log_record: &mut LR) {
75-
if let Some(body) = self.log_record_body {
76-
log_record.set_body(body);
76+
self.log_record
77+
.add_attribute(Key::new("code.lineno"), AnyValue::from(line));
7778
}
78-
log_record.add_attributes(self.log_record_attributes);
7979
}
8080
}
8181

82-
impl tracing::field::Visit for EventVisitor {
82+
impl<'a, LR: LogRecord> tracing::field::Visit for EventVisitor<'a, LR> {
8383
fn record_debug(&mut self, field: &tracing::field::Field, value: &dyn std::fmt::Debug) {
8484
#[cfg(feature = "experimental_metadata_attributes")]
8585
if is_duplicated_metadata(field.name()) {
8686
return;
8787
}
8888
if field.name() == "message" {
89-
self.log_record_body = Some(format!("{value:?}").into());
89+
self.log_record.set_body(format!("{:?}", value).into());
9090
} else {
91-
self.log_record_attributes
92-
.push((field.name().into(), format!("{value:?}").into()));
91+
self.log_record
92+
.add_attribute(Key::new(field.name()), AnyValue::from(format!("{value:?}")));
9393
}
9494
}
9595

@@ -98,27 +98,27 @@ impl tracing::field::Visit for EventVisitor {
9898
if is_duplicated_metadata(field.name()) {
9999
return;
100100
}
101-
self.log_record_attributes
102-
.push((field.name().into(), value.to_owned().into()));
101+
self.log_record
102+
.add_attribute(Key::new(field.name()), AnyValue::from(value.to_owned()));
103103
}
104104

105105
fn record_bool(&mut self, field: &tracing_core::Field, value: bool) {
106-
self.log_record_attributes
107-
.push((field.name().into(), value.into()));
106+
self.log_record
107+
.add_attribute(Key::new(field.name()), AnyValue::from(value));
108108
}
109109

110110
fn record_f64(&mut self, field: &tracing::field::Field, value: f64) {
111-
self.log_record_attributes
112-
.push((field.name().into(), value.into()));
111+
self.log_record
112+
.add_attribute(Key::new(field.name()), AnyValue::from(value));
113113
}
114114

115115
fn record_i64(&mut self, field: &tracing::field::Field, value: i64) {
116116
#[cfg(feature = "experimental_metadata_attributes")]
117117
if is_duplicated_metadata(field.name()) {
118118
return;
119119
}
120-
self.log_record_attributes
121-
.push((field.name().into(), value.into()));
120+
self.log_record
121+
.add_attribute(Key::new(field.name()), AnyValue::from(value));
122122
}
123123

124124
// TODO: Remaining field types from AnyValue : Bytes, ListAny, Boolean
@@ -173,11 +173,10 @@ where
173173
log_record.set_severity_number(severity_of_level(meta.level()));
174174
log_record.set_severity_text(meta.level().to_string().into());
175175

176-
let mut visitor = EventVisitor::default();
176+
let mut visitor = EventVisitor::new(&mut log_record);
177177
visitor.visit_metadata(meta);
178178
// Visit fields.
179179
event.record(&mut visitor);
180-
visitor.push_to_otel_log_record(&mut log_record);
181180

182181
self.logger.emit(log_record);
183182
}

opentelemetry-jaeger-propagator/src/propagator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl Propagator {
138138
/// First bit controls whether to sample
139139
/// Second bit controls whether it's a debug trace
140140
/// Third bit is not used.
141-
/// Forth bit is firehose flag, which is not supported in OT now.
141+
/// Fourth bit is firehose flag, which is not supported in OT now.
142142
fn extract_trace_flags(&self, flag: &str) -> Result<TraceFlags, ()> {
143143
if flag.len() > 2 {
144144
return Err(());

opentelemetry-otlp/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Instead of using
1212
`.with_config(Config::default().with_resource(RESOURCE::default()))` users must
1313
now use `.with_resource(RESOURCE::default())` to configure Resource when using
1414
`OtlpLogPipeline`.
15+
- **Breaking** The methods `OtlpTracePipeline::install_simple()` and `OtlpTracePipeline::install_batch()` would now return `TracerProvider` instead of `Tracer`.
16+
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.
1517

1618
## v0.16.0
1719

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use once_cell::sync::Lazy;
22
use opentelemetry::{
33
global,
4-
metrics::{MetricsError, Unit},
4+
metrics::MetricsError,
55
trace::{TraceContextExt, TraceError, Tracer, TracerProvider as _},
66
Key, KeyValue,
77
};
@@ -37,7 +37,7 @@ fn init_logs() -> Result<sdklogs::LoggerProvider, opentelemetry::logs::LogError>
3737
.install_batch(opentelemetry_sdk::runtime::Tokio)
3838
}
3939

40-
fn init_tracer() -> Result<sdktrace::Tracer, TraceError> {
40+
fn init_tracer_provider() -> Result<sdktrace::TracerProvider, TraceError> {
4141
opentelemetry_otlp::new_pipeline()
4242
.tracing()
4343
.with_exporter(
@@ -67,13 +67,16 @@ fn init_metrics() -> Result<opentelemetry_sdk::metrics::SdkMeterProvider, Metric
6767

6868
#[tokio::main]
6969
async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
70-
let result = init_tracer();
70+
let result = init_tracer_provider();
7171
assert!(
7272
result.is_ok(),
7373
"Init tracer failed with error: {:?}",
7474
result.err()
7575
);
7676

77+
let tracer_provider = result.unwrap();
78+
global::set_tracer_provider(tracer_provider.clone());
79+
7780
let result = init_metrics();
7881
assert!(
7982
result.is_ok(),
@@ -125,7 +128,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
125128
let counter = meter
126129
.u64_counter("test_counter")
127130
.with_description("a simple counter for demo purposes.")
128-
.with_unit(Unit::new("my_unit"))
131+
.with_unit("my_unit")
129132
.init();
130133
for _ in 0..10 {
131134
counter.add(1, &[KeyValue::new("test_key", "test_value")]);

0 commit comments

Comments
 (0)