Skip to content

Commit

Permalink
Merge pull request #514 from OpenMined/shubham/track-geo-loc
Browse files Browse the repository at this point in the history
track user geo location of the client user
  • Loading branch information
shubham3121 authored Dec 20, 2024
2 parents cbe5c89 + a906361 commit b4260b2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions syftbox/lib/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
HEADER_OS_NAME = b"x-os-name"
HEADER_OS_VERSION = b"x-os-ver"
HEADER_OS_ARCH = b"x-os-arch"
HEADER_GEO_COUNTRY = b"x-geo-country" # Country of the user, added by Azure Front Door

SYFTBOX_HEADERS = {
"User-Agent": f"SyftBox/{__version__} (Python {PYTHON_VERSION}; {OS_NAME} {OS_VERSION}; {OS_ARCH})",
Expand Down
3 changes: 3 additions & 0 deletions syftbox/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from syftbox import __version__
from syftbox.lib.http import (
HEADER_GEO_COUNTRY,
HEADER_OS_ARCH,
HEADER_OS_NAME,
HEADER_OS_VERSION,
Expand All @@ -42,6 +43,7 @@
OTEL_ATTR_CLIENT_OS_VER,
OTEL_ATTR_CLIENT_PYTHON,
OTEL_ATTR_CLIENT_USER,
OTEL_ATTR_CLIENT_USER_LOC,
OTEL_ATTR_CLIENT_VERSION,
setup_otel_exporter,
)
Expand Down Expand Up @@ -72,6 +74,7 @@ def server_request_hook(span: Span, scope: dict[str, Any]) -> None:
span.set_attribute(OTEL_ATTR_CLIENT_OS_NAME, headers.get(HEADER_OS_NAME, ""))
span.set_attribute(OTEL_ATTR_CLIENT_OS_VER, headers.get(HEADER_OS_VERSION, ""))
span.set_attribute(OTEL_ATTR_CLIENT_OS_ARCH, headers.get(HEADER_OS_ARCH, ""))
span.set_attribute(OTEL_ATTR_CLIENT_USER_LOC, headers.get(HEADER_GEO_COUNTRY, ""))


@contextlib.asynccontextmanager
Expand Down
1 change: 1 addition & 0 deletions syftbox/server/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
OTEL_ATTR_CLIENT_VERSION = "syftbox.client.version"
OTEL_ATTR_CLIENT_PYTHON = "syftbox.client.python"
OTEL_ATTR_CLIENT_USER = "syftbox.client.user"
OTEL_ATTR_CLIENT_USER_LOC = "syftbox.client.user.location"
OTEL_ATTR_CLIENT_OS_NAME = "syftbox.client.os.name"
OTEL_ATTR_CLIENT_OS_VER = "syftbox.client.os.version"
OTEL_ATTR_CLIENT_OS_ARCH = "syftbox.client.os.arch"
Expand Down

0 comments on commit b4260b2

Please sign in to comment.