Module: Lescopr

Defined in:
lib/lescopr.rb,
lib/lescopr/version.rb,
lib/lescopr/core/client.rb,
lib/lescopr/modes/direct.rb,
lib/lescopr/core/log_queue.rb,
lib/lescopr/modes/detector.rb,
lib/lescopr/modes/embedded.rb,
lib/lescopr/monitoring/logger.rb,
lib/lescopr/core/daemon_runner.rb,
lib/lescopr/transport/http_client.rb,
lib/lescopr/filesystem/config_manager.rb,
lib/lescopr/integrations/rails/railtie.rb,
lib/lescopr/filesystem/project_analyzer.rb,
lib/lescopr/integrations/rack/middleware.rb,
lib/lescopr/integrations/sinatra/extension.rb

Overview

Lescopr — zero-configuration Ruby monitoring SDK.

Examples:

Plain Ruby / Rack

require "lescopr"
Lescopr.init!(sdk_key: "lsk_xxx", api_key: "lak_xxx")

Rails (auto-init via Railtie)

# config/initializers/lescopr.rb
Lescopr.configure do |c|
  c.sdk_key     = ENV["LESCOPR_SDK_KEY"]
  c.api_key     = ENV["LESCOPR_API_KEY"]
  c.environment = ENV.fetch("LESCOPR_ENVIRONMENT", "production")
end

Defined Under Namespace

Modules: Core, Filesystem, Integrations, Modes, Monitoring, Transport Classes: Configuration

Constant Summary collapse

BASE_URL =
"https://api.lescopr.com/api/v1"
VERSION =
"1.0.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.clientLescopr::Core::Client (readonly)

Returns the active SDK client instance.

Returns:



52
53
54
# File 'lib/lescopr.rb', line 52

def client
  @client
end

Class Method Details

.configurationLescopr::Configuration



112
113
114
# File 'lib/lescopr.rb', line 112

def configuration
  @configuration ||= Configuration.new
end

.configure {|config| ... } ⇒ Object

Configure the SDK via a block.

Yield Parameters:



57
58
59
60
61
62
# File 'lib/lescopr.rb', line 57

def configure
  yield(configuration)
  @client = Core::Client.new(configuration)
  @client.setup_auto_logging!
  @client
end

.init!(opts = {}) ⇒ Object

Shorthand initialiser — accepts a hash or keyword args.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :sdk_key (String)

    SDK key (lsk_xxx)

  • :api_key (String)

    API key (lak_xxx)

  • :environment (String)

    “development” or “production”



93
94
95
96
97
98
# File 'lib/lescopr.rb', line 93

def init!(opts = {})
  configuration.sdk_key     = opts[:sdk_key]     if opts[:sdk_key]
  configuration.api_key     = opts[:api_key]     if opts[:api_key]
  configuration.environment = opts[:environment] if opts[:environment]
  configure { |_c| } # trigger setup
end

.log(level, message, metadata = {}) ⇒ Object

Send a log entry manually.

Parameters:

  • level (String, Symbol)

    log level (debug/info/warn/error/fatal)

  • message (String)
  • metadata (Hash) (defaults to: {})

    extra context



105
106
107
108
109
# File 'lib/lescopr.rb', line 105

def log(level, message,  = {})
  return unless client&.ready?

  client.send_log(level.to_s.upcase, message, )
end

.logsLescopr::Core::Client?

Zero-config init — loads SDK keys from .lescopr/config.json and auto-detects the best transport mode (daemon / embedded / direct).

Usage (e.g. config/initializers/lescopr.rb or top of application.rb):

Lescopr.logs

Returns:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/lescopr.rb', line 71

def logs
  return @client if @client

  config_mgr = Filesystem::ConfigManager.new
  saved      = config_mgr.load
  return nil unless saved && saved[:sdk_key]

  configuration.sdk_key     = saved[:sdk_key]
  configuration.api_key     = saved[:api_key]
  configuration.environment = saved[:environment] || "development"

  @client = Core::Client.new(configuration)
  @client.setup_auto_logging!
  @client
end

.reset!Object

Reset the SDK (useful in tests).



117
118
119
120
121
# File 'lib/lescopr.rb', line 117

def reset!
  @client&.shutdown!
  @client        = nil
  @configuration = nil
end