-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logs flooded with cannot find the current context
#85
Comments
Okay, I think I get it. The HTTP Interceptor uses the following logic: entity = XRay.recorder.current_entity
capture = !(entity && entity.namespace && entity.namespace == 'aws'.freeze)
if started? && capture && entity
XRay.recorder.capture(address, namespace: 'remote') do |subsegment|
protocol = use_ssl? ? 'https'.freeze : 'http'.freeze Now, |
Hi @moritonal - thanks for finding this bug! in #83 we changed this behavior from a runtime error to a log message, but it seems you're right that we should be avoiding the context missing issue in the first place here. Please feel free to submit a PR to address this, otherwise we will take a look when we're able. |
cannot find the current context
This is making more sense, Unleash runs a scheduled job which runs in a thread and makes an HTTP call. Because this isn't wrapped in the Rails middleware then there isn't an active segment. This causes the error to be thrown. So... it's not really a bug, it's kind of reasonable that the the sub-call to HTTP is throwing an error because it isn't owned by a particular segment. Thinking it through we have a few choices I'd like your input on:
Or some combo of all of the above? |
This missing context was fixed with the following monkey-patch to intercept calls from Unleash. Although it does beg the question of how do I tell X-Ray that a message isn't related to a specific request? module Unleash
module ToggleFetcherExtensions
def fetch
XRay.recorder.begin_segment "Unleash"
super
XRay.recorder.end_segment
end
end
# Add the extension to the ToggleFetcher class
class ToggleFetcher
prepend ToggleFetcherExtensions
end
end |
The same effect occurs actually when using it with |
We would be open to a PR for improving the log message's prescriptiveness.
It seems like your monkeypatch should basically do this! It should produce a single segment named "Unleash" and that segment will parent any subsegments for HTTP calls made in that scope. |
Hihi
On the latest-version, seeing a lot of this in the logs:
This is coming from this line which may be mistakenly hiding a bug?
The code is:
But when I run
Thread.current[LOCAL_KEY]
I getuninitialized constant XRay::NetHttp::HTTPInstanceInterceptor::LOCAL_KEY
which I imagine is unintended.Ah, but further research shows this is coming from the Unleash gem I use which runs on a scheduled task on it's own Thread.
So Unleash fires, calling http-fetch which get's intercepted by XRay which throws an error because no context is set.
I've also found an undocumented
context_missing
option ofIGNORE_ERROR
which silences the issue.The text was updated successfully, but these errors were encountered: