Class: LogBrew::Client

Inherits:
Object
  • Object
show all
Includes:
TraceClientMethods
Defined in:
lib/logbrew.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, sdk:, max_retries:) ⇒ Client

Returns a new instance of Client.



755
756
757
758
759
760
761
# File 'lib/logbrew.rb', line 755

def initialize(api_key:, sdk:, max_retries:)
  @api_key = api_key
  @sdk = sdk
  @max_retries = max_retries
  @events = []
  @closed = false
end

Class Method Details

.create(api_key:, sdk_name:, sdk_version:, max_retries: 2) ⇒ Object

Raises:



742
743
744
745
746
747
748
749
750
751
752
753
# File 'lib/logbrew.rb', line 742

def self.create(api_key:, sdk_name:, sdk_version:, max_retries: 2)
  Validation.require_non_empty("api_key", api_key)
  Validation.require_non_empty("sdk_name", sdk_name)
  Validation.require_non_empty("sdk_version", sdk_version)
  raise SdkError.new("validation_error", "max_retries must be non-negative") if max_retries.negative?

  new(
    api_key: api_key,
    sdk: { "name" => sdk_name, "language" => "ruby", "version" => sdk_version },
    max_retries: max_retries
  )
end

Instance Method Details

#action(id, timestamp, attributes) ⇒ Object



795
796
797
# File 'lib/logbrew.rb', line 795

def action(id, timestamp, attributes)
  push_event("action", id, timestamp, validate_action(attributes))
end

#environment(id, timestamp, attributes) ⇒ Object



775
776
777
# File 'lib/logbrew.rb', line 775

def environment(id, timestamp, attributes)
  push_event("environment", id, timestamp, validate_environment(attributes))
end

#flush(transport) ⇒ Object

Raises:



799
800
801
802
803
# File 'lib/logbrew.rb', line 799

def flush(transport)
  raise SdkError.new("shutdown_error", "client is already shut down") if @closed

  flush_internal(transport)
end

#issue(id, timestamp, attributes) ⇒ Object



779
780
781
# File 'lib/logbrew.rb', line 779

def issue(id, timestamp, attributes)
  push_event("issue", id, timestamp, validate_issue(attributes))
end

#log(id, timestamp, attributes) ⇒ Object



783
784
785
# File 'lib/logbrew.rb', line 783

def log(id, timestamp, attributes)
  push_event("log", id, timestamp, validate_log(attributes))
end

#metric(id, timestamp, attributes) ⇒ Object



791
792
793
# File 'lib/logbrew.rb', line 791

def metric(id, timestamp, attributes)
  push_event("metric", id, timestamp, validate_metric(attributes))
end

#pending_eventsObject



763
764
765
# File 'lib/logbrew.rb', line 763

def pending_events
  @events.length
end

#preview_jsonObject



767
768
769
# File 'lib/logbrew.rb', line 767

def preview_json
  JSON.pretty_generate("sdk" => @sdk, "events" => @events)
end

#release(id, timestamp, attributes) ⇒ Object



771
772
773
# File 'lib/logbrew.rb', line 771

def release(id, timestamp, attributes)
  push_event("release", id, timestamp, validate_release(attributes))
end

#shutdown(transport) ⇒ Object

Raises:



805
806
807
808
809
810
811
# File 'lib/logbrew.rb', line 805

def shutdown(transport)
  raise SdkError.new("shutdown_error", "client is already shut down") if @closed

  response = flush_internal(transport)
  @closed = true
  response
end

#span(id, timestamp, attributes) ⇒ Object



787
788
789
# File 'lib/logbrew.rb', line 787

def span(id, timestamp, attributes)
  push_event("span", id, timestamp, validate_span(attributes))
end