The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
fix(sdk): honor disabled providers during manual patching (#830)
Rudy Mizrahi Celeklicebd678fc69b
diff --git a/docs/sdk/instrumentation.mdx b/docs/sdk/instrumentation.mdxindex 7fef18bd..5e2f5e8e 100644--- a/docs/sdk/instrumentation.mdx+++ b/docs/sdk/instrumentation.mdx@@ -86,6 +86,8 @@ Observe.patch({`Observe.patch()` requires at least one module. It applies supported OpenLLMetry instrumentation and wraps Claude Agent SDK query functions when the module object is writable.+Provider selections remain in effect for `instrumentModules` and later `Observe.patch()` calls. Setting both `instrumentationOptions.openAI` and `instrumentationOptions.anthropic` to `false` keeps both providers disabled when modules are supplied manually.+## Existing OpenTelemetry providersIf your application already owns OpenTelemetry setup, use `Observe.instrumentations()` with your provider instead of calling `Observe.initialize()` twice.diff --git a/packages/asymptote-sdk-js/src/disabled-instrumentation.test.ts b/packages/asymptote-sdk-js/src/disabled-instrumentation.test.tsnew file mode 100644index 00000000..c09d2ec2--- /dev/null+++ b/packages/asymptote-sdk-js/src/disabled-instrumentation.test.ts@@ -0,0 +1,34 @@+import * as Anthropic from "@anthropic-ai/sdk";+import { afterEach, expect, it } from "vitest";+import { initialize, patch, shutdown } from "./index.js";++const resources = [Anthropic.Anthropic.Completions, Anthropic.Anthropic.Messages, Anthropic.Anthropic.Beta.Messages];+const originals = resources.map(resource => resource.prototype.create);+const descriptors = resources.map(resource => Object.getOwnPropertyDescriptor(resource.prototype, "create")!);++afterEach(async () => {+ await shutdown();+ // Manual upstream patching mutates provider prototypes. Restore the fixture's+ // real SDK classes explicitly so a failing regression cannot affect controls.+ resources.forEach((resource, index) => { Object.defineProperty(resource.prototype, "create", descriptors[index]); });+});++it.each(["initial modules", "later patch"])("keeps disabled providers unpatched with %s", (mode) => {+ initialize({+ disableDefaultExporter: true,+ instrumentationOptions: { openAI: false, anthropic: false },+ ...(mode === "initial modules" ? { instrumentModules: { Anthropic } } : {}),+ });+ if (mode === "later patch") patch({ Anthropic });+ resources.forEach((resource, index) => { expect(resource.prototype.create).toBe(originals[index]); });+});++it("still manually patches the real provider when it is enabled", () => {+ initialize({ disableDefaultExporter: true, instrumentationOptions: { openAI: false }, instrumentModules: { Anthropic } });+ expect(Anthropic.Anthropic.Messages.prototype.create).not.toBe(originals[1]);+});++it("keeps globally disabled instrumentations unpatched", () => {+ initialize({ disableDefaultExporter: true, disableInstrumentations: true, instrumentModules: { Anthropic } });+ resources.forEach((resource, index) => { expect(resource.prototype.create).toBe(originals[index]); });+});diff --git a/packages/asymptote-sdk-js/src/index.ts b/packages/asymptote-sdk-js/src/index.tsindex e1ab2f56..0fecd2ac 100644--- a/packages/asymptote-sdk-js/src/index.ts+++ b/packages/asymptote-sdk-js/src/index.ts@@ -509,15 +509,7 @@ function patchOpenLLMetryModules(modules: InstrumentModules): void {if (state?.instrumentationsDisabled) {return;}- let instrumentations: Instrumentation[];- if (state?.instrumentations.length) {- instrumentations = state.instrumentations;- } else {- instrumentations = initializeAsymptoteInstrumentations();- if (state) {- state.instrumentations = instrumentations;- }- }+ const instrumentations = state ? state.instrumentations : initializeAsymptoteInstrumentations();manuallyInstrumentModules(instrumentations, modules);}