Skip to content

Commit 398fdba

Browse files
authored
Merge branch 'main' into observable-cumulative-aggregation-fix
2 parents 153f6d0 + 6a16baf commit 398fdba

File tree

9 files changed

+48
-11
lines changed

9 files changed

+48
-11
lines changed

opentelemetry-otlp/CHANGELOG.md

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

33
## vNext
44

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

710
- Add "metrics", "logs" to default features. With this, default feature list is

opentelemetry-otlp/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ temp-env = { workspace = true }
5656
trace = ["opentelemetry/trace", "opentelemetry_sdk/trace", "opentelemetry-proto/trace"]
5757
metrics = ["opentelemetry/metrics", "opentelemetry_sdk/metrics", "opentelemetry-proto/metrics"]
5858
logs = ["opentelemetry/logs", "opentelemetry_sdk/logs", "opentelemetry-proto/logs"]
59+
populate-logs-event-name = ["opentelemetry-proto/populate-logs-event-name"]
5960

6061
# add ons
6162
serialize = ["serde", "serde_json"]

opentelemetry-otlp/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@
9191
//!
9292
//! The following feature flags generate additional code and types:
9393
//! * `serialize`: Enables serialization support for type defined in this create via `serde`.
94+
//! * `populate-logs-event-name`: Enables sending `LogRecord::event_name` as an attribute
95+
//! with the key `name`
9496
//!
9597
//! The following feature flags offer additional configurations on gRPC:
9698
//!

opentelemetry-proto/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ path = "tests/json_deserialize.rs"
3030

3131
[features]
3232
default = ["full"]
33-
3433
full = ["gen-tonic", "trace", "logs", "metrics", "zpages", "with-serde"]
3534

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

5151
[dependencies]
5252
tonic = { workspace = true, optional = true, features = ["codegen", "prost"] }

opentelemetry-proto/src/transform/logs.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub mod tonic {
8989
time_unix_nano: log_record.timestamp.map(to_nanos).unwrap_or_default(),
9090
observed_time_unix_nano: to_nanos(log_record.observed_timestamp.unwrap()),
9191
attributes: {
92-
let mut attributes: Vec<KeyValue> = log_record
92+
let attributes: Vec<KeyValue> = log_record
9393
.attributes_iter()
9494
.map(|kv| KeyValue {
9595
key: kv.0.to_string(),
@@ -98,14 +98,22 @@ pub mod tonic {
9898
}),
9999
})
100100
.collect();
101-
if let Some(event_name) = log_record.event_name.as_ref() {
102-
attributes.push(KeyValue {
103-
key: "name".into(),
104-
value: Some(AnyValue {
105-
value: Some(Value::StringValue(event_name.to_string())),
106-
}),
107-
});
101+
#[cfg(feature = "populate-logs-event-name")]
102+
{
103+
if let Some(event_name) = &log_record.event_name {
104+
let mut attributes_with_name = attributes;
105+
attributes_with_name.push(KeyValue {
106+
key: "name".into(),
107+
value: Some(AnyValue {
108+
value: Some(Value::StringValue(event_name.to_string())),
109+
}),
110+
});
111+
attributes_with_name
112+
} else {
113+
attributes
114+
}
108115
}
116+
#[cfg(not(feature = "populate-logs-event-name"))]
109117
attributes
110118
},
111119
severity_number: severity_number.into(),

opentelemetry-stdout/CHANGELOG.md

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

33
## vNext
44

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

710
- Update `opentelemetry` dependency version to 0.24

opentelemetry-stdout/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ default = ["trace", "metrics", "logs"]
2020
trace = ["opentelemetry/trace", "opentelemetry_sdk/trace", "futures-util"]
2121
metrics = ["async-trait", "opentelemetry/metrics", "opentelemetry_sdk/metrics"]
2222
logs = ["opentelemetry/logs", "opentelemetry_sdk/logs", "async-trait", "thiserror", "opentelemetry_sdk/logs_level_enabled"]
23+
populate-logs-event-name = []
2324

2425
[dependencies]
2526
async-trait = { workspace = true, optional = true }

opentelemetry-stdout/src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
//! exhaustive and is subject to change at any time.
55
//! </div>
66
//!
7+
//! # Feature Flags
8+
//! The following feature flags can enable exporters for different telemetry signals:
9+
//!
10+
//! * `trace`: Includes the trace exporters (enabled by default).
11+
//! * `metrics`: Includes the metrics exporters.
12+
//! * `logs`: Includes the logs exporters.
13+
//!
14+
//! The following feature flags generate additional code and types:
15+
//! * `populate-logs-event-name`: Enables sending `LogRecord::event_name` as an attribute
16+
//! with the key `name`
17+
//!
718
//! # Examples
819
//!
920
//! ```no_run

opentelemetry-stdout/src/logs/transform.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,25 @@ impl From<opentelemetry_sdk::export::logs::LogData> for LogRecord {
108108
fn from(value: opentelemetry_sdk::export::logs::LogData) -> Self {
109109
LogRecord {
110110
attributes: {
111-
let mut attributes = value
111+
let attributes = value
112112
.record
113113
.attributes_iter()
114114
.map(|(k, v)| KeyValue::from((k.clone(), v.clone()))) // Map each pair to a KeyValue
115115
.collect::<Vec<KeyValue>>(); // Collect into a Vec<KeyValue>s
116+
117+
#[cfg(feature = "populate-logs-event-name")]
116118
if let Some(event_name) = &value.record.event_name {
117-
attributes.push(KeyValue::from((
119+
let mut attributes_with_name = attributes;
120+
attributes_with_name.push(KeyValue::from((
118121
"name".into(),
119122
opentelemetry::Value::String(event_name.clone().into()),
120123
)));
124+
attributes_with_name
125+
} else {
126+
attributes
121127
}
128+
129+
#[cfg(not(feature = "populate-logs-event-name"))]
122130
attributes
123131
},
124132
trace_id: value

0 commit comments

Comments
 (0)