ObservabilityDebug.h#
Fully qualified name: omni/observability/ObservabilityDebug.h
File members: omni/observability/ObservabilityDebug.h
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: LicenseRef-NvidiaProprietary
//
// NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
// property and proprietary rights in and to this material, related
// documentation and any modifications thereto. Any use, reproduction,
// disclosure or distribution of this material and related documentation
// without an express license agreement from NVIDIA CORPORATION or
// its affiliates is strictly prohibited.
#pragma once
#include <carb/cpp/StringView.h>
#include <omni/observability/Utils.h>
#include <atomic>
#include <chrono>
namespace omni
{
namespace observability
{
constexpr char kOmniTelemetrySetupChannel[] = "omni.observability.setup";
constexpr char kOmniSettingsChannel[] = "omni.observability.settings";
constexpr char kOmniMetricsSetupChannel[] = "omni.observability.metrics.setup";
constexpr char kOmniTracesSetupChannel[] = "omni.observability.traces.setup";
constexpr char kOmniLogsSetupChannel[] = "omni.observability.logs.setup";
using LogLevel = int32_t;
constexpr LogLevel kLogLevelVerbose = -2;
constexpr LogLevel kLogLevelInfo = -1;
constexpr LogLevel kLogLevelWarn = 0;
constexpr LogLevel kLogLevelError = 1;
inline const char* getLogLevelName(LogLevel level)
{
switch (level)
{
case kLogLevelVerbose:
return "verbose";
case kLogLevelInfo:
return "info";
case kLogLevelWarn:
return "warn";
case kLogLevelError:
return "error";
default:
return level < kLogLevelVerbose ? "verbose" : "error";
}
}
class LogMetadata
{
public:
const char* channelName = "";
const char* filename = "";
const char* function = "";
LogLevel level = kLogLevelWarn;
int32_t lineNumber = 0;
ThreadId threadId = 0;
ProcessId processId = 0;
std::chrono::nanoseconds timestamp;
LogMetadata() = default;
~LogMetadata() = default;
LogMetadata(const char* channel_,
const char* filename_,
const char* function_,
LogLevel level_,
int32_t lineNumber_,
ThreadId threadId_,
ProcessId processId_);
LogMetadata(const LogMetadata& other)
{
*this = other;
}
LogMetadata& operator=(const LogMetadata& other)
{
if (this == &other)
return *this;
channelName = other.channelName;
filename = other.filename;
function = other.function;
level = other.level;
lineNumber = other.lineNumber;
threadId = other.threadId;
processId = other.processId;
return *this;
}
};
class RefCountedObject
{
public:
void addRef()
{
m_refCount++;
}
void release()
{
if (--m_refCount == 0)
{
delete this;
}
}
protected:
virtual ~RefCountedObject() = default;
std::atomic<int32_t> m_refCount = 1;
};
class Logger : public RefCountedObject
{
public:
virtual void handleMsg(const LogMetadata& metadata, carb::cpp::string_view messageText) = 0;
};
class SilentLogger : public Logger
{
void handleMsg(const LogMetadata& /* metadata */, carb::cpp::string_view /* messageText */) final
{
// intentionally do nothing.
}
};
} // namespace observability
} // namespace omni