Skip to content

Commit 2c7e140

Browse files
committed
chore: add agent in requests
1 parent 471b7e7 commit 2c7e140

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

replane/_async.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from ._eval import evaluate_config
1414
from ._sse import SSEParser
15+
from .version import VERSION
1516
from .errors import (
1617
AuthenticationError,
1718
ClientClosedError,
@@ -34,6 +35,9 @@
3435
# Sentinel value for detecting when no default was provided
3536
_MISSING: Any = object()
3637

38+
# Default agent identifier
39+
DEFAULT_AGENT = f"replane-python/{VERSION}"
40+
3741
logger = logging.getLogger("replane")
3842

3943

@@ -86,6 +90,7 @@ def __init__(
8690
initialization_timeout_ms: int = 5000,
8791
retry_delay_ms: int = 200,
8892
inactivity_timeout_ms: int = 30000,
93+
agent: str | None = None,
8994
debug: bool = False,
9095
) -> None:
9196
"""Initialize the async Replane client.
@@ -100,6 +105,7 @@ def __init__(
100105
initialization_timeout_ms: Timeout for initial connection.
101106
retry_delay_ms: Initial delay between retries.
102107
inactivity_timeout_ms: Max time without SSE events before reconnect.
108+
agent: Agent identifier sent in X-Replane-Agent header. Defaults to SDK identifier.
103109
debug: Enable debug logging to see all client activity.
104110
105111
Raises:
@@ -138,6 +144,7 @@ def __init__(
138144
self._init_timeout = initialization_timeout_ms / 1000.0
139145
self._retry_delay = retry_delay_ms / 1000.0
140146
self._inactivity_timeout = inactivity_timeout_ms / 1000.0
147+
self._agent = agent or DEFAULT_AGENT
141148

142149
# Config storage
143150
self._configs: dict[str, Config] = {}
@@ -402,6 +409,7 @@ async def _connect_stream(self) -> None:
402409
"Authorization": f"Bearer {self._sdk_key}",
403410
"Accept": "text/event-stream",
404411
"Cache-Control": "no-cache",
412+
"X-Replane-Agent": self._agent,
405413
}
406414

407415
logger.debug("Connecting to SSE: %s", url)

replane/_sync.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from ._eval import evaluate_config
2020
from ._sse import SSEParser
21+
from .version import VERSION
2122
from .errors import (
2223
AuthenticationError,
2324
ClientClosedError,
@@ -34,6 +35,9 @@
3435
# Sentinel value for detecting when no default was provided
3536
_MISSING: Any = object()
3637

38+
# Default agent identifier
39+
DEFAULT_AGENT = f"replane-python/{VERSION}"
40+
3741
logger = logging.getLogger("replane")
3842

3943

@@ -85,6 +89,7 @@ def __init__(
8589
initialization_timeout_ms: int = 5000,
8690
retry_delay_ms: int = 200,
8791
inactivity_timeout_ms: int = 30000,
92+
agent: str | None = None,
8893
debug: bool = False,
8994
) -> None:
9095
"""Initialize the Replane client.
@@ -99,6 +104,7 @@ def __init__(
99104
initialization_timeout_ms: Timeout for initial connection.
100105
retry_delay_ms: Initial delay between retries.
101106
inactivity_timeout_ms: Max time without SSE events before reconnect.
107+
agent: Agent identifier sent in X-Replane-Agent header. Defaults to SDK identifier.
102108
debug: Enable debug logging to see all client activity.
103109
"""
104110
# Configure debug logging
@@ -130,6 +136,7 @@ def __init__(
130136
self._init_timeout = initialization_timeout_ms / 1000.0
131137
self._retry_delay = retry_delay_ms / 1000.0
132138
self._inactivity_timeout = inactivity_timeout_ms / 1000.0
139+
self._agent = agent or DEFAULT_AGENT
133140

134141
# Config storage
135142
self._configs: dict[str, Config] = {}
@@ -400,6 +407,7 @@ def _connect_stream(self) -> None:
400407
"Content-Type": "application/json",
401408
"Accept": "text/event-stream",
402409
"Cache-Control": "no-cache",
410+
"X-Replane-Agent": self._agent,
403411
}
404412

405413
logger.debug("Sending POST request to %s", path)

0 commit comments

Comments
 (0)