Skip to content

Commit 9ca638d

Browse files
authored
Merge branch 'main' into 1464
2 parents bd9a2eb + 27b19b6 commit 9ca638d

Some content is hidden

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

59 files changed

+1352
-529
lines changed

.cspell.json

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"Lalit",
4343
"msrv",
4444
"Ochtman",
45-
"openetelemetry",
4645
"opentelemetry",
4746
"OTLP",
4847
"protoc",

.github/codecov.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ ignore:
2222
- "opentelemetry-jaeger/examples"
2323
- "opentelemetry-zipkin/examples"
2424
- "opentelemetry-otlp/examples"
25-
- "opentelemetry-aws/examples"
26-
- "opentelemetry-datadog/examples"
27-
- "opentelemetry-dynatrace/examples"
2825
- "opentelemetry-http/examples"
2926
- "opentelemetry-prometheus/examples"
30-
- "opentelemetry-zpages/examples"
27+
- "opentelemetry-appender-tracing/examples"
28+
- "opentelemetry-appender-log/examples"
29+
# stress test
30+
- "stress"

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ For a deeper discussion, see:
126126

127127
Currently, the Opentelemetry Rust SDK has two ways to handle errors. In the situation where errors are not allowed to return. One should call global error handler to process the errors. Otherwise, one should return the errors.
128128

129-
The Opentelemetry Rust SDK comes with an error type `openetelemetry::Error`. For different function, one error has been defined. All error returned by trace module MUST be wrapped in `opentelemetry::trace::TraceError`. All errors returned by metrics module MUST be wrapped in `opentelemetry::metrics::MetricsError`.
129+
The Opentelemetry Rust SDK comes with an error type `opentelemetry::Error`. For different function, one error has been defined. All error returned by trace module MUST be wrapped in `opentelemetry::trace::TraceError`. All errors returned by metrics module MUST be wrapped in `opentelemetry::metrics::MetricsError`. All errors returned by logs module MUST be wrapped in `opentelemetry::logs::LogsError`.
130130

131131
For users that want to implement their own exporters. It's RECOMMENDED to wrap all errors from the exporter into a crate-level error type, and implement `ExporterError` trait.
132132

examples/metrics-basic/src/main.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use opentelemetry::metrics::Unit;
2+
use opentelemetry::AttributeSet;
23
use opentelemetry::{metrics::MeterProvider as _, KeyValue};
34
use opentelemetry_sdk::metrics::{PeriodicReader, SdkMeterProvider};
45
use opentelemetry_sdk::{runtime, Resource};
@@ -52,11 +53,10 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
5253
observer.observe_u64(
5354
&observable_counter,
5455
100,
55-
[
56+
AttributeSet::from(&[
5657
KeyValue::new("mykey1", "myvalue1"),
5758
KeyValue::new("mykey2", "myvalue2"),
58-
]
59-
.as_ref(),
59+
]),
6060
)
6161
})?;
6262

@@ -84,11 +84,10 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
8484
observer.observe_i64(
8585
&observable_up_down_counter,
8686
100,
87-
[
87+
AttributeSet::from(&[
8888
KeyValue::new("mykey1", "myvalue1"),
8989
KeyValue::new("mykey2", "myvalue2"),
90-
]
91-
.as_ref(),
90+
]),
9291
)
9392
})?;
9493

@@ -142,11 +141,10 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
142141
observer.observe_f64(
143142
&observable_gauge,
144143
1.0,
145-
[
144+
AttributeSet::from(&[
146145
KeyValue::new("mykey1", "myvalue1"),
147146
KeyValue::new("mykey2", "myvalue2"),
148-
]
149-
.as_ref(),
147+
]),
150148
)
151149
})?;
152150

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use opentelemetry_sdk::metrics as sdkmetrics;
1111
use opentelemetry_sdk::resource;
1212
use opentelemetry_sdk::trace as sdktrace;
1313

