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

OpenTelemetry Protocol (OTLP) trace exporter implementation. More...

#include <trace_exporters.h>

Inheritance diagram for kcenon::monitoring::otlp_exporter:
Inheritance graph
Collaboration diagram for kcenon::monitoring::otlp_exporter:
Collaboration graph

Public Member Functions

 otlp_exporter (const trace_export_config &config, const otel_resource &resource)
 
common::VoidResult export_spans (const std::vector< trace_span > &spans) override
 Export a batch of spans.
 
common::VoidResult flush () override
 Flush any pending spans.
 
common::VoidResult shutdown () override
 Shutdown the exporter.
 
std::unordered_map< std::string, std::size_t > get_stats () const override
 Get exporter statistics.
 
- Public Member Functions inherited from kcenon::monitoring::trace_exporter_interface
virtual ~trace_exporter_interface ()=default
 

Private Member Functions

common::VoidResult send_grpc_batch (const std::vector< otel_span_data > &spans)
 
common::VoidResult send_http_json_batch (const std::vector< otel_span_data > &spans)
 
common::VoidResult send_http_protobuf_batch (const std::vector< otel_span_data > &spans)
 

Private Attributes

trace_export_config config_
 
std::unique_ptr< opentelemetry_tracer_adapterotel_adapter_
 
std::atomic< std::size_t > exported_spans_ {0}
 
std::atomic< std::size_t > failed_exports_ {0}
 
std::atomic< std::size_t > dropped_spans_ {0}
 

Detailed Description

OpenTelemetry Protocol (OTLP) trace exporter implementation.

Definition at line 827 of file trace_exporters.h.

Constructor & Destructor Documentation

◆ otlp_exporter()

kcenon::monitoring::otlp_exporter::otlp_exporter ( const trace_export_config & config,
const otel_resource & resource )
inlineexplicit

Definition at line 836 of file trace_exporters.h.

837 : config_(config), otel_adapter_(std::make_unique<opentelemetry_tracer_adapter>(resource)) {}
std::unique_ptr< opentelemetry_tracer_adapter > otel_adapter_

Member Function Documentation

◆ export_spans()

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

Export a batch of spans.

Implements kcenon::monitoring::trace_exporter_interface.

Definition at line 839 of file trace_exporters.h.

839 {
840 try {
841 // Convert to OpenTelemetry format first
842 auto otel_result = otel_adapter_->convert_spans(spans);
843 if (otel_result.is_err()) {
845 return common::VoidResult::err(error_info(monitoring_error_code::processing_failed,
846 "Failed to convert spans to OTEL format: " + otel_result.error().message, "monitoring_system").to_common_error());
847 }
848
849 const auto& otel_spans = otel_result.value();
850
851 // Send via appropriate OTLP protocol
852 common::VoidResult send_result = common::ok();
854 send_result = send_grpc_batch(otel_spans);
856 send_result = send_http_json_batch(otel_spans);
858 send_result = send_http_protobuf_batch(otel_spans);
859 } else {
860 return common::VoidResult::err(error_info(monitoring_error_code::invalid_configuration,
861 "Invalid OTLP export format", "monitoring_system").to_common_error());
862 }
863
864 if (send_result.is_ok()) {
865 exported_spans_ += spans.size();
866 } else {
868 return send_result;
869 }
870
871 return common::ok();
872
873 } catch (const std::exception& e) {
875 return common::VoidResult::err(error_info(monitoring_error_code::operation_failed,
876 "OTLP export failed: " + std::string(e.what()), "monitoring_system").to_common_error());
877 }
878 }
std::atomic< std::size_t > exported_spans_
common::VoidResult send_http_json_batch(const std::vector< otel_span_data > &spans)
std::atomic< std::size_t > failed_exports_
common::VoidResult send_http_protobuf_batch(const std::vector< otel_span_data > &spans)
common::VoidResult send_grpc_batch(const std::vector< otel_span_data > &spans)
@ otlp_http_json
OTLP HTTP JSON protocol.
@ otlp_http_protobuf
OTLP HTTP Protocol Buffers.

References config_, exported_spans_, failed_exports_, kcenon::monitoring::trace_export_config::format, kcenon::monitoring::invalid_configuration, kcenon::monitoring::operation_failed, otel_adapter_, kcenon::monitoring::otlp_grpc, kcenon::monitoring::otlp_http_json, kcenon::monitoring::otlp_http_protobuf, kcenon::monitoring::processing_failed, send_grpc_batch(), send_http_json_batch(), send_http_protobuf_batch(), and kcenon::monitoring::error_info::to_common_error().

