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 662 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 671 of file trace_exporters.h.

672 : 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 674 of file trace_exporters.h.

674 {
675 try {
676 // Convert to OpenTelemetry format first
677 auto otel_result = otel_adapter_->convert_spans(spans);
678 if (otel_result.is_err()) {
680 return common::VoidResult::err(error_info(monitoring_error_code::processing_failed,
681 "Failed to convert spans to OTEL format: " + otel_result.error().message, "monitoring_system").to_common_error());
682 }
683
684 const auto& otel_spans = otel_result.value();
685
686 // Send via appropriate OTLP protocol
687 common::VoidResult send_result = common::ok();
689 send_result = send_grpc_batch(otel_spans);
691 send_result = send_http_json_batch(otel_spans);
693 send_result = send_http_protobuf_batch(otel_spans);
694 } else {
695 return common::VoidResult::err(error_info(monitoring_error_code::invalid_configuration,
696 "Invalid OTLP export format", "monitoring_system").to_common_error());
697 }
698
699 if (send_result.is_ok()) {
700 exported_spans_ += spans.size();
701 } else {
703 return send_result;
704 }
705
706 return common::ok();
707
708 } catch (const std::exception& e) {
710 return common::VoidResult::err(error_info(monitoring_error_code::operation_failed,
711 "OTLP export failed: " + std::string(e.what()), "monitoring_system").to_common_error());
712 }
713 }
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 715 of file trace_exporters.h.

715 {
716 // OTLP exporter typically sends immediately, so flush is a no-op
717 return common::ok();
718 }

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 724 of file trace_exporters.h.

724 {
725 return {
726 {"exported_spans", exported_spans_.load()},
727 {"failed_exports", failed_exports_.load()},
728 {"dropped_spans", dropped_spans_.load()}
729 };
730 }
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 733 of file trace_exporters.h.

733 {
734 // Simulate OTLP gRPC sending
735 // In real implementation, this would use OTLP gRPC client
736 (void)spans; // Suppress unused parameter warning
737 return common::ok();
738 }

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 740 of file trace_exporters.h.

740 {
741 // Simulate OTLP HTTP JSON sending
742 // In real implementation, this would serialize OTEL spans to JSON and POST
743 (void)spans; // Suppress unused parameter warning
744 return common::ok();
745 }

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 747 of file trace_exporters.h.

747 {
748 // Simulate OTLP HTTP protobuf sending
749 // In real implementation, this would serialize OTEL spans to protobuf and POST
750 (void)spans; // Suppress unused parameter warning
751 return common::ok();
752 }

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 720 of file trace_exporters.h.

720 {
721 return flush();
722 }
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 664 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 668 of file trace_exporters.h.

668{0};

Referenced by get_stats().

◆ exported_spans_

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

Definition at line 666 of file trace_exporters.h.

666{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 667 of file trace_exporters.h.

667{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 665 of file trace_exporters.h.

Referenced by export_spans().


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