Skip to content

Commit 14c7788

Browse files
committed
Update DevelopmentGuide
1 parent eae7fc6 commit 14c7788

File tree

1 file changed

+53
-48
lines changed

1 file changed

+53
-48
lines changed

docs/DevelopmentGuide.md

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This guide covers some of the common how-tos and technical reference material fo
1919

2020
The trace library uses Docker Compose to create a Ruby environment to develop and test within, as well as containers for any dependencies that might be necessary for certain kinds of tests.
2121

22-
To start a development environment, choose a target Ruby version then run the following:
22+
To start a development environment, choose a target Ruby or JRuby version. Then run the following:
2323

2424
```bash
2525
# In the root directory of the project...
@@ -28,12 +28,15 @@ cd ~/dd-trace-rb
2828
# Create and start a Ruby 3.3 test environment with its dependencies
2929
docker compose run --rm tracer-3.3 /bin/bash
3030

31+
# or a JRuby test environment with its dependencies
32+
docker compose run --rm tracer-jruby-9.4 /bin/bash
33+
3134
# Then inside the container (e.g. `root@2a73c6d8673e:/app`)...
3235
# Install the library dependencies
3336
bundle install
3437
```
3538

36-
Then within this container you can [run tests](#running-tests), or [run code quality checks](#checking-code-quality).
39+
Within this container, you can [run tests](#running-tests) or [run code quality checks](#checking-code-quality).
3740

3841
## Testing
3942

@@ -43,7 +46,7 @@ The test suite uses [RSpec](https://rspec.info/) tests to verify the correctness
4346

4447
New tests should be written as RSpec tests in the `spec/datadog` folder. Test files should generally mirror the structure of `lib`.
4548

46-
All changes should be covered by a corresponding RSpec tests. Unit tests are preferred, and integration tests are accepted where appropriate (e.g. acceptance tests, verifying compatibility with datastores, etc) but should be kept to a minimum.
49+
All changes should be covered by corresponding RSpec tests. Unit tests are preferred, and integration tests are accepted where appropriate (e.g. acceptance tests, verifying compatibility with datastores, etc) but should be kept to a minimum.
4750

4851
### Running tests
4952

@@ -54,31 +57,31 @@ Any file that is **not** inside a `contrib` folder is part of the core library.
5457
You can run all the tests for the core library with:
5558

5659
```
57-
$ bundle exec rake test:main
60+
bundle exec rake test:main
5861
```
5962

6063
##### Specific core tests
6164

6265
You can also run only a subset of the core library tests.
6366

64-
For example, for the test files [utils_spec.rb](https://github.com/DataDog/dd-trace-rb/blob/d66a6688f6cddab6a8c3cb1d6e0a6bfe86928e44/spec/datadog/core/utils_spec.rb) and
67+
For example, for the test files [utils_spec.rb](https://github.com/DataDog/dd-trace-rb/blob/d66a6688f6cddab6a8c3cb1d6e0a6bfe86928e44/spec/datadog/core/utils_spec.rb) and
6568
[error_spec.rb](https://github.com/DataDog/dd-trace-rb/blob/d66a6688f6cddab6a8c3cb1d6e0a6bfe86928e44/spec/datadog/core/error_spec.rb), you can run:
6669

6770
```bash
6871
# Runs all tests in utils_spec.rb
69-
$ bundle exec rspec spec/datadog/core/utils_spec.rb
72+
bundle exec rspec spec/datadog/core/utils_spec.rb
7073

71-
# Runs only the test in line 24
72-
$ bundle exec rspec spec/datadog/core/utils_spec.rb:24
74+
# Runs only the test on line 24
75+
bundle exec rspec spec/datadog/core/utils_spec.rb:24
7376

74-
# Runs the test in line 24 of utils_spec.rb and all the tests in error_spec.rb
75-
$ bundle exec rspec spec/datadog/core/utils_spec.rb:24 spec/datadog/core/error_spec.rb
77+
# Runs the test on line 24 of utils_spec.rb and all the tests in error_spec.rb
78+
bundle exec rspec spec/datadog/core/utils_spec.rb:24 spec/datadog/core/error_spec.rb
7679
```
7780

7881
#### All tests
7982

8083
`bundle exec rake ci` will run the entire test suite with any given Ruby runtime, just as CI does.
81-
However, this is not recommended because it is going take a long time.
84+
However, this is not recommended because it will take a long time.
8285

8386
Instead, run [specific core tests](#specific-core-tests), [integation tests](#for-integrations), or [the core library tests](#for-the-core-library).
8487

@@ -90,9 +93,9 @@ Any file that **is** inside a `contrib` folder is part of an integration.
9093

9194
To get a list of the test tasks, run `bundle exec rake -T test:`
9295

93-
To run test, run `bundle exec rake test:<spec_name>`
96+
To run a test, run `bundle exec rake test:<spec_name>`
9497

95-
Take `bundle exec rake test:redis` as example, multiple versions of `redis` from different dependency definitions are being tested (from `Matrixfile`).
98+
Take `bundle exec rake test:redis` as example: multiple versions of `redis` from different dependency definitions are being tested (from `Matrixfile`).
9699

97100

98101
```ruby
@@ -105,7 +108,7 @@ Take `bundle exec rake test:redis` as example, multiple versions of `redis` from
105108
}
106109
```
107110

108-
If the dependency groups are prepared (with up-to-date gemfile and lockfile), the test task would install them before running the test.
111+
If the dependency groups are prepared (with up-to-date gemfile and lockfile), the test task will install them before running the test.
109112

110113
**Working with different dependencies**
111114

@@ -117,39 +120,39 @@ You can find them by running the following command:
117120
bundle exec rake -T dependency:
118121
```
119122

120-
Dependency group definitions are located under `appraisal/` directory using the same DSL provided by [Appraisal](https://github.com/thoughtbot/appraisal). These definitions are used to generate `gemfiles/*.gemfile` and then `gemfiles/*.lock`. All the files are underscored and prefixed with Ruby runtime.
123+
Dependency group definitions are located under the `appraisal/` directory using the same DSL provided by [Appraisal](https://github.com/thoughtbot/appraisal). These definitions are used to generate `gemfiles/*.gemfile` and then `gemfiles/*.lock`. All the files are underscored and prefixed with the Ruby or JRuby runtime version.
121124

122125
> [!IMPORTANT]
123-
> Do NOT manually edit `gemfiles/*.gemfile` or `gemfiles/*.lock`. Instead, make changes to `appraisal/*.rb` and propagates your changes programmatically
126+
> Do NOT manually edit `gemfiles/*.gemfile` or `gemfiles/*.lock`. Instead, make changes to `appraisal/*.rb` and propagate your changes programmatically.
124127
125-
To find out existing gemfiles in your environment, run
128+
To find the existing gemfiles in your environment, run
126129

127130
```bash
128131
bundle exec rake dependency:list
129132
```
130133

131-
`dependency:list` is convenient to look for a specific gemfile path before assigning it to the environment variable `BUNDLE_GEMFILE` for doing all kinds of stuff.
134+
`dependency:list` is convenient to look for a specific gemfile path before assigning it to the environment variable `BUNDLE_GEMFILE`. `BUNDLE_GEMFILE` is useful for doing all kinds of stuff, such as:
132135

133136
```bash
134137
env BUNDLE_GEMFILE=/app/gemfiles/ruby_3.3_stripe_latest.gemfile bundle update stripe
135138
```
136139

137-
After introducing a new dependency group or changing existing one, run `bundle exec rake dependency:generate` to propagate the changes to the gemfile. `dependency:generate` is idempotent and only changes `gemfiles/*.gemfile` but not `gemfiles/*.lock`.
140+
After introducing a new dependency group or changing an existing one, run `bundle exec rake dependency:generate` to propagate the changes to the gemfile. `dependency:generate` is idempotent and only changes `gemfiles/*.gemfile` but not `gemfiles/*.lock`.
138141

139-
To keep lockfile up-to-date with the gemfile, run `bundle exec rake dependency:lock`.
142+
To keep lockfiles up-to-date with the gemfile, run `bundle exec rake dependency:lock`.
140143

141-
To install, run `bundle exec rake dependency:install`.
144+
To install the dependencies, run `bundle exec rake dependency:install`.
142145

143146
Both `dependency:lock` and `dependency:install` can be provided with a specific gemfile path (from `dependency:list`) or pattern to target specific groups. For example:
144147

145148
```bash
146-
# Generates lockfiles for all the stripe groups with `stripe_*` pattern
149+
# Generate lockfiles for all the stripe groups with `stripe_*` pattern
147150
bundle exec rake dependency:lock['/app/gemfiles/ruby_3.3_stripe_*.gemfile']
148-
# or only generate lockfile for `stripe_latest` group
151+
# or only generate lockfile for the `stripe_latest` group
149152
bundle exec rake dependency:lock['/app/gemfiles/ruby_3.3_stripe_latest.gemfile']
150153
```
151154

152-
**How to add new dependency group**
155+
**How to add a new dependency group**
153156

154157
> [!IMPORTANT]
155158
> Add a new group only if the existing groups do not meet your requirements, or if adding a new dependency to an existing group is impractical.
@@ -171,18 +174,18 @@ For example, if you want tests to run only on Ruby 3.3 for tracing, you can defi
171174
}
172175
```
173176

174-
2. Define the required gems in the corresponding Appraisal file. For this example, we are going to use [`Appraisal/ruby-3.3.rb`](../Appraisal/ruby-3.3.rb). Let's define what `rails-edge` group needs.
177+
2. Define the required gems in the corresponding Appraisal file. For this example, we are going to use [`Appraisal/ruby-3.3.rb`](../Appraisal/ruby-3.3.rb). Let's define what the `rails-edge` group needs.
175178

176179
```ruby
177180
appraise 'rails-edge' do
178181
gem 'rails', '>= 8'
179182
end
180183
```
181184

182-
3. Now let's generate that dependency Gemfile with `rake`, simply run
185+
3. Now let's generate that dependency Gemfile with `rake`. Simply run
183186

184187
> [!IMPORTANT]
185-
> Ensure you are using Ruby 3.3 as the current Ruby version (`ruby -v`) or run commands within a Docker container.
188+
> Ensure you are either using Ruby 3.3 as the current Ruby version (`ruby -v`) or running commands within a Docker container.
186189
187190
```console
188191
$ bundle exec rake dependency:generate
@@ -242,7 +245,7 @@ At this point, the new tests will be automatically included in the CI that runs
242245
When running tests, you may pass additional args as parameters to the Rake task. For example:
243246

244247
```
245-
# Runs Redis tests with seed 1234
248+
# Run Redis tests with seed 1234
246249
$ bundle exec rake test:redis'[--seed 1234]'
247250
```
248251

@@ -261,13 +264,13 @@ $ bundle exec rake coverage:report
261264
A webpage will be generated at `coverage/report/index.html` with the resulting report.
262265

263266
Because you are likely not running all tests locally, your report will contain partial coverage results.
264-
You *must* check the CI step `coverage` for the complete test coverage report, ensuring coverage is not
265-
decreased.
267+
You *must* check the CI step `coverage` for the complete test coverage report, ensuring coverage does not
268+
decrease.
266269

267270
**Ensuring tests don't leak resources**
268271

269-
Tests execution can create resources that are hard to track: threads, sockets, files, etc. Because these resources can come
270-
from the both the test setup as well as the code under test, making sure all resources are properly disposed is important
272+
Test execution can create resources that are hard to track: threads, sockets, files, etc. Because these resources can come
273+
from both the test setup as well as the test code itself, making sure all resources are properly disposed of is important
271274
to prevent the application from inadvertently creating cumulative resources during its execution.
272275

273276
When running tests that utilize threads, you might see an error message similar to this one:
@@ -288,21 +291,23 @@ Thread Backtrace:
288291
This means that this test did not finish all threads by the time the test had finished. In this case, the thread
289292
creation can be traced to `workers_integration_spec.rb:245:in 'new'`. The thread itself is sleeping at `workers_integration_spec.rb:262:in 'sleep'`.
290293

291-
The actionable in this case would be to ensure that the thread created in `workers_integration_spec.rb:245` is properly terminated by invoking `Thread#join` during the test tear down, which will wait for the thread to finish before returning.
294+
The actionable in this case would be to ensure that the thread created in `workers_integration_spec.rb:245` is properly terminated by invoking `Thread#join` during the test teardown, which will wait for the thread to finish before returning.
292295

293296
Depending on the situation, the thread in question might need to be forced to terminate. It's recommended to have a mechanism in place to terminate it (a shared variable that changes value when the thread should exit), but as a last resort, `Thread#terminate` forces the thread to finish. Keep in mind that regardless of the termination method, `Thread#join` must be called to ensure that the thread has completely finished its shutdown process.
294297

295298
**The APM Test Agent**
296299

297300
The APM test agent emulates the APM endpoints of the Datadog Agent. The Test Agent container
298-
runs alongside the Ruby tracer locally and in CI, handles all traces during test runs and performs a number
301+
runs alongside the Ruby tracer locally and in CI, handles all traces during test runs, and performs a number
299302
of 'Trace Checks'. For more information on these checks, see:
300303
https://github.com/DataDog/dd-apm-test-agent#trace-invariant-checks
301304

302-
The APM Test Agent also emits helpful logging, which can be viewed in local testing or in CircleCI as a job step for tracer and contrib
303-
tests. Locally, to get Test Agent logs:
305+
The APM Test Agent also emits helpful logging, which can be viewed in local testing or in CI as a job step for tracer and contrib
306+
tests. Locally, to get Test Agent logs run:
304307

305-
$ docker-compose logs -f testagent
308+
```
309+
docker-compose logs -f testagent
310+
```
306311

307312
Read more about the APM Test Agent:
308313
https://github.com/datadog/dd-apm-test-agent#readme
@@ -314,29 +319,29 @@ https://github.com/datadog/dd-apm-test-agent#readme
314319
Most of the library uses Rubocop to enforce [code style](https://github.com/bbatsov/ruby-style-guide) and quality. To check, run:
315320

316321
```
317-
$ bundle exec rake rubocop
322+
bundle exec rake rubocop
318323
```
319324

320325
To change your code to the version that rubocop wants, run:
321326

322327
```
323-
$ bundle exec rake rubocop -A
328+
bundle exec rake rubocop -A
324329
```
325330

326331
Profiling and Dynamic Instrumentation use [standard](https://github.com/standardrb/standard)
327332
instead of Rubocop. To check files with standard, run:
328333

329334
```
330-
$ bundle exec rake standard
335+
bundle exec rake standard
331336
```
332337

333338
To change your code to the version that standard wants, run:
334339

335340
```
336-
$ bundle exec rake standard:fix
341+
bundle exec rake standard:fix
337342
```
338343

339-
For non-Ruby code, follow the instructions below to debug locally, if CI failed with respective linter.
344+
For non-Ruby code, follow the instructions below to debug locally, if CI failed with the respective linter.
340345

341346
- For `yamllint`, run:
342347
```bash
@@ -383,12 +388,12 @@ If you modify any of the `.proto` files under `./spec/datadog/tracing/contrib/gr
383388
testing the `grpc` integration, you'll need to regenerate the Ruby code by running:
384389

385390
```
386-
$ docker run \
387-
--platform linux/amd64 \
388-
-v ${PWD}:/app \
389-
-w /app \
390-
ruby:latest \
391-
./spec/datadog/tracing/contrib/grpc/support/gen_proto.sh
391+
docker run \
392+
--platform linux/amd64 \
393+
-v ${PWD}:/app \
394+
-w /app \
395+
ruby:latest \
396+
./spec/datadog/tracing/contrib/grpc/support/gen_proto.sh
392397
```
393398

394399
### Community pull requests

0 commit comments

Comments
 (0)