Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/OtlpHttpLogger.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion include/logit_cpp/logit/enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion include/logit_cpp/logit/loggers/OtlpHttpLogger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <cstdint>
#include <deque>
#include <future>
#include <limits>
#include <mutex>
#include <string>
#include <thread>
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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<double>(get_last_log_ts()) / 1000.0;
case LoggerParam::TimeSinceLastLog:
return static_cast<double>(get_time_since_last_log()) / 1000.0;
case LoggerParam::DroppedLogCount:
return static_cast<double>(dropped_count());
case LoggerParam::FailedExportCount:
return static_cast<double>(failed_export_count());
default:
break;
}
Expand Down Expand Up @@ -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<uint64_t>((std::numeric_limits<int64_t>::max)());
return value > max_value ? (std::numeric_limits<int64_t>::max)() : static_cast<int64_t>(value);
}
};

} // namespace logit
Expand Down
Loading