|
1 | 1 | import { describe, test, expect, beforeEach, afterEach } from "bun:test" |
2 | | -import { parseEnvInt, loadConfig, resolveHelperPath, resolveLogLevel, TRACE_TYPES } from "../src/config.ts" |
| 2 | +import { parseAttributePairs, parseEnvInt, loadConfig, resolveHelperPath, resolveLogLevel, TRACE_TYPES } from "../src/config.ts" |
| 3 | + |
| 4 | +describe("parseAttributePairs", () => { |
| 5 | + test("parses comma-separated key=value pairs", () => { |
| 6 | + expect(parseAttributePairs("team=platform,env=prod")).toEqual({ team: "platform", env: "prod" }) |
| 7 | + }) |
| 8 | + |
| 9 | + test("trims whitespace and keeps empty values", () => { |
| 10 | + expect(parseAttributePairs(" team = platform , empty = ")).toEqual({ team: "platform", empty: "" }) |
| 11 | + }) |
| 12 | + |
| 13 | + test("uses only the first equals sign as the separator", () => { |
| 14 | + expect(parseAttributePairs("auth=Bearer abc=123")).toEqual({ auth: "Bearer abc=123" }) |
| 15 | + }) |
| 16 | + |
| 17 | + test("ignores malformed pairs", () => { |
| 18 | + expect(parseAttributePairs("missingequals,=novalue,,valid=yes")).toEqual({ valid: "yes" }) |
| 19 | + }) |
| 20 | +}) |
3 | 21 |
|
4 | 22 | describe("parseEnvInt", () => { |
5 | 23 | test("returns fallback when env var is unset", () => { |
@@ -50,6 +68,7 @@ describe("loadConfig", () => { |
50 | 68 | "OPENCODE_OTLP_HEADERS", |
51 | 69 | "OPENCODE_OTLP_HEADERS_HELPER", |
52 | 70 | "OPENCODE_RESOURCE_ATTRIBUTES", |
| 71 | + "OPENCODE_SPAN_ATTRIBUTES", |
53 | 72 | "OPENCODE_TRACEPARENT", |
54 | 73 | "OPENCODE_TRACESTATE", |
55 | 74 | "OPENCODE_OTLP_METRICS_TEMPORALITY", |
@@ -144,6 +163,11 @@ describe("loadConfig", () => { |
144 | 163 | expect(cfg.tracestate).toBe("vendor=value") |
145 | 164 | }) |
146 | 165 |
|
| 166 | + test("reads OPENCODE_SPAN_ATTRIBUTES", () => { |
| 167 | + process.env["OPENCODE_SPAN_ATTRIBUTES"] = "team=platform,env=prod" |
| 168 | + expect(loadConfig().spanAttributes).toBe("team=platform,env=prod") |
| 169 | + }) |
| 170 | + |
147 | 171 | test("does not set OTEL_EXPORTER_OTLP_HEADERS when OPENCODE_OTLP_HEADERS is unset", () => { |
148 | 172 | delete process.env["OPENCODE_OTLP_HEADERS"] |
149 | 173 | loadConfig() |
|
0 commit comments