Skip to content

Commit

Permalink
fix: centralize config
Browse files Browse the repository at this point in the history
  • Loading branch information
Kl0ven committed Jan 9, 2023
1 parent 056a78c commit ec74720
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
21 changes: 14 additions & 7 deletions sentry_dynamic_sampling_lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

import psutil

from sentry_dynamic_sampling_lib.config import (
CONTROLLER_HOST,
CONTROLLER_PATH,
METRIC_INTERVAL,
METRIC_PATH,
POLL_INTERVAL,
)
from sentry_dynamic_sampling_lib.sampler import TraceSampler

if TYPE_CHECKING:
Expand Down Expand Up @@ -34,13 +41,13 @@ def init_wrapper():

sentry_sdk: sentry_sdk_type = importlib.import_module("sentry_sdk")
client = sentry_sdk.Hub.current.client
controller_host = os.getenv("SENTRY_CONTROLLER_HOST")
controller_path = os.getenv("SENTRY_CONTROLLER_PATH", "/sentry/apps/{}/")
metric_path = os.getenv(
"SENTRY_CONTROLLER_METRIC_PATH", "/sentry/apps/{}/metrics/{}/"
)
poll_interval = int(os.getenv("SENTRY_CONTROLLER_POLL_INTERVAL", "30"))
metric_interval = int(os.getenv("SENTRY_CONTROLLER_METRIC_INTERVAL", "300"))

controller_host = CONTROLLER_HOST
controller_path = CONTROLLER_PATH
metric_path = METRIC_PATH
poll_interval = POLL_INTERVAL
metric_interval = METRIC_INTERVAL

if controller_host:
app_key = build_app_key(client.options)
controller_endpoint = urljoin(controller_host, controller_path)
Expand Down
13 changes: 13 additions & 0 deletions sentry_dynamic_sampling_lib/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import os

# default value overridden by controller
DEFAULT_IGNORED_PATH = {"/health", "/healthz", "/health/", "/healthz/"}
DEFAULT_IGNORED_TASK = set()
DEFAULT_SAMPLE_RATE = 0.0

# controller variables
CONTROLLER_HOST = os.getenv("SENTRY_CONTROLLER_HOST")
CONTROLLER_PATH = os.getenv("SENTRY_CONTROLLER_PATH", "/sentry/apps/{}/")
METRIC_PATH = os.getenv("SENTRY_CONTROLLER_METRIC_PATH", "/sentry/apps/{}/metrics/{}/")
POLL_INTERVAL = int(os.getenv("SENTRY_CONTROLLER_POLL_INTERVAL", "60"))
METRIC_INTERVAL = int(os.getenv("SENTRY_CONTROLLER_METRIC_INTERVAL", "600"))
17 changes: 8 additions & 9 deletions sentry_dynamic_sampling_lib/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@
from enum import Enum
from threading import RLock

from sentry_dynamic_sampling_lib.config import (
DEFAULT_IGNORED_PATH,
DEFAULT_IGNORED_TASK,
DEFAULT_SAMPLE_RATE,
)
from sentry_dynamic_sampling_lib.utils import synchronized


class Config:
def __init__(self) -> None:
self._lock = RLock()
self._sample_rate = 0.0
self._ignored_paths = {
"/health",
"/healthz",
"/health/",
"/healthz/",
}

self._ignored_tasks = set()
self._sample_rate = DEFAULT_SAMPLE_RATE
self._ignored_paths = DEFAULT_IGNORED_PATH
self._ignored_tasks = DEFAULT_IGNORED_TASK

@property
@synchronized
Expand Down

0 comments on commit ec74720

Please sign in to comment.