-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(tasks) Add taskbroker-client metrics for tasks #118052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
bbd23f9
6a04c4e
6fc270b
2d76ea0
56b556f
08b72ea
8cb98aa
785bf98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,10 @@ | ||
| import logging | ||
| import os | ||
|
|
||
| from django.conf import settings | ||
| from django.core.cache import cache | ||
| from taskbroker_client.app import TaskbrokerApp | ||
| from taskbroker_client.metrics import DatadogMetrics, MetricsBackend | ||
|
|
||
| from sentry.taskworker.adapters import ( | ||
| DjangoCacheAtMostOnceStore, | ||
|
|
@@ -10,10 +14,47 @@ | |
| make_producer, | ||
| ) | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def _extract_metrics_config() -> tuple[str | None, int | None]: | ||
| host, port = None, None | ||
| metric_options = settings.SENTRY_METRICS_OPTIONS | ||
| try: | ||
| # Use the metrics settings options to infer the host/port. | ||
| # The metrics options have different structures depending on which backend is used. | ||
| if settings.SENTRY_METRICS_BACKEND == "sentry.metrics.dualwrite.DualWriteMetricsBackend": | ||
| metric_options = settings.SENTRY_METRICS_OPTIONS["primary_backend_args"] | ||
|
|
||
| # Some backends use `host` and others use `statsd_host` | ||
| host = metric_options.get("statsd_host", None) or metric_options.get("host", None) | ||
| port = metric_options.get("statsd_port", None) or metric_options.get("port", None) | ||
| port = int(port) | ||
| except Exception as e: | ||
| logger.warning("Could not extract metrics settings", extra={"error": str(e)}) | ||
|
sentry[bot] marked this conversation as resolved.
|
||
| return host, port | ||
|
|
||
|
|
||
| metrics_class: MetricsBackend = SentryMetricsBackend() | ||
|
|
||
| if os.getenv("USE_TASKWORKER_METRICS", None) == "1": | ||
| host, port = _extract_metrics_config() | ||
| if host and port: | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| # Metrics created by this interface will not | ||
| # have `sentry.` prefix, and will not have | ||
| # K8S_LABEL applied. | ||
| metrics_class = DatadogMetrics( | ||
| application="sentry", | ||
| statsd_host=host, | ||
|
sentry[bot] marked this conversation as resolved.
|
||
| statsd_port=port, | ||
| sample_rate=settings.SENTRY_METRICS_SAMPLE_RATE, | ||
| enable_prefixed_metrics=True, | ||
| ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Env enabled, metrics silently unchangedMedium Severity With Reviewed by Cursor Bugbot for commit 6fc270b. Configure here.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll have options defined in all the environments, and if extracting configuration fails we'll get a log message. |
||
|
|
||
| app = TaskbrokerApp( | ||
| name="sentry", | ||
| producer_factory=make_producer, | ||
| metrics_class=SentryMetricsBackend(), | ||
| metrics_class=metrics_class, | ||
| router_class=SentryRouter(), | ||
| at_most_once_store=DjangoCacheAtMostOnceStore(cache), | ||
| context_hooks=[ViewerContextHook()], | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I regret asking for this. but i think architecturally it's probably still better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its a bit gnarly, but better than having more environment variables.