brut 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/brut/cli/apps/db.rb +4 -6
- data/lib/brut/cli.rb +1 -6
- data/lib/brut/framework/mcp.rb +70 -42
- data/lib/brut/version.rb +1 -1
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 2e624fb125bcb14a88b3b7adb148561c404befc86974a77423b6cd66293bba31
         | 
| 4 | 
            +
              data.tar.gz: e2a20fc23b6aa7d0708ea7adf9852333b10616aa4e633d972031c726b9d43316
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 59b7398fbf77fafd04c770e617b8fcb341887db4b14691828ab94775c4d36b44d8475889293a39a8cfc92c7b27ef935c487c60d8f7a7f25f96edbfa57db8b75b
         | 
| 7 | 
            +
              data.tar.gz: aa3ce63a03296837fb5c425ce430a8a0658d732edf32fbed4ac7d01d74fb39dfde6e0b91e0aeadfb7f26d970ac3f23fcf6aab3216354152884fe9f86f4772412
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/lib/brut/cli/apps/db.rb
    CHANGED
    
    | @@ -13,12 +13,10 @@ class Brut::CLI::Apps::DB < Brut::CLI::App | |
| 13 13 | 
             
                def handle_bootstrap_exception(ex)
         | 
| 14 14 | 
             
                  case ex
         | 
| 15 15 | 
             
                  when Sequel::DatabaseConnectionError
         | 
| 16 | 
            -
                     | 
| 17 | 
            -
                    stop_execution
         | 
| 16 | 
            +
                    abort_execution("Database needs to be created")
         | 
| 18 17 | 
             
                  when Sequel::DatabaseError
         | 
| 19 18 | 
             
                    if ex.cause.kind_of?(PG::UndefinedTable)
         | 
| 20 | 
            -
                       | 
| 21 | 
            -
                      stop_execution
         | 
| 19 | 
            +
                      abort_execution("Migrations need to be run")
         | 
| 22 20 | 
             
                    else
         | 
| 23 21 | 
             
                      super
         | 
| 24 22 | 
             
                    end
         | 
| @@ -87,6 +85,7 @@ class Brut::CLI::Apps::DB < Brut::CLI::App | |
| 87 85 | 
             
                    stop_execution
         | 
| 88 86 | 
             
                  when Sequel::DatabaseError
         | 
| 89 87 | 
             
                    if ex.cause.kind_of?(PG::UndefinedTable)
         | 
| 88 | 
            +
                      out.puts ex.message
         | 
| 90 89 | 
             
                      out.puts "Migrations need to be run"
         | 
| 91 90 | 
             
                      continue_execution
         | 
| 92 91 | 
             
                    else
         | 
| @@ -151,8 +150,7 @@ class Brut::CLI::Apps::DB < Brut::CLI::App | |
| 151 150 | 
             
                def handle_bootstrap_exception(ex)
         | 
| 152 151 | 
             
                  case ex
         | 
| 153 152 | 
             
                  when Sequel::DatabaseConnectionError
         | 
| 154 | 
            -
                     | 
| 155 | 
            -
                    stop_execution
         | 
| 153 | 
            +
                    abort_execution("Database does not exist. Create it first")
         | 
| 156 154 | 
             
                  when Sequel::DatabaseError
         | 
| 157 155 | 
             
                    if ex.cause.kind_of?(PG::UndefinedTable)
         | 
| 158 156 | 
             
                      # ignoring - we are running migrations which will address this
         | 
    
        data/lib/brut/cli.rb
    CHANGED
    
    | @@ -26,12 +26,7 @@ module Brut | |
| 26 26 | 
             
                # @param project_root [Pathname] the path to the root of your project. This is needed before the Brut framework is initialized so
         | 
| 27 27 | 
             
                # it must be specified explicitly.
         | 
| 28 28 | 
             
                def self.app(app_klass, project_root:)
         | 
| 29 | 
            -
                  Brut::CLI::AppRunner.new(app_klass:,project_root:).run | 
| 30 | 
            -
                    otel_configured = OpenTelemetry.tracer_provider.is_a?(OpenTelemetry::SDK::Trace::TracerProvider)
         | 
| 31 | 
            -
                    if otel_configured
         | 
| 32 | 
            -
                      OpenTelemetry.tracer_provider.shutdown
         | 
| 33 | 
            -
                    end
         | 
| 34 | 
            -
                  }
         | 
| 29 | 
            +
                  Brut::CLI::AppRunner.new(app_klass:,project_root:).run!
         | 
| 35 30 | 
             
                end
         | 
| 36 31 | 
             
                autoload(:App, "brut/cli/app")
         | 
| 37 32 | 
             
                autoload(:Command, "brut/cli/command")
         | 
    
        data/lib/brut/framework/mcp.rb
    CHANGED
    
    | @@ -17,6 +17,9 @@ require "opentelemetry/exporter/otlp" | |
| 17 17 | 
             
            # intended to use or interact with this class at all. End of line.
         | 
| 18 18 | 
             
            class Brut::Framework::MCP
         | 
