Files
tracer-cloud--opensre/integrations/betterstack/tools/betterstack_logs_tool/__init__.py
T
wehub-resource-sync 4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

76 lines
2.6 KiB
Python

"""Better Stack Telemetry Logs Tool."""
from __future__ import annotations
from typing import Any
from core.tool_framework.tool_decorator import tool
from integrations.betterstack import (
BetterStackConfig,
betterstack_extract_params,
betterstack_is_available,
query_logs,
)
@tool(
name="query_betterstack_logs",
display_name="Better Stack logs",
description=(
"Query a Better Stack Telemetry source for log rows using ClickHouse "
"SQL over HTTP. Returns (dt, raw) pairs by UNIONing recent logs from "
"remote(<source>_logs) with historical logs from s3Cluster(primary, "
"<source>_s3) WHERE _row_type = 1, optionally bounded by since/until "
"timestamps (ISO 8601)."
),
source="betterstack",
surfaces=("investigation", "chat"),
use_cases=[
"Fetching application log lines from a Better Stack source during RCA",
"Correlating timestamped log events with an alert window",
"Scanning a specific source (e.g. t123456_myapp) for recent and archived activity",
],
is_available=betterstack_is_available,
injected_params=("password", "query_endpoint", "username"),
extract_params=betterstack_extract_params,
)
def query_betterstack_logs(
query_endpoint: str,
username: str,
password: str = "",
sources: list[str] | None = None,
source: str = "",
since: str | None = None,
until: str | None = None,
limit: int | None = None,
) -> dict[str, Any]:
"""Query log rows from a Better Stack source (recent + historical).
``query_endpoint`` / ``username`` / ``password`` / ``sources`` are sourced
automatically from the Better Stack integration via ``extract_params``.
The planner supplies ``source`` (a single source identifier to query);
when it omits ``source`` we fall back to the first entry in the configured
``sources`` hint list, or return a structured error if nothing is configured.
The ``source`` argument is the base identifier (e.g. ``t123456_myapp``);
the integration appends ``_logs`` and ``_s3`` internally to build the
``remote(...)`` and ``s3Cluster(primary, ...)`` table functions.
"""
effective_source = (source or "").strip()
if not effective_source and sources:
effective_source = next((s for s in sources if s), "")
config = BetterStackConfig(
query_endpoint=query_endpoint,
username=username,
password=password,
sources=list(sources or []),
)
return query_logs(
config,
effective_source,
since=since,
until=until,
limit=limit,
)