From 7977c2e75c84a9c931bd588be4456cec7886babf Mon Sep 17 00:00:00 2001 From: Jon McCallum Date: Thu, 26 Nov 2026 15:01:56 +0000 Subject: [PATCH] feat(integration): add tracing to default runs behind wizard-default-tracing --- .../__tests__/flow-graphs.test.ts | 14 ++-- .../__tests__/prompt.test.ts | 24 +++++- .../posthog-integration/agent-prompts.ts | 2 + .../posthog-integration/agent/report.md | 2 +- .../posthog-integration/agent/review.md | 4 +- .../posthog-integration/agent/tracing.md | 75 +++++++++++++++++++ src/programs/posthog-integration/index.ts | 7 +- src/shared/constants.ts | 3 + 8 files changed, 119 insertions(+), 12 deletions(-) create mode 100644 src/programs/posthog-integration/agent/tracing.md diff --git a/src/agent/runner/sequence/orchestrator/__tests__/flow-graphs.test.ts b/src/agent/runner/sequence/orchestrator/__tests__/flow-graphs.test.ts index cb576df37..994fb9fdb 100644 --- a/src/agent/runner/sequence/orchestrator/__tests__/flow-graphs.test.ts +++ b/src/agent/runner/sequence/orchestrator/__tests__/flow-graphs.test.ts @@ -116,6 +116,7 @@ describe("posthog-integration's bundled graph", () => { ]; const AIO_LOGS = ['ai-observability', 'logs']; const MCP = 'mcp-analytics'; + const TRACING = 'tracing'; const types = (exclude: string[]) => plan(prompts, FLOW, exclude) .map((task) => task.type) @@ -127,10 +128,11 @@ describe("posthog-integration's bundled graph", () => { // The task sets a run queues, by what the program excludes. `warehouse` is the wizard's own to queue. it.each([ - ['the default run', [MCP], [...CORE, ...AIO_LOGS]], - ['a project with an MCP server', [], [...CORE, ...AIO_LOGS, MCP]], - ['AI Observability and Logs off', [MCP, ...AIO_LOGS], CORE], - ['both', AIO_LOGS, [...CORE, MCP]], + ['the default run', [MCP, TRACING], [...CORE, ...AIO_LOGS]], + ['a project with an MCP server', [TRACING], [...CORE, ...AIO_LOGS, MCP]], + ['tracing on', [MCP], [...CORE, ...AIO_LOGS, TRACING]], + ['AI Observability and Logs off', [MCP, TRACING, ...AIO_LOGS], CORE], + ['both', [TRACING, ...AIO_LOGS], [...CORE, MCP]], ])('queues the task set for %s', (_, exclude, expected) => { expect(types(exclude)).toEqual([...expected].sort()); }); @@ -145,6 +147,7 @@ describe("posthog-integration's bundled graph", () => { capture: ['install', 'init', 'identify', 'mcp-analytics'], 'ai-observability': ['capture'], logs: ['ai-observability'], + tracing: ['logs'], dashboard: ['capture', 'mcp-analytics'], review: [ 'install', @@ -155,13 +158,14 @@ describe("posthog-integration's bundled graph", () => { 'capture', 'ai-observability', 'logs', + 'tracing', ], report: ['dashboard', 'review'], }); }); it('keeps the order around the tasks a run leaves out', () => { - const left = edges([MCP, ...AIO_LOGS]); + const left = edges([MCP, TRACING, ...AIO_LOGS]); expect(left.capture).toEqual(['install', 'init', 'identify']); expect(left.dashboard).toEqual(['capture', 'install', 'init', 'identify']); expect(left.review).toEqual([ diff --git a/src/programs/posthog-integration/__tests__/prompt.test.ts b/src/programs/posthog-integration/__tests__/prompt.test.ts index 6f6e74254..45640e13b 100644 --- a/src/programs/posthog-integration/__tests__/prompt.test.ts +++ b/src/programs/posthog-integration/__tests__/prompt.test.ts @@ -10,6 +10,7 @@ import { WIZARD_DEFAULT_AIO_LOGS_FLAG_KEY, WIZARD_DEFAULT_MCP_ANALYTICS_FLAG_KEY, + WIZARD_DEFAULT_TRACING_FLAG_KEY, } from '@shared/constants'; import { config as posthogIntegration } from '@programs/posthog-integration'; import { buildSession } from '@services/session'; @@ -67,10 +68,14 @@ function sessionWithServers(candidates: string[]) { } describe('default observability flag gating', () => { - // A project with a server and the MCP flag on, so the MCP step's own gate stays out of these cases. + // A project with a server and the MCP and tracing flags on, so their own gates stay out of these cases. const excluded = (flags: Record) => posthogIntegration.excludedTaskTypes!( - { [WIZARD_DEFAULT_MCP_ANALYTICS_FLAG_KEY]: 'true', ...flags }, + { + [WIZARD_DEFAULT_MCP_ANALYTICS_FLAG_KEY]: 'true', + [WIZARD_DEFAULT_TRACING_FLAG_KEY]: 'true', + ...flags, + }, sessionWithServers(['src/server.ts']), ); @@ -87,6 +92,21 @@ describe('default observability flag gating', () => { ); expect(excluded({})).toEqual([]); }); + + it("keeps tracing only when its flag is 'true'", () => { + const excludesTracing = (flags: Record) => + posthogIntegration.excludedTaskTypes!( + flags, + sessionWithServers([]), + ).includes('tracing'); + expect(excludesTracing({ [WIZARD_DEFAULT_TRACING_FLAG_KEY]: 'true' })).toBe( + false, + ); + expect(excludesTracing({})).toBe(true); + expect( + excludesTracing({ [WIZARD_DEFAULT_TRACING_FLAG_KEY]: 'false' }), + ).toBe(true); + }); }); describe('MCP analytics gating', () => { diff --git a/src/programs/posthog-integration/agent-prompts.ts b/src/programs/posthog-integration/agent-prompts.ts index 1c91cc155..155d527e8 100644 --- a/src/programs/posthog-integration/agent-prompts.ts +++ b/src/programs/posthog-integration/agent-prompts.ts @@ -9,6 +9,7 @@ import logs from './agent/logs.md'; import mcpAnalytics from './agent/mcp-analytics.md'; import report from './agent/report.md'; import review from './agent/review.md'; +import tracing from './agent/tracing.md'; import warehouse from './agent/warehouse.md'; /** This program's agent prompts by task type, imported as text, in the order tasks that can start together are queued. */ @@ -21,6 +22,7 @@ export const AGENT_PROMPTS: Readonly> = { capture, 'ai-observability': aiObservability, logs, + tracing, review, dashboard, report, diff --git a/src/programs/posthog-integration/agent/report.md b/src/programs/posthog-integration/agent/report.md index 4b23013a6..94332deb5 100644 --- a/src/programs/posthog-integration/agent/report.md +++ b/src/programs/posthog-integration/agent/report.md @@ -45,7 +45,7 @@ before those events mean anything. One `publish_handoff` call went through with the full report: what was installed and initialized, the events captured, whether identify was wired or -skipped, error tracking added, AI Observability, Logs, and MCP analytics configured, +skipped, error tracking added, AI Observability, Logs, tracing, and MCP analytics configured, skipped, or failed with reasons, the dashboard link, any build conflict in full, and the next steps for the user. Every claim in it traces to a handoff, and what the run could not confirm reads as unconfirmed. The notebook mirror is diff --git a/src/programs/posthog-integration/agent/review.md b/src/programs/posthog-integration/agent/review.md index d6d67804e..0fb6112a1 100644 --- a/src/programs/posthog-integration/agent/review.md +++ b/src/programs/posthog-integration/agent/review.md @@ -11,7 +11,7 @@ effort_sdk: high skills: [posthog-best-practices, integration-build] allowedTools: [Read, Edit, Glob, Grep, Bash] disallowedTools: [enqueue_task] -dependsOn: [install, init, identify, mcp-analytics, error-tracking, capture, ai-observability, logs] +dependsOn: [install, init, identify, mcp-analytics, error-tracking, capture, ai-observability, logs, tracing] --- ## Goal @@ -78,7 +78,7 @@ a handoff's minimum surfaces here as a failed install or build in that task's files; handle it the same way. Build Go with `go build -o /dev/null ./...` so no binary lands in the project, and never run `cargo fmt`, which reformats the whole crate. An optional upstream task -(AI Observability, Logs, MCP analytics) may have failed and left partial edits no handoff +(AI Observability, Logs, tracing, MCP analytics) may have failed and left partial edits no handoff describes — install and run the chosen compile checks either way, and let them surface stray imports; fix or revert them like any other defect. Do not run the test suite; the runtime does not allow it, and the chosen compile checks are the bar. A bad version only surfaces diff --git a/src/programs/posthog-integration/agent/tracing.md b/src/programs/posthog-integration/agent/tracing.md new file mode 100644 index 000000000..87e6fd486 --- /dev/null +++ b/src/programs/posthog-integration/agent/tracing.md @@ -0,0 +1,75 @@ +--- +type: tracing +flow: integration-v2 +label: Add distributed tracing +model_pi: openai/gpt-5.6-terra +effort_pi: medium +model_sdk: claude-sonnet-5 +effort_sdk: high +skills: [] +allowedTools: [Read, Write, Edit, Glob, Grep, load_skill_menu, install_skill] +disallowedTools: [enqueue_task] +dependsOn: [logs] +optional: true +--- + +## Goal + +Configure PostHog distributed tracing for this project's server runtimes. Load the +`tracing` skill menu, install its matching skill, and read the platform reference +before editing. Choose the capture path the skill describes for this runtime. If +the app already uses OpenTelemetry, write against its existing OTel version and +name exporter packages compatible with it — never require, or write code that +assumes, an upgrade of a package this integration did not introduce. A +browser-only app gets no tracing. If no documented setup applies, complete as +`not needed` and explain why. + +Where a web app or other application sits beside an MCP server (the detected facts +name any MCP server), the app is your target, and MCP analytics owns the MCP server. +Workers, queues and shared packages belong to the app. Leave a separately run MCP +server's files alone. If the MCP server is the whole project, it is your target. + +This run cannot ask questions, so where the skill says to ask, decide as follows: + +- If the app already exports traces to another tracing backend, do not add PostHog + as a second destination. Complete as `not needed`, name the backend, and give the + user the exporter change that would add PostHog beside it. +- If the app already exports OpenTelemetry traces to PostHog, report that without + adding a second exporter. +- If the setup needs a new launch command (such as `opentelemetry-instrument` or a + Java agent flag), do not change how the app starts. Use a code-based setup the + platform reference documents, or skip with that reason. + +Preserve any tracer provider AIO or Logs configured in earlier steps. Reuse it and +add a separate span processor with its own exporter to `/i/v1/traces`; never repoint +an exporter another step set up, and never send spans to `/i/v0/ai/otel`. Set a +service name. Do not put secrets, tokens, request bodies, or user data in span +names or attributes, and add manual spans only where the skill says auto +instrumentation has no coverage. + +Never wait on span export before the app starts serving, because a slow PostHog +host would hold up its boot. Let the batch processor export on its interval, and +flush only at shutdown, or at the end of each invocation where the skill says a +short-lived or serverless handler needs it. + +This is the instrumentation part of a larger integration. Instead of the +standalone skill's install command, name the required packages in your handoff, +list each one in the handoff's `packages` field, +and leave installation, manifest and lockfile updates, builds, and lint to +review. Do not run `opentelemetry-bootstrap` or any other installer. Do not edit +dependency manifests or write a version number you invented — the package manager +resolves real versions when review installs by name. Use `detect_package_manager` +if needed. Use the wizard's supplied project and region and the env names from +upstream handoffs; inspect and write environment files only through +`check_env_keys` and `set_env_values`. Do not request credentials or select a +different project. If required configuration is unavailable, report what is +missing instead of guessing a region. + +## How you know you succeeded + +Tracing is configured once for the supported runtime, was already present, or has +a clear skip reason. The handoff names the changed files, packages, env variable +names (never values), the service name, and any dependency work for review. Give a +specific request the user can send to produce a trace and where to find it in +PostHog Tracing, filtered by that service name; delivery remains unverified until +observed. Do not publish a separate report. diff --git a/src/programs/posthog-integration/index.ts b/src/programs/posthog-integration/index.ts index 36cb9173a..103d95f33 100644 --- a/src/programs/posthog-integration/index.ts +++ b/src/programs/posthog-integration/index.ts @@ -35,6 +35,7 @@ import { Sequence, WIZARD_DEFAULT_AIO_LOGS_FLAG_KEY, WIZARD_DEFAULT_MCP_ANALYTICS_FLAG_KEY, + WIZARD_DEFAULT_TRACING_FLAG_KEY, WIZARD_INTERACTION_EVENT_NAME, } from '@shared/constants'; import { withUtm } from '@utils/links'; @@ -316,13 +317,15 @@ export const config: ProgramConfig = { ], // AI Observability and Logs are a kill switch over a shipped default: only an - // explicit 'false' excludes them. MCP analytics is a launch flag: it needs - // 'true', so a failed flag fetch leaves it out, and a server from the scan. + // explicit 'false' excludes them. MCP analytics and tracing are launch flags: + // they need 'true', so a failed flag fetch leaves them out. MCP analytics also + // needs a server from the scan. excludedTaskTypes: (flags, sess) => [ ...(flags[WIZARD_DEFAULT_AIO_LOGS_FLAG_KEY] === 'false' ? ['ai-observability', 'logs'] : []), ...(mcpAnalyticsStepOn(flags, sess) ? [] : [MCP_ANALYTICS_TASK_TYPE]), + ...(flags[WIZARD_DEFAULT_TRACING_FLAG_KEY] === 'true' ? [] : ['tracing']), ], // The fact exists only beside the task, so no other task acts on it alone. detectedFacts: (flags, sess) => diff --git a/src/shared/constants.ts b/src/shared/constants.ts index 3dc7913bc..116f93566 100644 --- a/src/shared/constants.ts +++ b/src/shared/constants.ts @@ -329,6 +329,8 @@ export const WIZARD_DEFAULT_AIO_LOGS_FLAG_KEY = 'wizard-default-aio-logs'; /** Launch flag: ONLY an explicit 'true' includes the MCP analytics task in default integration runs — absent or fetch-failed means exclude. */ export const WIZARD_DEFAULT_MCP_ANALYTICS_FLAG_KEY = 'wizard-default-mcp-analytics'; +/** Launch flag: ONLY an explicit 'true' includes the tracing task in default integration runs — absent or fetch-failed means exclude. */ +export const WIZARD_DEFAULT_TRACING_FLAG_KEY = 'wizard-default-tracing'; /** Multivariate flag for the Decisions service. `compare`, or `true`, asks and only logs the answers. `traits` also writes them as traits when project discovery is on. Anything else, a failed read included, makes no request. */ export const WIZARD_DECISIONS_DETECTION_FLAG_KEY = 'wizard-decisions-detection'; /** Boolean flag: true lets the warehouse-destination program run. */ @@ -348,6 +350,7 @@ export const WIZARD_FLAG_KEYS = [ WIZARD_BASIC_INTEGRATION_AGENTIC_DETECTION_FLAG_KEY, WIZARD_DEFAULT_AIO_LOGS_FLAG_KEY, WIZARD_DEFAULT_MCP_ANALYTICS_FLAG_KEY, + WIZARD_DEFAULT_TRACING_FLAG_KEY, WIZARD_DECISIONS_DETECTION_FLAG_KEY, WIZARD_WAREHOUSE_DESTINATIONS_FLAG_KEY, WIZARD_PROJECT_DISCOVERY_FLAG_KEY,