O configure my Ruby on Rails application to use sentry with error report, but it show-me this error:
URI::InvalidURIError:
bad URI(is not URI?): 'http://9ba0c50c55c94603a488a55516d5xxx:xxxx6d6468a4cb892140c1f86a9f228#sentry.myaddres.com/24'
When I remove 9ba0c50c55c94603a488a55516d5xxx:xxxx6d6468a4cb892140c1f86a9f228# this part of addresss all works fine, but in sentry documentation is:
Raven.configure do |config|
config.dsn = 'http://public:secret#example.com/project-id'
end
How can I solve this problem?
I was using ENV var to set sentry DSN:
# .env
SENTRY_DSN_URL='http://public:secret#example.com/project-id'
and in initializer
Raven.configure do |config|
config.dsn = ENV['SENTRY_DSN']
end
This problem is the quotation marks. To solve just remove them.
# .env
SENTRY_DSN_URL=http://public:secret#example.com/project-id
Works fine.
Related
I am experiencing a strange issue from Passenger docker ruby 2.3 with aws redis:
bad URI(is not URI?): 'redis://redis.xxx.ng.0001.apse1.cache.amazonaws.com:6379/1' (URI::InvalidURIError)
/usr/local/rvm/rubies/ruby-2.3.8/lib/ruby/2.3.0/uri/rfc3986_parser.rb:67:in `split'
/usr/local/rvm/rubies/ruby-2.3.8/lib/ruby/2.3.0/uri/rfc3986_parser.rb:73:in `parse'
/usr/local/rvm/rubies/ruby-2.3.8/lib/ruby/2.3.0/uri/common.rb:227:in `parse'
/usr/local/rvm/gems/ruby-2.3.8/gems/sidekiq-5.2.7/lib/sidekiq/redis_connection.rb:97:in `log_info'
/usr/local/rvm/gems/ruby-2.3.8/gems/sidekiq-5.2.7/lib/sidekiq/redis_connection.rb:31:in `create'
/usr/local/rvm/gems/ruby-2.3.8/gems/sidekiq-5.2.7/lib/sidekiq.rb:126:in `redis_pool'
/usr/local/rvm/gems/ruby-2.3.8/gems/sidekiq-5.2.7/lib/sidekiq.rb:94:in `redis'
My sidekiq config:
# ENV['REDIS_URL']= redis://redis.xxx.ng.0001.apse1.cache.amazonaws.com:6379/1
Sidekiq.configure_server do |config|
config.redis = { url: ENV['REDIS_URL'] }
end
Sidekiq.configure_client do |config|
config.redis = { url: ENV['REDIS_URL'] }
end
However if I run:
docker exec -it container_id bash
and then rails console everything seems to work just fine.
I also tried this:
redis_url = ENV['REDIS_URL']
# The statement below parsed successfully thus the redis_url is correct
uri = URI.parse(redis_url)
redis_options = {
host: uri.host,
port: 6379,
db: uri.path[1..-1]
}
Sidekiq.configure_server do |config|
config.redis = redis_options
end
Sidekiq.configure_client do |config|
config.redis = redis_options
end
But it raised the exact same error. I could run the docker locally connected to local redis just fine. I am wondering there might be something wrong with the ENV['REDIS_URL'] value.
Is there anyone experiencing this issue or any clues?
My env is
- passenger-docker ruby 2.3.8
- aws elastic cache redis: 5.0.5
- sidekiq 5.2.7
After many hours, I just realize that the redis_url from the container was pointed to the deleted Redis cluster in aws. My first launch of Redis was set to default to r5 16GM instance type which is very big and costly for testing. I decided to launch a new one with just t2 small and deleted the r5 one to save some money, however in passenger-config I have the REDIS_URL set and Nginx overridden the env value over the one I set in the ECS task.
The error raised by ruby Redis is not straightforward and having two places to set ENV (in Nginx config and in ECS-task ) make the debugging painful.
Using Carrierwave and fog and everything working fine with AWS but when I try and do a migration and some other rails commands I get:
lib/fog/core/service.rb:244:in validate_options: Missing required arguments: aws_access_key_id, aws_secret_access_key (ArgumentError)
This also happens with the Rails console. I think for some reason rails is not able to access my ENV variables for some reason? But it works when running as part of a Rails server...
Any thoughts on why? aws key defined as below:
CarrierWave.configure do |config|
config.fog_provider = 'fog/aws'
config.fog_credentials = {
provider: 'AWS',
aws_access_key_id: ENV['AWS_ACCESS_KEY'],
aws_secret_access_key: ENV['AWS_SECRET'],
region: 'eu-west-2'
}
config.fog_directory = 'images' # bucket name
config.cache_dir = "#{Rails.root}/tmp/uploads" # To let CarrierWave work on heroku
end
Not an answer to the above question but as OP has asked again for any advice..
Stop using ENV variables in development. Create a secrets.yml file, and you'll be able to access these values in your project. Make sure you add this to your .gitignore file as committing this is obviously not a good idea.
A very brief, succinct runthrough of how to use secrets:
https://richonrails.com/articles/the-rails-4-1-secrets-yml-file
Following this RailsCast : http://railscasts.com/episodes/256-i18n-backends but using Rails 5.2, I raise this error :
Redis::CommandError in Pages#home<br>
ERR unknown command '[]'
In config/initializers/i18n_backend.rb
TRANSLATION_STORE = Redis.new seems causing this problem.
Whereas TRANSLATION_STORE = {} works like a charm.
But without Redis!
Any hint?
The problem is defined here:
https://github.com/ruby-i18n/i18n/blob/master/lib/i18n/backend/key_value.rb#L25-L30
I haven't investigated redis 4 but it seems that these methods has been removed.
The solution is to patch the Redis gem and add these methods to the redis.
# config/initializers/redis.rb
class RedisHash
def initialize(redis)
#redis = redis
end
def [](key)
#redis.get(key)
end
def []=(key, value)
#redis.set(key, value)
end
end
Redis.current = Redis.new(host: 127.0.0.1,
port: 6379,
db: 0,
thread_safe: true)
# config/initializers/i18n.rb
I18n::Backend::KeyValue.new(RedisHash.new(Redis.current))
This code above is sample initializer. It works with the newest version of redis 4.3.5
I've tested also redis-store/redis-i18n and it also works with the newest redis versions but in my opinion this implementation enforces huge overload on redis.
EDIT:
Due to the redis contributors [answer][1]
[1]: https://github.com/redis/redis-rb/issues/997#issuecomment-871302883 I've updated my solution
Not a full answer I know, but I had a similar problem after upgrading redis gem from 3.3.1 to 4.0.2
I set it back to 3.3.1 and it got fixed. Odd thing for me was that the problem only occurred in the production environment.
I am using a chained backend
I18n.backend= I18n::Backend::Chain.new(
I18n::Backend::KeyValue.new(Redis.current),
I18n.backend
)
Running on Linux Mint 16, I followed this guide here: http://pivotallabs.com/rspec-elasticsearchruby-elasticsearchmodel/ to setup elasticsearch with Ruby on Rails application.
When I run rspec, when it hits this line spec_helper.rb:
config.before :each, elasticsearch: true do
Elasticsearch::Extensions::Test::Cluster.start(port: 9200) unless Elasticsearch::Extensions::Test::Cluster.running?
end
I received the following error:
Starting 2 Elasticsearch nodes..sh: 1: elasticsearch: not found
I thought it might be a path issue....
So I added the following to ~/.bashrc:
export PATH="/etc/init.d:$PATH" since sudo /etc/init.d/elasticsearch start starts the elasticsearch service.
Then I issued command source ~/.bashrc
This got rid of the sh: 1: elasticsearch: not found message and instead the message from the error triggered in spec_helper.rb was:
............Starting 2 Elasticsearch nodes..
[!!!] Process failed to start (see output above)
F........
Below is the config block in my spec_helper.rb file:
config.before :each, elasticsearch: true do
Article.__elasticsearch__.client = Elasticsearch::Client.new host: 'http://localhost:9200'
Article.__elasticsearch__.create_index!(force: true)
Article.__elasticsearch__.refresh_index!
Elasticsearch::Extensions::Test::Cluster.start(port: 9200) unless Elasticsearch::Extensions::Test::Cluster.running?
end
config.after :suite do
Elasticsearch::Extensions::Test::Cluster.stop(port: 9200) if Elasticsearch::Extensions::Test::Cluster.running?
end
Any ideas on what the issue might be?
EDIT: If I change to port 9250 as suggested by commenter below:
config.before :each, elasticsearch: true do
Article.__elasticsearch__.client = Elasticsearch::Client.new host: 'http://localhost:9250'
Article.__elasticsearch__.create_index!(force: true)
Article.__elasticsearch__.refresh_index!
Elasticsearch::Extensions::Test::Cluster.start(port: 9250) unless Elasticsearch::Extensions::Test::Cluster.running?
end
config.after :suite do
Elasticsearch::Extensions::Test::Cluster.stop(port: 9250) if Elasticsearch::Extensions::Test::Cluster.running?
end
I get this new error:
An error occurred in an after hook
Faraday::ConnectionFailed: Connection refused - connect(2) for "localhost" port 9250
occurred at /home/nona/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/net/http.rb:879:in `initialize'
F........
I remember having a similar problem, and I solved it with the following line in my test_helper:
ENV["TEST_CLUSTER_NODES"] = "1" # need to set so we trigger correct ES defaults
I figured it out by looking at the Elasticsearch::Extensions::Test::Cluster source and realizing that Elasticsearch::Extensions::Test::Cluster.running? was returning true (and therefore not starting the cluster) unless that TEST_CLUSTER_NODES value is set.
I've written my own yaml config file as described in railscast #85. APP_CONFIG['FOO'] works in the initializers (e.g. sidekiq.yml), but not in database.yml (error: undefined method '+' for nil:NilClass; the '+' is being used in a concatenation: APP_CONFIG['FOO'] + 'bar').
Even putting APP_CONFIG into before_configuration did not solve this issue.
Rails.application.config.before_configuration do
APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/config.yml")
end
Same problem. APP_CONFIG is still causing the nil:NilClass error in database.yml. So here's the question: how can i force my config.yml to be loaded before database.yml, so that it is available in database.yml as well as in the initializers (sidekiq.yml)?