14+
use opentelemetry::AttributeSet;
1415
use std::error::Error;
1516
use tracing::info;
1617
use tracing_subscriber::prelude::*;
@@ -62,13 +63,13 @@ fn init_metrics() -> metrics::Result<sdkmetrics::SdkMeterProvider> {
6263
const LEMONS_KEY: Key = Key::from_static_str("ex.com/lemons");
6364
const ANOTHER_KEY: Key = Key::from_static_str("ex.com/another");
6465

65-
static COMMON_ATTRIBUTES: Lazy<[KeyValue; 4]> = Lazy::new(|| {
66-
[
66+
static COMMON_ATTRIBUTES: Lazy<AttributeSet> = Lazy::new(|| {
67+
AttributeSet::from(&[
6768
LEMONS_KEY.i64(10),
6869
KeyValue::new("A", "1"),
6970
KeyValue::new("B", "2"),
7071
KeyValue::new("C", "3"),
71-
]
72+
])
7273
});
7374

7475
#[tokio::main]
@@ -104,7 +105,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
104105
info!(target: "my-target", "hello from {}. My price is {}", "apple", 1.99);
105106

106107
let histogram = meter.f64_histogram("ex.com.two").init();
107-
histogram.record(5.5, COMMON_ATTRIBUTES.as_ref());
108+
histogram.record(5.5, COMMON_ATTRIBUTES.clone());
108109

109110
global::shutdown_tracer_provider();
110111
global::shutdown_logger_provider();

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use opentelemetry::global;
44
use opentelemetry::global::{logger_provider, shutdown_logger_provider, shutdown_tracer_provider};
55
use opentelemetry::logs::LogError;
66
use opentelemetry::trace::TraceError;
7+
use opentelemetry::AttributeSet;
78
use opentelemetry::{
89
metrics,
910
trace::{TraceContextExt, Tracer},
@@ -72,13 +73,13 @@ fn init_logs() -> Result<opentelemetry_sdk::logs::Logger, LogError> {
7273
const LEMONS_KEY: Key = Key::from_static_str("lemons");
7374
const ANOTHER_KEY: Key = Key::from_static_str("ex.com/another");
7475

75-
static COMMON_ATTRIBUTES: Lazy<[KeyValue; 4]> = Lazy::new(|| {
76-
[
76+
static COMMON_ATTRIBUTES: Lazy<AttributeSet> = Lazy::new(|| {
77+
AttributeSet::from(&[
7778
LEMONS_KEY.i64(10),
7879
KeyValue::new("A", "1"),
7980
KeyValue::new("B", "2"),
8081
KeyValue::new("C", "3"),
81-
]
82+
])
8283
});
8384

8485
#[tokio::main]
@@ -109,11 +110,11 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
109110
.init();
110111

111112
meter.register_callback(&[gauge.as_any()], move |observer| {
112-
observer.observe_f64(&gauge, 1.0, COMMON_ATTRIBUTES.as_ref())
113+
observer.observe_f64(&gauge, 1.0, COMMON_ATTRIBUTES.clone())
113114
})?;
114115

115116
let histogram = meter.f64_histogram("ex.com.two").init();
116-
histogram.record(5.5, COMMON_ATTRIBUTES.as_ref());
117+
histogram.record(5.5, COMMON_ATTRIBUTES.clone());
117118

118119
tracer.in_span("operation", |cx| {
119120
let span = cx.span();

opentelemetry-otlp/src/logs.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ impl OtlpPipeline {
4242
OtlpLogPipeline {
4343
log_config: None,
4444
exporter_builder: NoExporterConfig(()),
45+
batch_config: None,
4546
}
4647
}
4748
}
@@ -124,6 +125,7 @@ impl opentelemetry_sdk::export::logs::LogExporter for LogExporter {
124125
pub struct OtlpLogPipeline<EB> {
125126
exporter_builder: EB,
126127
log_config: Option<opentelemetry_sdk::logs::Config>,
128+
batch_config: Option<opentelemetry_sdk::logs::BatchConfig>,
127129
}
128130

129131
impl<EB> OtlpLogPipeline<EB> {
@@ -132,6 +134,12 @@ impl<EB> OtlpLogPipeline<EB> {
132134
self.log_config = Some(log_config);
133135
self
134136
}
137+
138+
/// Set the batch log processor configuration, and it will override the env vars.
139+
pub fn with_batch_config(mut self, batch_config: opentelemetry_sdk::logs::BatchConfig) -> Self {
140+
self.batch_config = Some(batch_config);
141+
self
142+
}
135143
}
136144

137145
impl OtlpLogPipeline<NoExporterConfig> {
@@ -143,6 +151,7 @@ impl OtlpLogPipeline<NoExporterConfig> {
143151
OtlpLogPipeline {
144152
exporter_builder: pipeline.into(),
145153
log_config: self.log_config,
154+
batch_config: self.batch_config,
146155
}
147156
}
148157
}
@@ -160,7 +169,7 @@ impl OtlpLogPipeline<LogExporterBuilder> {
160169
))
161170
}
162171

163-
/// Install the configured log exporter and a batch span processor using the
172+
/// Install the configured log exporter and a batch log processor using the
164173
/// specified runtime.
165174
///
166175
/// Returns a [`Logger`] with the name `opentelemetry-otlp` and the current crate version.
@@ -174,6 +183,7 @@ impl OtlpLogPipeline<LogExporterBuilder> {
174183
self.exporter_builder.build_log_exporter()?,
175184
self.log_config,
176185
runtime,
186+
self.batch_config,
177187
))
178188
}
179189
}
@@ -202,9 +212,14 @@ fn build_batch_with_exporter<R: RuntimeChannel>(
202212
exporter: LogExporter,
203213
log_config: Option<opentelemetry_sdk::logs::Config>,
204214
runtime: R,
215+
batch_config: Option<opentelemetry_sdk::logs::BatchConfig>,
205216
) -> opentelemetry_sdk::logs::Logger {
206-
let mut provider_builder =
207-
opentelemetry_sdk::logs::LoggerProvider::builder().with_batch_exporter(exporter, runtime);
217+
let mut provider_builder = opentelemetry_sdk::logs::LoggerProvider::builder();
218+
let batch_processor = opentelemetry_sdk::logs::BatchLogProcessor::builder(exporter, runtime)
219+
.with_batch_config(batch_config.unwrap_or_default())
220+
.build();
221+
provider_builder = provider_builder.with_log_processor(batch_processor);
222+
208223
if let Some(config) = log_config {
209224
provider_builder = provider_builder.with_config(config);
210225
}

opentelemetry-prometheus/examples/hyper.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use hyper::{
44
Body, Method, Request, Response, Server,
55
};
66
use once_cell::sync::Lazy;
7+
use opentelemetry::AttributeSet;
78
use opentelemetry::{
89
metrics::{Counter, Histogram, MeterProvider as _, Unit},
910
KeyValue,
@@ -14,7 +15,8 @@ use std::convert::Infallible;
1415
use std::sync::Arc;
1516
use std::time::SystemTime;
1617

17-
static HANDLER_ALL: Lazy<[KeyValue; 1]> = Lazy::new(|| [KeyValue::new("handler", "all")]);
18+
static HANDLER_ALL: Lazy<AttributeSet> =
19+
Lazy::new(|| AttributeSet::from(&[KeyValue::new("handler", "all")]));
1820

1921
async fn serve_req(
2022
req: Request<Body>,
@@ -23,7 +25,7 @@ async fn serve_req(
2325
println!("Receiving request at path {}", req.uri());
2426
let request_start = SystemTime::now();
2527

26-
state.http_counter.add(1, HANDLER_ALL.as_ref());
28+
state.http_counter.add(1, HANDLER_ALL.clone());
2729

2830
let response = match (req.method(), req.uri().path()) {
2931
(&Method::GET, "/metrics") => {
@@ -33,7 +35,7 @@ async fn serve_req(
3335
encoder.encode(&metric_families, &mut buffer).unwrap();
3436
state
3537
.http_body_gauge
36-
.record(buffer.len() as u64, HANDLER_ALL.as_ref());
38+
.record(buffer.len() as u64, HANDLER_ALL.clone());
3739

3840
Response::builder()
3941
.status(200)
@@ -53,7 +55,7 @@ async fn serve_req(
5355

5456
state.http_req_histogram.record(
5557
request_start.elapsed().map_or(0.0, |d| d.as_secs_f64()),
56-
&[],
58+
AttributeSet::default(),
5759
);
5860
Ok(response)
5961
}

opentelemetry-prometheus/src/lib.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
//! [Prometheus]: https://prometheus.io
44
//!
55
//! ```
6-
//! use opentelemetry::{metrics::MeterProvider, KeyValue};
6+
//! use opentelemetry::{AttributeSet, metrics::MeterProvider, KeyValue};
77
//! use opentelemetry_sdk::metrics::SdkMeterProvider;
88
//! use prometheus::{Encoder, TextEncoder};
99
//!
1010
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
1111
//!
1212
//! // create a new prometheus registry
13+
//! use opentelemetry::AttributeSet;
1314
//! let registry = prometheus::Registry::new();
1415
//!
1516
//! // configure OpenTelemetry to use this registry
@@ -31,8 +32,10 @@
3132
//! .with_description("Records values")
3233
//! .init();
3334
//!
34-
//! counter.add(100, &[KeyValue::new("key", "value")]);
35-
//! histogram.record(100, &[KeyValue::new("key", "value")]);
35+
//! let attributes = AttributeSet::from(&[KeyValue::new("key", "value")]);
36+
//!
37+
//! counter.add(100, attributes.clone());
38+
//! histogram.record(100, attributes);
3639
//!
3740
//! // Encode data as text or protobuf
3841
//! let encoder = TextEncoder::new();

0 commit comments

Comments
 (0)