Skip to content

Commit 6f78c7f

Browse files
authored
Merge branch 'main' into http-1.0
2 parents 92f1513 + 60a3cbe commit 6f78c7f

File tree

14 files changed

+77
-70
lines changed

14 files changed

+77
-70
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,6 @@ jobs:
150150
- name: cargo llvm-cov
151151
run: cargo llvm-cov --locked --all-features --workspace --lcov --output-path lcov.info
152152
- name: Upload to codecov.io
153-
uses: codecov/codecov-action@v3
153+
uses: codecov/codecov-action@v4
154154
with:
155-
fail_ci_if_error: false
155+
fail_ci_if_error: true

opentelemetry-jaeger/src/exporter/config/collector/mod.rs

-35
Original file line numberDiff line numberDiff line change
@@ -546,43 +546,8 @@ impl CollectorPipeline {
546546
#[cfg(test)]
547547
#[cfg(feature = "rt-tokio")]
548548
mod tests {
549-
use opentelemetry_sdk::runtime::Tokio;
550-
551-
use crate::config::collector::http_client::test_http_client;
552-
553549
use super::*;
554550

555-
#[test]
556-
fn test_set_collector_endpoint() {
557-
let invalid_uri = new_collector_pipeline()
558-
.with_endpoint("127.0.0.1:14268/api/traces")
559-
.with_http_client(test_http_client::TestHttpClient)
560-
.build_uploader::<Tokio>();
561-
assert!(invalid_uri.is_err());
562-
assert_eq!(
563-
format!("{:?}", invalid_uri.err().unwrap()),
564-
"ConfigError { pipeline_name: \"collector\", config_name: \"collector_endpoint\", reason: \"invalid uri from the builder, invalid format\" }",
565-
);
566-
567-
let valid_uri = new_collector_pipeline()
568-
.with_http_client(test_http_client::TestHttpClient)
569-
.with_endpoint("http://127.0.0.1:14268/api/traces")
570-
.build_uploader::<Tokio>();
571-
572-
assert!(valid_uri.is_ok());
573-
}
574-
575-
// Ignore this test as it is flaky and the opentelemetry-jaeger is on-track for deprecation
576-
#[ignore]
577-
#[test]
578-
fn test_collector_exporter() {
579-
let exporter = new_collector_pipeline()
580-
.with_endpoint("http://127.0.0.1:14268/api/traces")
581-
.with_http_client(test_http_client::TestHttpClient)
582-
.build_collector_exporter::<Tokio>();
583-
assert!(exporter.is_ok());
584-
}
585-
586551
#[test]
587552
fn test_resolve_endpoint() {
588553
struct TestCase<'a> {

opentelemetry-sdk/benches/metric_counter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ fn create_counter() -> Counter<u64> {
1313
.with_reader(ManualReader::builder().build())
1414
.build();
1515
let meter = meter_provider.meter("benchmarks");
16-
let counter = meter.u64_counter("counter_bench").init();
17-
counter
16+
17+
meter.u64_counter("counter_bench").init()
1818
}
1919

2020
fn criterion_benchmark(c: &mut Criterion) {

opentelemetry-sdk/src/logs/log_emitter.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use opentelemetry::{
1313
#[cfg(feature = "logs_level_enabled")]
1414
use opentelemetry::logs::Severity;
1515

16-
use std::sync::atomic::AtomicBool;
1716
use std::{borrow::Cow, sync::Arc};
17+
use std::{sync::atomic::AtomicBool, time::SystemTime};
1818

1919
use once_cell::sync::Lazy;
2020

@@ -242,6 +242,9 @@ impl opentelemetry::logs::Logger for Logger {
242242
if let Some(ref trace_context) = trace_context {
243243
cloned_record.trace_context = Some(trace_context.clone());
244244
}
245+
if cloned_record.observed_timestamp.is_none() {
246+
cloned_record.observed_timestamp = Some(SystemTime::now());
247+
}
245248
let data = LogData {
246249
record: cloned_record,
247250
instrumentation: self.instrumentation_library().clone(),

opentelemetry-sdk/src/logs/record.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ use opentelemetry::{
55
};
66
use std::{borrow::Cow, time::SystemTime};
77

8-
#[derive(Debug, Clone, Default)]
8+
#[derive(Debug, Default, Clone)]
99
#[non_exhaustive]
1010
/// LogRecord represents all data carried by a log record, and
1111
/// is provided to `LogExporter`s as input.
1212
pub struct LogRecord {
13+
/// Event name. Optional as not all the logging API support it.
14+
pub event_name: Option<Cow<'static, str>>,
15+
1316
/// Record timestamp
1417
pub timestamp: Option<SystemTime>,
1518

@@ -32,6 +35,13 @@ pub struct LogRecord {
3235
}
3336

3437
impl opentelemetry::logs::LogRecord for LogRecord {
38+
fn set_event_name<T>(&mut self, name: T)
39+
where
40+
T: Into<Cow<'static, str>>,
41+
{
42+
self.event_name = Some(name.into());
43+
}
44+
3545
fn set_timestamp(&mut self, timestamp: SystemTime) {
3646
self.timestamp = Some(timestamp);
3747
}

opentelemetry-sdk/src/metrics/meter_provider.rs

+25
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ mod tests {
253253
use crate::testing::metrics::metric_reader::TestMetricReader;
254254
use crate::Resource;
255255
use opentelemetry::global;
256+
use opentelemetry::metrics::MeterProvider;
256257
use opentelemetry::{Key, KeyValue, Value};
257258
use std::env;
258259

@@ -433,4 +434,28 @@ mod tests {
433434
// Now the shutdown should be invoked
434435
assert!(reader.is_shutdown());
435436
}
437+
438+
#[test]
439+
fn same_meter_reused_same_scope() {
440+
let provider = super::SdkMeterProvider::builder().build();
441+
let _meter1 = provider.meter("test");
442+
let _meter2 = provider.meter("test");
443+
assert_eq!(provider.inner.meters.lock().unwrap().len(), 1);
444+
let _meter3 =
445+
provider.versioned_meter("test", Some("1.0.0"), Some("http://example.com"), None);
446+
let _meter4 =
447+
provider.versioned_meter("test", Some("1.0.0"), Some("http://example.com"), None);
448+
let _meter5 =
449+
provider.versioned_meter("test", Some("1.0.0"), Some("http://example.com"), None);
450+
assert_eq!(provider.inner.meters.lock().unwrap().len(), 2);
451+
452+
// the below are different meters, as meter names are case sensitive
453+
let _meter6 =
454+
provider.versioned_meter("ABC", Some("1.0.0"), Some("http://example.com"), None);
455+
let _meter7 =
456+
provider.versioned_meter("Abc", Some("1.0.0"), Some("http://example.com"), None);
457+
let _meter8 =
458+
provider.versioned_meter("abc", Some("1.0.0"), Some("http://example.com"), None);
459+
assert_eq!(provider.inner.meters.lock().unwrap().len(), 5);
460+
}
436461
}

opentelemetry/benches/metrics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use opentelemetry::{global, metrics::Counter, KeyValue};
66

77
fn create_counter() -> Counter<u64> {
88
let meter = global::meter("benchmarks");
9-
let counter = meter.u64_counter("counter_bench").init();
10-
counter
9+
10+
meter.u64_counter("counter_bench").init()
1111
}
1212

1313
fn criterion_benchmark(c: &mut Criterion) {

opentelemetry/src/logs/noop.rs

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ pub struct NoopLogRecord;
4141
impl LogRecord for NoopLogRecord {
4242
// Implement the LogRecord trait methods with empty bodies.
4343
#[inline]
44+
fn set_event_name<T>(&mut self, _name: T)
45+
where
46+
T: Into<Cow<'static, str>>,
47+
{
48+
}
49+
#[inline]
4450
fn set_timestamp(&mut self, _timestamp: SystemTime) {}
4551
#[inline]
4652
fn set_observed_timestamp(&mut self, _timestamp: SystemTime) {}

opentelemetry/src/logs/record.rs

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ use std::{borrow::Cow, collections::HashMap, time::SystemTime};
33

44
/// SDK implemented trait for managing log records
55
pub trait LogRecord {
6+
/// Sets the `event_name` of a record
7+
fn set_event_name<T>(&mut self, _name: T)
8+
where
9+
T: Into<Cow<'static, str>>,
10+
{
11+
}
12+
613
/// Sets the time when the event occurred measured by the origin clock, i.e. the time at the source.
714
fn set_timestamp(&mut self, timestamp: SystemTime);
815

opentelemetry/src/metrics/instruments/counter.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,19 @@ impl TryFrom<InstrumentBuilder<'_, Counter<u64>>> for Counter<u64> {
4141
type Error = MetricsError;
4242

4343
fn try_from(builder: InstrumentBuilder<'_, Counter<u64>>) -> Result<Self, Self::Error> {
44-
builder.meter.instrument_provider.u64_counter(
45-
builder.name,
46-
builder.description,
47-
builder.unit,
48-
)
44+
builder
45+
.instrument_provider
46+
.u64_counter(builder.name, builder.description, builder.unit)
4947
}
5048
}
5149

5250
impl TryFrom<InstrumentBuilder<'_, Counter<f64>>> for Counter<f64> {
5351
type Error = MetricsError;
5452

5553
fn try_from(builder: InstrumentBuilder<'_, Counter<f64>>) -> Result<Self, Self::Error> {
56-
builder.meter.instrument_provider.f64_counter(
57-
builder.name,
58-
builder.description,
59-
builder.unit,
60-
)
54+
builder
55+
.instrument_provider
56+
.f64_counter(builder.name, builder.description, builder.unit)
6157
}
6258
}
6359

opentelemetry/src/metrics/instruments/gauge.rs

-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ impl TryFrom<InstrumentBuilder<'_, Gauge<u64>>> for Gauge<u64> {
4242

4343
fn try_from(builder: InstrumentBuilder<'_, Gauge<u64>>) -> Result<Self, Self::Error> {
4444
builder
45-
.meter
4645
.instrument_provider
4746
.u64_gauge(builder.name, builder.description, builder.unit)
4847
}
@@ -53,7 +52,6 @@ impl TryFrom<InstrumentBuilder<'_, Gauge<f64>>> for Gauge<f64> {
5352

5453
fn try_from(builder: InstrumentBuilder<'_, Gauge<f64>>) -> Result<Self, Self::Error> {
5554
builder
56-
.meter
5755
.instrument_provider
5856
.f64_gauge(builder.name, builder.description, builder.unit)
5957
}
@@ -64,7 +62,6 @@ impl TryFrom<InstrumentBuilder<'_, Gauge<i64>>> for Gauge<i64> {
6462

6563
fn try_from(builder: InstrumentBuilder<'_, Gauge<i64>>) -> Result<Self, Self::Error> {
6664
builder
67-
.meter
6865
.instrument_provider
6966
.i64_gauge(builder.name, builder.description, builder.unit)
7067
}

opentelemetry/src/metrics/instruments/histogram.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,18 @@ impl TryFrom<InstrumentBuilder<'_, Histogram<f64>>> for Histogram<f64> {
4040
type Error = MetricsError;
4141

4242
fn try_from(builder: InstrumentBuilder<'_, Histogram<f64>>) -> Result<Self, Self::Error> {
43-
builder.meter.instrument_provider.f64_histogram(
44-
builder.name,
45-
builder.description,
46-
builder.unit,
47-
)
43+
builder
44+
.instrument_provider
45+
.f64_histogram(builder.name, builder.description, builder.unit)
4846
}
4947
}
5048

5149
impl TryFrom<InstrumentBuilder<'_, Histogram<u64>>> for Histogram<u64> {
5250
type Error = MetricsError;
5351

5452
fn try_from(builder: InstrumentBuilder<'_, Histogram<u64>>) -> Result<Self, Self::Error> {
55-
builder.meter.instrument_provider.u64_histogram(
56-
builder.name,
57-
builder.description,
58-
builder.unit,
59-
)
53+
builder
54+
.instrument_provider
55+
.u64_histogram(builder.name, builder.description, builder.unit)
6056
}
6157
}

opentelemetry/src/metrics/instruments/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use std::borrow::Cow;
66
use std::marker;
77
use std::sync::Arc;
88

9+
use super::InstrumentProvider;
10+
911
pub(super) mod counter;
1012
pub(super) mod gauge;
1113
pub(super) mod histogram;
@@ -24,7 +26,7 @@ pub trait AsyncInstrument<T>: Send + Sync {
2426

2527
/// Configuration for building a sync instrument.
2628
pub struct InstrumentBuilder<'a, T> {
27-
meter: &'a Meter,
29+
instrument_provider: &'a dyn InstrumentProvider,
2830
name: Cow<'static, str>,
2931
description: Option<Cow<'static, str>>,
3032
unit: Option<Unit>,
@@ -38,7 +40,7 @@ where
3840
/// Create a new instrument builder
3941
pub(crate) fn new(meter: &'a Meter, name: Cow<'static, str>) -> Self {
4042
InstrumentBuilder {
41-
meter,
43+
instrument_provider: meter.instrument_provider.as_ref(),
4244
name,
4345
description: None,
4446
unit: None,

opentelemetry/src/metrics/instruments/up_down_counter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl TryFrom<InstrumentBuilder<'_, UpDownCounter<i64>>> for UpDownCounter<i64> {
4646
type Error = MetricsError;
4747

4848
fn try_from(builder: InstrumentBuilder<'_, UpDownCounter<i64>>) -> Result<Self, Self::Error> {
49-
builder.meter.instrument_provider.i64_up_down_counter(
49+
builder.instrument_provider.i64_up_down_counter(
5050
builder.name,
5151
builder.description,
5252
builder.unit,
@@ -58,7 +58,7 @@ impl TryFrom<InstrumentBuilder<'_, UpDownCounter<f64>>> for UpDownCounter<f64> {
5858
type Error = MetricsError;
5959

6060
fn try_from(builder: InstrumentBuilder<'_, UpDownCounter<f64>>) -> Result<Self, Self::Error> {
61-
builder.meter.instrument_provider.f64_up_down_counter(
61+
builder.instrument_provider.f64_up_down_counter(
6262
builder.name,
6363
builder.description,
6464
builder.unit,

0 commit comments

Comments
 (0)