Class: Tasker::Telemetry::Plugins::JsonExporter
- Inherits:
-
BaseExporter
- Object
- BaseExporter
- Tasker::Telemetry::Plugins::JsonExporter
- Defined in:
- lib/tasker/telemetry/plugins/json_exporter.rb
Overview
JSON format exporter for metrics data
Exports metrics in structured JSON format with optional pretty printing and custom field mapping.
Constant Summary collapse
- VERSION =
'1.0.0'
- DESCRIPTION =
'JSON format exporter with customizable field mapping'
Constants included from Concerns::StructuredLogging
Concerns::StructuredLogging::CORRELATION_ID_KEY
Instance Attribute Summary
Attributes inherited from BaseExporter
Instance Method Summary collapse
-
#export(metrics_data, options = {}) ⇒ Hash
Export metrics data as JSON.
-
#initialize(options = {}) ⇒ JsonExporter
constructor
A new instance of JsonExporter.
-
#supported_formats ⇒ Array<String>
Get supported formats.
-
#supports_format?(format) ⇒ Boolean
Check if format is supported.
Methods inherited from BaseExporter
#log_plugin_event, #log_plugin_exception, #log_plugin_performance, #metadata, #on_cache_sync, #on_export_complete, #on_export_request, #safe_export
Methods included from Concerns::StructuredLogging
#correlation_id, #correlation_id=, #log_exception, #log_orchestration_event, #log_performance_event, #log_step_event, #log_structured, #log_task_event, #with_correlation_id
Constructor Details
#initialize(options = {}) ⇒ JsonExporter
Returns a new instance of JsonExporter.
31 32 33 34 35 |
# File 'lib/tasker/telemetry/plugins/json_exporter.rb', line 31 def initialize( = {}) super() @field_mapping = .fetch(:field_mapping, {}) @include_metadata = .fetch(:include_metadata, true) end |
Instance Method Details
#export(metrics_data, options = {}) ⇒ Hash
Export metrics data as JSON
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/tasker/telemetry/plugins/json_exporter.rb', line 44 def export(metrics_data, = {}) pretty = .fetch(:pretty, false) additional_fields = .fetch(:additional_fields, {}) # Build export data with field mapping export_data = build_export_data(metrics_data, additional_fields) # Generate JSON json_output = if pretty JSON.pretty_generate(export_data) else JSON.generate(export_data) end { success: true, format: 'json', data: json_output, size_bytes: json_output.bytesize, metrics_count: metrics_data[:metrics]&.size || 0 } end |
#supported_formats ⇒ Array<String>
Get supported formats
78 79 80 |
# File 'lib/tasker/telemetry/plugins/json_exporter.rb', line 78 def supported_formats %w[json] end |
#supports_format?(format) ⇒ Boolean
Check if format is supported
71 72 73 |
# File 'lib/tasker/telemetry/plugins/json_exporter.rb', line 71 def supports_format?(format) %w[json].include?(format.to_s.downcase) end |