Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
kcenon::monitoring::opentelemetry_compatibility_layer Class Reference

Main OpenTelemetry compatibility layer. More...

#include <opentelemetry_adapter.h>

Collaboration diagram for kcenon::monitoring::opentelemetry_compatibility_layer:
Collaboration graph

Classes

struct  compatibility_stats
 Get compatibility layer statistics. More...
 

Public Member Functions

 opentelemetry_compatibility_layer (const otel_resource &resource)
 
common::VoidResult initialize ()
 Initialize the compatibility layer.
 
common::VoidResult shutdown ()
 Shutdown the compatibility layer.
 
common::VoidResult export_spans (const std::vector< trace_span > &spans)
 Export spans using OpenTelemetry format.
 
common::VoidResult export_metrics (const monitoring_data &data)
 Export metrics using OpenTelemetry format.
 
common::VoidResult flush ()
 Flush pending data to exporters.
 
compatibility_stats get_stats () const
 
const otel_resourceget_resource () const
 Get resource information.
 

Private Attributes

otel_resource resource_
 
opentelemetry_tracer_adapter tracer_adapter_
 
opentelemetry_metrics_adapter metrics_adapter_
 
std::mutex mutex_
 
bool initialized_ {false}
 
std::vector< otel_span_datapending_spans_
 
std::vector< otel_metric_datapending_metrics_
 
std::size_t spans_exported_ {0}
 
std::size_t metrics_exported_ {0}
 
std::chrono::system_clock::time_point last_export_
 
std::size_t export_errors_ {0}
 

Detailed Description

Main OpenTelemetry compatibility layer.

Definition at line 380 of file opentelemetry_adapter.h.

Constructor & Destructor Documentation

◆ opentelemetry_compatibility_layer()

kcenon::monitoring::opentelemetry_compatibility_layer::opentelemetry_compatibility_layer ( const otel_resource & resource)
inlineexplicit

Member Function Documentation

◆ export_metrics()

common::VoidResult kcenon::monitoring::opentelemetry_compatibility_layer::export_metrics ( const monitoring_data & data)
inline

Export metrics using OpenTelemetry format.

Definition at line 445 of file opentelemetry_adapter.h.

445 {
446 if (!initialized_) {
447 return common::VoidResult::err(error_info(monitoring_error_code::invalid_state,
448 "Compatibility layer not initialized", "monitoring_system").to_common_error());
449 }
450
451 auto convert_result = metrics_adapter_.convert_monitoring_data(data);
452 if (convert_result.is_err()) {
453 return common::VoidResult::err(error_info(monitoring_error_code::processing_failed,
454 "Failed to convert metrics: " + convert_result.error().message).to_common_error());
455 }
456
457 // Store converted metrics for batching
458 std::lock_guard<std::mutex> lock(mutex_);
459 const auto& otel_metrics = convert_result.value();
460 pending_metrics_.insert(pending_metrics_.end(), otel_metrics.begin(), otel_metrics.end());
461
462 return common::ok();
463 }
common::Result< std::vector< otel_metric_data > > convert_monitoring_data(const monitoring_data &data)
Convert monitoring data to OpenTelemetry metric data.

References kcenon::monitoring::opentelemetry_metrics_adapter::convert_monitoring_data(), initialized_, kcenon::monitoring::invalid_state, metrics_adapter_, mutex_, pending_metrics_, kcenon::monitoring::processing_failed, and kcenon::monitoring::error_info::to_common_error().

Here is the call graph for this function:

◆ export_spans()

common::VoidResult kcenon::monitoring::opentelemetry_compatibility_layer::export_spans ( const std::vector< trace_span > & spans)
inline

Export spans using OpenTelemetry format.

Definition at line 422 of file opentelemetry_adapter.h.

422 {
423 if (!initialized_) {
424 return common::VoidResult::err(error_info(monitoring_error_code::invalid_state,
425 "Compatibility layer not initialized", "monitoring_system").to_common_error());
426 }
427
428 auto convert_result = tracer_adapter_.convert_spans(spans);
429 if (convert_result.is_err()) {
430 return common::VoidResult::err(error_info(monitoring_error_code::processing_failed,
431 "Failed to convert spans: " + convert_result.error().message).to_common_error());
432 }
433
434 // Store converted spans for batching
435 std::lock_guard<std::mutex> lock(mutex_);
436 const auto& otel_spans = convert_result.value();
437 pending_spans_.insert(pending_spans_.end(), otel_spans.begin(), otel_spans.end());
438
439 return common::ok();
440 }
common::Result< std::vector< otel_span_data > > convert_spans(const std::vector< trace_span > &spans)
Convert multiple spans to OpenTelemetry format.

References kcenon::monitoring::opentelemetry_tracer_adapter::convert_spans(), initialized_, kcenon::monitoring::invalid_state, mutex_, pending_spans_, kcenon::monitoring::processing_failed, kcenon::monitoring::error_info::to_common_error(), and tracer_adapter_.

Here is the call graph for this function:

◆ flush()

common::VoidResult kcenon::monitoring::opentelemetry_compatibility_layer::flush ( )
inline

Flush pending data to exporters.

Definition at line 468 of file opentelemetry_adapter.h.

468 {
469 std::lock_guard<std::mutex> lock(mutex_);
470
471 // In a real implementation, this would send data to OpenTelemetry collectors
472 // For now, we'll just clear the pending data
473 pending_spans_.clear();
474 pending_metrics_.clear();
475
476 return common::ok();
477 }

References mutex_, pending_metrics_, and pending_spans_.

