diff --git a/CHANGELOG.md b/CHANGELOG.md index 37d4a31e..cd0f165e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,7 +55,7 @@ All significant changes to this project will be documented in this file. * Remove the redundant `"timestamp"` event property (and `jiff` dependency) from `FastraceEvent` in `logforth-append-fastrace` and require an active sampled `SpanContext::current_local_parent()` before recording events (skipping parentless `LocalCollector::start()` scopes); read event timestamps from `fastrace::collector::EventRecord::timestamp_unix_ns` instead. * Broaden `Journald::with_syslog_identifier` in `logforth-append-journald` from `String` to `impl Into`; pass string literals directly without `.into()` where type inference would otherwise be ambiguous. * Upgrade `opentelemetry` and `opentelemetry_sdk` from `0.32.0` to `0.33.1` (re-exporting both crates), remove the mandatory `opentelemetry-otlp` dependency, and replace `OpentelemetryLogBuilder` (including `OpentelemetryLogBuilder::{label, labels}`) with `OpentelemetryLog::{new, with_make_body}` over `(InstrumentationScope, SdkLoggerProvider)` in `logforth-append-opentelemetry` so multiple channels can share a provider, custom `Resource` attributes, and custom `LogProcessor` pipelines without premature shutdown on `Drop`. -* `OpentelemetryLog` in `logforth-append-opentelemetry` now emits source location attributes under the OpenTelemetry semantic convention keys `code.function.name` (`Record::module_path`), `code.file.path`, `code.line.number`, and `code.column.number` instead of `module_path`, `file`, `line`, and `column`; update queries and processors matching the previous attribute names. +* `OpentelemetryLog` in `logforth-append-opentelemetry` now emits source location attributes under `code.module.name` (`Record::module_path`), `code.file.path`, `code.line.number`, and `code.column.number` instead of `module_path`, `file`, `line`, and `column`; update queries and processors matching the previous attribute names. * Replace `fasyslog` with `logforth-syslog` in `logforth-append-syslog` and remove the `rustls` and `native-tls` Cargo features from `logforth-append-syslog` and `logforth`: `Syslog` and `SyslogBuilder` are renamed to `SocketSyslog` and `SocketSyslogBuilder` (re-exported as `logforth::append::SocketSyslog`), and `Facility`, `Severity`, `ParseError`, `SyslogContext`, `Framing`, and `jiff` are exported at the crate root. * Mark `SyslogFormat` as `#[non_exhaustive]` in `logforth-append-syslog` and rename its variants `{RFC3164, RFC5424}` to `{Rfc3164, Rfc5424}`. * Replace `{tcp_well_known, udp_well_known, broadcast_well_known, rustls*, native_tls*, new}` on `SocketSyslogBuilder` in `logforth-append-syslog` with fallible constructors returning `Result` (preserving `io::Error` via `.source()`), auto-binding `udp(remote)` (use `udp_bind` or `udp_socket` for explicit sockets), `tcp_tls(addr, handshake)` over caller-supplied TLS closures (defaulting to `Rfc5424` with RFC 5425 `Framing::OctetCounting`), and unbuffered `Framing::LineFeed` (`\n`) with lazy reconnection instead of buffered `\r\n` on stream transports. diff --git a/appenders/opentelemetry/README.md b/appenders/opentelemetry/README.md index c1c6da0a..7eb01669 100644 --- a/appenders/opentelemetry/README.md +++ b/appenders/opentelemetry/README.md @@ -53,14 +53,14 @@ fn main() -> Result<(), Box> { Each `Record` is projected onto an `opentelemetry_sdk::logs::SdkLogRecord`: -| `SdkLogRecord` field | Source in Logforth | -| :------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `timestamp` | `Record::time()` (event creation time, preserved across `Async` queues and explicit `RecordBuilder::time`). | -| `observed_timestamp` | `SystemTime::now()` captured when `OpentelemetryLog::append` processes the record. | -| `severity_number` / `text` | 1-to-1 mapping across all 24 `Level` variants (`Trace`..=`Fatal4` -> `Severity::Trace`..=`Severity::Fatal4`) and `Level::name()`. | -| `body` | `AnyValue::String` from `Record::payload()` (omitted when empty), or custom `AnyValue` via `MakeBody` (such as `MakeBodyLayout`). | -| `trace_context` | Extracted from `Diagnostic` `("trace_id", "span_id")` (32- and 16-digit non-zero hex) and optional boolean `"sampled"`. | -| `attributes` | Present `code.function.name` (`module_path`), `code.file.path`, `code.line.number`, `code.column.number`, remaining `Diagnostic` entries, and `Record::key_values()`. | +| `SdkLogRecord` field | Source in Logforth | +| :------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `timestamp` | `Record::time()` (event creation time, preserved across `Async` queues and explicit `RecordBuilder::time`). | +| `observed_timestamp` | `SystemTime::now()` captured when `OpentelemetryLog::append` processes the record. | +| `severity_number` / `text` | 1-to-1 mapping across all 24 `Level` variants (`Trace`..=`Fatal4` -> `Severity::Trace`..=`Severity::Fatal4`) and `Level::name()`. | +| `body` | `AnyValue::String` from `Record::payload()` (omitted when empty), or custom `AnyValue` via `MakeBody` (such as `MakeBodyLayout`). | +| `trace_context` | Extracted from `Diagnostic` `("trace_id", "span_id")` (32- and 16-digit non-zero hex) and optional boolean `"sampled"`. | +| `attributes` | Present `code.module.name` (`module_path`), `code.file.path`, `code.line.number`, `code.column.number`, remaining `Diagnostic` entries, and `Record::key_values()`. | | `OpentelemetryLog` method | Effect | | :-------------------------- | :------------------------------------------------------------------------------------------------------- | diff --git a/appenders/opentelemetry/src/lib.rs b/appenders/opentelemetry/src/lib.rs index 3438e9ff..90931a3f 100644 --- a/appenders/opentelemetry/src/lib.rs +++ b/appenders/opentelemetry/src/lib.rs @@ -25,7 +25,7 @@ //! - `trace_context` comes from [`Diagnostic`] entries when both `trace_id` and `span_id` are //! nonzero hexadecimal IDs of 32 and 16 digits respectively. An optional boolean `sampled` sets //! the trace flags. Unconsumed entries remain available as attributes. -//! - `attributes` begin with the available source location fields (`code.function.name` from +//! - `attributes` begin with the available source location fields (`code.module.name` from //! [`Record::module_path`], `code.file.path`, `code.line.number`, and `code.column.number`), //! followed by diagnostic entries and then [`Record::key_values`]. By default only the last //! occurrence of each key survives, in its original position. @@ -78,7 +78,9 @@ use opentelemetry_sdk::logs::SdkLogRecord; use opentelemetry_sdk::logs::SdkLogger; use opentelemetry_sdk::logs::SdkLoggerProvider; -const ATTR_CODE_FUNCTION_NAME: &str = "code.function.name"; +// Rust compile-time callsites expose only `module_path!()` without a function name. +// `code.module.name` is proposed in https://github.com/open-telemetry/semantic-conventions/issues/4440. +const ATTR_CODE_MODULE_NAME: &str = "code.module.name"; const ATTR_CODE_FILE_PATH: &str = "code.file.path"; const ATTR_CODE_LINE_NUMBER: &str = "code.line.number"; const ATTR_CODE_COLUMN_NUMBER: &str = "code.column.number"; @@ -302,13 +304,13 @@ fn add_source_location( mut keep: impl FnMut(&str) -> bool, ) { if let Some(module_path) = record.module_path_static() { - if keep(ATTR_CODE_FUNCTION_NAME) { - log_record.add_attribute(ATTR_CODE_FUNCTION_NAME, module_path); + if keep(ATTR_CODE_MODULE_NAME) { + log_record.add_attribute(ATTR_CODE_MODULE_NAME, module_path); } } else if let Some(module_path) = record.module_path() - && keep(ATTR_CODE_FUNCTION_NAME) + && keep(ATTR_CODE_MODULE_NAME) { - log_record.add_attribute(ATTR_CODE_FUNCTION_NAME, module_path.to_owned()); + log_record.add_attribute(ATTR_CODE_MODULE_NAME, module_path.to_owned()); } if let Some(file) = record.file_static() { diff --git a/tests-integration/tests/append_test/opentelemetry.rs b/tests-integration/tests/append_test/opentelemetry.rs index a9723079..77e1bcc7 100644 --- a/tests-integration/tests/append_test/opentelemetry.rs +++ b/tests-integration/tests/append_test/opentelemetry.rs @@ -136,7 +136,7 @@ fn opentelemetry_appender_preserves_event_timestamp_maps_all_levels_and_shuts_do attrs_vec(&first.record), vec![ ( - "code.function.name".to_owned(), + "code.module.name".to_owned(), AnyValue::from("app::billing") ), ( @@ -216,7 +216,7 @@ fn opentelemetry_appender_encodes_typed_attributes_and_diagnostics() { .filter(|(k, _)| { !matches!( k.as_str(), - "code.function.name" | "code.file.path" | "code.line.number" | "code.column.number" + "code.module.name" | "code.file.path" | "code.line.number" | "code.column.number" ) }) .collect();