Class: Tracekit::SDK
- Inherits:
-
Object
- Object
- Tracekit::SDK
- Defined in:
- lib/tracekit/sdk.rb
Overview
Main SDK class for TraceKit Ruby SDK with OpenTelemetry integration Provides distributed tracing, metrics collection, and code monitoring capabilities
Class Attribute Summary collapse
-
.instance ⇒ Object
Global SDK instance.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#service_name ⇒ Object
readonly
Returns the value of attribute service_name.
Class Method Summary collapse
-
.configure(config) ⇒ SDK
Creates and configures the SDK singleton.
-
.current ⇒ SDK?
Returns the global SDK instance.
Instance Method Summary collapse
-
#capture_snapshot(label, variables) ⇒ Object
Captures a snapshot of local variables at the current code location Only active if code monitoring is enabled and there’s an active breakpoint.
-
#counter(name, tags = {}) ⇒ Metrics::Counter
Creates a Counter metric for tracking monotonically increasing values.
-
#gauge(name, tags = {}) ⇒ Metrics::Gauge
Creates a Gauge metric for tracking point-in-time values.
-
#histogram(name, tags = {}) ⇒ Metrics::Histogram
Creates a Histogram metric for tracking value distributions.
-
#initialize(config) ⇒ SDK
constructor
A new instance of SDK.
-
#shutdown ⇒ Object
Shuts down the SDK and flushes any pending data.
Constructor Details
#initialize(config) ⇒ SDK
Returns a new instance of SDK.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/tracekit/sdk.rb', line 73 def initialize(config) @config = config @service_name = config.service_name puts "Initializing TraceKit SDK v#{Tracekit::VERSION} for service: #{config.service_name}, environment: #{config.environment}" # Auto-detect local UI local_ui_detector = LocalUIDetector.new(config.local_ui_port) if local_endpoint = local_ui_detector.local_ui_endpoint puts "Local UI detected at #{local_endpoint}" end # Resolve endpoints traces_endpoint = EndpointResolver.resolve(config.endpoint, "/v1/traces", config.use_ssl) metrics_endpoint = EndpointResolver.resolve(config.endpoint, "/v1/metrics", config.use_ssl) snapshot_base_url = EndpointResolver.resolve(config.endpoint, "", config.use_ssl) # Initialize OpenTelemetry tracer setup_tracing(traces_endpoint) # Initialize LLM instrumentation (auto-detect providers) setup_llm_instrumentation if defined?(Tracekit::LLM) # Initialize metrics registry @metrics_registry = Metrics::Registry.new(metrics_endpoint, config.api_key, config.service_name) # Initialize snapshot client if code monitoring is enabled if config.enable_code_monitoring @snapshot_client = Snapshots::Client.new( config.api_key, snapshot_base_url, config.service_name, config.code_monitoring_poll_interval ) puts "Code monitoring enabled - Snapshot client started" end puts "TraceKit SDK initialized successfully. Traces: #{traces_endpoint}, Metrics: #{metrics_endpoint}" end |
Class Attribute Details
.instance ⇒ Object
Global SDK instance
284 285 286 |
# File 'lib/tracekit/sdk.rb', line 284 def instance @instance end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
71 72 73 |
# File 'lib/tracekit/sdk.rb', line 71 def config @config end |
#service_name ⇒ Object (readonly)
Returns the value of attribute service_name.
71 72 73 |
# File 'lib/tracekit/sdk.rb', line 71 def service_name @service_name end |
Class Method Details
.configure(config) ⇒ SDK
Creates and configures the SDK singleton
289 290 291 |
# File 'lib/tracekit/sdk.rb', line 289 def configure(config) @instance = new(config) end |
.current ⇒ SDK?
Returns the global SDK instance
295 296 297 |
# File 'lib/tracekit/sdk.rb', line 295 def current @instance end |
Instance Method Details
#capture_snapshot(label, variables) ⇒ Object
Captures a snapshot of local variables at the current code location Only active if code monitoring is enabled and there’s an active breakpoint
141 142 143 144 145 146 |
# File 'lib/tracekit/sdk.rb', line 141 def capture_snapshot(label, variables) return unless @snapshot_client caller_location = caller_locations(1, 1).first @snapshot_client.capture_snapshot(label, variables, caller_location) end |
#counter(name, tags = {}) ⇒ Metrics::Counter
Creates a Counter metric for tracking monotonically increasing values
117 118 119 |
# File 'lib/tracekit/sdk.rb', line 117 def counter(name, = {}) Metrics::Counter.new(name, , @metrics_registry) end |
#gauge(name, tags = {}) ⇒ Metrics::Gauge
Creates a Gauge metric for tracking point-in-time values
125 126 127 |
# File 'lib/tracekit/sdk.rb', line 125 def gauge(name, = {}) Metrics::Gauge.new(name, , @metrics_registry) end |
#histogram(name, tags = {}) ⇒ Metrics::Histogram
Creates a Histogram metric for tracking value distributions
133 134 135 |
# File 'lib/tracekit/sdk.rb', line 133 def histogram(name, = {}) Metrics::Histogram.new(name, , @metrics_registry) end |
#shutdown ⇒ Object
Shuts down the SDK and flushes any pending data
149 150 151 152 153 154 |
# File 'lib/tracekit/sdk.rb', line 149 def shutdown @metrics_registry&.shutdown @snapshot_client&.shutdown OpenTelemetry.tracer_provider&.shutdown puts "TraceKit SDK shutdown complete" end |