Comments (9)
Hey there @kliuless. Sorry again for the delay on getting back to you. We've tried to replicate the issue here, and from that investigation had the following questions to help us track it down:
- What Ruby version are you running?
- What's the expected encoding of the page contents itself (specifically is the page UTF-8 or something else)?
- What's the exact error message that it's giving when it fails?
- Would it be possible for you to patch the agent to call
beginning_of_source.encoding
andbeginning_of_source.valid_encoding?
We'd be happy to help you figure out how to do that if you're in a position where that'd be a possibility.
Additionally, a possible workaround would be to disable the auto-instrumentation provided by NewRelic::Rack::BrowserMonitoring
and instead manually inject the javascript per this doc: https://docs.newrelic.com/docs/ruby/page-load-timing-in-ruby
from newrelic-ruby-agent.
@jasonclark - let me try to reproduce this in our dev environment.
from newrelic-ruby-agent.
@jasonrclark Well, for some reason the response object passed to BrowserMonitoring#call
is yielding strings with US-ASCII encoding. I also tried with a new rails (3.2) app with a simple pass-thru middleware, and the middleware received a UTF-8 response. Could you please use a test app with the BrowserMonitoring middleware to see what's the encoding of a fragment in the gather_source
method? If you get UTF-8, it's probably something in our particular app. If you get US-ASCII, then it seems like we have a bigger problem.
I'll keep trying to track this down. It's possible we have some middleware that's changing the encoding.
from newrelic-ruby-agent.
@kliuless Ran a few of our test apps, and much like your new rails 3.2 app we're getting UTF-8 through consistently.
I was running this on Ruby 2.1. What version are you working with?
It does seem likely to be something in your app, but you're likely not the only one with different encodings, so I'd love to get a repro on this so we can address it in the agent.
Beyond other middlewares, I'd also be curious whether any of your template files are stored with a different encoding. I haven't managed to get my test app to duplicate passing through the altered encoding yet, but it seems like a likely way that might happen.
Appreciate your continued searching on this!
from newrelic-ruby-agent.
@jasonrclark Turns out that this probably isn't a bug in the newrelic gem. We're doing some post-processing on some of our rendered content that's changing the encoding to US-ASCII.
from newrelic-ruby-agent.
@kliuless Good to hear you're making progress. We've definitely encountered similar situations where a string is forced to an encoding where it's invalid and code downstream reacts badly.
From your description that sounds like the case here (a "Jürgen" getting forced to US-ASCII where it isn't valid). Things other than the agent might be unhappy with that, so you'll want to deal with it in your app, but the agent should be more resilient. I'm adding better error handling in that region thanks to your report, so these type of errors won't be a crashing situation due to the agent anymore.
I will report back here when we've got an agent released that has the fix, although it sounds like you might fix up the problem in your app more directly before that happens.
Thanks again for the report and investigation!
from newrelic-ruby-agent.
@jasonrclark I found a minimal test case to reproduce this in Rails 3.2.17. Put this in an erb view:
Hello world <%= "\u2014".force_encoding(Encoding::US_ASCII).html_safe %>
The critical elements:
- A UTF-8 character outside the US-ASCII set is forced to US-ASCII.
- The forced part of the string is marked as html_safe. If this is omitted, Rails does some regexp matching which would raise the encoding error instead of letting the string pass through to the rest of the stack.
Our app is doing something much more complex than this contrived example, but believe it or not, the "US-ASCII" never explicitly appears anywhere in our code, any of our gems, or even the ruby standard lib. Net::HTTP
creates an internal string for use as a buffer, and because ruby 1.9's default source file encoding is US-ASCII, that becomes the buffer's encoding too. We're inserting a string we've fetched from an http service, causing the problem above.
See this stackoverflow answer for more the Net::HTTP
issue.
from newrelic-ruby-agent.
@kliuless Great detective work! That's a fascinating problem.
I'll take that case and make sure that the fix I was applying will handle this nicely for the next agent release. Thanks again for all your work on this.
from newrelic-ruby-agent.
Hi @kliuless - thanks again for reporting this, and for your help in tracking it down! The latest version of the Ruby agent (3.9.0, just released today) should handle this scenario in a more graceful way. Please give it a try, and let us know if you run into any trouble!
from newrelic-ruby-agent.
Related Issues (20)
- ElasticSearch instrumentation is currently incompatible with Ruby v3.4.0 HOT 1
- Add Rails 7.2-specific test environments HOT 3
- CI: Ruby v3.4.0-preview1 fails to provide SQL explain plan info for Sequel HOT 2
- Newrelic 9.10.0 breaks our CI - caused by a collision with the 'bootstrap' gem HOT 11
- NewRelic 9.10.0 stopped reporting background jobs HOT 6
- SQS end to end testing HOT 1
- Logs full of undefined method `access_key_id' HOT 8
- ActiveSupport notifications improvements HOT 1
- FOSSA Ruby scanning - enhancements for our public repos HOT 2
- Add testing constraints for ffi HOT 1
- Revert `autostart_denylisted_constants` default change and document options HOT 1
- Spike: Investigate `autostart.denylisted_constants` HOT 1
- Investigate rspec-mocks incompatibility with `add_method_tracer` HOT 3
- Add a configuration option to permit custom method tracers to be defined automatically HOT 1
- CI: GHA - DRY up the action version shas HOT 1
- Meet OYC standards for Agent2Query service HOT 1
- Add Errors Inbox metadata configuration content to generated doc HOT 3
- [Spike] k8s & container integration HOT 1
- [Spike] Support FM/SA configuration HOT 1
- API driven noticed errors display as `expected: true`, and observed errors should too HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from newrelic-ruby-agent.