Referenced by TEST_F(), TEST_F(), and TEST_F().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ flush()

common::VoidResult kcenon::monitoring::otlp_exporter::flush ( )
inlineoverridevirtual

Flush any pending spans.

Implements kcenon::monitoring::trace_exporter_interface.

Definition at line 880 of file trace_exporters.h.

880 {
881 // OTLP exporter typically sends immediately, so flush is a no-op
882 return common::ok();
883 }

Referenced by shutdown(), and TEST_F().

Here is the caller graph for this function:

◆ get_stats()

std::unordered_map< std::string, std::size_t > kcenon::monitoring::otlp_exporter::get_stats ( ) const
inlineoverridevirtual

Get exporter statistics.

Implements kcenon::monitoring::trace_exporter_interface.

Definition at line 889 of file trace_exporters.h.

889 {
890 return {
891 {"exported_spans", exported_spans_.load()},
892 {"failed_exports", failed_exports_.load()},
893 {"dropped_spans", dropped_spans_.load()}
894 };
895 }
std::atomic< std::size_t > dropped_spans_

References dropped_spans_, exported_spans_, and failed_exports_.

Referenced by TEST_F(), and TEST_F().

Here is the caller graph for this function:

◆ send_grpc_batch()

common::VoidResult kcenon::monitoring::otlp_exporter::send_grpc_batch ( const std::vector< otel_span_data > & spans)
inlineprivate

Definition at line 898 of file trace_exporters.h.

898 {
899 // Simulate OTLP gRPC sending
900 // In real implementation, this would use OTLP gRPC client
901 (void)spans; // Suppress unused parameter warning
902 return common::ok();
903 }

Referenced by export_spans().

Here is the caller graph for this function:

◆ send_http_json_batch()

common::VoidResult kcenon::monitoring::otlp_exporter::send_http_json_batch ( const std::vector< otel_span_data > & spans)
inlineprivate

Definition at line 905 of file trace_exporters.h.

905 {
906 // Simulate OTLP HTTP JSON sending
907 // In real implementation, this would serialize OTEL spans to JSON and POST
908 (void)spans; // Suppress unused parameter warning
909 return common::ok();
910 }

Referenced by export_spans().

Here is the caller graph for this function:

◆ send_http_protobuf_batch()

common::VoidResult kcenon::monitoring::otlp_exporter::send_http_protobuf_batch ( const std::vector< otel_span_data > & spans)
inlineprivate

Definition at line 912 of file trace_exporters.h.

912 {
913 // Simulate OTLP HTTP protobuf sending
914 // In real implementation, this would serialize OTEL spans to protobuf and POST
915 (void)spans; // Suppress unused parameter warning
916 return common::ok();
917 }

Referenced by export_spans().

Here is the caller graph for this function:

◆ shutdown()

common::VoidResult kcenon::monitoring::otlp_exporter::shutdown ( )
inlineoverridevirtual

Shutdown the exporter.

Implements kcenon::monitoring::trace_exporter_interface.

Definition at line 885 of file trace_exporters.h.

885 {
886 return flush();
887 }
common::VoidResult flush() override
Flush any pending spans.

References flush().

Referenced by TEST_F().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ config_

trace_export_config kcenon::monitoring::otlp_exporter::config_
private

Definition at line 829 of file trace_exporters.h.

Referenced by export_spans().

◆ dropped_spans_

std::atomic<std::size_t> kcenon::monitoring::otlp_exporter::dropped_spans_ {0}
private

Definition at line 833 of file trace_exporters.h.

833{0};

Referenced by get_stats().

◆ exported_spans_

std::atomic<std::size_t> kcenon::monitoring::otlp_exporter::exported_spans_ {0}
private

Definition at line 831 of file trace_exporters.h.

831{0};

Referenced by export_spans(), and get_stats().

◆ failed_exports_

std::atomic<std::size_t> kcenon::monitoring::otlp_exporter::failed_exports_ {0}
private

Definition at line 832 of file trace_exporters.h.

832{0};

Referenced by export_spans(), and get_stats().

◆ otel_adapter_

std::unique_ptr<opentelemetry_tracer_adapter> kcenon::monitoring::otlp_exporter::otel_adapter_
private

Definition at line 830 of file trace_exporters.h.

Referenced by export_spans().


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