Repository navigation
2026 11 26 selenium flow telemetry design
History. Drafted 2026-11-26 for #65 (programme E4, rescoped), built by PR #217 from its plan. Dr K approved the spec in #65's notes on 2026-11-26. This file finishes that draft against the code; "Found at plan time" says what changed. Its requirements are RUN-32 to RUN-36 in runtime.md, with edits to WS-28 and WS-29 (workspaces-and-sessions.md), GRID-12 and the request table (grid.md), and ERR-30 and ERR-35 (errors-and-logging.md). At plan approval Dr K dropped
selenium_flow.grid.sessions("Found at plan time", 12), took the test dependency as planned (9) and approved the free-slot rule with GRID-12's new fields (10). "Found at plan time" item 3 was wrong about the thread: the last collection runs on the reader's thread, so the gauge stops reading when the server stops (RUN-33). #221 seeds the gauge at 0 for each browser and state, so a Grid with no free slot or no node reports zeros, not no series (RUN-33). #220 timed every MCP tool,open_sessionandend_browserincluded, throughCalls.timed, without a turn, and RUN-32, RUN-34 and WS-28 say so.
The operator wants three things from selenium-flow, all through kubed-mcp's telemetry
(telemetry.otel, RUN-29):
- how often each browser action runs, how long the browser takes and how often it fails, on every surface;
- how busy the Grid is;
- each call's trace naming the workspace, the tool, the surface and the flow step.
History lives in the operator's backends, never here (programme R12, R7). What every server needs
(the OTel SDK and its OTEL_* configuration, FastMCP's spans, mcp.server.operation.duration,
trace ids on log records, profiles) is kubed-mcp's since quick-mcp#12, released in 0.3.0. With
telemetry.otel on, metrics are pushed over OTLP or scraped from the exporter's own port, and
there is no route on the server's port (quick-mcp TEL-17), so the epic's /metrics route is
overtaken.
- The rescope in #65's body (Dr K): only what selenium-flow has is built here.
- The call histogram covers all three surfaces (mcp, http, flow), by tool and browser, because it measures the browser's work inside its turn, which FastMCP's request timing does not (Dr K, 2026-11-26).
- Claude's recommendations are the calls, the conservative option wherever one was open (Dr K, 2026-11-26). They are marked (call) below. Dr K approved the spec with them.
- A dashboard or alerting.
- The workspace as a metric attribute: it is caller-chosen and unbounded (R12).
- Per-request logs.
- A
/metricsroute (TEL-17). - OTel SDK setup, FastMCP's spans, call metrics, log correlation and profiles: kubed-mcp's.
- A new config key (call): everything follows
telemetry.otel.
-
selenium_flow.call.duration, a histogram in seconds, fed by a bus subscriber oncall.finished(WS-28) namedmetrics, which records the event'sduration. - Exactly four attributes:
selenium_flow.tool,selenium_flow.surface(mcp|http|flow),selenium_flow.outcome(ok|4xx|5xx) andselenium_flow.browser. Never the workspace, the session key or a Grid id. Abrowserthat is""on the event is recorded as given. - It measures the browser's work inside the session's turn:
Calls.beginruns holding the lock, so the wait for it is not counted, and a call refused because a person holds the browser is never begun, so it is never counted. - Buckets are
mcp.server.operation.duration's, 0.01 to 300 s, given as the API's bucket advisory, so the two histograms compare (call). - No separate counter: the histogram's count is the call count.
- The subscriber runs on the loop and only records, so it never blocks (WS-29).
- Attribute keys are namespaced
selenium_flow.*(call); Prometheus spells themselenium_flow_tooland so on.
- An observable gauge,
selenium_flow.grid.slots, byselenium_flow.browserandselenium_flow.slot.state(free|busy). - Why the Grid's numbers: they survive a restart, and the monitor's own listing runs only while
a watch exists (WS-31). Every replica reports the same Grid, so a dashboard takes
max, neversum. - One
GET /statusper collection, 5 s (SHOWN_TIMEOUT) and no retry, in the reader's thread, never on the loop. The interval isOTEL_METRIC_EXPORT_INTERVAL, or one read per scrape with the Prometheus exporter. - A failed or slow read observes nothing for that collection and is logged once a streak, by the error's type only (ERR-32: the Grid URL may carry userinfo). It never raises into the reader.
-
Calls.beginstarts a span andCalls.endends it, on every surface and for every flow step.Begungains aspanfield. -
beginstarts it with the current context as its parent: FastMCP'stools/callspan over MCP, the route span (item 4) over HTTP, and for a flow step the context the run was called in. The span is not made current (call): nothing is attached acrossbeginandend, and nothing inside the call parents to it. - Name:
call <tool>, such ascall navigate(call). - Attributes:
selenium_flow.workspace(the workspace part of the key,sessions.split(key)[0]),selenium_flow.sub_session(true for a sub-session's key),selenium_flow.tool,selenium_flow.browser, and, set atend,selenium_flow.surfaceandselenium_flow.outcome. - Never on a span: a sub-session's name (WS-49 (3),
sessions.logged), a Grid session id (WS-33), an argument, a URL or a value (programme R6, ERR-35). - A failed call's span has status ERROR with no description, and
error.type, the exception's class name.record_exceptionis never used (call): an exception's text and traceback may carry a value. -
endstill never raises; a span API failure is logged by type. - The workspace stays off FastMCP's own
tools/callspan (call). The child span carries it, and TraceQL finds a trace by any of its spans.
- An ASGI middleware in
http_middleware(), so it sits under the mount and at the root alike. One SERVER span per HTTP request. - Name:
<METHOD> <route template>, the template fromRouteTemplates(ERR-29), so a workspace name,?workspace=and a signature never reach a span. - Attributes:
http.request.method,http.routeandhttp.response.status_code, and nothing else from the request: no query, no headers, no client address (call). - Parent: the global propagator's context from the request headers (
traceparent), so a gateway's trace continues. A 5xx sets ERROR. - Skipped (call):
/mcp(FastMCP's spans own it), the four probes (/health,/started,/ready,/info), and WebSocket scopes (the live view).
- One tracer and one meter, named
kubed.selenium_flow, with the package's version. Their providers can be injected and default to the global ones, so the unit tests use in-memory providers without setting globals (call). -
kubed/selenium_flow/telemetry.pyholds the subscriber, the gauge, the tracer and meter, and the span helpers. It imports only the OpenTelemetry API and kernel modules, soworkspace/calls.pycan import it; it joinsNO_PROTOCOLintests/test_boundaries.py(call). The middleware ishttp/tracing.py, besideRouteTemplates. -
server.pywires all of it whensettings.telemetry.otelis on. Off, nothing is subscribed, registered or added. -
opentelemetry-apicomes withfastmcp-slim[mcp], so importing it needs no guard and is a no-op until an SDK is configured.
What reading the code changed in the approved draft, each the conservative reading:
-
Grid.status()waits 30 s and retries (_json("get", "/status")). The gauge's read isGrid.status(timeout=SHOWN_TIMEOUT, retry=False), two keywords whose defaults keep every other caller as it is. - Two gauges are two callbacks per collection. The read was to be shared, one read serving both for 1 s. With the sessions gauge dropped (12) one callback is left, so a collection reads once and nothing is shared.
- kubed-mcp shuts the meter provider down at the lifespan's exit, on the loop, and a shutdown runs a last collection. A collection on the event loop's thread reads nothing and observes nothing, so the loop never waits on the Grid.
- The instruments are made at build, and kubed-mcp sets the global providers in the lifespan, after it (RUN-29). The API's proxy tracer, meter and instruments delegate once the providers are set, so they record; a test in a fresh interpreter holds it.
-
http_middleware()takes nothing, andrun()builds the access log'sRouteTemplatesfrom an app of its own.access_log.quietreturns the filter it installs, andhttp_middleware(telemetry, templates=, prefix=)hands the same one to the route spans. That settles the draft's "how the middleware learns the routes". -
A path no route serves is named by its method alone, with no
http.route(OTel's HTTP convention).RouteTemplates.template's/<first segment>/…fallback is a log line's; a span takes nothing from a path it cannot name.RouteTemplates.matchedsays which. -
Flow steps need no carried context.
run_forruns every step in the one worker thread it is handed (anyio.to_thread.run_sync), and anyio copies the caller's context into it, whichcore/cancel.pyalready relies on. A test asserts the parentage. A run that became a Docket task parents its steps to whatever context its worker has. -
The unit suite must not start kubed-mcp's SDK.
SeleniumMCP(telemetry=)takes aTelemetrybuilt on in-memory providers, used whatevertelemetry.otelsays; without one,telemetry.otelbuilds it on the global providers. Tests inject withoteloff. -
The SDK the tests need is not in
[test], and CI installs.[test]only. Whenopentelemetry.sdkdoes not already import there,testgainsopentelemetry-sdk, and #199'stest_the_telemetry_extra_is_kubed_mcps_and_nothing_else_carries_it(whose substring check readsopentelemetryastelemetry) says what it means: the runtime dependencies carry no telemetry package, and nothing but the extra carrieskubed-mcp[telemetry]orpyroscope. -
A free slot is one that can take a session. A slot is
busywith a session, andfreewithout one only on a node whoseavailabilityisUPand whose busy slots are below itsmaxSessions. Other slots are not counted. The browser is the slot'sstereotype.browserName. A node withoutavailabilitycounts as up, one withoutmaxSessionshas no cap. GRID-12 gains these fields. -
telemetry.pytakes the workspace and the sub-session flag as arguments (calls.pysplits the key), so it imports nothing ofworkspace/and no import cycle forms. -
selenium_flow.grid.sessionsequalsselenium_flow.grid.slots{state="busy"}on a Grid 4, where a slot holds at most one session. Dr K dropped it at plan approval: it only adds a series.
- A bus-drops metric (
Subscription.dropped). - A count of this server's own live browsers.
- The workspace on FastMCP's span.
- A hashed workspace.
- Spans for the live view's WebSockets.
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