Skip to content

Commit

Permalink
Merge branch 'main' into http-json-example
Browse files Browse the repository at this point in the history
  • Loading branch information
ramgdev committed Jun 21, 2024
2 parents f3e4fa4 + c1f351c commit 89d71fc
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
os: windows-latest
- rust: stable
os: macos-latest
- rust: stable
os: actuated-arm64-4cpu-16gb
runs-on: ${{ matrix.os }}
steps:
- name: Free disk space
Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-appender-log/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## vNext

- [1869](https://github.com/open-telemetry/opentelemetry-rust/pull/1869) Utilize the `LogRecord::set_target()` method to pass the log target to the SDK.

## v0.4.0

- Add log key-values as attributes [#1628](https://github.com/open-telemetry/opentelemetry-rust/pull/1628)
Expand Down
1 change: 1 addition & 0 deletions opentelemetry-appender-log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ where
log_record.set_severity_text(record.level().as_str().into());
log_record.set_body(AnyValue::from(record.args().to_string()));
log_record.add_attributes(log_attributes(record.key_values()));
log_record.set_target(record.metadata().target().to_string());

self.logger.emit(log_record);
}
Expand Down
3 changes: 3 additions & 0 deletions opentelemetry-appender-tracing/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## vNext

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

## v0.4.0

- Removed unwanted dependency on opentelemetry-sdk.
Expand Down
1 change: 1 addition & 0 deletions opentelemetry-appender-tracing/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ where
let mut log_record = self.logger.create_log_record();
log_record.set_severity_number(severity_of_level(meta.level()));
log_record.set_severity_text(meta.level().to_string().into());
log_record.set_target(meta.target().to_string());

let mut visitor = EventVisitor::new(&mut log_record);
visitor.visit_metadata(meta);
Expand Down
1 change: 1 addition & 0 deletions opentelemetry-otlp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ now use `.with_resource(RESOURCE::default())` to configure Resource when using
- Bump MSRV to 1.70 [#1840](https://github.com/open-telemetry/opentelemetry-rust/pull/1840)
- Fixing the OTLP HTTP/JSON exporter. [#1882](https://github.com/open-telemetry/opentelemetry-rust/pull/1882) - The exporter was broken in the
previous release.
- **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.

## v0.16.0

Expand Down
76 changes: 58 additions & 18 deletions opentelemetry-proto/src/transform/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,68 @@ pub mod tonic {
#[cfg(any(feature = "trace", feature = "logs"))]
use opentelemetry_sdk::Resource;

impl From<opentelemetry_sdk::InstrumentationLibrary> for InstrumentationScope {
fn from(library: opentelemetry_sdk::InstrumentationLibrary) -> Self {
InstrumentationScope {
name: library.name.into_owned(),
version: library.version.map(Cow::into_owned).unwrap_or_default(),
attributes: Attributes::from(library.attributes).0,
..Default::default()
impl
From<(
opentelemetry_sdk::InstrumentationLibrary,
Option<Cow<'static, str>>,
)> for InstrumentationScope
{
fn from(
data: (
opentelemetry_sdk::InstrumentationLibrary,
Option<Cow<'static, str>>,
),
) -> Self {
let (library, target) = data;
if let Some(t) = target {
InstrumentationScope {
name: t.to_string(),
version: String::new(),
attributes: vec![],
..Default::default()
}
} else {
InstrumentationScope {
name: library.name.into_owned(),
version: library.version.map(Cow::into_owned).unwrap_or_default(),
attributes: Attributes::from(library.attributes).0,
..Default::default()
}
}
}
}

impl From<&opentelemetry_sdk::InstrumentationLibrary> for InstrumentationScope {
fn from(library: &opentelemetry_sdk::InstrumentationLibrary) -> Self {
InstrumentationScope {
name: library.name.to_string(),
version: library
.version
.as_ref()
.map(ToString::to_string)
.unwrap_or_default(),
attributes: Attributes::from(library.attributes.clone()).0,
..Default::default()
impl
From<(
&opentelemetry_sdk::InstrumentationLibrary,
Option<Cow<'static, str>>,
)> for InstrumentationScope
{
fn from(
data: (
&opentelemetry_sdk::InstrumentationLibrary,
Option<Cow<'static, str>>,
),
) -> Self {
let (library, target) = data;
if let Some(t) = target {
InstrumentationScope {
name: t.to_string(),
version: String::new(),
attributes: vec![],
..Default::default()
}
} else {
InstrumentationScope {
name: library.name.to_string(),
version: library
.version
.as_ref()
.map(ToString::to_string)
.unwrap_or_default(),
attributes: Attributes::from(library.attributes.clone()).0,
..Default::default()
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-proto/src/transform/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub mod tonic {
.clone()
.map(Into::into)
.unwrap_or_default(),
scope: Some(log_data.instrumentation.into()),
scope: Some((log_data.instrumentation, log_data.record.target.clone()).into()),
log_records: vec![log_data.record.into()],
}],
}
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-proto/src/transform/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub mod tonic {
impl From<&SdkScopeMetrics> for TonicScopeMetrics {
fn from(sm: &SdkScopeMetrics) -> Self {
TonicScopeMetrics {
scope: Some((&sm.scope).into()),
scope: Some((&sm.scope, None).into()),
metrics: sm.metrics.iter().map(Into::into).collect(),
schema_url: sm
.scope
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-proto/src/transform/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub mod tonic {
.as_ref()
.map(ToString::to_string)
.unwrap_or_default(),
scope: Some(source_span.instrumentation_lib.into()),
scope: Some((source_span.instrumentation_lib, None).into()),
spans: vec![Span {
trace_id: source_span.span_context.trace_id().to_bytes().to_vec(),
span_id: source_span.span_context.span_id().to_bytes().to_vec(),
Expand Down
30 changes: 29 additions & 1 deletion opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[`opentelemetry-aws`](https://crates.io/crates/opentelemetry-aws), version
0.10.0 or newer.
- Performance Improvement - Counter/UpDownCounter instruments internally use
`RwLock` instead of `Mutex` to reduce contention.
`RwLock` instead of `Mutex` to reduce contention

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

- [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.

- [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.
```rust
async fn export<'a>(&mut self, batch: Vec<Cow<'a, LogData>>) -> LogResult<()>;
```
where `LogRecord` within `LogData` now includes:
```rust
LogData {
LogRecord {
event_name,
target, // newly added
timestamp,
observed_timestamp,
trace_context,
trace_context,
severity_number,
body,
attributes
}
Instrumentation {
name,
version,
schema_url,
version
}
}
```
The `LogRecord::target` field contains the actual target/component emitting the logs, while the `Instrumentation::name` contains the name of the OpenTelemetry appender.

## v0.23.0

- Fix SimpleSpanProcessor to be consistent with log counterpart. Also removed
Expand Down
25 changes: 25 additions & 0 deletions opentelemetry-sdk/src/logs/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pub struct LogRecord {
/// Event name. Optional as not all the logging API support it.
pub event_name: Option<Cow<'static, str>>,

/// Target of the log record
pub target: Option<Cow<'static, str>>,

/// Record timestamp
pub timestamp: Option<SystemTime>,

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

// Sets the `target` of a record
fn set_target<T>(&mut self, _target: T)
where
T: Into<Cow<'static, str>>,
{
self.target = Some(_target.into());
}

fn set_timestamp(&mut self, timestamp: SystemTime) {
self.timestamp = Some(timestamp);
}
Expand Down Expand Up @@ -116,6 +127,20 @@ mod tests {
use std::borrow::Cow;
use std::time::SystemTime;

#[test]
fn test_set_eventname() {
let mut log_record = LogRecord::default();
log_record.set_event_name("test_event");
assert_eq!(log_record.event_name, Some(Cow::Borrowed("test_event")));
}

#[test]
fn test_set_target() {
let mut log_record = LogRecord::default();
log_record.set_target("foo::bar");
assert_eq!(log_record.target, Some(Cow::Borrowed("foo::bar")));
}

#[test]
fn test_set_timestamp() {
let mut log_record = LogRecord::default();
Expand Down
3 changes: 3 additions & 0 deletions opentelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
opaque string. Migration: Replace `.with_unit(Unit::new("myunit"))` with
`.with_unit("myunit")`.

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

## v0.23.0

### Added
Expand Down
8 changes: 8 additions & 0 deletions opentelemetry/src/logs/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ impl LogRecord for NoopLogRecord {
V: Into<AnyValue>,
{
}

#[inline]
// Sets the `target` of a record
fn set_target<T>(&mut self, _target: T)
where
T: Into<Cow<'static, str>>,
{
}
}

/// A no-op implementation of a [`Logger`]
Expand Down
8 changes: 8 additions & 0 deletions opentelemetry/src/logs/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ pub trait LogRecord {
{
}

/// Sets the `target` of a record.
/// Currently, both `opentelemetry-appender-tracing` and `opentelemetry-appender-log` create a single logger
/// with a scope that doesn't accurately reflect the component emitting the logs.
/// Exporters MAY use this field to override the `instrumentation_scope.name`.
fn set_target<T>(&mut self, _target: T)
where
T: Into<Cow<'static, str>>;

/// Sets the time when the event occurred measured by the origin clock, i.e. the time at the source.
fn set_timestamp(&mut self, timestamp: SystemTime);

Expand Down

0 comments on commit 89d71fc

Please sign in to comment.