Skip to content

Commit b5e982d

Browse files
karlwaldmanclaude
andcommitted
feat: Add telemetry headers for app tracking (v1.5.0)
- Add app_url and app_name config options for SDK telemetry - Send X-SDK-Name, X-SDK-Version headers on every request - Send X-App-URL, X-App-Name headers when configured (10% bonus!) - Rename headers from X-Api-Client to X-SDK-Name for consistency - Bump version to 1.5.0 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 61a9ac7 commit b5e982d

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

oilpriceapi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
The official Python SDK for OilPriceAPI - Real-time and historical oil prices.
55
"""
66

7-
__version__ = "1.4.2"
7+
__version__ = "1.5.0"
88
__author__ = "OilPriceAPI"
99
__email__ = "support@oilpriceapi.com"
1010

oilpriceapi/async_client.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ def __init__(
6161
headers: Optional[Dict[str, str]] = None,
6262
max_connections: int = 100,
6363
max_keepalive_connections: int = 20,
64+
app_url: Optional[str] = None,
65+
app_name: Optional[str] = None,
6466
):
6567
# Get API key
6668
self.api_key = api_key or os.environ.get("OILPRICEAPI_KEY")
@@ -76,6 +78,8 @@ def __init__(
7678
self.retry_on = retry_on or self.DEFAULT_RETRY_CODES
7779
self.max_connections = max_connections
7880
self.max_keepalive_connections = max_keepalive_connections
81+
self.app_url = app_url
82+
self.app_name = app_name
7983

8084
# Initialize retry strategy
8185
self._retry_strategy = RetryStrategy(
@@ -84,15 +88,23 @@ def __init__(
8488
)
8589

8690
# Build headers
91+
import sys
92+
python_version = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
8793
self.headers = {
8894
"Authorization": f"Token {self.api_key}",
8995
"Content-Type": "application/json",
9096
"Accept": "application/json",
91-
"User-Agent": "OilPriceAPI-Python-Async/1.4.0",
92-
"X-SDK-Language": "python",
93-
"X-SDK-Version": "1.4.0",
94-
"X-Client-Type": "sdk",
97+
"User-Agent": f"oilpriceapi-python/1.5.0 python/{python_version}",
98+
"X-SDK-Name": "oilpriceapi-python",
99+
"X-SDK-Version": "1.5.0",
95100
}
101+
102+
# Add optional telemetry headers (10% bonus for app_url!)
103+
if self.app_url:
104+
self.headers["X-App-URL"] = self.app_url
105+
if self.app_name:
106+
self.headers["X-App-Name"] = self.app_name
107+
96108
if headers:
97109
self.headers.update(headers)
98110

oilpriceapi/client.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def __init__(
7878
max_retries: Optional[int] = None,
7979
retry_on: Optional[list] = None,
8080
headers: Optional[Dict[str, str]] = None,
81+
app_url: Optional[str] = None,
82+
app_name: Optional[str] = None,
8183
):
8284
# Get API key from parameter or environment
8385
self.api_key = api_key or os.environ.get("OILPRICEAPI_KEY")
@@ -104,17 +106,28 @@ def __init__(
104106
f"timeout={self.timeout}s, max_retries={self.max_retries}"
105107
)
106108

109+
# Store telemetry settings
110+
self.app_url = app_url
111+
self.app_name = app_name
112+
107113
# Build headers
108114
import sys
109115
python_version = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
110116
self.headers = {
111117
"Authorization": f"Token {self.api_key}",
112118
"Content-Type": "application/json",
113119
"Accept": "application/json",
114-
"User-Agent": f"oilpriceapi-python/1.4.2 python/{python_version}",
115-
"X-Api-Client": "oilpriceapi-python",
116-
"X-Client-Version": "1.4.2",
120+
"User-Agent": f"oilpriceapi-python/1.5.0 python/{python_version}",
121+
"X-SDK-Name": "oilpriceapi-python",
122+
"X-SDK-Version": "1.5.0",
117123
}
124+
125+
# Add optional telemetry headers (10% bonus for app_url!)
126+
if self.app_url:
127+
self.headers["X-App-URL"] = self.app_url
128+
if self.app_name:
129+
self.headers["X-App-Name"] = self.app_name
130+
118131
if headers:
119132
self.headers.update(headers)
120133

0 commit comments

Comments
 (0)