mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-07 08:26:10 +00:00
proxy: add PYROSCOPE_SAMPLE_RATE env, use verbose logging, fix int type
- Add optional PYROSCOPE_SAMPLE_RATE env (integer, no default) - Pass sample_rate to pyroscope.configure() as int for pyroscope-io - Replace print with verbose_proxy_logger (info/warning) - Document PYROSCOPE_SAMPLE_RATE in config_settings.md
This commit is contained in:
parent
2fb793d8c7
commit
8087cab8aa
2 changed files with 24 additions and 8 deletions
|
|
@ -775,6 +775,7 @@ router_settings:
|
|||
| LITELLM_ENABLE_PYROSCOPE | If true, enables Pyroscope CPU profiling. Profiles are sent to PYROSCOPE_SERVER_ADDRESS. Off by default. See [Pyroscope profiling](/proxy/pyroscope_profiling).
|
||||
| PYROSCOPE_APP_NAME | Application name reported to Pyroscope. Required when LITELLM_ENABLE_PYROSCOPE is true. No default.
|
||||
| PYROSCOPE_SERVER_ADDRESS | Pyroscope server URL to send profiles to. Required when LITELLM_ENABLE_PYROSCOPE is true. No default.
|
||||
| PYROSCOPE_SAMPLE_RATE | Optional. Sample rate for Pyroscope profiling (integer). No default; when unset, the pyroscope-io library default is used.
|
||||
| LITELLM_MASTER_KEY | Master key for proxy authentication
|
||||
| LITELLM_MODE | Operating mode for LiteLLM (e.g., production, development)
|
||||
| LITELLM_NON_ROOT | Flag to run LiteLLM in non-root mode for enhanced security in Docker containers
|
||||
|
|
|
|||
|
|
@ -5561,9 +5561,10 @@ class ProxyStartupEvent:
|
|||
Off by default. Enable with LITELLM_ENABLE_PYROSCOPE=true.
|
||||
Requires: pip install pyroscope-io
|
||||
Sends profiles to PYROSCOPE_SERVER_ADDRESS (default http://localhost:4040).
|
||||
Optional: PYROSCOPE_SAMPLE_RATE (float, no default) to set the sample rate.
|
||||
"""
|
||||
if not get_secret_bool("LITELLM_ENABLE_PYROSCOPE", False):
|
||||
print( # noqa: T201
|
||||
verbose_proxy_logger.info(
|
||||
"LiteLLM: Pyroscope profiling is disabled (set LITELLM_ENABLE_PYROSCOPE=true to enable)."
|
||||
)
|
||||
return
|
||||
|
|
@ -5588,17 +5589,31 @@ class ProxyStartupEvent:
|
|||
)
|
||||
if env_name:
|
||||
tags["environment"] = env_name
|
||||
pyroscope.configure(
|
||||
app_name=app_name,
|
||||
server_address=server_address,
|
||||
tags=tags if tags else None,
|
||||
)
|
||||
print( # noqa: T201
|
||||
sample_rate_env = os.getenv("PYROSCOPE_SAMPLE_RATE")
|
||||
configure_kwargs = {
|
||||
"app_name": app_name,
|
||||
"server_address": server_address,
|
||||
"tags": tags if tags else None,
|
||||
}
|
||||
if sample_rate_env is not None:
|
||||
try:
|
||||
# pyroscope-io expects sample_rate as an integer
|
||||
configure_kwargs["sample_rate"] = int(float(sample_rate_env))
|
||||
except (ValueError, TypeError):
|
||||
raise ValueError(
|
||||
"PYROSCOPE_SAMPLE_RATE must be a number, got: "
|
||||
f"{sample_rate_env!r}"
|
||||
)
|
||||
pyroscope.configure(**configure_kwargs)
|
||||
msg = (
|
||||
f"LiteLLM: Pyroscope profiling started (app_name={app_name}, server_address={server_address}). "
|
||||
f"View CPU profiles at the Pyroscope UI and select application '{app_name}'."
|
||||
)
|
||||
if "sample_rate" in configure_kwargs:
|
||||
msg += f" sample_rate={configure_kwargs['sample_rate']}"
|
||||
verbose_proxy_logger.info(msg)
|
||||
except ImportError:
|
||||
print( # noqa: T201
|
||||
verbose_proxy_logger.warning(
|
||||
"LiteLLM: LITELLM_ENABLE_PYROSCOPE is set but the 'pyroscope-io' package is not installed. "
|
||||
"Pyroscope profiling will not run. Install with: pip install pyroscope-io"
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue