Skip to content

Commit b4c6054

Browse files
authored
[DOCS] Add Scarf telemetry to SedonaDB (#2345)
1 parent 4935905 commit b4c6054

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

python/sedona/db/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
# Send telemetry on import
19+
from .telemetry import track_package_import
20+
21+
track_package_import()
22+
23+
# Import the actual sedonadb functions
1824
from sedonadb import connect, context, dataframe
1925

2026
__all__ = [

python/sedona/db/telemetry.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
"""
19+
Simple Scarf telemetry for sedona.db package.
20+
"""
21+
22+
import os
23+
import platform
24+
import threading
25+
import urllib.request
26+
27+
28+
def _send_telemetry():
29+
"""Send simple telemetry data to Scarf gateway."""
30+
# Check if telemetry is disabled
31+
if os.getenv("SCARF_NO_ANALYTICS", "").lower() in ("true", "1", "yes") or os.getenv(
32+
"DO_NOT_TRACK", ""
33+
).lower() in ("true", "1", "yes"):
34+
return
35+
36+
try:
37+
# Build URL with system info (replace spaces with underscores)
38+
arch = platform.machine().lower().replace(" ", "_")
39+
os_name = platform.system().lower().replace(" ", "_")
40+
language = "python"
41+
url = f"https://sedona.gateway.scarf.sh/sedona-db/{arch}/{os_name}/{language}"
42+
43+
# Send simple GET request in background
44+
def _send():
45+
try:
46+
# Only allow HTTPS requests for security
47+
if url.startswith("https://"):
48+
urllib.request.urlopen(url, timeout=5) # nosec B310
49+
except Exception: # nosec B110
50+
pass # Silently fail
51+
52+
thread = threading.Thread(target=_send, daemon=True)
53+
thread.start()
54+
55+
except Exception: # nosec B110
56+
pass # Silently fail
57+
58+
59+
def track_package_import():
60+
"""Track when the sedona.db package is imported."""
61+
_send_telemetry()

0 commit comments

Comments
 (0)