Skip to content

Commit 9cc333f

Browse files
authored
Merge branch 'main' into otlp-batching
2 parents 0c97965 + c1f351c commit 9cc333f

File tree

15 files changed

+144
-22
lines changed

15 files changed

+144
-22
lines changed

.github/workflows/ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
os: windows-latest
2222
- rust: stable
2323
os: macos-latest
24+
- rust: stable
25+
os: actuated-arm64-4cpu-16gb
2426
runs-on: ${{ matrix.os }}
2527
steps:
2628
- name: Free disk space

opentelemetry-appender-log/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## vNext
44

5+
- [1869](https://github.com/open-telemetry/opentelemetry-rust/pull/1869) Utilize the `LogRecord::set_target()` method to pass the log target to the SDK.
6+
57
## v0.4.0
68

79
- Add log key-values as attributes [#1628](https://github.com/open-telemetry/opentelemetry-rust/pull/1628)

opentelemetry-appender-log/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ where
131131
log_record.set_severity_text(record.level().as_str().into());
132132
log_record.set_body(AnyValue::from(record.args().to_string()));
133133
log_record.add_attributes(log_attributes(record.key_values()));
134+
log_record.set_target(record.metadata().target().to_string());
134135

135136
self.logger.emit(log_record);
136137
}

opentelemetry-appender-tracing/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## vNext
44

5+
- [1869](https://github.com/open-telemetry/opentelemetry-rust/pull/1869) Utilize the `LogRecord::set_target()` method to pass the tracing target to the SDK.
6+
Exporters might use the target to override the instrumentation scope, which previously contained "opentelemetry-appender-tracing".
7+
58
## v0.4.0
69

710
- Removed unwanted dependency on opentelemetry-sdk.

opentelemetry-appender-tracing/src/layer.rs

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ where
172172
let mut log_record = self.logger.create_log_record();
173173
log_record.set_severity_number(severity_of_level(meta.level()));
174174
log_record.set_severity_text(meta.level().to_string().into());
175+
log_record.set_target(meta.target().to_string());
175176

176177
let mut visitor = EventVisitor::new(&mut log_record);
177178
visitor.visit_metadata(meta);

opentelemetry-otlp/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ now use `.with_resource(RESOURCE::default())` to configure Resource when using
1818
- Bump MSRV to 1.70 [#1840](https://github.com/open-telemetry/opentelemetry-rust/pull/1840)
1919
- Fixing the OTLP HTTP/JSON exporter. [#1882](https://github.com/open-telemetry/opentelemetry-rust/pull/1882) - The exporter was broken in the
2020
previous release.
21+
- **Breaking** [1869](https://github.com/open-telemetry/opentelemetry-rust/pull/1869) The OTLP logs exporter now overrides the [InstrumentationScope::name](https://github.com/open-telemetry/opentelemetry-proto/blob/b3060d2104df364136d75a35779e6bd48bac449a/opentelemetry/proto/common/v1/common.proto#L73) field with the `target` from `LogRecord`, if target is populated.
2122
- Group batch of `LogRecord` and `Span` by their resource and instrumentation scope before exporting, for better efficiency [#1873](https://github.com/open-telemetry/opentelemetry-rust/pull/1873).
2223
- This optimization reduces redundancy and improves the efficiency of log export.
2324
- The OTLP compliant Collector or Agents would be able to successfully parse these events.

opentelemetry-proto/src/transform/common.rs

+58-18
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,68 @@ pub mod tonic {
4242
#[cfg(any(feature = "trace", feature = "logs"))]
4343
use opentelemetry_sdk::Resource;
4444

45-
impl From<opentelemetry_sdk::InstrumentationLibrary> for InstrumentationScope {
46-
fn from(library: opentelemetry_sdk::InstrumentationLibrary) -> Self {
47-
InstrumentationScope {
48-
name: library.name.into_owned(),
49-
version: library.version.map(Cow::into_owned).unwrap_or_default(),
50-
attributes: Attributes::from(library.attributes).0,
51-
..Default::default()
45+
impl
46+
From<(
47+
opentelemetry_sdk::InstrumentationLibrary,
48+
Option<Cow<'static, str>>,
49+
)> for InstrumentationScope
50+
{
51+
fn from(
52+
data: (
53+
opentelemetry_sdk::InstrumentationLibrary,
54+
Option<Cow<'static, str>>,
55+
),
56+
) -> Self {
57+
let (library, target) = data;
58+
if let Some(t) = target {
59+
InstrumentationScope {
60+
name: t.to_string(),
61+
version: String::new(),
62+
attributes: vec![],
63+
..Default::default()
64+
}
65+
} else {
66+
InstrumentationScope {
67+
name: library.name.into_owned(),
68+
version: library.version.map(Cow::into_owned).unwrap_or_default(),
69+
attributes: Attributes::from(library.attributes).0,
70+
..Default::default()
71+
}
5272
}
5373
}
5474
}
5575

56-
impl From<&opentelemetry_sdk::InstrumentationLibrary> for InstrumentationScope {
57-
fn from(library: &opentelemetry_sdk::InstrumentationLibrary) -> Self {
58-
InstrumentationScope {
59-
name: library.name.to_string(),
60-
version: library
61-
.version
62-
.as_ref()
63-
.map(ToString::to_string)
64-
.unwrap_or_default(),
65-
attributes: Attributes::from(library.attributes.clone()).0,
66-
..Default::default()
76+
impl
77+
From<(
78+
&opentelemetry_sdk::InstrumentationLibrary,
79+
Option<Cow<'static, str>>,
80+
)> for InstrumentationScope
81+
{
82+
fn from(
83+
data: (
84+
&opentelemetry_sdk::InstrumentationLibrary,
85+
Option<Cow<'static, str>>,
86+
),
87+
) -> Self {
88+
let (library, target) = data;
89+
if let Some(t) = target {
90+
InstrumentationScope {
91+
name: t.to_string(),
92+
version: String::new(),
93+
attributes: vec![],
94+
..Default::default()
95+
}
96+
} else {
97+
InstrumentationScope {
98+
name: library.name.to_string(),
99+
version: library
100+
.version
101+
.as_ref()
102+
.map(ToString::to_string)
103+
.unwrap_or_default(),
104+
attributes: Attributes::from(library.attributes.clone()).0,
105+
..Default::default()
106+
}
67107
}
68108
}
69109
}

opentelemetry-proto/src/transform/logs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub mod tonic {
138138
.clone()
139139
.map(Into::into)
140140
.unwrap_or_default(),
141-
scope: Some(log_data.instrumentation.into()),
141+
scope: Some((log_data.instrumentation, log_data.record.target.clone()).into()),
142142
log_records: vec![log_data.record.into()],
143143
}],
144144
}

opentelemetry-proto/src/transform/metrics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub mod tonic {
131131
impl From<&SdkScopeMetrics> for TonicScopeMetrics {
132132
fn from(sm: &SdkScopeMetrics) -> Self {
133133
TonicScopeMetrics {
134-
scope: Some((&sm.scope).into()),
134+
scope: Some((&sm.scope, None).into()),
135135
metrics: sm.metrics.iter().map(Into::into).collect(),
136136
schema_url: sm
137137
.scope

opentelemetry-proto/src/transform/trace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub mod tonic {
106106
.as_ref()
107107
.map(ToString::to_string)
108108
.unwrap_or_default(),
109-
scope: Some(source_span.instrumentation_lib.into()),
109+
scope: Some((source_span.instrumentation_lib, None).into()),
110110
spans: vec![Span {
111111
trace_id: source_span.span_context.trace_id().to_bytes().to_vec(),
112112
span_id: source_span.span_context.span_id().to_bytes().to_vec(),

opentelemetry-sdk/CHANGELOG.md

+29-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
[`opentelemetry-aws`](https://crates.io/crates/opentelemetry-aws), version
1515
0.10.0 or newer.
1616
- Performance Improvement - Counter/UpDownCounter instruments internally use
17-
`RwLock` instead of `Mutex` to reduce contention.
17+
`RwLock` instead of `Mutex` to reduce contention
1818

1919
- **Breaking** [1726](https://github.com/open-telemetry/opentelemetry-rust/pull/1726)
2020
Update `LogProcessor::emit() method to take mutable reference to LogData. This is breaking
@@ -47,6 +47,34 @@
4747

4848
- [1857](https://github.com/open-telemetry/opentelemetry-rust/pull/1857) Fixed an issue in Metrics SDK which prevented export errors from being send to global error handler. With the fix, errors occurring during export like OTLP Endpoint unresponsive shows up in stderr by default.
4949

50+
- [1869](https://github.com/open-telemetry/opentelemetry-rust/pull/1869) Added a `target` field to `LogRecord` structure, populated by `opentelemetry-appender-tracing` and `opentelemetry-appender-log` appenders.
51+
```rust
52+
async fn export<'a>(&mut self, batch: Vec<Cow<'a, LogData>>) -> LogResult<()>;
53+
```
54+
where `LogRecord` within `LogData` now includes:
55+
```rust
56+
LogData {
57+
LogRecord {
58+
event_name,
59+
target, // newly added
60+
timestamp,
61+
observed_timestamp,
62+
trace_context,
63+
trace_context,
64+
severity_number,
65+
body,
66+
attributes
67+
}
68+
Instrumentation {
69+
name,
70+
version,
71+
schema_url,
72+
version
73+
}
74+
}
75+
```
76+
The `LogRecord::target` field contains the actual target/component emitting the logs, while the `Instrumentation::name` contains the name of the OpenTelemetry appender.
77+
5078
## v0.23.0
5179

5280
- Fix SimpleSpanProcessor to be consistent with log counterpart. Also removed

opentelemetry-sdk/src/logs/record.rs

+25
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ pub struct LogRecord {
1313
/// Event name. Optional as not all the logging API support it.
1414
pub event_name: Option<Cow<'static, str>>,
1515

16+
/// Target of the log record
17+
pub target: Option<Cow<'static, str>>,
18+
1619
/// Record timestamp
1720
pub timestamp: Option<SystemTime>,
1821

@@ -42,6 +45,14 @@ impl opentelemetry::logs::LogRecord for LogRecord {
4245
self.event_name = Some(name.into());
4346
}
4447

48+
// Sets the `target` of a record
49+
fn set_target<T>(&mut self, _target: T)
50+
where
51+
T: Into<Cow<'static, str>>,
52+
{
53+
self.target = Some(_target.into());
54+
}
55+
4556
fn set_timestamp(&mut self, timestamp: SystemTime) {
4657
self.timestamp = Some(timestamp);
4758
}
@@ -116,6 +127,20 @@ mod tests {
116127
use std::borrow::Cow;
117128
use std::time::SystemTime;
118129

130+
#[test]
131+
fn test_set_eventname() {
132+
let mut log_record = LogRecord::default();
133+
log_record.set_event_name("test_event");
134+
assert_eq!(log_record.event_name, Some(Cow::Borrowed("test_event")));
135+
}
136+
137+
#[test]
138+
fn test_set_target() {
139+
let mut log_record = LogRecord::default();
140+
log_record.set_target("foo::bar");
141+
assert_eq!(log_record.target, Some(Cow::Borrowed("foo::bar")));
142+
}
143+
119144
#[test]
120145
fn test_set_timestamp() {
121146
let mut log_record = LogRecord::default();

opentelemetry/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
opaque string. Migration: Replace `.with_unit(Unit::new("myunit"))` with
1212
`.with_unit("myunit")`.
1313

14+
- [1869](https://github.com/open-telemetry/opentelemetry-rust/pull/1869) Introduced the `LogRecord::set_target()` method in the log bridge API.
15+
This method allows appenders to set the target/component emitting the logs.
16+
1417
## v0.23.0
1518

1619
### Added

opentelemetry/src/logs/noop.rs

+8
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ impl LogRecord for NoopLogRecord {
7171
V: Into<AnyValue>,
7272
{
7373
}
74+
75+
#[inline]
76+
// Sets the `target` of a record
77+
fn set_target<T>(&mut self, _target: T)
78+
where
79+
T: Into<Cow<'static, str>>,
80+
{
81+
}
7482
}
7583

7684
/// A no-op implementation of a [`Logger`]

opentelemetry/src/logs/record.rs

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ pub trait LogRecord {
1010
{
1111
}
1212

13+
/// Sets the `target` of a record.
14+
/// Currently, both `opentelemetry-appender-tracing` and `opentelemetry-appender-log` create a single logger
15+
/// with a scope that doesn't accurately reflect the component emitting the logs.
16+
/// Exporters MAY use this field to override the `instrumentation_scope.name`.
17+
fn set_target<T>(&mut self, _target: T)
18+
where
19+
T: Into<Cow<'static, str>>;
20+
1321
/// Sets the time when the event occurred measured by the origin clock, i.e. the time at the source.
1422
fn set_timestamp(&mut self, timestamp: SystemTime);
1523

0 commit comments

Comments
 (0)