Detecting external ips running sentry for lms or cms
Bug description
Using sentry with lms or cms we noticed that all events are coming from the same ip (which is the ip of the box running tutor & docker)
I read here: https://github.com/moby/moby/issues/15086 that maybe solved by using a specific (host) network-mode https://docs.docker.com/compose/compose-file/#network_mode
How to reproduce Install sentry on lms or cms and check which is the ip related with the events (it should be always the same)
Environment
- Ubuntu 18.04
- tutor, version 3.7.4
Additional context
Initial post: https://discuss.overhang.io/t/detecting-external-ips-running-sentry-for-lms-or-cms/208
I don't know if this is a bun in tutor or a limitation on docker & docker-compose see: https://github.com/moby/moby/issues/15086
Wait, I don't understand. Are you referring to IPs of users accessing the website, or the IPs of containers running the lms/cms?
I'm referring to IPs of users accessing the website, I want to detect which users are generating the different events on Sentry.
With the default configuration I see that all errors are generate from the same IP. Just to clarify this is a screenshot:

but these errors are from different users.
Let me know if you need more information.
Ok, so I understood this problem correctly. However, my initial intuition that gunicorn was the faulty link is invalid., According to my experiments, gunicorn correctly processes the X-Forwarded-For header to django. Can you please check the value of this header inside your sentry events?
Also, are you running your Open edX platform behind a proxy? (WEB_PROXY=True) if yes, this proxy needs to properly set the X-Forwarded-For header.
Given a random event on LMS, I see:

No, we are not running behind a proxy.
When I review the issue I understood that this is related with a more general issue related with the ability of detecting an external IP when running a webpp inside a container. That is why I linked: https://github.com/moby/moby/issues/15086.
The fact that the X-Forwarded-For header is empty for all events is the cause that all events appear to come from the same IP. This is not an issue with docker. Now we need to figure out why the header is not properly sent to Sentry.
I think this might be due to the fact that Sentry wraps the django app with its own middleware. At the same time, Open edX attempts to properly capture the X-Forwarded-For header with the XForwardedForMiddleware.
I am going to need more time to investigate this properly. I want to propose a sentry plugin for tutor at some point, but it's not at the top of my priority list. If you understand what's going on please post your findings here. Otherwise, we'll have to wait until I investigate this further.
@regisb based on your comments I tried to continue with this issue but didn't find the cause, let me share what I found:
- As you mention
X-Forwarded-Foris removed, I tried adding a custom header in nginx and I see the remote addr properly defined:

- Checked this method: https://github.com/getsentry/sentry-python/blob/733662d417a7c272764baeeb41b947e5eccc1ad5/sentry_sdk/integrations/wsgi.py#L132 to see if we could use a different header, when I tried with
HTTP_X_REAL_IPalso was empty :(
If I have another update on this I'll let you know.
@regisb I took another look to this one, it seems that this is a configuration issue in Sentry, I notice this line: https://github.com/getsentry/sentry-python/blob/733662d417a7c272764baeeb41b947e5eccc1ad5/sentry_sdk/integrations/wsgi.py#L235 so I changed that setting in the sentry sdk configuration, for example:
sentry_sdk.init(
dsn=dsn_address,
send_default_pii=True,
integrations=[DjangoIntegration()]
)
and now I see IPs correctly, so this is for sure not an issue in tutor and docker, just a configuration issue.
Sorry for reporting the issue without proper validation of configuration.
This is good to know, because the sentry docs don't mention that the IP address is part of the personally identifiable information (PII) https://docs.sentry.io/error-reporting/configuration/?platform=python#send-default-pii