Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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());
});
Expand All @@ -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',
Expand All @@ -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([
Expand Down
24 changes: 22 additions & 2 deletions src/programs/posthog-integration/__tests__/prompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<string, string>) =>
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']),
);

Expand All @@ -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<string, string>) =>
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', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/programs/posthog-integration/agent-prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -21,6 +22,7 @@ export const AGENT_PROMPTS: Readonly<Record<string, string>> = {
capture,
'ai-observability': aiObservability,
logs,
tracing,
review,
dashboard,
report,
Expand Down
2 changes: 1 addition & 1 deletion src/programs/posthog-integration/agent/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/programs/posthog-integration/agent/review.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
75 changes: 75 additions & 0 deletions src/programs/posthog-integration/agent/tracing.md
Original file line number Diff line number Diff line change
@@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new tracing task turns on OTel auto instrumentation with no scrubbing, so query-string tokens and outbound API keys get exported to PostHog as span attributes, despite the prompt's own no-secrets rule

medium secrets (confidence 3/5)

Details

Latent: this goes live once the wizard-default-tracing flag returns 'true' (excludedTaskTypes in src/programs/posthog-integration/index.ts).

src/programs/posthog-integration/agent/tracing.md tells the task to use the skill's capture path (line 20) and to add manual spans only where auto instrumentation has no coverage (lines 47-48). So the default result is OpenTelemetry auto instrumentation on the shared tracer provider, exporting to /i/v1/traces.

The rule on line 46, "Do not put secrets, tokens, request bodies, or user data in span names or attributes", only covers what the agent writes itself. Auto instrumentation fills attributes on its own:

  • By default, the OTel HTTP server and client instrumentations record the inbound path with its query string (http.target, or url.path plus url.query). They also record the full outbound URL (http.url / url.full). Recent versions redact only a few signature parameters.
  • DB instrumentations record the statement text (db.statement / db.query.text).

Nothing in the prompt asks the agent to strip any of this.

The new task also drops the guard its sibling logs.md keeps for the same situation: "the app's existing logs are data this run has no mandate to export, and every line that leaves must be visible in this run's diff". Here the data that leaves never shows up in the diff the wizard writes.

Impact — Take an app with a route that carries a credential in the query string, such as GET /reset-password?token=..., /auth/callback?code=... or a magic link. Or take an app that calls a third-party API with ?key= / ?api_key=. After a default wizard run with the flag on, every such request exports that value as a span attribute to the customer's PostHog project. Anyone who can read that project can read it: every project member, and anyone holding a leaked PostHog personal API key with read scope. For example, an analyst who has PostHog access but no production access can query traces for token= and use an unexpired reset token to take over that user's account in the app. The limits: only secrets that the app puts in URLs or SQL text are exposed, and the app's own token expiry still applies.

Fix — Make the prompt require scrubbing of auto-instrumented attributes, and make the handoff disclose what leaves. For example, replace lines 46-48 with:

Auto instrumentation records URLs and queries on its own. Configure it so no
query string leaves the app: strip `url.query`, and the query part of
`url.full`, `http.url` and `http.target`, through the instrumentation's
request/response hooks or a processor or exporter wrapper on the PostHog
exporter only. Do not turn on header capture or DB parameter or enhanced
statement reporting. Do not put secrets, tokens, request bodies, or user data
in span names or attributes you add. List the auto-instrumented attributes
that are exported in your handoff, so the report shows the user what leaves.

Agent-driven security review. The tracing skill lives outside this repo (context-mill) and may already scrub these attributes. OTel defaults also vary by runtime and instrumentation version. No OTel package was available in this environment to probe them, so the confidence is capped.

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.
7 changes: 5 additions & 2 deletions src/programs/posthog-integration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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';
Expand Down Expand Up @@ -355,13 +356,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']),
...SDK_FEATURE_TASKS.filter(([, feature]) =>
sdkFeatureGaps(sess, [feature]).some((gap) => gap.blocking),
).map(([type]) => type),
Expand Down
3 changes: 3 additions & 0 deletions src/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -351,6 +353,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,
Expand Down
Loading