ORE Studio 0.0.4
Loading...
Searching...
No Matches
Public Member Functions | List of all members
lifecycle_manager Class Referencefinal

Extends the base lifecycle_manager with telemetry sink support. More...

#include <lifecycle_manager.hpp>

Inheritance diagram for lifecycle_manager:
Inheritance graph
Collaboration diagram for lifecycle_manager:
Collaboration graph

Public Member Functions

 lifecycle_manager (lifecycle_manager &&)=delete
 
lifecycle_manageroperator= (const lifecycle_manager &)=delete
 
 lifecycle_manager (std::optional< logging_options > ocfg)
 Initialise logging for the entire application.
 
 ~lifecycle_manager () override
 Shutdown logging for the entire application.
 
void add_telemetry_sink (std::shared_ptr< domain::resource > resource, telemetry_sink_backend::log_record_handler handler)
 Adds a telemetry sink for log record correlation.
 
- Public Member Functions inherited from lifecycle_manager
 lifecycle_manager (lifecycle_manager &&)=delete
 
lifecycle_manageroperator= (const lifecycle_manager &)=delete
 
 lifecycle_manager (std::optional< logging_options > ocfg)
 Initialise logging for the entire application.
 

Additional Inherited Members

- Protected Types inherited from lifecycle_manager
using file_sink_type = boost::log::sinks::synchronous_sink< boost::log::sinks::text_file_backend >
 
using console_sink_type = boost::log::sinks::synchronous_sink< boost::log::sinks::text_ostream_backend >
 
- Static Protected Member Functions inherited from lifecycle_manager
static boost::shared_ptr< file_sink_type > make_file_sink (std::filesystem::path path, boost_severity severity, std::string tag)
 Creates a boost log file sink.
 
static boost::shared_ptr< console_sink_type > make_console_sink (boost_severity severity, std::string tag)
 Creates a boost log console sink.
 
- Protected Attributes inherited from lifecycle_manager
boost::shared_ptr< file_sink_type > file_sink_
 
boost::shared_ptr< console_sink_type > console_sink_
 

Detailed Description

Extends the base lifecycle_manager with telemetry sink support.

This class inherits from ores::logging::lifecycle_manager and adds the ability to attach a telemetry sink for OpenTelemetry log correlation. The telemetry sink extracts trace_id and span_id from log attributes and creates domain::log_record instances for export.

Note: this class uses boost shared_ptr due to legacy reasons (boost log does not support std::shared_ptr).

Constructor & Destructor Documentation

◆ lifecycle_manager()

lifecycle_manager ( std::optional< logging_options ocfg)
explicit

Initialise logging for the entire application.

If no configuration is supplied, logging is disabled. This constructor delegates to the base class for console and file sink setup, and initializes the telemetry sink member.

Note
Must be done in a thread-safe context.

◆ ~lifecycle_manager()

~lifecycle_manager ( )
overridevirtual

Shutdown logging for the entire application.

Stops and flushes the telemetry sink before base class cleanup.

Reimplemented from lifecycle_manager.

Member Function Documentation

◆ add_telemetry_sink()

void add_telemetry_sink ( std::shared_ptr< domain::resource resource,
telemetry_sink_backend::log_record_handler  handler 
)

Adds a telemetry sink for log record correlation.

The telemetry sink extracts trace_id and span_id attributes from log records and creates domain::log_record instances for export. The sink is asynchronous to avoid blocking the logging thread.

Parameters
resourceThe resource describing the entity producing logs.
handlerFunction called for each converted log record.

Example:

auto resource = domain::resource::from_environment("my-service", "1.0");
auto exporter = std::make_shared<file_log_exporter>("logs/telemetry.jsonl");
lm.add_telemetry_sink(resource, [exporter](auto rec) {
exporter->export_record(std::move(rec));
});
Options related to logging.
Definition logging_options.hpp:32
static resource from_environment(std::string_view service_name, std::string_view service_version)
Creates a resource by detecting the local environment.
Definition resource.cpp:59
Extends the base lifecycle_manager with telemetry sink support.
Definition lifecycle_manager.hpp:47