This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-ruby.git


The following commit(s) were added to refs/heads/main by this push:
     new 4f3e927  Polish the code and add docs (#3)
4f3e927 is described below

commit 4f3e927b7f88450d34dfc50d5473e62a8c7e6baa
Author: Zixin Zhou <[email protected]>
AuthorDate: Tue Jan 14 19:44:05 2025 +0800

    Polish the code and add docs (#3)
---
 CHANGELOG.md                                       |   1 +
 docs/README.md                                     |   4 +-
 docs/en/agent/plugins.md                           |  10 ++
 .../development-and-contribution/how-to-release.md |   9 +-
 docs/en/setup/configuration.md                     |   0
 docs/en/setup/quick-start.md                       | 106 +++++++++++++++++++
 .../workflows/publish-docker.yaml => docs/menu.yml |  48 +++------
 examples/rails-demo/README.md                      |   9 --
 .../generators/skywalking/start_generator.rb}      |  49 +++++----
 .../skywalking/templates/skywalking_initializer.rb |  17 +--
 lib/skywalking/agent.rb                            |  10 +-
 lib/skywalking/configuration.rb                    |  85 +++++++++------
 lib/skywalking/environment.rb                      | 114 +++++++++++++++++++--
 lib/skywalking/log/logger.rb                       |   2 +-
 lib/skywalking/tracing/exit_span.rb                |   2 +-
 lib/skywalking/tracing/span_context.rb             |   2 +-
 skywalking.gemspec                                 |   2 +-
 spec/fixtures/agent.yaml                           |  23 +++--
 spec/skywalking/config_spec.rb                     |   2 +-
 19 files changed, 344 insertions(+), 151 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index e1bbbe6..c8861b4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ Release Notes.
 #### Features
 - Initialize the ruby agent core.
 - Implement e2e tests.
+- Add docs.
 
 #### Plugins
 * Support [Sinatra](https://github.com/sinatra/sinatra)
diff --git a/docs/README.md b/docs/README.md
index 650dd1e..45cfbd5 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -2,6 +2,6 @@
 
 **This is the official documentation of SkyWalking Ruby agent. Welcome to the 
SkyWalking community!**
 
-SkyWalking Ruby is an open-source auto-instrument agent that provides support 
for
+SkyWalking Ruby is an open-source auto-instrument agent that provides support 
for distributed tracing across different frameworks within the Ruby language.
 
-distributed tracing across different frameworks within the Ruby language.
\ No newline at end of file
+This documentation covers a number of ways to set up the Ruby agent for 
various use cases.
\ No newline at end of file
diff --git a/docs/en/agent/plugins.md b/docs/en/agent/plugins.md
new file mode 100644
index 0000000..a22d930
--- /dev/null
+++ b/docs/en/agent/plugins.md
@@ -0,0 +1,10 @@
+# Tracing Plugins
+
+The following plugins provide the distributed tracing capability, and the OAP 
backend would analyze the topology and
+metrics based on the tracing data.
+
+| Library                                       | Version  | Plugin Name |
+|:----------------------------------------------|:---------|:------------|
+| [redis](https://github.com/redis/redis-rb)    | ~> 5.0   | `redis`     |
+| [net-http](https://github.com/ruby/net-http)  | ~> 0.6.0 | `net_http`  |
+| [sinatra](https://github.com/sinatra/sinatra) | ~> 4.1   | `sinatra`   |
\ No newline at end of file
diff --git a/docs/en/development-and-contribution/how-to-release.md 
b/docs/en/development-and-contribution/how-to-release.md
index 143888a..bd9d4db 100644
--- a/docs/en/development-and-contribution/how-to-release.md
+++ b/docs/en/development-and-contribution/how-to-release.md
@@ -143,6 +143,8 @@ Vote result should follow these:
 1. Publish to rubygems.org, this is optional for Apache releases, but we 
usually want to do this to let users use it conveniently.
 
   ```shell
+  gem build skywalking.gemspec
+  gem push skywalking.gemspec
   ```
 
 **NOTE**: please double check before publishing to rubygems.org, it's 
difficult to unpublish and republish the module at the moment.
@@ -169,11 +171,10 @@ Vote result should follow these:
     Website: http://skywalking.apache.org/
 
     SkyWalking Ruby Resources:
-- Issue: https://github.com/apache/skywalking/issues
+    Issue: https://github.com/apache/skywalking/issues
+
     - Mailing list: [email protected]
     - Documents: 
https://github.com/apache/skywalking-ruby/blob/v$VERSION/README.md
 
     The Apache SkyWalking Team
-```
-
-
+   ```
diff --git a/docs/en/setup/configuration.md b/docs/en/setup/configuration.md
deleted file mode 100644
index e69de29..0000000
diff --git a/docs/en/setup/quick-start.md b/docs/en/setup/quick-start.md
index e69de29..68f4f9e 100644
--- a/docs/en/setup/quick-start.md
+++ b/docs/en/setup/quick-start.md
@@ -0,0 +1,106 @@
+# Quick Start
+
+## Requirements
+
+**SkyWalking Ruby agent requires SkyWalking 8.0+ and Ruby 3.0+**
+
+## Installing the gem
+
+The Ruby agent's gem is available from [RubyGems](https://rubygems.org/) as 
`skywalking`, we recommend you install and
+manage the skywalking gem dependency with [Bundler](http://bundler.io/), add 
the following line to your `Gemfile`, then
+run `bundle install` to install the gem.
+
+~~~ruby
+# Gemfile
+source "https://rubygems.org";
+
+gem "skywalking"
+~~~
+
+Besides, you can also make installation as simple as `gem install skywalking`.
+
+## Getting started with Rails
+
+You need to manually add `Skywalking.start` under config/initializers 
directory.
+
+Optionally the command `bundle exec rails generate skywalking:start`, will 
create a config file
+`config/initializers/skywalking.rb`, and then you can configure the start 
parameters.
+
+## Getting started with Sinatra
+
+You can list `gem 'skywalking'` after sinatra in your Gemfile and use 
`Bundler.require` during initialization or calling
+`require 'skywalking'` after sinatra gem is loaded, that is, skywalking gem 
needs to be after the other gems you
+require (e.g. redis, elasticsearch), like the following code:
+
+~~~ruby
+require 'redis'
+require 'sinatra'
+require 'skywalking'
+
+Skywalking.start
+
+get '/sw' do
+  "Hello, SkyWalking!"
+end
+~~~
+
+## Configuration
+
+You can configure the SkyWalking Ruby agent in various ways, the Ruby agent 
follows this order of precedence for
+configuration:
+
+- Defaults (please
+  see 
[DEFAULTS](https://github.com/apache/skywalking-ruby/blob/main/lib/skywalking/configuration.rb#L21))
+- Arguments to `Skywalking.start`
+- Configuration file (e.g. `conifg/skywalking.yml`)
+- Environment variables
+
+The following is an example of configuration at start:
+
+~~~ruby
+Skywalking.start(
+  service_name: 'sw-srv',
+  instance_name: 'sw-inst',
+  collector_backend_services: 'oap:11800'
+)
+~~~
+
+The following is an example of a configuration file:
+~~~yaml
+common: &defaults
+  service_name: Ruby-Agent-Common
+  log_level: debug
+
+development:
+  <<: *defaults
+  service_name: Ruby-Agent-Development
+
+test:
+  <<: *defaults
+  service_name: Ruby-Agent-Test
+
+production:
+  <<: *defaults
+  service_name: Ruby-Agent-Production
+~~~
+
+The following lists all the configuration options:
+
+| key                             | environment key                          | 
default value        | description                                              
                                                                                
 |
+|---------------------------------|------------------------------------------|----------------------|-------------------------------------------------------------------------------------------------------------------------------------------|
+| service_name                    | SW_AGENT_SERVICE_NAME                    | 
Your_ApplicationName | The name of the service which showed in UI.              
                                                                                
 |
+| instance_name                   | SW_AGENT_INSTANCE_NAME                   | 
Your_InstanceName    | To obtain the environment variable key for the instance 
name, if it cannot be obtained, an instance name will be automatically 
generated. |
+| namespace                       | SW_AGENT_NAMESPACE                       | 
Not set              | Namespace represents a subnet, such as kubernetes 
namespace, or 172.10..                                                          
        |
+| environment                     | SW_AGENT_ENVIRONMENT                     | 
Not set              | The name of the environment this service is deployed in  
                                                                                
 |
+| collector_backend_services      | SW_AGENT_COLLECTOR_BACKEND_SERVICES      | 
127.0.0.1:11800      | Collector SkyWalking trace receiver service addresses.   
                                                                                
 |
+| config_file                     | SW_AGENT_CONFIG_FILE                     | 
Not set              | The absolute path to the configuration file, if empty, 
it will automatically search for config/skywalking.yml in the root directory.   
   |
+| log_file_name                   | SW_AGENT_LOG_FILE_NAME                   | 
skywalking           | The name of the log file.                                
                                                                                
 |
+| log_file_path                   | SW_AGENT_LOG_FILE_PATH                   | 
Not set              | The path to the log file.                                
                                                                                
 |
+| log_level                       | SW_AGENT_LOG_LEVEL                       | 
info                 | The log level.                                           
                                                                                
 |
+| disable_plugins                 | SW_AGENT_DISABLE_PLUGINS                 | 
Not set              | The plugins to disable.                                  
                                                                                
 |
+| report_protocol                 | SW_AGENT_REPORT_PROTOCOL                 | 
grpc                 | The protocol to use for reporting.                       
                                                                                
 |
+| re_ignore_operation             | SW_AGENT_RE_IGNORE_OPERATION             | 
Not set              | Ignore specific URL paths.                               
                                                                                
 |
+| instance_properties_json        | SW_AGENT_INSTANCE_PROPERTIES_JSON        | 
Not set              | A custom JSON string to be reported as service instance 
properties, e.g. `{"key": "value"}`.                                            
  |
+| collector_heartbeat_period      | SW_AGENT_COLLECTOR_HEARTBEAT_PERIOD      | 
30                   | he agent will send heartbeat to OAP every 
`collector_heartbeat_period` seconds.                                           
                |
+| properties_report_period_factor | SW_AGENT_PROPERTIES_REPORT_PERIOD_FACTOR | 
10                   | The agent will report service instance properties every 
`collector_heartbeat_period * properties_report_period_factor` seconds.         
  |
+| max_queue_size                  | SW_AGENT_MAX_QUEUE_SIZE                  | 
10000                | The maximum queue size for reporting data.               
                                                                                
 |
diff --git a/.github/workflows/publish-docker.yaml b/docs/menu.yml
similarity index 51%
rename from .github/workflows/publish-docker.yaml
rename to docs/menu.yml
index da211a5..2fa797f 100644
--- a/.github/workflows/publish-docker.yaml
+++ b/docs/menu.yml
@@ -14,36 +14,18 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-name: publish-docker
-
-on:
-  push:
-    branches:
-      - main
-
-env:
-  HUB: ghcr.io/apache/skywalking-ruby
-
-jobs:
-  build:
-    if: github.repository == 'apache/skywalking-ruby'
-    runs-on: ubuntu-latest
-    permissions:
-      contents: read
-      packages: write
-    timeout-minutes: 150
-    env:
-      VERSION: ${{ github.sha }}
-    steps:
-      - uses: actions/checkout@v4
-        with:
-          submodules: true
-      - name: Log in to the Container registry
-        uses: docker/[email protected]
-        with:
-          registry: ${{ env.HUB }}
-          username: ${{ github.actor }}
-          password: ${{ secrets.GITHUB_TOKEN }}
-      - name: Polish docker image
-        run: |
-          make docker.push || make docker.push
+catalog:
+  - name: SkyWalking Ruby Overview
+    path: /readme
+  - name: Quick Start
+    path: /en/setup/quick-start
+  - name: Agent
+    catalog:
+      - name: Supported Plugins
+        path: /en/agent/plugins
+  - name: Development and Contribution
+    catalog:
+      - name: How to Release
+        path: /en/development-and-contribution/how-to-release
+  - name: Changelog
+    path: https://github.com/apache/skywalking-ruby/blob/master/CHANGELOG.md
\ No newline at end of file
diff --git a/examples/rails-demo/README.md b/examples/rails-demo/README.md
deleted file mode 100644
index 0fda4c2..0000000
--- a/examples/rails-demo/README.md
+++ /dev/null
@@ -1,9 +0,0 @@
-# rails-demo
-
-```ruby
-# config/skywalking.rb
-
-require 'skywalking'
-
-Skywalking.start
-```
\ No newline at end of file
diff --git a/lib/skywalking/environment.rb 
b/lib/rails/generators/skywalking/start_generator.rb
similarity index 53%
copy from lib/skywalking/environment.rb
copy to lib/rails/generators/skywalking/start_generator.rb
index 9d83b52..a92977f 100644
--- a/lib/skywalking/environment.rb
+++ b/lib/rails/generators/skywalking/start_generator.rb
@@ -13,38 +13,35 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 
-require 'singleton'
-
 module Skywalking
-  class Environment
-    include Singleton
-    include Log::Logging
+  class StartGenerator < ::Rails::Generators::Base
+    source_root File.join(File.dirname(__FILE__), 'templates')
+    desc 'Creates a skywalking initializer'
 
-    def framework_info
-      @framework_info ||= generate_framework_info
-    end
+    @namespace = "skywalking:start"
+
+    def copy_initializer
+      print_header
+      print_footer
 
-    def generate_framework_info
-      if defined?(::Rails::Application)
-        :rails
-      elsif defined?(::Sinatra::Base)
-        :sinatra
-      else
-        :ruby
-      end
+      template "skywalking_initializer.rb", "config/initializers/skywalking.rb"
     end
-    
-    def sinatra?
-      @framework_info = :sinatra
+
+    private
+
+    def print_header
+      say ""
+      say shell.set_color "Welcome to the SkyWalking Ruby Agent 
instrumentation setup.", :green, :bold
+      say ""
     end
 
-    def shutdown_handler_supported?
-      if sinatra?
-        info "Shutdown handler not supported for Sinatra"
-        false
-      else
-        true
-      end
+    def print_footer
+      say ""
+      say "You can configure skywalking start parameters by modifying 
config/initializers/skywalking.rb."
+      say ""
+      say "Thanks for using! Welcome to contribute to the SkyWalking 
community."
+      say ""
     end
   end
 end
+
diff --git a/examples/sinatra-demo/sinatra-demo.rb 
b/lib/rails/generators/skywalking/templates/skywalking_initializer.rb
similarity index 74%
rename from examples/sinatra-demo/sinatra-demo.rb
rename to lib/rails/generators/skywalking/templates/skywalking_initializer.rb
index 9b8720c..2b6fdbc 100644
--- a/examples/sinatra-demo/sinatra-demo.rb
+++ b/lib/rails/generators/skywalking/templates/skywalking_initializer.rb
@@ -13,19 +13,4 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 
-require 'sinatra'
-require 'redis'
-require 'skywalking'
-
-Skywalking.start
-
-get '/sw' do
-  "Hello, SkyWalking!"
-end
-
-get '/hello/:name' do
-  redis = Redis.new(host: 'localhost', port: 6379)
-  redis.set('hello', 'world')
-  value = redis.get("hello")
-  "Hello #{value}!"
-end
\ No newline at end of file
+Skywalking.start
\ No newline at end of file
diff --git a/lib/skywalking/agent.rb b/lib/skywalking/agent.rb
index edb1310..2c61272 100644
--- a/lib/skywalking/agent.rb
+++ b/lib/skywalking/agent.rb
@@ -41,7 +41,9 @@ module Skywalking
           config ||= {}
           config = Configuration.new(config) unless config.is_a?(Configuration)
 
-          @agent = new(config.agent_config).start!
+          @logger = config.logger
+          @agent_config = config.agent_config
+          @agent = new(@agent_config).start!
           config.freeze
         end
       end
@@ -59,12 +61,10 @@ module Skywalking
         !!(defined?(@agent) && @agent)
       end
 
-      def config
-        @config ||= Configuration.new.agent_config
-      end
+      attr_reader :logger, :agent_config
     end
 
-    attr_reader :plugins, :logger, :reporter
+    attr_reader :plugins, :reporter
 
     def initialize(config)
       @plugins = Plugins::PluginsManager.new(config)
diff --git a/lib/skywalking/configuration.rb b/lib/skywalking/configuration.rb
index 43c6d26..2d83988 100644
--- a/lib/skywalking/configuration.rb
+++ b/lib/skywalking/configuration.rb
@@ -29,6 +29,16 @@ module Skywalking
         default: 'Your_InstanceName',
         desc: 'The name of this particular awesome Ruby service instance'
       },
+      :namespace => {
+        type: :string,
+        default: '',
+        desc: 'The namespace of the service'
+      },
+      :environment => {
+        type: :string,
+        default: '',
+        desc: 'The name of the environment this service is deployed in'
+      },
       :collector_backend_services => {
         type: :string,
         default: '127.0.0.1:11800',
@@ -37,16 +47,16 @@ module Skywalking
       :config_file => {
         type: :string,
         default: '',
-        desc: 'The path to the config file'
+        desc: 'The absolute path to the configuration file'
       },
-      :log_file => {
+      :log_file_name => {
         type: :string,
-        default: 'skywalking.log',
+        default: 'skywalking',
         desc: 'The name of the log file'
       },
       :log_file_path => {
         type: :string,
-        default: 'STDOUT',
+        default: '',
         desc: 'The path to the log file'
       },
       :log_level => {
@@ -69,11 +79,6 @@ module Skywalking
         default: '',
         desc: 'Ignore specific URL paths'
       },
-      :namespace => {
-        type: :string,
-        default: '',
-        desc: 'The namespace of the service'
-      },
       :instance_properties_json => {
         type: :string,
         default: '',
@@ -98,19 +103,24 @@ module Skywalking
     }.freeze
 
     # @api private
-    attr_reader :agent_config
+    attr_reader :agent_config, :logger
 
     def initialize(opts = {})
       @agent_config = {}
       initialize_config(opts)
+      if @logger.nil?
+        @logger ||= Mutex.new.synchronize { build_logger }
+      end
     end
 
     def initialize_config(opts)
       # from the default value
       merge_config(DEFAULTS.transform_values { |v| v[:default] })
+      # start parameters
       merge_config(opts)
       # from the custom config file
       merge_config(override_config_by_file)
+      # environment variables
       merge_config(override_config_by_env)
     end
 
@@ -124,10 +134,15 @@ module Skywalking
 
     def override_config_by_file
       config_yaml = @agent_config[:config_file]
-      return if config_yaml.nil? || config_yaml.empty?
+      if config_yaml.nil? || config_yaml.empty?
+        config_yaml = File.join(srv_root, "config", "skywalking.yml")
+      end
 
       unless File.exist?(config_yaml)
-        logger.warn "No config file found at #{config_yaml}"
+        return
+      end
+
+      unless srv_environment
         return
       end
 
@@ -140,10 +155,10 @@ module Skywalking
                       else
                         YAML.safe_load(erb_file, permitted_classes: [], 
permitted_symbols: [], aliases: true)
                       end
+        loaded_yaml = loaded_yaml[srv_environment]
         error = "Invalid format in config file" if loaded_yaml && 
!loaded_yaml.is_a?(Hash)
       rescue Exception => e
         error = e.message
-        logger.error "override config by file failed, error=%s", e.message
         nil
       end
       raise StandardError, "Error loading config file: #{config_yaml} - 
#{error}" if error
@@ -187,14 +202,18 @@ module Skywalking
       self
     end
 
+    def srv_environment
+      @agent_config[:environment].to_s.empty? ? 
Skywalking::Environment.instance.framework_env : @agent_config[:environment]
+    end
+
+    def srv_root
+      Skywalking::Environment.instance.framework_root
+    end
+
     #####
     # LOAD LOG
     #####
-    def logger
-      @logger ||= Mutex.new.synchronize { get_logger }
-    end
-
-    def get_logger
+    def build_logger
       return @logger if @logger
 
       log_dest = log_destination
@@ -203,17 +222,17 @@ module Skywalking
 
     def create_log(log_dest, level)
       if log_dest.is_a?(String)
-        log_dest = File.expand_path(out, Pathname.new(Dir.pwd).realpath)
+        log_dest = File.expand_path(log_dest, Pathname.new(Dir.pwd).realpath)
         FileUtils.mkdir_p(File.dirname(log_dest))
       end
 
       begin
-        logger = ::Logger.new(log_dest, progname: "Skywalking-Ruby", level: 
level)
+        logger = ::Logger.new(log_dest, progname: "Skywalking", level: level)
         logger.formatter = log_formatter
 
         logger
       rescue => e
-        logger = ::Logger.new($stdout, progname: "Skywalking-Ruby", level: 
level)
+        logger = ::Logger.new($stdout, progname: "Skywalking", level: level)
         logger.warn "Create logger for file #{log_dest} failed, using standard 
out for logging error=#{e.message}"
       end
     end
@@ -226,30 +245,32 @@ module Skywalking
     end
 
     def log_destination
-      if stdout?
+      candidate = @agent_config[:log_file_path].upcase
+
+      case candidate
+      when "STDOUT"
         $stdout
-      elsif !agent_config[:log_file].nil?
-        agent_config[:log_file]
-      elsif !agent_config[:log_file_path].nil?
-        "#{agent_config[:log_file_path]}/skywalking.log"
-      else
+      when "STDERR"
+        $stderr
+      when nil? || ''
         $stdout
+      else
+        "#{@agent_config[:log_file_path]}/#{@agent_config[:log_file_name]}.log"
       end
     end
 
     def get_log_level
-      case @agent_config[:log_level]
+      candidate = @agent_config[:log_level].downcase
+
+      case candidate
       when "debug" then ::Logger::DEBUG
       when "info" then ::Logger::INFO
       when "warn" then ::Logger::WARN
       when "error" then ::Logger::ERROR
       when "fatal" then ::Logger::FATAL
+      when ::Logger::DEBUG, ::Logger::INFO, ::Logger::WARN, ::Logger::ERROR, 
::Logger::FATAL then candidate
       else ::Logger::INFO
       end
     end
-
-    def stdout?
-      @agent_config[:log_file_path] == "STDOUT"
-    end
   end
 end
\ No newline at end of file
diff --git a/lib/skywalking/environment.rb b/lib/skywalking/environment.rb
index 9d83b52..aa914e2 100644
--- a/lib/skywalking/environment.rb
+++ b/lib/skywalking/environment.rb
@@ -20,27 +20,119 @@ module Skywalking
     include Singleton
     include Log::Logging
 
-    def framework_info
-      @framework_info ||= generate_framework_info
+    class RailsFramework
+      def name
+        :rails
+      end
+
+      def present?
+        defined?(::Rails) && defined?(::Rails::VERSION)
+      end
+
+      def app_name
+        if defined?(::Rails)
+          ::Rails.application.class.to_s
+                 .sub(/::Application$/, '')
+        end
+      rescue
+        nil
+      end
+      
+      def env
+        ::Rails.env
+      end
     end
 
-    def generate_framework_info
-      if defined?(::Rails::Application)
-        :rails
-      elsif defined?(::Sinatra::Base)
+    class SinatraFramework
+      def name
         :sinatra
-      else
+      end
+
+      def present?
+        defined?(::Sinatra) && defined?(::Sinatra::Base)
+      end
+
+      def app_name
+        candidate = ObjectSpace.each_object(Class).select { |klass| klass < 
::Sinatra::Base } - [::Sinatra::Application]
+
+        if candidate.length == 1
+          candidate.first.name
+        else
+          "Sinatra"
+        end
+      rescue
+        "Sinatra"
+      end
+      
+      def env
+        ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
+      end
+    end
+
+    class RubyFramework
+      def name
         :ruby
       end
+
+      def present?
+        true
+      end
+
+      def app_name
+        "Ruby"
+      end
+      
+      def env
+        ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
+      end
+    end
+
+    FRAMEWORKS = [
+      RailsFramework.new,
+      SinatraFramework.new,
+      RubyFramework.new
+    ].freeze
+
+    def framework_info
+      @framework ||= FRAMEWORKS.detect { |candidate| candidate.present? }
+    end
+
+    def framework_name
+      @framework_name ||= framework_info.name
+    end
+
+    def framework_root
+      @framework_root ||= case @framework_name
+                          when :rails
+                            ::Rails.root
+                          when :sinatra
+                            Sinatra::Application.root || "."
+                          else
+                            "."
+                          end
     end
     
-    def sinatra?
-      @framework_info = :sinatra
+    def framework_env
+      @framework_env ||= framework_info.env
+    end
+
+    def app_name
+      framework_info.app_name
+    end
+
+    def rails?
+      if defined?(::Rails)
+        ::Rails.application.class.to_s
+               .sub(/::Application$/, '')
+      end
+    rescue
+      nil
     end
 
     def shutdown_handler_supported?
-      if sinatra?
-        info "Shutdown handler not supported for Sinatra"
+      case framework_name
+      when :sinatra
+        warn "Shutdown handler not supported for Sinatra"
         false
       else
         true
diff --git a/lib/skywalking/log/logger.rb b/lib/skywalking/log/logger.rb
index da623a8..0461594 100644
--- a/lib/skywalking/log/logger.rb
+++ b/lib/skywalking/log/logger.rb
@@ -33,7 +33,7 @@ module Skywalking
       end
 
       def log(level, msg, *args)
-        logger = Configuration.new.logger
+        logger = Agent.logger
         if logger
           if logger.respond_to?(level)
             if args.empty?
diff --git a/lib/skywalking/tracing/exit_span.rb 
b/lib/skywalking/tracing/exit_span.rb
index e7d78df..6fec2bd 100644
--- a/lib/skywalking/tracing/exit_span.rb
+++ b/lib/skywalking/tracing/exit_span.rb
@@ -33,7 +33,7 @@ module Skywalking
       end
 
       def cfg
-        @config ||= ::Skywalking::Agent.config
+        @config ||= ::Skywalking::Agent.agent_config
       end
 
       def inject
diff --git a/lib/skywalking/tracing/span_context.rb 
b/lib/skywalking/tracing/span_context.rb
index 52c0cd1..6dff1a5 100644
--- a/lib/skywalking/tracing/span_context.rb
+++ b/lib/skywalking/tracing/span_context.rb
@@ -36,7 +36,7 @@ module Skywalking
       end
 
       def cfg
-        @config ||= ::Skywalking::Agent.config
+        @config ||= ::Skywalking::Agent.agent_config
       end
 
       def ignore_check(operation, carrier: nil)
diff --git a/skywalking.gemspec b/skywalking.gemspec
index cef22fc..cf46aa3 100644
--- a/skywalking.gemspec
+++ b/skywalking.gemspec
@@ -45,7 +45,7 @@ Gem::Specification.new do |spec|
   spec.add_dependency 'grpc', '1.68.1'
 
   # Base dev dependency
-  spec.add_development_dependency 'bundler', '>= 2.0'
+  spec.add_development_dependency 'bundler', '~> 2.0'
   spec.add_development_dependency 'rake', '13.2.1'
   spec.add_development_dependency 'rspec', '~> 3'
   spec.add_development_dependency 'rubocop', '1.69.2'
diff --git a/spec/fixtures/agent.yaml b/spec/fixtures/agent.yaml
index 7948e7c..b0c9921 100644
--- a/spec/fixtures/agent.yaml
+++ b/spec/fixtures/agent.yaml
@@ -15,12 +15,19 @@
 # specific language governing permissions and limitations
 # under the License.
 
-# The service name in UI
-service_name: sw-ruby
-instance_name: Your_InstanceName  
+common: &defaults
+  service_name: Ruby-Agent-Common
+  log_level: debug
 
-# Whether to enable the reporter
-collector_discard: false
-# The gRPC server address of the backend service.
-collector_backend_services: 127.0.0.1:11800
-config_file: config/skywalking.yaml
\ No newline at end of file
+development:
+  <<: *defaults
+  service_name: Ruby-Agent-Development
+
+test:
+  <<: *defaults
+  service_name: Ruby-Agent-Test
+
+production:
+  <<: *defaults
+  service_name: Ruby-Agent-Production
+  
\ No newline at end of file
diff --git a/spec/skywalking/config_spec.rb b/spec/skywalking/config_spec.rb
index 7f135da..0ed38be 100644
--- a/spec/skywalking/config_spec.rb
+++ b/spec/skywalking/config_spec.rb
@@ -29,7 +29,7 @@ module Skywalking
     
     it 'loads from yaml' do
       config = Configuration.new(config_file: 
'spec/fixtures/agent.yaml').agent_config
-      expect(config[:service_name]).to eq 'sw-ruby'
+      expect(config[:service_name]).to eq 'Ruby-Agent-Development'
     end
     
     it 'loads from env' do

Reply via email to