Skip to content

2026 11 25 telemetry

kubed-io[bot] edited this page Nov 25, 2026 · 1 revision

Telemetry from kubed-mcp Plan

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.TelemetrySettings and a telemetry extra (pyroscope-io and the OpenTelemetry packages), and QuickMCP starts the signals its config's telemetry section 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 is class TelemetrySettings(kubed.mcp.TelemetrySettings, Section), Section last so its model_config wins pydantic's merge, re-declaring only tags.
  • tags from the environment or a flag is a JSON object, refused as must be a JSON object as CFG-7 does, with NoDecode, 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.4 in #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.profiles joins URL_LEAVES; the config= line gains telemetry=; the image's build check imports pyroscope and opentelemetry.sdk; the telemetry extra'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 ## Telemetry section at the end of runtime.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.

What kubed-mcp 0.3.0 gives (read at tag v0.3.0)

  • 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. name is the QuickMCP name, selenium-flow; OTEL_SERVICE_NAME beats 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_NAMESPACE and POD_NAME become the namespace and pod labels; a key in tags wins (TEL-9). These and OTEL_* are read by kubed-mcp, not by config.py.
  • The telemetry extra: pyroscope-io>=1.2,<2, opentelemetry-distro, opentelemetry-sdk, the OTLP HTTP and Prometheus exporters, opentelemetry-instrumentation-logging, pyroscope-otel.

Global Constraints

  • 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 telemetry section 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-profiles and so on.
  • The address is never logged and its userinfo is never shown (Pyroscope basic auth). telemetry.profiles stays str, so the sensitive set stays CFG-40's three.
  • Examples use example.com: http://pyroscope.example.com:4040.
  • Leave mcp/tools.py, mcp/instructions.py and .github/ alone (AGENTS.md).
  • Never edit docs/Configuration.md by hand: run python 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 . and pytest, both clean, as test.yml runs them. No ui/ change, so the UI's checks don't apply. The image build (CI on main, image.yml) is what proves pyroscope imports in the image.
  • Commits: exact paths staged, never -a. docs/ is committed by the workflow on the wiki branch issue-199.

Review Focus

  1. A tag value that is not a string (TELEMETRY_TAGS='{"tier": 1}', or tier: 1 in the file): refused at boot as a ConfigError naming telemetry.tags, never coerced, never a traceback. Pinned in Task 1 by test_telemetry_tags_that_are_not_strings_stop_the_boot.
  2. Pyroscope credentials in the address (http://u:hunter2@pyroscope.example.com:4040): the Settings tab shows the address without them and the config= line names no address at all. Pinned in Task 1 by test_the_settings_tab_strips_userinfo_from_telemetry_profiles and test_the_startup_log_never_shows_the_profiles_address.
  3. A blank address (TELEMETRY_PROFILES="", what compose sends for ${VAR:-}): profiles stay off. Pinned in Task 1 by test_a_blank_telemetry_profiles_is_off.
  4. Profiles switched on where pyroscope is absent (a wheel install without the extra): the server still serves, with kubed-mcp's warning naming the extra. Pinned in Task 1 by test_profiles_on_without_the_extra_still_serve.
  5. 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.

Task 1: The telemetry section, the config= line and the config docs

Files:

  • Modify: kubed/selenium_flow/config.py (the new section after SecuritySettings; the Settings.telemetry field after security; URL_LEAVES)
  • Modify: kubed/selenium_flow/main.py (_telemetry_summary; the config= 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 (by scripts/generate_wiki.py)

Interfaces:

  • Consumes: kubed.mcp.TelemetrySettings; Section, NoDecode, field_validator, without_userinfo (already imported in config.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 shown

test_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.text

Imports 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 (or from kubed.mcp import TelemetrySettings as _Telemetry).

  • class TelemetrySettings(_Telemetry, Section), docstring: kubed-mcp's telemetry settings, made a Section so leaves() reads its keys and its errors hide their input; QuickMCP reads it as config.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 a ConfigError (pydantic-settings' own JSON decode would raise SettingsError outside it).

  • @field_validator("tags", mode="before") doing exactly what SessionSettings._capabilities_json does. 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 after security.

  • Add "telemetry.profiles" to URL_LEAVES, with the Pyroscope basic-auth reason in its comment.

  • Step 7: Write _telemetry_summary and the log field in main.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.md CFG-1: a row | telemetry.* | [runtime.md](runtime.md) | before the last row.

  • CFG-7: session.capabilities and telemetry.tags are JSON objects; the rest of the statement stands.

  • CFG-51: add telemetry.profiles to 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 as TELEMETRY_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)"

Task 2: The telemetry extra, the image, and the runtime docs

Files:

  • Modify: pyproject.toml ([project.optional-dependencies], after redis)
  • 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 telemetry section (RUN-28 describes it); dockerfile_stages(), PYPROJECT, DOCKERFILE (tests/test_packaging.py).

  • Produces: the telemetry extra.

  • 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 listed

And 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: pyroscope ships a native library, the one wheel here most likely to need what only the fat image has.

  • scripts/requirements.py docstring: 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 signal telemetry switches on; RUN-30), build and test.

  • RUN-23, stage 2: installs the runtime dependencies and the redis and telemetry extras; stage 3: checks at build that the server, pyroscope and the OpenTelemetry SDK import.

  • A new ## Telemetry section at the end, after "Behind a gateway", with the link definition [telemetry]: https://github.com/kubed-io/quick-mcp/wiki/telemetry and these four:

    • RUN-28. The telemetry section is kubed-mcp's TelemetrySettings ([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. QuickMCP reads it off the settings the server passes (TEL-2). telemetry.tags is a JSON object (CFG-7).
    • RUN-29. With no telemetry setting every signal is off. telemetry.profiles pushes CPU and allocation profiles to that Pyroscope address under the service name selenium-flow, or OTEL_SERVICE_NAME when it is set (TEL-7, TEL-8). telemetry.otel runs OpenTelemetry, configured by the standard OTEL_* 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 telemetry extra, 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 namespace and pod labels when POD_NAMESPACE and POD_NAME are set, which a deployment sets from the downward API, and each telemetry.tags key, which wins over them (TEL-9). kubed-mcp reads these variables and OTEL_*; the server's config reads none of them (CFG-14).
  • 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)"

After the tasks

  • 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 Package job installs the wheel without extras, so it proves a plain install runs without pyroscope. The image is built on main (image.yml); its build check proves pyroscope imports.
  • Dr K checks the last done-when in the cluster: with TELEMETRY_PROFILES set to the deployment's Pyroscope, the profiles appear under selenium-flow. The runners can't reach it.

Clone this wiki locally