Skip to content

Commit

Permalink
Merge branch 'main' into observable-cumulative-aggregation-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Aug 9, 2024
2 parents 153f6d0 + 6a16baf commit 398fdba
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 11 deletions.
3 changes: 3 additions & 0 deletions opentelemetry-otlp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## vNext

- **Breaking** [1994](https://github.com/open-telemetry/opentelemetry-rust/pull/1994) The logrecord event-name is added as attribute with
key `name` only if the feature flag `populate-logs-event-name` is enabled.

## v0.17.0

- Add "metrics", "logs" to default features. With this, default feature list is
Expand Down
1 change: 1 addition & 0 deletions opentelemetry-otlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ temp-env = { workspace = true }
trace = ["opentelemetry/trace", "opentelemetry_sdk/trace", "opentelemetry-proto/trace"]
metrics = ["opentelemetry/metrics", "opentelemetry_sdk/metrics", "opentelemetry-proto/metrics"]
logs = ["opentelemetry/logs", "opentelemetry_sdk/logs", "opentelemetry-proto/logs"]
populate-logs-event-name = ["opentelemetry-proto/populate-logs-event-name"]

# add ons
serialize = ["serde", "serde_json"]
Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-otlp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
//!
//! The following feature flags generate additional code and types:
//! * `serialize`: Enables serialization support for type defined in this create via `serde`.
//! * `populate-logs-event-name`: Enables sending `LogRecord::event_name` as an attribute
//! with the key `name`
//!
//! The following feature flags offer additional configurations on gRPC:
//!
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ path = "tests/json_deserialize.rs"

[features]
default = ["full"]

full = ["gen-tonic", "trace", "logs", "metrics", "zpages", "with-serde"]

# crates used to generate rs files
Expand All @@ -47,6 +46,7 @@ testing = ["opentelemetry/testing"]
# add ons
with-schemars = ["schemars"]
with-serde = ["serde", "hex"]
populate-logs-event-name = []

[dependencies]
tonic = { workspace = true, optional = true, features = ["codegen", "prost"] }
Expand Down
24 changes: 16 additions & 8 deletions opentelemetry-proto/src/transform/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub mod tonic {
time_unix_nano: log_record.timestamp.map(to_nanos).unwrap_or_default(),
observed_time_unix_nano: to_nanos(log_record.observed_timestamp.unwrap()),
attributes: {
let mut attributes: Vec<KeyValue> = log_record
let attributes: Vec<KeyValue> = log_record
.attributes_iter()
.map(|kv| KeyValue {
key: kv.0.to_string(),
Expand All @@ -98,14 +98,22 @@ pub mod tonic {
}),
})
.collect();
if let Some(event_name) = log_record.event_name.as_ref() {
attributes.push(KeyValue {
key: "name".into(),
value: Some(AnyValue {
value: Some(Value::StringValue(event_name.to_string())),
}),
});
#[cfg(feature = "populate-logs-event-name")]
{
if let Some(event_name) = &log_record.event_name {
let mut attributes_with_name = attributes;
attributes_with_name.push(KeyValue {
key: "name".into(),
value: Some(AnyValue {
value: Some(Value::StringValue(event_name.to_string())),
}),
});
attributes_with_name
} else {
attributes
}
}
#[cfg(not(feature = "populate-logs-event-name"))]
attributes
},
severity_number: severity_number.into(),
Expand Down
3 changes: 3 additions & 0 deletions opentelemetry-stdout/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## vNext

- **Breaking** [1994](https://github.com/open-telemetry/opentelemetry-rust/pull/1994) The logrecord event-name is added as attribute with
key `name` only if the feature flag `populate-logs-event-name` is enabled.

## v0.5.0

- Update `opentelemetry` dependency version to 0.24
Expand Down
1 change: 1 addition & 0 deletions opentelemetry-stdout/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ default = ["trace", "metrics", "logs"]
trace = ["opentelemetry/trace", "opentelemetry_sdk/trace", "futures-util"]
metrics = ["async-trait", "opentelemetry/metrics", "opentelemetry_sdk/metrics"]
logs = ["opentelemetry/logs", "opentelemetry_sdk/logs", "async-trait", "thiserror", "opentelemetry_sdk/logs_level_enabled"]
populate-logs-event-name = []

[dependencies]
async-trait = { workspace = true, optional = true }
Expand Down
11 changes: 11 additions & 0 deletions opentelemetry-stdout/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
//! exhaustive and is subject to change at any time.
//! </div>
//!
//! # Feature Flags
//! The following feature flags can enable exporters for different telemetry signals:
//!
//! * `trace`: Includes the trace exporters (enabled by default).
//! * `metrics`: Includes the metrics exporters.
//! * `logs`: Includes the logs exporters.
//!
//! The following feature flags generate additional code and types:
//! * `populate-logs-event-name`: Enables sending `LogRecord::event_name` as an attribute
//! with the key `name`
//!
//! # Examples
//!
//! ```no_run
Expand Down
12 changes: 10 additions & 2 deletions opentelemetry-stdout/src/logs/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,25 @@ impl From<opentelemetry_sdk::export::logs::LogData> for LogRecord {
fn from(value: opentelemetry_sdk::export::logs::LogData) -> Self {
LogRecord {
attributes: {
let mut attributes = value
let attributes = value
.record
.attributes_iter()
.map(|(k, v)| KeyValue::from((k.clone(), v.clone()))) // Map each pair to a KeyValue
.collect::<Vec<KeyValue>>(); // Collect into a Vec<KeyValue>s

#[cfg(feature = "populate-logs-event-name")]
if let Some(event_name) = &value.record.event_name {
attributes.push(KeyValue::from((
let mut attributes_with_name = attributes;
attributes_with_name.push(KeyValue::from((
"name".into(),
opentelemetry::Value::String(event_name.clone().into()),
)));
attributes_with_name
} else {
attributes
}

#[cfg(not(feature = "populate-logs-event-name"))]
attributes
},
trace_id: value
Expand Down

0 comments on commit 398fdba

Please sign in to comment.