Repository navigation
2026 11 25 telemetry
History. Drafted 2026-11-25 for #199 (PR #211). kubed-mcp 0.3.0 is on PyPI, released from quick-mcp#12. It exports
kubed.mcp.TelemetrySettingsand atelemetryextra (pyroscope-ioand the OpenTelemetry packages), andQuickMCPstarts the signals its config'stelemetrysection switches on (quick-mcp TEL-2). This plan is the record for #199: there is no draft spec on the branch, and the area files below carry the requirements. Dr K's rulings (2026-11-24, 2026-11-25):
- Upstream owns the field descriptions (CFG-46's form) and
extra="forbid". Here the section isclass TelemetrySettings(kubed.mcp.TelemetrySettings, Section),Sectionlast so itsmodel_configwins pydantic's merge, re-declaring onlytags.tagsfrom the environment or a flag is a JSON object, refused asmust be a JSON objectas CFG-7 does, withNoDecode, and it keeps upstream's description.- Docs: the generated Configuration page, a CFG-1 row and
runtime.md. Not the README, not AGENTS.md.- Dr K changes
lint.yml's pip-audit to.[redis,telemetry]on this PR. The agents don't touch.github/.- Order: the pin moves to
kubed-mcp[tasks]>=0.3.0,<0.4in #209 first. This PR adds the telemetry config on that pin and changes no pin of its own.Calls made here (Claude's, reverse freely):
telemetry.profilesjoinsURL_LEAVES; theconfig=line gainstelemetry=; the image's build check importspyroscopeandopentelemetry.sdk; thetelemetryextra's kubed-mcp range is held equal to the dependency's by a test; the new requirements are RUN-28 to RUN-31 in a## Telemetrysection at the end ofruntime.md.
For agentic workers: REQUIRED SUB-SKILL: Use skill://superpowers/subagent-driven-development/SKILL.md (recommended) or skill://superpowers/executing-plans/SKILL.md to implement this plan task by task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: a telemetry section on Settings that QuickMCP reads, so TELEMETRY_PROFILES
pushes the server's profiles to Pyroscope, and an image that carries the packages while a plain
install doesn't.
Architecture: one section class in config.py built on kubed-mcp's model, declared last on
Settings; everything else (env names, flags, wiki rows, the Settings tab) is derived from it
(CFG-55). server.py already passes config=settings to QuickMCP, which reads
config.telemetry with getattr and starts the signals in its lifespan. Packaging is a
telemetry extra, installed by the Dockerfile beside redis.
Tech Stack: Python 3.11+, kubed-mcp 0.3.0 (pydantic 2, pydantic-settings 2.8+), pytest, ruff, Docker.
Spec: this plan, and the area files it edits: config.md (CFG-1, CFG-7, CFG-51) and
runtime.md (RUN-21, RUN-23, new RUN-28 to RUN-31). Upstream: quick-mcp
telemetry TEL-2 to TEL-12.
-
kubed/mcp/telemetry.py:class TelemetrySettings(BaseModel),model_config = ConfigDict(extra="forbid"), no validators. Fields:profiles: str | None = None,profile_cpu: bool = True,profile_memory: bool = True,otel: bool = False,tags: dict[str, str] = Field(default_factory=dict), each with a one-sentence description. -
kubed/mcp/app.py:telemetry = getattr(config, "telemetry", None);_start_signals(name, telemetry)runs when the lifespan is entered, before the server's own, and stops after it.nameis theQuickMCPname,selenium-flow;OTEL_SERVICE_NAMEbeats it (TEL-7). - A signal on whose package is missing logs one warning,
Profiles are on, but pyroscope-io is not installed: install kubed-mcp[telemetry], and the server serves (TEL-4, TEL-6). -
POD_NAMESPACEandPOD_NAMEbecome thenamespaceandpodlabels; a key intagswins (TEL-9). These andOTEL_*are read by kubed-mcp, not byconfig.py. - The
telemetryextra:pyroscope-io>=1.2,<2,opentelemetry-distro,opentelemetry-sdk, the OTLP HTTP and Prometheus exporters,opentelemetry-instrumentation-logging,pyroscope-otel.
-
The pin is #209's.
pyproject.toml's dependency line reads"kubed-mcp[tasks]>=0.3.0,<0.4"from main before Task 1 starts. This PR does not edit it. -
The extra:
telemetry = ["kubed-mcp[telemetry]>=0.3.0,<0.4"], the same range as the dependency, exactly. -
With no
telemetrysection nothing changes: every default is upstream's, so profiles and OpenTelemetry are off. -
Env names, derived, never declared:
TELEMETRY_PROFILES,TELEMETRY_PROFILE_CPU,TELEMETRY_PROFILE_MEMORY,TELEMETRY_OTEL,TELEMETRY_TAGS; flags--telemetry-profilesand so on. -
The address is never logged and its userinfo is never shown (Pyroscope basic auth).
telemetry.profilesstaysstr, so the sensitive set stays CFG-40's three. -
Examples use
example.com:http://pyroscope.example.com:4040. -
Leave
mcp/tools.py,mcp/instructions.pyand.github/alone (AGENTS.md). -
Never edit
docs/Configuration.mdby hand: runpython scripts/generate_wiki.py. - Spec rules (Specification.md, "Ids"): statements only, present tense, no dates or issue numbers; ids count up and are never reused; code cited by symbol, never by line.
-
Checks, every task:
ruff check .andpytest, both clean, astest.ymlruns them. Noui/change, so the UI's checks don't apply. The image build (CI on main,image.yml) is what provespyroscopeimports in the image. -
Commits: exact paths staged, never
-a.docs/is committed by the workflow on the wiki branchissue-199.
-
A tag value that is not a string (
TELEMETRY_TAGS='{"tier": 1}', ortier: 1in the file): refused at boot as aConfigErrornamingtelemetry.tags, never coerced, never a traceback. Pinned in Task 1 bytest_telemetry_tags_that_are_not_strings_stop_the_boot. -
Pyroscope credentials in the address (
http://u:hunter2@pyroscope.example.com:4040): the Settings tab shows the address without them and theconfig=line names no address at all. Pinned in Task 1 bytest_the_settings_tab_strips_userinfo_from_telemetry_profilesandtest_the_startup_log_never_shows_the_profiles_address. -
A blank address (
TELEMETRY_PROFILES="", what compose sends for${VAR:-}): profiles stay off. Pinned in Task 1 bytest_a_blank_telemetry_profiles_is_off. -
Profiles switched on where
pyroscopeis absent (a wheel install without the extra): the server still serves, with kubed-mcp's warning naming the extra. Pinned in Task 1 bytest_profiles_on_without_the_extra_still_serve. -
The extra's range drifting from the dependency's (a later bump moves one line and not the
other, and the image resolves two kubed-mcp ranges): pinned in Task 2 by
test_the_telemetry_extra_pins_kubed_mcp_as_the_dependency_does.
Files:
- Modify:
kubed/selenium_flow/config.py(the new section afterSecuritySettings; theSettings.telemetryfield aftersecurity;URL_LEAVES) - Modify:
kubed/selenium_flow/main.py(_telemetry_summary; theconfig=log line) - Test:
tests/test_config_schema.py,tests/test_config_load.py,tests/test_config_wiring.py - Modify:
docs/superpowers/specs/config.md(CFG-1, CFG-7, CFG-51) - Modify:
docs/notes/Configuration.notes.md("Lists and booleans in env and flags") - Regenerate:
docs/Configuration.md(byscripts/generate_wiki.py)
Interfaces:
-
Consumes:
kubed.mcp.TelemetrySettings;Section,NoDecode,field_validator,without_userinfo(already imported inconfig.py);over_http,TOKEN(tests/conftest.py). -
Produces:
config.TelemetrySettings;Settings.telemetry: TelemetrySettings;main._telemetry_summary(telemetry: config.TelemetrySettings) -> str. Task 2 relies on none of them. -
Step 1: Check the branch is on #209's pin
Run: git fetch origin main && git merge origin/main, then grep 'kubed-mcp\[tasks\]' pyproject.toml
and pip install -e ".[test]" and python -c "from kubed.mcp import TelemetrySettings; import kubed.mcp; print(kubed.mcp.__version__)".
Expected: "kubed-mcp[tasks]>=0.3.0,<0.4", and 0.3.0 (or a later 0.3.x). If the pin is not
there, stop and say so in the PR: the pin is #209's, and this PR does not move it.
- Step 2: Write the schema tests in
tests/test_config_schema.py
import json
import kubed.mcp
TELEMETRY = "http://pyroscope.example.com:4040"
def test_the_telemetry_section_is_kubed_mcps_and_strict_like_every_section():
cls = config.TelemetrySettings
assert issubclass(cls, kubed.mcp.TelemetrySettings) and issubclass(cls, config.Section)
assert cls.model_config["extra"] == "forbid"
assert cls.model_config["hide_input_in_errors"] is True
assert config.SECTION_ORDER[-1] == "telemetry"
def test_telemetry_defaults_are_all_off():
t = Settings().telemetry
assert (t.profiles, t.otel, t.tags) == (None, False, {})
assert (t.profile_cpu, t.profile_memory) == (True, True)
def test_the_telemetry_settings_and_their_spellings():
found = {(x.path, x.env, x.flag) for x in config.leaves() if x.section == "telemetry"}
assert found == {
("telemetry.profiles", "TELEMETRY_PROFILES", "--telemetry-profiles"),
("telemetry.profile_cpu", "TELEMETRY_PROFILE_CPU", "--telemetry-profile-cpu"),
("telemetry.profile_memory", "TELEMETRY_PROFILE_MEMORY", "--telemetry-profile-memory"),
("telemetry.otel", "TELEMETRY_OTEL", "--telemetry-otel"),
("telemetry.tags", "TELEMETRY_TAGS", "--telemetry-tags"),
}
def test_telemetry_tags_keeps_kubed_mcps_description():
upstream = kubed.mcp.TelemetrySettings.model_fields["tags"].description
assert config.TelemetrySettings.model_fields["tags"].description == upstream
def test_the_settings_tab_strips_userinfo_from_telemetry_profiles():
s = Settings(telemetry={"profiles": "http://u:hunter2@pyroscope.example.com:4040"})
shown = json.dumps(config.describe(s, {}))
assert "hunter2" not in shown
assert TELEMETRY in showntest_the_sensitive_settings_are_exactly_the_three and test_every_leaf_has_a_one_sentence_description
stay as they are and cover the new leaves.
- Step 3: Write the load tests in
tests/test_config_load.py, in a new# ---- telemetry ----section at the end
TELEMETRY = "http://pyroscope.example.com:4040"
def test_telemetry_comes_from_env():
loaded = load([], {
"TELEMETRY_PROFILES": TELEMETRY,
"TELEMETRY_PROFILE_MEMORY": "false",
"TELEMETRY_OTEL": "true",
"TELEMETRY_TAGS": '{"cluster": "example"}',
})
t = loaded.settings.telemetry
assert (t.profiles, t.profile_cpu, t.profile_memory, t.otel) == (TELEMETRY, True, False, True)
assert t.tags == {"cluster": "example"}
assert loaded.sources["telemetry.tags"] == "env"
def test_telemetry_comes_from_flags_and_the_file(tmp_path):
loaded = load(["--telemetry-profiles", TELEMETRY, "--telemetry-tags", '{"a": "b"}'], {})
assert loaded.settings.telemetry.profiles == TELEMETRY
assert loaded.settings.telemetry.tags == {"a": "b"}
path = _file(tmp_path, f"telemetry:\n profiles: {TELEMETRY}\n tags:\n cluster: example\n")
t = load(["--config-file", path], {}).settings.telemetry
assert (t.profiles, t.tags) == (TELEMETRY, {"cluster": "example"})
def test_a_blank_telemetry_profiles_is_off():
assert load([], {"TELEMETRY_PROFILES": " "}).settings.telemetry.profiles is None
@pytest.mark.parametrize("value", ["not json", "[1, 2]", '"a string"'])
def test_telemetry_tags_that_are_not_an_object_stop_the_boot(value):
with pytest.raises(ConfigError) as refused:
load([], {"TELEMETRY_TAGS": value})
message = str(refused.value)
assert "telemetry.tags" in message and "must be a JSON object" in message
assert "TELEMETRY_TAGS" in message
def test_telemetry_tags_that_are_not_strings_stop_the_boot(tmp_path):
with pytest.raises(ConfigError, match=r"telemetry\.tags"):
load([], {"TELEMETRY_TAGS": '{"tier": 1}'})
path = _file(tmp_path, "telemetry:\n tags:\n tier: 1\n")
with pytest.raises(ConfigError, match=r"telemetry\.tags"):
load(["--config-file", path], {})
def test_a_typo_under_telemetry_in_the_file_stops_the_boot(tmp_path):
path = _file(tmp_path, f"telemetry:\n profile: {TELEMETRY}\n")
with pytest.raises(ConfigError, match=r"telemetry\.profile\b"):
load(["--config-file", path], {})test_nothing_set_is_every_default and test_a_bare_section_name_in_env_is_ignored_not_a_crash
(parametrised over SECTION_ORDER) cover TELEMETRY=x with no change.
- Step 4: Write the wiring tests in
tests/test_config_wiring.py
def test_the_startup_log_says_telemetry_off_by_default(monkeypatch, caplog):
monkeypatch.setattr(SeleniumMCP, "run", lambda self, **kw: None)
with caplog.at_level(logging.INFO, logger="kubed.selenium_flow.main"):
main_module.main([])
assert "telemetry=off" in caplog.text
def test_the_startup_log_never_shows_the_profiles_address(monkeypatch, caplog):
monkeypatch.setattr(SeleniumMCP, "run", lambda self, **kw: None)
monkeypatch.setenv("TELEMETRY_PROFILES", "http://u:hunter2@pyroscope.example.com:4040")
monkeypatch.setenv("TELEMETRY_OTEL", "true")
with caplog.at_level(logging.INFO, logger="kubed.selenium_flow.main"):
main_module.main([])
assert "telemetry=profiles, otel" in caplog.text
assert "pyroscope.example.com" not in caplog.text and "hunter2" not in caplog.text
def test_profiles_without_a_sampler_are_off_in_the_log():
t = config.TelemetrySettings(profiles="http://pyroscope.example.com:4040",
profile_cpu=False, profile_memory=False)
assert main_module._telemetry_summary(t) == "off"
async def test_profiles_on_without_the_extra_still_serve(monkeypatch, caplog):
monkeypatch.setitem(sys.modules, "pyroscope", None) # import fails as on a plain install
server = SeleniumMCP(Settings(grid=GRID, auth={"token": TOKEN},
telemetry={"profiles": "http://pyroscope.example.com:4040"}))
with caplog.at_level(logging.WARNING):
async with over_http(server) as client:
assert await client.list_tools()
assert "kubed-mcp[telemetry]" in caplog.textImports to add: sys, from kubed.selenium_flow import config, from .conftest import TOKEN, over_http.
- Step 5: Run the new tests to see them fail
Run: pytest tests/test_config_schema.py tests/test_config_load.py tests/test_config_wiring.py -k "telemetry or profiles" -p no:randomly
Expected: FAIL, config has no attribute TelemetrySettings / Settings has no telemetry.
-
Step 6: Write the section in
config.py -
import kubed.mcp(orfrom kubed.mcp import TelemetrySettings as _Telemetry). -
class TelemetrySettings(_Telemetry, Section), docstring: kubed-mcp's telemetry settings, made aSectionsoleaves()reads its keys and its errors hide their input;QuickMCPreads it asconfig.telemetry. -
Re-declare
tags: Annotated[dict[str, str], NoDecode] = Field(default_factory=dict, description=_Telemetry.model_fields["tags"].description), with a comment that NoDecode keeps a bad env value aConfigError(pydantic-settings' own JSON decode would raiseSettingsErroroutside it). -
@field_validator("tags", mode="before")doing exactly whatSessionSettings._capabilities_jsondoes. Share it as a module function_json_object(value)that both validators call, rather than a second copy. -
Settings.telemetry: TelemetrySettings = Field(default_factory=TelemetrySettings, description="Profiles, traces and metrics, run by kubed-mcp; all off unless set."), declared aftersecurity. -
Add
"telemetry.profiles"toURL_LEAVES, with the Pyroscope basic-auth reason in its comment. -
Step 7: Write
_telemetry_summaryand the log field inmain.py
_telemetry_summary(telemetry) -> str: "off", or the signals on joined by ", ", in the order
profiles, otel. profiles is on when telemetry.profiles is set and profile_cpu or profile_memory (TEL-8). The config= line gains telemetry=%s after recordings=%s.
- Step 8: Run the tests to see them pass
Run: pytest tests/test_config_schema.py tests/test_config_load.py tests/test_config_wiring.py
Expected: PASS.
-
Step 9: Edit the config docs
-
config.mdCFG-1: a row| telemetry.* | [runtime.md](runtime.md) |before the last row. -
CFG-7:
session.capabilitiesandtelemetry.tagsare JSON objects; the rest of the statement stands. -
CFG-51: add
telemetry.profilesto the list of settings shown without userinfo. -
Configuration.notes.md, "Lists and booleans in env and flags": one sentence, a mapping (session.capabilities,telemetry.tags) is a JSON object in env and flags, such asTELEMETRY_TAGS='{"cluster": "example"}'. -
Run
python scripts/generate_wiki.py. -
Step 10: Run the checks
Run: ruff check . and pytest
Expected: both clean, tests/test_wiki.py included, and no golden moved (git status tests/golden
shows nothing).
- Step 11: Commit
git add kubed/selenium_flow/config.py kubed/selenium_flow/main.py tests/test_config_schema.py \
tests/test_config_load.py tests/test_config_wiring.py docs
git commit -m "Config: a telemetry section from kubed-mcp, read by QuickMCP (#199)"Files:
- Modify:
pyproject.toml([project.optional-dependencies], afterredis) - Modify:
Dockerfile(the builder's two install lines and their comments; the runner's check) - Modify:
scripts/requirements.py(the docstring's example) - Test:
tests/test_packaging.py - Modify:
docs/superpowers/specs/runtime.md(RUN-21, RUN-23, new## Telemetry) - Modify:
CHANGELOG.md([Unreleased], one line)
Interfaces:
-
Consumes: Task 1's
telemetrysection (RUN-28 describes it);dockerfile_stages(),PYPROJECT,DOCKERFILE(tests/test_packaging.py). -
Produces: the
telemetryextra. -
Step 1: Write the packaging tests in
tests/test_packaging.py
def test_the_telemetry_extra_is_kubed_mcps_and_nothing_else_carries_it():
project = tomllib.loads(PYPROJECT.read_text())["project"]
extra = project["optional-dependencies"]["telemetry"]
assert len(extra) == 1 and extra[0].startswith("kubed-mcp[telemetry]")
everywhere_else = project["dependencies"] + project["optional-dependencies"]["test"]
assert not [d for d in everywhere_else if "telemetry" in d or "pyroscope" in d]
def test_the_telemetry_extra_pins_kubed_mcp_as_the_dependency_does():
project = tomllib.loads(PYPROJECT.read_text())["project"]
pin = next(d for d in project["dependencies"] if d.startswith("kubed-mcp["))
extra = project["optional-dependencies"]["telemetry"][0]
assert extra.split("]", 1)[1] == pin.split("]", 1)[1]
def test_the_image_installs_both_extras():
builder = dockerfile_stages()["builder"]
listed = next(ln for ln in builder if "requirements.py runtime" in ln)
assert "--extra redis" in listed and "--extra telemetry" in listedAnd edit three that exist: test_the_copied_venv_is_proved_to_work_at_build_time also asserts a
runner line has import pyroscope and opentelemetry.sdk; test_the_project_is_installed_with_its_extra
asserts "[redis,telemetry]" in install (rename it ..._with_its_extras);
test_the_ui_is_built_in_its_own_stage_and_reaches_the_package indexes
"pip install --no-cache-dir .[redis,telemetry]".
- Step 2: Run them to see them fail
Run: pytest tests/test_packaging.py -p no:randomly
Expected: FAIL, KeyError: 'telemetry' and the Dockerfile asserts.
- Step 3: Add the extra to
pyproject.toml
After redis, with a comment in its style:
# Profiles, traces and metrics (kubed-mcp's telemetry). The image installs it so
# turning one on is a config change, not a rebuild; a plain install leaves it out,
# and a signal switched on without it logs a warning and the server still serves.
# Its range is the kubed-mcp dependency's (test_packaging holds them equal).
telemetry = [
"kubed-mcp[telemetry]>=0.3.0,<0.4",
]-
Step 4: Edit the
Dockerfile -
Builder line 80:
python scripts/requirements.py runtime --extra redis --extra telemetry > /tmp/requirements.txt. The comment above gains:[telemetry] likewise, so profiles and traces are TELEMETRY_PROFILES and TELEMETRY_OTEL away. -
Builder line 98:
pip install --no-cache-dir .[redis,telemetry]; the comment's "silently ignores [redis]" becomes "the extras". -
Runner check:
RUN python -c "from kubed.selenium_flow.server import SeleniumMCP; import pyroscope, opentelemetry.sdk". The comment above gains one sentence:pyroscopeships a native library, the one wheel here most likely to need what only the fat image has. -
scripts/requirements.pydocstring:python scripts/requirements.py runtime --extra redis --extra telemetry # what the image runs. -
Step 5: Run them to see them pass
Run: pytest tests/test_packaging.py and python scripts/requirements.py runtime --extra redis --extra telemetry
Expected: PASS, and the list ends with redis>=5.0,<9 and kubed-mcp[telemetry]>=0.3.0,<0.4.
-
Step 6: Edit
runtime.md -
RUN-21: the optional extras are
redis,telemetry(kubed-mcp's telemetry packages, needed only for a signaltelemetryswitches on; RUN-30),buildandtest. -
RUN-23, stage 2: installs the runtime dependencies and the
redisandtelemetryextras; stage 3: checks at build that the server,pyroscopeand the OpenTelemetry SDK import. -
A new
## Telemetrysection at the end, after "Behind a gateway", with the link definition[telemetry]: https://github.com/kubed-io/quick-mcp/wiki/telemetryand these four:-
RUN-28. The
telemetrysection is kubed-mcp'sTelemetrySettings([quick-mcp TEL-3][telemetry]) as a config section, so its keys have environment names and flags (CFG-3) and an unknown key stops the boot.QuickMCPreads it off the settings the server passes (TEL-2).telemetry.tagsis a JSON object (CFG-7). -
RUN-29. With no
telemetrysetting every signal is off.telemetry.profilespushes CPU and allocation profiles to that Pyroscope address under the service nameselenium-flow, orOTEL_SERVICE_NAMEwhen it is set (TEL-7, TEL-8).telemetry.otelruns OpenTelemetry, configured by the standardOTEL_*variables (TEL-11, TEL-12). The signals start before the server serves and stop after its lifespan ends (TEL-5). -
RUN-30. The packages are the
telemetryextra, which the image installs and a plain install does not. A signal switched on without its package logs one warning naming the extra, and the server serves without it; telemetry never stops the server (TEL-4, TEL-6). -
RUN-31. Profiles carry
namespaceandpodlabels whenPOD_NAMESPACEandPOD_NAMEare set, which a deployment sets from the downward API, and eachtelemetry.tagskey, which wins over them (TEL-9). kubed-mcp reads these variables andOTEL_*; the server's config reads none of them (CFG-14).
-
RUN-28. The
-
Step 7: Add the changelog line
At the top of [Unreleased], in the flat style of the lines below it:
- **Profiles and traces:** the image pushes profiles to Pyroscope when `TELEMETRY_PROFILES` names it, and runs OpenTelemetry with `TELEMETRY_OTEL=true` (#199).- Step 8: Run the checks
Run: ruff check . and pytest
Expected: both clean.
- Step 9: Commit
git add pyproject.toml Dockerfile scripts/requirements.py tests/test_packaging.py CHANGELOG.md docs
git commit -m "Image: the telemetry extra, checked at build (#199)"- In the PR: the installed kubed-mcp version, and that
lint.yml's audit of.[redis,telemetry]is Dr K's to add. - CI's
Packagejob installs the wheel without extras, so it proves a plain install runs withoutpyroscope. The image is built on main (image.yml); its build check provespyroscopeimports. - Dr K checks the last done-when in the cluster: with
TELEMETRY_PROFILESset to the deployment's Pyroscope, the profiles appear underselenium-flow. The runners can't reach it.
The action pages are generated from the server's tool schemas, so they describe the version that shipped.
selenium-flow · MIT
Start here
Guides
Lifecycle
Going places
Doing things
Getting things out
Site data
Console and network