◆ get_resource()

const otel_resource & kcenon::monitoring::opentelemetry_compatibility_layer::get_resource ( ) const
inline

Get resource information.

Definition at line 506 of file opentelemetry_adapter.h.

506 {
507 return resource_;
508 }

References resource_.

◆ get_stats()

compatibility_stats kcenon::monitoring::opentelemetry_compatibility_layer::get_stats ( ) const
inline

Definition at line 491 of file opentelemetry_adapter.h.

491 {
492 std::lock_guard<std::mutex> lock(mutex_);
493 compatibility_stats stats;
494 stats.pending_spans = pending_spans_.size();
495 stats.pending_metrics = pending_metrics_.size();
496 stats.spans_exported = spans_exported_;
497 stats.metrics_exported = metrics_exported_;
498 stats.last_export = last_export_;
499 stats.export_errors = export_errors_;
500 return stats;
501 }

References kcenon::monitoring::opentelemetry_compatibility_layer::compatibility_stats::export_errors, export_errors_, kcenon::monitoring::opentelemetry_compatibility_layer::compatibility_stats::last_export, last_export_, kcenon::monitoring::opentelemetry_compatibility_layer::compatibility_stats::metrics_exported, metrics_exported_, mutex_, kcenon::monitoring::opentelemetry_compatibility_layer::compatibility_stats::pending_metrics, pending_metrics_, kcenon::monitoring::opentelemetry_compatibility_layer::compatibility_stats::pending_spans, pending_spans_, kcenon::monitoring::opentelemetry_compatibility_layer::compatibility_stats::spans_exported, and spans_exported_.

◆ initialize()

common::VoidResult kcenon::monitoring::opentelemetry_compatibility_layer::initialize ( )
inline

Initialize the compatibility layer.

Definition at line 390 of file opentelemetry_adapter.h.

390 {
391 std::lock_guard<std::mutex> lock(mutex_);
392 if (initialized_) {
393 return common::VoidResult::err(error_info(monitoring_error_code::already_exists,
394 "Compatibility layer already initialized", "monitoring_system").to_common_error());
395 }
396
397 initialized_ = true;
398 return common::ok();
399 }

References kcenon::monitoring::already_exists, initialized_, and mutex_.

◆ shutdown()

common::VoidResult kcenon::monitoring::opentelemetry_compatibility_layer::shutdown ( )
inline

Shutdown the compatibility layer.

Definition at line 404 of file opentelemetry_adapter.h.

404 {
405 std::lock_guard<std::mutex> lock(mutex_);
406 if (!initialized_) {
407 return common::ok();
408 }
409
410 // Flush any pending data without re-locking
411 // In a real implementation, this would send data to OpenTelemetry collectors
412 pending_spans_.clear();
413 pending_metrics_.clear();
414
415 initialized_ = false;
416 return common::ok();
417 }

References initialized_, mutex_, pending_metrics_, and pending_spans_.

Member Data Documentation

◆ export_errors_

std::size_t kcenon::monitoring::opentelemetry_compatibility_layer::export_errors_ {0}
private

Definition at line 524 of file opentelemetry_adapter.h.

524{0};

Referenced by get_stats().

◆ initialized_

bool kcenon::monitoring::opentelemetry_compatibility_layer::initialized_ {false}
private

Definition at line 516 of file opentelemetry_adapter.h.

516{false};

Referenced by export_metrics(), export_spans(), initialize(), and shutdown().

◆ last_export_

std::chrono::system_clock::time_point kcenon::monitoring::opentelemetry_compatibility_layer::last_export_
private

Definition at line 523 of file opentelemetry_adapter.h.

Referenced by get_stats().

◆ metrics_adapter_

opentelemetry_metrics_adapter kcenon::monitoring::opentelemetry_compatibility_layer::metrics_adapter_
private

Definition at line 513 of file opentelemetry_adapter.h.

Referenced by export_metrics().

◆ metrics_exported_

std::size_t kcenon::monitoring::opentelemetry_compatibility_layer::metrics_exported_ {0}
private

Definition at line 522 of file opentelemetry_adapter.h.

522{0};

Referenced by get_stats().

◆ mutex_

std::mutex kcenon::monitoring::opentelemetry_compatibility_layer::mutex_
mutableprivate

◆ pending_metrics_

std::vector<otel_metric_data> kcenon::monitoring::opentelemetry_compatibility_layer::pending_metrics_
private

Definition at line 519 of file opentelemetry_adapter.h.

Referenced by export_metrics(), flush(), get_stats(), and shutdown().

◆ pending_spans_

std::vector<otel_span_data> kcenon::monitoring::opentelemetry_compatibility_layer::pending_spans_
private

Definition at line 518 of file opentelemetry_adapter.h.

Referenced by export_spans(), flush(), get_stats(), and shutdown().

◆ resource_

otel_resource kcenon::monitoring::opentelemetry_compatibility_layer::resource_
private

Definition at line 511 of file opentelemetry_adapter.h.

Referenced by get_resource().

◆ spans_exported_

std::size_t kcenon::monitoring::opentelemetry_compatibility_layer::spans_exported_ {0}
private

Definition at line 521 of file opentelemetry_adapter.h.

521{0};

Referenced by get_stats().

◆ tracer_adapter_

opentelemetry_tracer_adapter kcenon::monitoring::opentelemetry_compatibility_layer::tracer_adapter_
private

Definition at line 512 of file opentelemetry_adapter.h.

Referenced by export_spans().


The documentation for this class was generated from the following file: