aws / aws/aws-xray-sdk-ruby

Logs flooded with `cannot find the current context`

Open
#85 6 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Ruby
Stars
60
Forks
54
PR merge metrics
No merged PRs in 30d

Description

Hihi

On the latest-version, seeing a lot of this in the logs:

```
E, [2023-02-14T16:46:29.307789 #87679] ERROR -- : cannot find the current context.
```

This is coming from [this](https://github.com/aws/aws-xray-sdk-ruby/blob/5430136e1c7e2586c306a4b58daf2db0d5045fe2/lib/aws-xray-sdk/context/default_context.rb#L32) line which may be mistakenly hiding a bug?

The code is:

```
def current_entity
if entity = Thread.current[LOCAL_KEY]
entity
else
handle_context_missing
end
end
```

But when I run `Thread.current[LOCAL_KEY]` I get `uninitialized 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 of `IGNORE_ERROR` which silences the issue.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.