Repository navigation
fix(runtime): emit oss.runtime.instance_created once per runtime - #8243
Conversation
The v1 integration wrappers captured `oss.runtime.instance_created` themselves and then built a v2 handler that captured it again. Express, Nest and Pages Router went through `copilotRuntimeNodeHttpEndpoint`, which captured a third time and overwrote `runtime.framework` with "node-http". The self-hosting docs built the endpoint inside the request handler, so each request sent two or three events. - The v2 factory is now the only emitter. The v1 wrappers pass their v1 payload to it through an internal `__instanceCreatedInfo` option. - `fireInstanceCreatedTelemetry` fires at most once per runtime object (WeakSet), so per-request endpoint construction reports one instance. - Express, Nest and Pages Router share an internal `createNodeHttpEndpoint` that takes the framework name, so `runtime.framework` is correct. - The self-hosting snippets build the endpoint once at module scope. Event name and property names are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
This PR was not deployed automatically as @BenTaylorDev does not have access to the Railway project. In order to get automatic PR deploys, please add @BenTaylorDev to your workspace on Railway. |
|
Caution Review failedThe pull request is closed. Walkthrough
Merge Risk:
|
Production Digest-Pinning AuditAll 43 services digest-pinned. Run 2026-11-06 06:26:46 PST — 0 finding(s). |
|
Size Change: 0 B Total Size: 2.38 MB ℹ️ View Unchanged
|
@copilotkit/a2ui-renderer
@copilotkit/agentcore-runner
@copilotkit/angular
@copilotkit/channels
@copilotkit/channels-core
@copilotkit/channels-discord
@copilotkit/channels-intelligence
@copilotkit/channels-slack
@copilotkit/channels-teams
@copilotkit/channels-ui
@copilotkit/channels-whatsapp
@copilotkit/core
@copilotkit/intelligence-langgraph
@copilotkit/intelligence-mastra
@copilotkit/learning
@copilotkit/mcp-apps-renderer
@copilotkit/react-core
@copilotkit/react-native
@copilotkit/react-textarea
@copilotkit/react-ui
@copilotkit/runtime
@copilotkit/runtime-client-gql
@copilotkit/sdk-js
@copilotkit/shared
@copilotkit/sqlite-runner
@copilotkit/voice
@copilotkit/vue
@copilotkit/web-components
@copilotkit/web-inspector
commit: |
#7942 added examples/integrations/omnara but left the README total at 65, so validate-examples-catalog fails on main and on every PR. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings over #8243 (emit oss.runtime.instance_created once per runtime) and #8244 (personless docs_pageview). Conflicts: - runtime v1 integration wrappers and the hono-single endpoint: kept deleted, 2.0 removed them. The once-per-runtime guard in instance-created.ts and fetch-handler.ts came over cleanly. - self-hosting docs snippets: kept 2.0's createCopilotNodeListener setup, which already builds the endpoint once at module scope. - examples/README.md: kept 2.0's catalog text; fixed the Starters anchor to #starters-25. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Problem
oss.runtime.instance_createdmust fire once per handler factory call. For v1 users on runtime ≥1.74 it fires on every HTTP request, two or three times per request. PostHog receives about 6.2M of these events each week, against about 10.75Mcopilot_request_createdevents.There are two causes:
createCopilotEndpointSingleRoute→createCopilotRuntimeHandler) that captured it again. Express, Nest and Pages Router also went throughcopilotRuntimeNodeHttpEndpoint, which captured a third time. That call also overwrote theruntime.frameworkglobal property with"node-http".showcase/GOTCHAS.md.Measured on
mainwith the new test (3 requests or 3 builds, from one runtime):Change
createCopilotRuntimeHandleris now the only place that sends the event. The v1 wrappers delegate to it, so they no longer callcapturethemselves. They pass the v1 payload (getRuntimeInstanceTelemetryInfo:endpointTypes,actionsAmount,agentsAmount,cloud.api_key_provided, ...) through a new internal option,__instanceCreatedInfo.fireInstanceCreatedTelemetrysends that payload in place of the v2 zeros. Every v1 wrapper delegates to a v2 handler, so no v1 wrapper keeps its own capture.runtime.frameworkis correct. Express, Nest and Pages Router now call an internalcreateNodeHttpEndpoint(options, framework)(node-http/endpoint.ts, not in the barrel). The property now names the entry point the user called, and is no longer overwritten with"node-http". The publiccopilotRuntimeNodeHttpEndpointis a one-line wrapper with an unchanged signature.fireInstanceCreatedTelemetrykeeps aWeakSetof the runtimes that already reported. The event fires at most once per runtime object.self-hosting-copilot-runtime-create-endpoint.mdx, five tabs, andself-hosting-copilot-runtime-starter.mdx, four v1 tabs) now build the runtime and the endpoint once, at module scope. The Nest tab now also has{{extraImports}}and{{clientSetup}}. Azure, LangChain and OpenAI Assistants need these lines, because theiradapterSetupuses a client.The event name and all property names are unchanged.
Why the guard keys on the runtime, not on the process
new CopilotRuntime()per request still reports once per request. The docs fix removes that pattern from the snippets. Severalexamples/v1/**routes still use it (see the follow-ups).WeakSetdoes not keep a discarded runtime in memory.Effect on the dashboards
The weekly count of
oss.runtime.instance_createdwill go down for v1 users after they upgrade. That drop is a correction of over-counting. It is not a loss of adoption. A single-build deployment goes from 2–3 events per process start to 1. A per-request deployment goes from 2–3 events per request to 1 per runtime. I did not estimate the new weekly total, because the data does not show how many users build per request.Testing
packages/runtime/src/v1-deprecated/lib/integrations/__tests__/instance-created-once.test.ts. For each of the five v1 wrappers it asserts these points:actionsAmount: 1,agentsAmount: 1,cloud.api_key_provided: true,cloud.public_api_key). Theruntime.frameworkin effect at capture time is the wrapper's own value.instance-created.test.ts: theinfooverride replaces the defaults, and the guard fires once per runtime object.mainsource, all 15 new v1 tests fail (expected [ Array(9) ] to have a length of 1 but got 9, and similar).WeakSetcheck removed, exactly the 5 "built per request" tests fail.nx run-many -t test,check-types -p @copilotkit/runtime:oxfmt --checkon all changed files is clean.oxlintreports 0 errors. Its warnings are on code that moved unchanged, and on the two empty mock classes in the test.pnpm check:public-api-manifest:manifest.v1.json is current.Notes for reviewers
node-http/index.ts. This PR moves that code tonode-http/endpoint.ts. Whichever PR lands second must re-apply its hunk in the other file. docs(packages): fix the docstrings behind the v1 API reference #8134 changes only the header comment, which stays inindex.ts.Follow-ups (not in this PR)
examples/v1/next-openai/**/route.ts,examples/v1/_legacy/*/route.ts, and others. They are deprecated v1 examples, so a separate change is cleaner.{{adapterSetup}}/{{clientSetup}}placeholders in these snippets come fromquickStartProviders. That module was removed with the retired docs app (33a7948) and does not exist in shell-docs. I checked each provider value in its last version: all are module-scope declarations that do not read the request.🤖 Generated with Claude Code
Summary by CodeRabbit