Skip to content

Commit 4f3e927

Browse files
Polish the code and add docs (#3)
1 parent 7ebe626 commit 4f3e927

File tree

19 files changed

+368
-125
lines changed

19 files changed

+368
-125
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Release Notes.
77
#### Features
88
- Initialize the ruby agent core.
99
- Implement e2e tests.
10+
- Add docs.
1011

1112
#### Plugins
1213
* Support [Sinatra](https://github.com/sinatra/sinatra)

docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
**This is the official documentation of SkyWalking Ruby agent. Welcome to the SkyWalking community!**
44

5-
SkyWalking Ruby is an open-source auto-instrument agent that provides support for
5+
SkyWalking Ruby is an open-source auto-instrument agent that provides support for distributed tracing across different frameworks within the Ruby language.
66

7-
distributed tracing across different frameworks within the Ruby language.
7+
This documentation covers a number of ways to set up the Ruby agent for various use cases.

docs/en/agent/plugins.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Tracing Plugins
2+
3+
The following plugins provide the distributed tracing capability, and the OAP backend would analyze the topology and
4+
metrics based on the tracing data.
5+
6+
| Library | Version | Plugin Name |
7+
|:----------------------------------------------|:---------|:------------|
8+
| [redis](https://github.com/redis/redis-rb) | ~> 5.0 | `redis` |
9+
| [net-http](https://github.com/ruby/net-http) | ~> 0.6.0 | `net_http` |
10+
| [sinatra](https://github.com/sinatra/sinatra) | ~> 4.1 | `sinatra` |

docs/en/development-and-contribution/how-to-release.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ Vote result should follow these:
143143
1. Publish to rubygems.org, this is optional for Apache releases, but we usually want to do this to let users use it conveniently.
144144

145145
```shell
146+
gem build skywalking.gemspec
147+
gem push skywalking.gemspec
146148
```
147149

148150
**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:
169171
Website: http://skywalking.apache.org/
170172
171173
SkyWalking Ruby Resources:
172-
- Issue: https://github.com/apache/skywalking/issues
174+
Issue: https://github.com/apache/skywalking/issues
175+
173176
- Mailing list: [email protected]
174177
- Documents: https://github.com/apache/skywalking-ruby/blob/v$VERSION/README.md
175178
176179
The Apache SkyWalking Team
177-
```
178-
179-
180+
```

docs/en/setup/configuration.md

Whitespace-only changes.

docs/en/setup/quick-start.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Quick Start
2+
3+
## Requirements
4+
5+
**SkyWalking Ruby agent requires SkyWalking 8.0+ and Ruby 3.0+**
6+
7+
## Installing the gem
8+
9+
The Ruby agent's gem is available from [RubyGems](https://rubygems.org/) as `skywalking`, we recommend you install and
10+
manage the skywalking gem dependency with [Bundler](http://bundler.io/), add the following line to your `Gemfile`, then
11+
run `bundle install` to install the gem.
12+
13+
~~~ruby
14+
# Gemfile
15+
source "https://rubygems.org"
16+
17+
gem "skywalking"
18+
~~~
19+
20+
Besides, you can also make installation as simple as `gem install skywalking`.
21+
22+
## Getting started with Rails
23+
24+
You need to manually add `Skywalking.start` under config/initializers directory.
25+
26+
Optionally the command `bundle exec rails generate skywalking:start`, will create a config file
27+
`config/initializers/skywalking.rb`, and then you can configure the start parameters.
28+
29+
## Getting started with Sinatra
30+
31+
You can list `gem 'skywalking'` after sinatra in your Gemfile and use `Bundler.require` during initialization or calling
32+
`require 'skywalking'` after sinatra gem is loaded, that is, skywalking gem needs to be after the other gems you
33+
require (e.g. redis, elasticsearch), like the following code:
34+
35+
~~~ruby
36+
require 'redis'
37+
require 'sinatra'
38+
require 'skywalking'
39+
40+
Skywalking.start
41+
42+
get '/sw' do
43+
"Hello, SkyWalking!"
44+
end
45+
~~~
46+
47+
## Configuration
48+
49+
You can configure the SkyWalking Ruby agent in various ways, the Ruby agent follows this order of precedence for
50+
configuration:
51+
52+
- Defaults (please
53+
see [DEFAULTS](https://github.com/apache/skywalking-ruby/blob/main/lib/skywalking/configuration.rb#L21))
54+
- Arguments to `Skywalking.start`
55+
- Configuration file (e.g. `conifg/skywalking.yml`)
56+
- Environment variables
57+
58+
The following is an example of configuration at start:
59+
60+
~~~ruby
61+
Skywalking.start(
62+
service_name: 'sw-srv',
63+
instance_name: 'sw-inst',
64+
collector_backend_services: 'oap:11800'
65+
)
66+
~~~
67+
68+
The following is an example of a configuration file:
69+
~~~yaml
70+
common: &defaults
71+
service_name: Ruby-Agent-Common
72+
log_level: debug
73+
74+
development:
75+
<<: *defaults
76+
service_name: Ruby-Agent-Development
77+
78+
test:
79+
<<: *defaults
80+
service_name: Ruby-Agent-Test
81+
82+
production:
83+
<<: *defaults
84+
service_name: Ruby-Agent-Production
85+
~~~
86+
87+
The following lists all the configuration options:
88+
89+
| key | environment key | default value | description |
90+
|---------------------------------|------------------------------------------|----------------------|-------------------------------------------------------------------------------------------------------------------------------------------|
91+
| service_name | SW_AGENT_SERVICE_NAME | Your_ApplicationName | The name of the service which showed in UI. |
92+
| 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. |
93+
| namespace | SW_AGENT_NAMESPACE | Not set | Namespace represents a subnet, such as kubernetes namespace, or 172.10.. |
94+
| environment | SW_AGENT_ENVIRONMENT | Not set | The name of the environment this service is deployed in |
95+
| collector_backend_services | SW_AGENT_COLLECTOR_BACKEND_SERVICES | 127.0.0.1:11800 | Collector SkyWalking trace receiver service addresses. |
96+
| 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. |
97+
| log_file_name | SW_AGENT_LOG_FILE_NAME | skywalking | The name of the log file. |
98+
| log_file_path | SW_AGENT_LOG_FILE_PATH | Not set | The path to the log file. |
99+
| log_level | SW_AGENT_LOG_LEVEL | info | The log level. |
100+
| disable_plugins | SW_AGENT_DISABLE_PLUGINS | Not set | The plugins to disable. |
101+
| report_protocol | SW_AGENT_REPORT_PROTOCOL | grpc | The protocol to use for reporting. |
102+
| re_ignore_operation | SW_AGENT_RE_IGNORE_OPERATION | Not set | Ignore specific URL paths. |
103+
| 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"}`. |
104+
| collector_heartbeat_period | SW_AGENT_COLLECTOR_HEARTBEAT_PERIOD | 30 | he agent will send heartbeat to OAP every `collector_heartbeat_period` seconds. |
105+
| 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. |
106+
| max_queue_size | SW_AGENT_MAX_QUEUE_SIZE | 10000 | The maximum queue size for reporting data. |

.github/workflows/publish-docker.yaml renamed to docs/menu.yml

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,18 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
name: publish-docker
18-
19-
on:
20-
push:
21-
branches:
22-
- main
23-
24-
env:
25-
HUB: ghcr.io/apache/skywalking-ruby
26-
27-
jobs:
28-
build:
29-
if: github.repository == 'apache/skywalking-ruby'
30-
runs-on: ubuntu-latest
31-
permissions:
32-
contents: read
33-
packages: write
34-
timeout-minutes: 150
35-
env:
36-
VERSION: ${{ github.sha }}
37-
steps:
38-
- uses: actions/checkout@v4
39-
with:
40-
submodules: true
41-
- name: Log in to the Container registry
42-
uses: docker/[email protected]
43-
with:
44-
registry: ${{ env.HUB }}
45-
username: ${{ github.actor }}
46-
password: ${{ secrets.GITHUB_TOKEN }}
47-
- name: Polish docker image
48-
run: |
49-
make docker.push || make docker.push
17+
catalog:
18+
- name: SkyWalking Ruby Overview
19+
path: /readme
20+
- name: Quick Start
21+
path: /en/setup/quick-start
22+
- name: Agent
23+
catalog:
24+
- name: Supported Plugins
25+
path: /en/agent/plugins
26+
- name: Development and Contribution
27+
catalog:
28+
- name: How to Release
29+
path: /en/development-and-contribution/how-to-release
30+
- name: Changelog
31+
path: https://github.com/apache/skywalking-ruby/blob/master/CHANGELOG.md

examples/rails-demo/README.md

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
module Skywalking
17+
class StartGenerator < ::Rails::Generators::Base
18+
source_root File.join(File.dirname(__FILE__), 'templates')
19+
desc 'Creates a skywalking initializer'
20+
21+
@namespace = "skywalking:start"
22+
23+
def copy_initializer
24+
print_header
25+
print_footer
26+
27+
template "skywalking_initializer.rb", "config/initializers/skywalking.rb"
28+
end
29+
30+
private
31+
32+
def print_header
33+
say ""
34+
say shell.set_color "Welcome to the SkyWalking Ruby Agent instrumentation setup.", :green, :bold
35+
say ""
36+
end
37+
38+
def print_footer
39+
say ""
40+
say "You can configure skywalking start parameters by modifying config/initializers/skywalking.rb."
41+
say ""
42+
say "Thanks for using! Welcome to contribute to the SkyWalking community."
43+
say ""
44+
end
45+
end
46+
end
47+

examples/sinatra-demo/sinatra-demo.rb renamed to lib/rails/generators/skywalking/templates/skywalking_initializer.rb

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
require 'sinatra'
17-
require 'redis'
18-
require 'skywalking'
19-
20-
Skywalking.start
21-
22-
get '/sw' do
23-
"Hello, SkyWalking!"
24-
end
25-
26-
get '/hello/:name' do
27-
redis = Redis.new(host: 'localhost', port: 6379)
28-
redis.set('hello', 'world')
29-
value = redis.get("hello")
30-
"Hello #{value}!"
31-
end
16+
Skywalking.start

0 commit comments

Comments
 (0)