Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add support for multiple headers containig IPs to be assigned to OT span

GrzegorzKowalik61967e610606
diff --git a/saleor/graphql/views.py b/saleor/graphql/views.py
index 35f16e93ed..a4b46bb254 100644
--- a/saleor/graphql/views.py
+++ b/saleor/graphql/views.py
@@ -176,8 +176,13 @@ class GraphQLView(View):
span.set_tag("http.useragent", request.META.get("HTTP_USER_AGENT", ""))
span.set_tag("span.type", "web")
- request_ips = request.META.get(settings.REAL_IP_ENVIRON, "")
- for ip in request_ips.split(","):
+ request_ips = []
+ for header in settings.REAL_IP_ENVIRON:
+ ips = request.META.get(header)
+ if ips:
+ request_ips.extend(ips.split(","))
+
+ for ip in request_ips:
if is_valid_ipv4(ip):
span.set_tag(opentracing.tags.PEER_HOST_IPV4, ip)
elif is_valid_ipv6(ip):
diff --git a/saleor/settings.py b/saleor/settings.py
index c381c9cc7c..714c2da978 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -618,7 +618,7 @@ if OBSERVABILITY_ACTIVE:
# Change this value if your application is running behind a proxy,
# e.g. HTTP_CF_Connecting_IP for Cloudflare or X_FORWARDED_FOR
-REAL_IP_ENVIRON = os.environ.get("REAL_IP_ENVIRON", "REMOTE_ADDR")
+REAL_IP_ENVIRON = get_list(os.environ.get("REAL_IP_ENVIRON", "REMOTE_ADDR"))
# Slugs for menus precreated in Django migrations
DEFAULT_MENUS = {"top_menu_name": "navbar", "bottom_menu_name": "footer"}