From 34935a72d74d89713b190204f1a0537df67dc18b Mon Sep 17 00:00:00 2001 From: Nir Gazit Date: Tue, 25 Nov 2025 09:38:24 +0200 Subject: [PATCH 1/3] fix(sdk): remove posthog and telemetry reporting --- packages/traceloop-sdk/package.json | 1 - .../traceloop-sdk/src/lib/prompts/index.ts | 3 - .../src/lib/telemetry/telemetry.ts | 86 ------------------- .../src/lib/tracing/decorators.ts | 7 +- .../traceloop-sdk/src/lib/tracing/index.ts | 7 +- pnpm-lock.yaml | 13 +-- 6 files changed, 9 insertions(+), 108 deletions(-) delete mode 100644 packages/traceloop-sdk/src/lib/telemetry/telemetry.ts diff --git a/packages/traceloop-sdk/package.json b/packages/traceloop-sdk/package.json index 7c19c580..f9256f0b 100644 --- a/packages/traceloop-sdk/package.json +++ b/packages/traceloop-sdk/package.json @@ -84,7 +84,6 @@ "fetch-retry": "^6.0.0", "nunjucks": "^3.2.4", "papaparse": "^5.5.3", - "posthog-node": "^5.5.1", "supports-color": "^10.0.0", "tslib": "^2.8.1", "uuid": "^11.1.0" diff --git a/packages/traceloop-sdk/src/lib/prompts/index.ts b/packages/traceloop-sdk/src/lib/prompts/index.ts index 69afb390..706c036a 100644 --- a/packages/traceloop-sdk/src/lib/prompts/index.ts +++ b/packages/traceloop-sdk/src/lib/prompts/index.ts @@ -1,6 +1,5 @@ import { TraceloopError } from "../errors"; import { Prompt, PromptVersion } from "../interfaces"; -import { Telemetry } from "../telemetry/telemetry"; import { getPromptByKey } from "./registry"; import { renderMessages } from "./template"; export { waitForInitialization } from "./registry"; @@ -40,8 +39,6 @@ const managedPromptTracingAttributes = ( }; export const getPrompt = (key: string, variables: Record) => { - Telemetry.getInstance().capture("prompt:rendered"); - const prompt = getPromptByKey(key); const promptVersion = getEffectiveVersion(prompt); diff --git a/packages/traceloop-sdk/src/lib/telemetry/telemetry.ts b/packages/traceloop-sdk/src/lib/telemetry/telemetry.ts deleted file mode 100644 index 14d95dc9..00000000 --- a/packages/traceloop-sdk/src/lib/telemetry/telemetry.ts +++ /dev/null @@ -1,86 +0,0 @@ -import * as os from "os"; -import * as fs from "fs"; -import * as path from "path"; -import { v4 as uuid } from "uuid"; -import { PostHog } from "posthog-node"; -import { version } from "../../../package.json"; - -export class Telemetry { - private static instance: Telemetry; - - private static readonly ANON_ID_PATH = `${os.homedir()}/.cache/traceloop/telemetry_anon_id`; - private static readonly UNKNOWN_ANON_ID = "UNKNOWN"; - - private telemetryEnabled: boolean; - private posthog: PostHog | undefined; - private anonId: string | undefined; - - public static getInstance(): Telemetry { - if (!Telemetry.instance) { - Telemetry.instance = new Telemetry(); - } - return Telemetry.instance; - } - - private constructor() { - this.telemetryEnabled = - !process.env.TRACELOOP_TELEMETRY || - process.env.TRACELOOP_TELEMETRY.toLowerCase() === "true"; - - if (this.telemetryEnabled) { - this.posthog = new PostHog( - "phc_JMTeAfG8OpaPsyHzSBtqquMvko1fmOHcW0gyqLCrF3t", - ); - } - } - - private getAnonId() { - if (this.anonId) { - return this.anonId; - } - - try { - if (!fs.existsSync(Telemetry.ANON_ID_PATH)) { - fs.mkdirSync(path.dirname(Telemetry.ANON_ID_PATH), { recursive: true }); - const anonIdFile = fs.openSync(Telemetry.ANON_ID_PATH, "w"); - this.anonId = uuid(); - fs.writeSync(anonIdFile, this.anonId); - fs.closeSync(anonIdFile); - } else { - const anonIdFile = fs.openSync(Telemetry.ANON_ID_PATH, "r"); - this.anonId = fs.readFileSync(anonIdFile, "utf8"); - fs.closeSync(anonIdFile); - } - return this.anonId; - } catch (e) { - return Telemetry.UNKNOWN_ANON_ID; - } - } - - private getContext() { - return { - sdk: "typescript", - sdk_version: version, - }; - } - - public capture(event: string, properties?: Record) { - if (this.telemetryEnabled && this.posthog) { - this.posthog.capture({ - distinctId: this.getAnonId(), - event, - properties: { - ...properties, - ...this.getContext(), - }, - }); - this.posthog.flush(); - } - } - - public logException(error: Error) { - if (this.telemetryEnabled) { - this.capture("error", { error: error.message, stack: error.stack || "" }); - } - } -} diff --git a/packages/traceloop-sdk/src/lib/tracing/decorators.ts b/packages/traceloop-sdk/src/lib/tracing/decorators.ts index e1c480d5..fb30ca25 100644 --- a/packages/traceloop-sdk/src/lib/tracing/decorators.ts +++ b/packages/traceloop-sdk/src/lib/tracing/decorators.ts @@ -14,7 +14,6 @@ import { TraceloopSpanKindValues, } from "@traceloop/ai-semantic-conventions"; import { shouldSendTraces } from "."; -import { Telemetry } from "../telemetry/telemetry"; export type DecoratorConfig = { name: string; @@ -134,7 +133,7 @@ function withEntity< ); } } catch (error) { - Telemetry.getInstance().logException(error); + console.debug("Error setting input attributes", error); } } @@ -149,7 +148,7 @@ function withEntity< ); } } catch (error) { - Telemetry.getInstance().logException(error); + console.debug("Error setting output attributes", error); } finally { span.end(); } @@ -165,7 +164,7 @@ function withEntity< ); } } catch (error) { - Telemetry.getInstance().logException(error); + console.debug("Error setting output attributes", error); } finally { span.end(); } diff --git a/packages/traceloop-sdk/src/lib/tracing/index.ts b/packages/traceloop-sdk/src/lib/tracing/index.ts index 3065ec01..ffc0c237 100644 --- a/packages/traceloop-sdk/src/lib/tracing/index.ts +++ b/packages/traceloop-sdk/src/lib/tracing/index.ts @@ -7,7 +7,6 @@ import { Resource } from "@opentelemetry/resources"; import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions"; import { Instrumentation } from "@opentelemetry/instrumentation"; import { InitializeOptions } from "../interfaces"; -import { Telemetry } from "../telemetry/telemetry"; import { _configuration } from "../configuration"; import { CONTEXT_KEY_ALLOW_TRACE_CONTENT } from "@traceloop/ai-semantic-conventions"; import { AnthropicInstrumentation } from "@traceloop/instrumentation-anthropic"; @@ -51,7 +50,8 @@ let mcpInstrumentation: McpInstrumentation | undefined; const instrumentations: Instrumentation[] = []; export const initInstrumentations = (apiKey?: string, baseUrl?: string) => { - const exceptionLogger = (e: Error) => Telemetry.getInstance().logException(e); + //eslint-disable-next-line @typescript-eslint/no-empty-function + const exceptionLogger = (e: Error) => {}; const enrichTokens = (process.env.TRACELOOP_ENRICH_TOKENS || "true").toLowerCase() === "true"; @@ -133,7 +133,8 @@ export const manuallyInitInstrumentations = ( apiKey?: string, baseUrl?: string, ) => { - const exceptionLogger = (e: Error) => Telemetry.getInstance().logException(e); + //eslint-disable-next-line @typescript-eslint/no-empty-function + const exceptionLogger = (e: Error) => {}; const enrichTokens = (process.env.TRACELOOP_ENRICH_TOKENS || "true").toLowerCase() === "true"; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 85abb193..a6889354 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -900,9 +900,6 @@ importers: papaparse: specifier: ^5.5.3 version: 5.5.3 - posthog-node: - specifier: ^5.5.1 - version: 5.6.0 supports-color: specifier: ^10.0.0 version: 10.0.0 @@ -7146,10 +7143,6 @@ packages: resolution: {integrity: sha512-Q8qQfPiZ+THO/3ZrOrO0cJJKfpYCagtMUkXbnEfmgUjwXg6z/WBeOyS9APBBPCTSiDV+s4SwQGu8yFsiMRIudg==} engines: {node: '>=4'} - posthog-node@5.6.0: - resolution: {integrity: sha512-MVXxKmqAYp2cPBrN1YMhnhYsJYIu6yc6wumbHz1dbo67wZBf2WtMm67Uh+4VCrp07049qierWlxQqz1W5zGDeg==} - engines: {node: '>=20'} - prelude-ls@1.2.1: resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==} engines: {node: '>= 0.8.0'} @@ -14326,7 +14319,7 @@ snapshots: isstream: 0.1.2 jsonwebtoken: 9.0.2 mime-types: 2.1.35 - retry-axios: 2.6.0(axios@1.10.0(debug@4.4.1)) + retry-axios: 2.6.0(axios@1.10.0) tough-cookie: 4.1.4 transitivePeerDependencies: - supports-color @@ -15970,8 +15963,6 @@ snapshots: cssesc: 3.0.0 util-deprecate: 1.0.2 - posthog-node@5.6.0: {} - prelude-ls@1.2.1: {} prettier-linter-helpers@1.0.0: @@ -16252,7 +16243,7 @@ snapshots: onetime: 5.1.2 signal-exit: 3.0.7 - retry-axios@2.6.0(axios@1.10.0(debug@4.4.1)): + retry-axios@2.6.0(axios@1.10.0): dependencies: axios: 1.10.0(debug@4.4.1) From 3d5c2f7c25ccd6b54936c1916da49baafcaf5326 Mon Sep 17 00:00:00 2001 From: Nir Gazit Date: Tue, 25 Nov 2025 09:50:38 +0200 Subject: [PATCH 2/3] Update packages/traceloop-sdk/src/lib/tracing/index.ts Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- packages/traceloop-sdk/src/lib/tracing/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/traceloop-sdk/src/lib/tracing/index.ts b/packages/traceloop-sdk/src/lib/tracing/index.ts index ffc0c237..e112707d 100644 --- a/packages/traceloop-sdk/src/lib/tracing/index.ts +++ b/packages/traceloop-sdk/src/lib/tracing/index.ts @@ -133,8 +133,9 @@ export const manuallyInitInstrumentations = ( apiKey?: string, baseUrl?: string, ) => { - //eslint-disable-next-line @typescript-eslint/no-empty-function - const exceptionLogger = (e: Error) => {}; + const exceptionLogger = (e: Error) => { + console.debug("[Traceloop] Instrumentation exception:", e.message); + }; const enrichTokens = (process.env.TRACELOOP_ENRICH_TOKENS || "true").toLowerCase() === "true"; From 72fca85dbed09c56ae605a90bf3c6d9bd15c591e Mon Sep 17 00:00:00 2001 From: Nir Gazit Date: Tue, 25 Nov 2025 09:50:48 +0200 Subject: [PATCH 3/3] Update packages/traceloop-sdk/src/lib/tracing/index.ts Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- packages/traceloop-sdk/src/lib/tracing/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/traceloop-sdk/src/lib/tracing/index.ts b/packages/traceloop-sdk/src/lib/tracing/index.ts index e112707d..ac7bf40c 100644 --- a/packages/traceloop-sdk/src/lib/tracing/index.ts +++ b/packages/traceloop-sdk/src/lib/tracing/index.ts @@ -50,8 +50,9 @@ let mcpInstrumentation: McpInstrumentation | undefined; const instrumentations: Instrumentation[] = []; export const initInstrumentations = (apiKey?: string, baseUrl?: string) => { - //eslint-disable-next-line @typescript-eslint/no-empty-function - const exceptionLogger = (e: Error) => {}; + const exceptionLogger = (e: Error) => { + console.debug("[Traceloop] Instrumentation exception:", e.message); + }; const enrichTokens = (process.env.TRACELOOP_ENRICH_TOKENS || "true").toLowerCase() === "true";