Skip to content
Merged
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
27 changes: 19 additions & 8 deletions apps/server/src/telemetry/AnalyticsService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,31 @@ it.layer(NodeServices.layer)("AnalyticsService test", (it) => {
}),
);

it.effect("does not send batch requests when telemetry is disabled", () =>
it.effect.each([
{
name: "telemetry is disabled",
config: {
T3CODE_TELEMETRY_ENABLED: false,
T3CODE_POSTHOG_KEY: "phc_test_key",
T3CODE_POSTHOG_HOST: "http://localhost",
},
},
{
name: "telemetry is not configured",
config: { T3CODE_POSTHOG_KEY: "phc_test_key", T3CODE_POSTHOG_HOST: "http://localhost" },
},
{
name: "no PostHog key is set",
config: { T3CODE_TELEMETRY_ENABLED: true, T3CODE_POSTHOG_HOST: "http://localhost" },
},
])("does not send batch requests when $name", ({ config }) =>
Effect.gen(function* () {
const capturedPaths: Array<string> = [];
const layerServerConfig = ServerConfig.ServerConfig.layerTest(process.cwd(), {
prefix: "t3-telemetry-disabled-",
});
const layerTelemetry = AnalyticsService.layer.pipe(Layer.provideMerge(layerServerConfig));
const layerConfig = ConfigProvider.layer(
ConfigProvider.fromUnknown({
T3CODE_TELEMETRY_ENABLED: false,
T3CODE_POSTHOG_KEY: "phc_test_key",
T3CODE_POSTHOG_HOST: "http://localhost",
}),
);
const layerConfig = ConfigProvider.layer(ConfigProvider.fromUnknown(config));
const layerBatchServer = HttpServer.serve(
Effect.gen(function* () {
const request = yield* HttpServerRequest.HttpServerRequest;
Expand Down
14 changes: 9 additions & 5 deletions apps/server/src/telemetry/AnalyticsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ export function retryDelayMs(failures: number, random: number): number {
return Math.round(ceiling / 2 + (ceiling / 2) * random);
}

// Fork policy: no upstream project key and off by default, so nothing is sent
// unless both T3CODE_POSTHOG_KEY and T3CODE_TELEMETRY_ENABLED=true are set.
const TelemetryEnvConfig = Config.all({
posthogKey: Config.String("T3CODE_POSTHOG_KEY").pipe(
Config.withDefault("phc_XOWci4oZP4VvLiEyrFqkFjP4CZn55mjYYBMREK5Wd6m"),
),
posthogKey: Config.String("T3CODE_POSTHOG_KEY").pipe(Config.withDefault("")),
posthogHost: Config.String("T3CODE_POSTHOG_HOST").pipe(
Config.withDefault("https://us.i.posthog.com"),
),
enabled: Config.Boolean("T3CODE_TELEMETRY_ENABLED").pipe(Config.withDefault(true)),
enabled: Config.Boolean("T3CODE_TELEMETRY_ENABLED").pipe(Config.withDefault(false)),
flushBatchSize: Config.Number("T3CODE_TELEMETRY_FLUSH_BATCH_SIZE").pipe(Config.withDefault(20)),
maxBufferedEvents: Config.Number("T3CODE_TELEMETRY_MAX_BUFFERED_EVENTS").pipe(
Config.withDefault(1_000),
Expand Down Expand Up @@ -121,7 +121,11 @@ function serverOsFromNodePlatform(platform: string): ClientOs {

/** @public Service construction is part of the canonical Effect module API. */
export const make = Effect.gen(function* () {
const telemetryConfig = yield* TelemetryEnvConfig;
const telemetryEnv = yield* TelemetryEnvConfig;
const telemetryConfig = {
...telemetryEnv,
enabled: telemetryEnv.enabled && telemetryEnv.posthogKey.trim() !== "",
};
const httpClient = yield* HttpClient.HttpClient;
const serverConfig = yield* ServerConfig.ServerConfig;
const identifier = yield* getTelemetryIdentifier;
Expand Down
8 changes: 3 additions & 5 deletions docs/user/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ turn result, duration, and main-agent token totals when available.
Events do not include prompts, responses, file contents, authentication tokens, conversation IDs,
raw provider events, or child-agent output. Child-agent token use is excluded from the totals.

To disable collection, set `T3CODE_TELEMETRY_ENABLED=false` in the server's environment before
starting it. This stops product events from being recorded or sent.

The desktop app reads the variable from your shell profile (for example `~/.zshrc`) on macOS and
Linux, so export it there and restart the app. On Windows, set it as a user environment variable.
Collection is off by default. To enable it, set both `T3CODE_TELEMETRY_ENABLED=true` and
`T3CODE_POSTHOG_KEY` to your own PostHog project key in the server's environment before starting
it. `T3CODE_POSTHOG_HOST` overrides the PostHog ingest host.
Loading