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): treat empty environment variables as unset (#1052)
Rudy Mizrahi Celeklib9bd3c5ee7bd
diff --git a/packages/asymptote-sdk-js/src/index.test.ts b/packages/asymptote-sdk-js/src/index.test.tsindex 2e10218d..a0bca2fc 100644--- a/packages/asymptote-sdk-js/src/index.test.ts+++ b/packages/asymptote-sdk-js/src/index.test.ts@@ -27,6 +27,7 @@ const envKeys = ["ASYMPTOTE_API_KEY","ASYMPTOTE_BASE_URL","OTEL_EXPORTER_OTLP_ENDPOINT",+ "OTEL_SERVICE_NAME",];describe("resolveExporterConfig", () => {@@ -57,6 +58,17 @@ describe("resolveExporterConfig", () => {expect(config.headers.authorization).toBe("Bearer env-key");});+ it("treats an empty ASYMPTOTE_BASE_URL as unset", () => {+ process.env.ASYMPTOTE_API_KEY = "env-key";+ process.env.ASYMPTOTE_BASE_URL = "";++ const config = resolveExporterConfig();++ expect(config.mode).toBe("hosted");+ expect(config.observeUrl).toBe("https://api.asymptotelabs.ai/v1/observe");+ expect(config.headers.authorization).toBe("Bearer env-key");+ });+it("prefers explicit api key and base URL over env", () => {process.env.ASYMPTOTE_API_KEY = "env-key";process.env.ASYMPTOTE_BASE_URL = "https://observe.example";@@ -248,6 +260,17 @@ describe("Asymptote Observe SDK", () => {expect(spans[0].resource.attributes["telemetry.sdk.version"]).toBe(packageVersion());});+ it("falls back to the default service name when OTEL_SERVICE_NAME is empty", async () => {+ process.env.OTEL_SERVICE_NAME = "";+ const exporter = new InMemorySpanExporter();+ initialize({ spanExporter: exporter, disableDefaultExporter: true, disableBatch: true });++ observe({ name: "agent.step" }, () => "ok")();+ await flush();++ expect(exporter.getFinishedSpans()[0].resource.attributes["service.name"]).toBe("asymptote-app");+ });+it("respects observe input/output suppression", async () => {const exporter = new InMemorySpanExporter();initialize({ spanExporter: exporter, disableDefaultExporter: true, disableBatch: true });diff --git a/packages/asymptote-sdk-js/src/index.ts b/packages/asymptote-sdk-js/src/index.tsindex 2fcb7aef..4ddef9f9 100644--- a/packages/asymptote-sdk-js/src/index.ts+++ b/packages/asymptote-sdk-js/src/index.ts@@ -207,7 +207,7 @@ export function initialize(options: InitializeOptions = {}): void {const provider = new NodeTracerProvider({resource: resourceFromAttributes({- [ATTR_SERVICE_NAME]: options.serviceName ?? process.env.OTEL_SERVICE_NAME ?? DEFAULT_SERVICE_NAME,+ [ATTR_SERVICE_NAME]: options.serviceName ?? envValue("OTEL_SERVICE_NAME") ?? DEFAULT_SERVICE_NAME,"telemetry.sdk.name": "asymptote-sdk-js","telemetry.sdk.version": SDK_VERSION,[ATTR_BEACON_ORIGIN]: "cloud",@@ -412,9 +412,9 @@ export function isInitialized(): boolean {}export function resolveExporterConfig(options: InitializeOptions = {}): ResolvedExporterConfig {- const explicitEndpoint = options.otlpEndpoint ?? process.env.OTEL_EXPORTER_OTLP_ENDPOINT;- const apiKey = options.apiKey ?? process.env.ASYMPTOTE_API_KEY;- const baseUrl = options.baseUrl ?? process.env.ASYMPTOTE_BASE_URL ?? DEFAULT_HOSTED_BASE_URL;+ const explicitEndpoint = options.otlpEndpoint ?? envValue("OTEL_EXPORTER_OTLP_ENDPOINT");+ const apiKey = options.apiKey ?? envValue("ASYMPTOTE_API_KEY");+ const baseUrl = options.baseUrl ?? envValue("ASYMPTOTE_BASE_URL") ?? DEFAULT_HOSTED_BASE_URL;const skipDefault = !!(options.disableDefaultExporter || options.spanExporter);const mode: ExportMode = skipDefault ? "custom" : explicitEndpoint ? "otlp" : apiKey ? "hosted" : "custom";@@ -432,6 +432,13 @@ export function resolveExporterConfig(options: InitializeOptions = {}): Resolvedreturn { observeUrl, headers, mode };}+// An empty variable is unset, as the OpenTelemetry environment spec has it: compose files and CI+// templates often declare a variable with no value.+function envValue(name: string): string | undefined {+ const value = process.env[name];+ return value === undefined || value.trim() === "" ? undefined : value;+}+// The Asymptote API key is a credential for Asymptote's own ingest, so it is// sent only there: in hosted mode, or when an explicit OTLP endpoint has the// same origin as the configured Asymptote base URL. OTEL_EXPORTER_OTLP_ENDPOINT