| 19 19 |  | 
| 20 | 
            +
              @otel_shutdown = Concurrent::AtomicBoolean.new(false)
         | 
| 21 | 
            +
              def self.otel_shutdown = @otel_shutdown
         | 
| 22 | 
            +
             | 
| 20 23 | 
             
              # Create and configure the MCP.  The app will not work until {#boot!} has been called, however most of the core configuration
         | 
| 21 24 | 
             
              # will be available via `Brut.container`.
         | 
| 22 25 | 
             
              #
         | 
| @@ -66,58 +69,34 @@ class Brut::Framework::MCP | |
| 66 69 | 
             
                  begin
         | 
| 67 70 | 
             
                    Brut.container.sequel_db_handle.disconnect
         | 
| 68 71 | 
             
                  rescue Sequel::DatabaseConnectionError
         | 
| 69 | 
            -
                    SemanticLogger[ | 
| 72 | 
            +
                    SemanticLogger[self.class].info "Not connected to database, so not disconnecting"
         | 
| 73 | 
            +
                  end
         | 
| 74 | 
            +
                  otel_configured = OpenTelemetry.tracer_provider.is_a?(OpenTelemetry::SDK::Trace::TracerProvider)
         | 
| 75 | 
            +
                  if otel_configured
         | 
| 76 | 
            +
                    if $PROGRAM_NAME =~ /^sidekiq/
         | 
| 77 | 
            +
                      SemanticLogger[self.class].info "Assuming we are sidekiq, which will shutdown OpenTelemetry, so doing nothing", program: $PROGRAM_NAME
         | 
| 78 | 
            +
                    else
         | 
| 79 | 
            +
                      if self.class.otel_shutdown.make_true
         | 
| 80 | 
            +
                        SemanticLogger[self.class].info "Shutting down OpenTelemetry", program: $PROGRAM_NAME
         | 
| 81 | 
            +
                        OpenTelemetry.tracer_provider.shutdown
         | 
| 82 | 
            +
                      else
         | 
| 83 | 
            +
                        SemanticLogger[self.class].info "OpenTelemetry already shutdown", program: $PROGRAM_NAME
         | 
| 84 | 
            +
                      end
         | 
| 85 | 
            +
                    end
         | 
| 86 | 
            +
                  else
         | 
| 87 | 
            +
                    SemanticLogger[self.class].info "OpenTelemetry was not configured, so no shutdown needed", program: $PROGRAM_NAME
         | 
| 70 88 | 
             
                  end
         | 
| 71 89 | 
             
                end
         | 
| 72 | 
            -
                Sequel::Database.extension :pg_array
         | 
| 73 | 
            -
                Sequel::Database.extension :pg_json
         | 
| 74 | 
            -
             | 
| 75 | 
            -
                sequel_db = Brut.container.sequel_db_handle
         | 
| 76 90 |  | 
| 77 | 
            -
                 | 
| 78 | 
            -
             | 
| 79 | 
            -
                Sequel::Model.plugin :find_bang
         | 
| 80 | 
            -
                Sequel::Model.plugin :created_at
         | 
| 81 | 
            -
                Sequel::Model.plugin :table_select
         | 
| 82 | 
            -
                Sequel::Model.plugin :skip_saving_columns
         | 
| 91 | 
            +
                boot_postgres!
         | 
| 92 | 
            +
                boot_otel!
         | 
| 83 93 |  | 
| 84 | 
            -
                if !Brut.container.external_id_prefix.nil?
         | 
| 85 | 
            -
                  Sequel::Model.plugin :external_id, global_prefix: Brut.container.external_id_prefix
         | 
| 86 | 
            -
                end
         | 
| 87 94 | 
             
                if Brut.container.eager_load_classes?
         | 
| 88 95 | 
             
                  SemanticLogger["Brut"].info("Eagerly loading app's classes")
         | 
| 89 96 | 
             
                  @loader.eager_load
         | 
| 90 97 | 
             
                else
         | 
| 91 98 | 
             
                  SemanticLogger["Brut"].info("Lazily loading app's classes")
         | 
| 92 99 | 
             
                end
         | 
| 93 | 
            -
                OpenTelemetry::SDK.configure do |c|
         | 
| 94 | 
            -
                  c.service_name = @app.id
         | 
| 95 | 
            -
                  if ENV["OTEL_TRACES_EXPORTER"]
         | 
| 96 | 
            -
                    SemanticLogger[self.class].info "OTEL_TRACES_EXPORTER was set (to '#{ENV['OTEL_TRACES_EXPORTER']}'), so Brut's OTel logging is disabled"
         | 
| 97 | 
            -
                  else
         | 
| 98 | 
            -
                    c.add_span_processor(
         | 
| 99 | 
            -
                      OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(
         | 
| 100 | 
            -
                        Brut::Instrumentation::LoggerSpanExporter.new
         | 
| 101 | 
            -
                      )
         | 
| 102 | 
            -
                    )
         | 
| 103 | 
            -
                  end
         | 
| 104 | 
            -
             | 
| 105 | 
            -
                  if defined?(OpenTelemetry::Instrumentation::Sidekiq)
         | 
| 106 | 
            -
                    c.use 'OpenTelemetry::Instrumentation::Sidekiq', {
         | 
| 107 | 
            -
                      span_naming: :job_class,
         | 
| 108 | 
            -
                    }
         | 
| 109 | 
            -
                  else
         | 
| 110 | 
            -
                    SemanticLogger[self.class].info "OpenTelemetry::Instrumentation::Sidekiq is not loaded, so Sidekiq traces will not be captured"
         | 
| 111 | 
            -
                  end
         | 
| 112 | 
            -
                end
         | 
| 113 | 
            -
             | 
| 114 | 
            -
                Brut.container.store(
         | 
| 115 | 
            -
                  "tracer",
         | 
| 116 | 
            -
                  OpenTelemetry::SDK::Trace::Tracer,
         | 
| 117 | 
            -
                  "Tracer for Open Telemetry",
         | 
| 118 | 
            -
                  OpenTelemetry.tracer_provider.tracer(@app.id)
         | 
| 119 | 
            -
                )
         | 
| 120 | 
            -
                Sequel::Database.extension :brut_instrumentation
         | 
| 121 100 |  | 
| 122 101 | 
             
                @app.boot!
         | 
| 123 102 |  | 
| @@ -304,4 +283,53 @@ private | |
| 304 283 |  | 
| 305 284 | 
             
                @loader.setup
         | 
| 306 285 | 
             
              end
         | 
| 286 | 
            +
             | 
| 287 | 
            +
              def boot_postgres!
         | 
| 288 | 
            +
                Sequel::Database.extension :pg_array
         | 
| 289 | 
            +
                Sequel::Database.extension :pg_json
         | 
| 290 | 
            +
             | 
| 291 | 
            +
                sequel_db = Brut.container.sequel_db_handle
         | 
| 292 | 
            +
             | 
| 293 | 
            +
                Sequel::Model.db = sequel_db
         | 
| 294 | 
            +
             | 
| 295 | 
            +
                Sequel::Model.plugin :find_bang
         | 
| 296 | 
            +
                Sequel::Model.plugin :created_at
         | 
| 297 | 
            +
                Sequel::Model.plugin :table_select
         | 
| 298 | 
            +
                Sequel::Model.plugin :skip_saving_columns
         | 
| 299 | 
            +
             | 
| 300 | 
            +
                if !Brut.container.external_id_prefix.nil?
         | 
| 301 | 
            +
                  Sequel::Model.plugin :external_id, global_prefix: Brut.container.external_id_prefix
         | 
| 302 | 
            +
                end
         | 
| 303 | 
            +
                Sequel::Database.extension :brut_instrumentation
         | 
| 304 | 
            +
              end
         | 
| 305 | 
            +
             | 
| 306 | 
            +
              def boot_otel!
         | 
| 307 | 
            +
                OpenTelemetry::SDK.configure do |c|
         | 
| 308 | 
            +
                  c.service_name = @app.id
         | 
| 309 | 
            +
                  if ENV["OTEL_TRACES_EXPORTER"]
         | 
| 310 | 
            +
                    SemanticLogger[self.class].info "OTEL_TRACES_EXPORTER was set (to '#{ENV['OTEL_TRACES_EXPORTER']}'), so Brut's OTel logging is disabled"
         | 
| 311 | 
            +
                  else
         | 
| 312 | 
            +
                    c.add_span_processor(
         | 
| 313 | 
            +
                      OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(
         | 
| 314 | 
            +
                        Brut::Instrumentation::LoggerSpanExporter.new
         | 
| 315 | 
            +
                      )
         | 
| 316 | 
            +
                    )
         | 
| 317 | 
            +
                  end
         | 
| 318 | 
            +
             | 
| 319 | 
            +
                  if defined?(OpenTelemetry::Instrumentation::Sidekiq)
         | 
| 320 | 
            +
                    c.use 'OpenTelemetry::Instrumentation::Sidekiq', {
         | 
| 321 | 
            +
                      span_naming: :job_class,
         | 
| 322 | 
            +
                    }
         | 
| 323 | 
            +
                  else
         | 
| 324 | 
            +
                    SemanticLogger[self.class].info "OpenTelemetry::Instrumentation::Sidekiq is not loaded, so Sidekiq traces will not be captured"
         | 
| 325 | 
            +
                  end
         | 
| 326 | 
            +
                end
         | 
| 327 | 
            +
             | 
| 328 | 
            +
                Brut.container.store(
         | 
| 329 | 
            +
                  "tracer",
         | 
| 330 | 
            +
                  OpenTelemetry::SDK::Trace::Tracer,
         | 
| 331 | 
            +
                  "Tracer for Open Telemetry",
         | 
| 332 | 
            +
                  OpenTelemetry.tracer_provider.tracer(@app.id)
         | 
| 333 | 
            +
                )
         | 
| 334 | 
            +
              end
         | 
| 307 335 | 
             
            end
         | 
    
        data/lib/brut/version.rb
    CHANGED