diff --git a/docs/OtlpHttpLogger.md b/docs/OtlpHttpLogger.md index 240aa8e..2fda1b1 100644 --- a/docs/OtlpHttpLogger.md +++ b/docs/OtlpHttpLogger.md @@ -64,6 +64,24 @@ LogIt++ -> OtlpHttpLogger -> kurlyk::HttpClient -> OpenTelemetry Collector / Lok Resource attributes are configured through `OtlpHttpLoggerConfig`, including `service.name`, `service.namespace`, `service.instance.id`, and `deployment.environment.name`. +## Diagnostics + +`OtlpHttpLogger` exposes its internal counters through the generic logger parameter API: + +```cpp +const auto dropped = LOGIT_GET_INT_PARAM(otlp_index, logit::LoggerParam::DroppedLogCount); +const auto failed = LOGIT_GET_INT_PARAM(otlp_index, logit::LoggerParam::FailedExportCount); +``` + +Available diagnostic params: + +| Parameter | Meaning | +| --- | --- | +| `LoggerParam::DroppedLogCount` | Number of records dropped because the backend queue overflowed or the logger was stopping. | +| `LoggerParam::FailedExportCount` | Number of failed OTLP export attempts. | + +These values are also available through `get_string_param()` and `get_float_param()`. Integer retrieval saturates at `int64_t` max if the underlying unsigned counter ever exceeds that range. + ## Notes - `OtlpHttpLogger` is an outbound client/exporter, not a server. diff --git a/include/logit_cpp/logit/enums.hpp b/include/logit_cpp/logit/enums.hpp index 1918585..14b50a0 100644 --- a/include/logit_cpp/logit/enums.hpp +++ b/include/logit_cpp/logit/enums.hpp @@ -48,7 +48,9 @@ namespace logit { LastFileName, ///< The name of the last file written to. LastFilePath, ///< The full path of the last file written to. LastLogTimestamp, ///< The timestamp of the last log. - TimeSinceLastLog ///< The time elapsed since the last log in seconds. + TimeSinceLastLog, ///< The time elapsed since the last log in seconds. + DroppedLogCount, ///< Number of log records dropped by the backend. + FailedExportCount ///< Number of failed export attempts reported by the backend. }; /// \enum CompressType diff --git a/include/logit_cpp/logit/loggers/OtlpHttpLogger.hpp b/include/logit_cpp/logit/loggers/OtlpHttpLogger.hpp index 8253c33..2d8fe2f 100644 --- a/include/logit_cpp/logit/loggers/OtlpHttpLogger.hpp +++ b/include/logit_cpp/logit/loggers/OtlpHttpLogger.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -126,6 +127,8 @@ namespace logit { switch (param) { case LoggerParam::LastLogTimestamp: return std::to_string(get_last_log_ts()); case LoggerParam::TimeSinceLastLog: return std::to_string(get_time_since_last_log()); + case LoggerParam::DroppedLogCount: return std::to_string(dropped_count()); + case LoggerParam::FailedExportCount: return std::to_string(failed_export_count()); default: break; } @@ -139,6 +142,8 @@ namespace logit { switch (param) { case LoggerParam::LastLogTimestamp: return get_last_log_ts(); case LoggerParam::TimeSinceLastLog: return get_time_since_last_log(); + case LoggerParam::DroppedLogCount: return counter_to_int64(dropped_count()); + case LoggerParam::FailedExportCount: return counter_to_int64(failed_export_count()); default: break; } @@ -147,13 +152,17 @@ namespace logit { /// \brief Retrieves a floating-point parameter from the logger. /// \param param Parameter to retrieve. - /// \return Parameter value in seconds, or 0.0 when unsupported. + /// \return Parameter value in seconds for time params, raw count for counter params, or 0.0 when unsupported. double get_float_param(const LoggerParam& param) const override { switch (param) { case LoggerParam::LastLogTimestamp: return static_cast(get_last_log_ts()) / 1000.0; case LoggerParam::TimeSinceLastLog: return static_cast(get_time_since_last_log()) / 1000.0; + case LoggerParam::DroppedLogCount: + return static_cast(dropped_count()); + case LoggerParam::FailedExportCount: + return static_cast(failed_export_count()); default: break; } @@ -317,6 +326,14 @@ namespace logit { const int64_t now = LOGIT_CURRENT_TIMESTAMP_MS(); return now > last ? now - last : 0; } + + /// \brief Converts unsigned counter value to int64_t with saturation. + /// \param value Counter value. + /// \return Counter value clamped to int64_t max. + static int64_t counter_to_int64(uint64_t value) { + const uint64_t max_value = static_cast((std::numeric_limits::max)()); + return value > max_value ? (std::numeric_limits::max)() : static_cast(value); + } }; } // namespace logit