Skip to content

Commit

Permalink
Work towards JRuby compatibility
Browse files Browse the repository at this point in the history
This is part of aws#4. Until JRuby 9.2.0.0 is released, the
required_ruby_version in the gemspec will keep this from working there,
as well as jruby/jruby#5099.

* Replaced Oj with MultiJson + Oj OR JrJackson
* Removed Oj.dump parameters, since those are defaults when using MultiJson
* Remove rdiscount for Markdown generation, use default Yard generator.
* Made two minor code syntax changes to make the Yard generator happy

I've roughly compared the generated RDoc and they look very similar.
  • Loading branch information
Dave Golombek committed Mar 22, 2018
1 parent 54831be commit 82c087e
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 16 deletions.
1 change: 0 additions & 1 deletion .yardopts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
--title 'AWS X-Ray SDK for Ruby'
--markup markdown
--markup-provider rdiscount
--no-progress
- LICENSE
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
source 'https://rubygems.org'

gemspec

# These are here instead of the gemspec so that they can be properly conditionalized by platform.
gem 'oj', platform: :mri
gem 'jrjackson', platform: :jruby
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

## Installing

The AWS X-Ray SDK for Ruby is compatible with Ruby 2.3.6 and newer Ruby versions.
The AWS X-Ray SDK for Ruby is compatible with Ruby 2.3.6 and newer Ruby versions. It has experimental support for JRuby 9.2.0.0 (still forthcoming).

To install the Ruby gem for your project, add it to your project Gemfile.
To install the Ruby gem for your project, add it to your project Gemfile. You must also add either the [Oj](https://github.com/ohler55/oj) or [JrJackson](https://github.com/guyboertje/jrjackson) gems, for MRI and JRuby respectively, for JSON parsing. The default JSON parser will not work properly, currently.

```
# Gemfile
gem 'aws-xray-sdk'
gem 'oj', platform: :mri
gem 'jrjackson', platform: :jruby
```
Then run `bundle install`.

Expand All @@ -28,7 +30,7 @@ issues for tracking bugs and feature requests.
If you encounter a bug with the AWS X-Ray SDK for Ruby, we want to hear about
it. Before opening a new issue, search the [existing issues](https://github.com/aws/aws-xray-sdk-ruby/issues)
to see if others are also experiencing the issue. Include the version of the AWS X-Ray
SDK for Ruby, Ruby language, and other gems if applicable. In addition,
SDK for Ruby, Ruby language, and other gems if applicable. In addition,
include the repro case when appropriate.

The GitHub issues are intended for bug reports and feature requests. For help and
Expand Down
3 changes: 1 addition & 2 deletions aws-xray-sdk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_dependency 'oj', '~> 3.0'
spec.add_dependency 'multi_json', '~> 1'

spec.add_development_dependency 'aws-sdk-dynamodb', '~> 1'
spec.add_development_dependency 'aws-sdk-s3', '~> 1'
spec.add_development_dependency 'bundler', '~> 1.0'
spec.add_development_dependency 'minitest', '~> 5.0'
spec.add_development_dependency 'rake', '~> 12.0'
spec.add_development_dependency 'rdiscount', '~> 2.2'
spec.add_development_dependency 'simplecov', '~> 0.15'
spec.add_development_dependency 'webmock', '~> 3.0'
spec.add_development_dependency 'yard', '~> 0.9'
Expand Down
2 changes: 1 addition & 1 deletion lib/aws-xray-sdk/facets/aws_sdk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def call(context)
operation = context.operation_name
service_name = context.client.class.api.metadata['serviceAbbreviation'] ||
context.client.class.to_s.split('::')[1]
recorder.capture service_name, namespace: 'aws' do |subsegment|
recorder.capture(service_name, namespace: 'aws') do |subsegment|
# inject header string before calling downstream AWS services
context.http_request.headers[TRACE_HEADER] = prep_header_str entity: subsegment
response = @handler.call(context)
Expand Down
2 changes: 1 addition & 1 deletion lib/aws-xray-sdk/facets/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module XRay
class Railtie < ::Rails::Railtie
RAILS_OPTIONS = %I[active_record].freeze

initializer "aws-xray-sdk.rack_middleware" do |app|
initializer("aws-xray-sdk.rack_middleware") do |app|
app.middleware.insert 0, Rack::Middleware
app.middleware.use XRay::Rails::ExceptionMiddleware
end
Expand Down
4 changes: 2 additions & 2 deletions lib/aws-xray-sdk/model/cause.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'oj'
require 'multi_json'

module XRay
# Represents cause section in segment and subsegment document.
Expand Down Expand Up @@ -26,7 +26,7 @@ def to_h

def to_json
@to_json ||= begin
Oj.dump to_h, mode: :compat, use_as_json: true
MultiJson.dump to_h
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/aws-xray-sdk/model/entity.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'securerandom'
require 'bigdecimal'
require 'oj'
require 'multi_json'
require 'aws-xray-sdk/exceptions'
require 'aws-xray-sdk/model/cause'
require 'aws-xray-sdk/model/annotations'
Expand Down Expand Up @@ -168,7 +168,7 @@ def to_h

def to_json
@to_json ||= begin
Oj.dump to_h, mode: :compat, use_as_json: true
MultiJson.dump(to_h)
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/aws-xray-sdk/model/metadata.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'oj'
require 'multi_json'
require 'aws-xray-sdk/exceptions'

module XRay
Expand Down Expand Up @@ -48,7 +48,7 @@ def to_h

def to_json
@to_json ||= begin
Oj.dump to_h, mode: :compat, use_as_json: true
MultiJson.dump to_h
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/aws-xray-sdk/plugins/elastic_beanstalk.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'oj'
require 'multi_json'
require 'aws-xray-sdk/logger'

module XRay
Expand All @@ -14,7 +14,7 @@ module ElasticBeanstalk
def self.aws
@@aws ||= begin
file = File.open(CONF_PATH)
{ elastic_beanstalk: Oj.load(file) }
{ elastic_beanstalk: MultiJson.load(file) }
rescue StandardError => e
@@aws = {}
Logging.logger.warn %(can not get the environment config due to: #{e.message}.)
Expand Down
6 changes: 6 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
require 'minitest/autorun'
require 'aws-xray-sdk/emitter/emitter'

if RUBY_PLATFORM == 'java'
require 'jrjackson'
else
require 'oj'
end

module XRay
# holds all testing needed classes and methods
module TestHelper
Expand Down

0 comments on commit 82c087e

Please sign in to comment.