| author | |
| committer | |
| log | 2598ce7a5ab0b25e32e0b67b084a9ec23cd8144f |
| tree | 4630598240ee9b4af358b75f4c9f5ebfb86edb86 |
| parent | 4293433eccbe6c6661acd020e584ae5d2234bf1e |
| signature | Signed by PGP key B5690EEEBB952194 |
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>5 files changed, 254 insertions(+), 54 deletions(-)
apps/desktop/src/app/DesktopObservability.test.ts+97-8| ... | @@ -93,6 +93,9 @@ const collectorLayer = (requests: Array<ExportedRequest>) => | ... | @@ -93,6 +93,9 @@ const collectorLayer = (requests: Array<ExportedRequest>) => |
| 93 | ), | 93 | ), |
| 94 | ); | 94 | ); |
| 95 | 95 | ||
| 96 | // A developer's own OTEL_* variables would otherwise pick the endpoints. | ||
| 97 | const emptyEnv = ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })); | ||
| 98 | |||
| 96 | const encodeObservabilitySettingsFile = Schema.encodeSync( | 99 | const encodeObservabilitySettingsFile = Schema.encodeSync( |
| 97 | Schema.fromJsonString( | 100 | Schema.fromJsonString( |
| 98 | Schema.Struct({ observability: Schema.Record(Schema.String, Schema.String) }), | 101 | Schema.Struct({ observability: Schema.Record(Schema.String, Schema.String) }), |
| ... | @@ -182,7 +185,7 @@ describe("DesktopObservability", () => { | ... | @@ -182,7 +185,7 @@ describe("DesktopObservability", () => { |
| 182 | assert.isFalse(yield* fileSystem.exists(logPath)); | 185 | assert.isFalse(yield* fileSystem.exists(logPath)); |
| 183 | }).pipe( | 186 | }).pipe( |
| 184 | Effect.scoped, | 187 | Effect.scoped, |
| 185 | Effect.provide(Layer.mergeAll(NodeServices.layer, NodeHttpClient.layerUndici)), | 188 | Effect.provide(Layer.mergeAll(NodeServices.layer, NodeHttpClient.layerUndici, emptyEnv)), |
| 186 | ), | 189 | ), |
| 187 | ); | 190 | ); |
| 188 | 191 | ||
| ... | @@ -260,7 +263,7 @@ describe("DesktopObservability", () => { | ... | @@ -260,7 +263,7 @@ describe("DesktopObservability", () => { |
| 260 | ); | 263 | ); |
| 261 | }).pipe( | 264 | }).pipe( |
| 262 | Effect.scoped, | 265 | Effect.scoped, |
| 263 | Effect.provide(Layer.mergeAll(NodeServices.layer, NodeHttpClient.layerUndici)), | 266 | Effect.provide(Layer.mergeAll(NodeServices.layer, NodeHttpClient.layerUndici, emptyEnv)), |
| 264 | ), | 267 | ), |
| 265 | ); | 268 | ); |
| 266 | 269 | ||
| ... | @@ -300,7 +303,7 @@ describe("DesktopObservability", () => { | ... | @@ -300,7 +303,7 @@ describe("DesktopObservability", () => { |
| 300 | assert.equal(records.at(-1)?.annotations.details, "code=1"); | 303 | assert.equal(records.at(-1)?.annotations.details, "code=1"); |
| 301 | }).pipe( | 304 | }).pipe( |
| 302 | Effect.scoped, | 305 | Effect.scoped, |
| 303 | Effect.provide(Layer.mergeAll(NodeServices.layer, NodeHttpClient.layerUndici)), | 306 | Effect.provide(Layer.mergeAll(NodeServices.layer, NodeHttpClient.layerUndici, emptyEnv)), |
| 304 | ), | 307 | ), |
| 305 | ); | 308 | ); |
| 306 | 309 | ||
| ... | @@ -344,7 +347,7 @@ describe("DesktopObservability", () => { | ... | @@ -344,7 +347,7 @@ describe("DesktopObservability", () => { |
| 344 | assert.isFalse(text.includes("y")); | 347 | assert.isFalse(text.includes("y")); |
| 345 | }).pipe( | 348 | }).pipe( |
| 346 | Effect.scoped, | 349 | Effect.scoped, |
| 347 | Effect.provide(Layer.mergeAll(NodeServices.layer, NodeHttpClient.layerUndici)), | 350 | Effect.provide(Layer.mergeAll(NodeServices.layer, NodeHttpClient.layerUndici, emptyEnv)), |
| 348 | ), | 351 | ), |
| 349 | ); | 352 | ); |
| 350 | 353 | ||
| ... | @@ -378,7 +381,7 @@ describe("DesktopObservability", () => { | ... | @@ -378,7 +381,7 @@ describe("DesktopObservability", () => { |
| 378 | assert.equal(lines.length, 258); | 381 | assert.equal(lines.length, 258); |
| 379 | }).pipe( | 382 | }).pipe( |
| 380 | Effect.scoped, | 383 | Effect.scoped, |
| 381 | Effect.provide(Layer.mergeAll(NodeServices.layer, NodeHttpClient.layerUndici)), | 384 | Effect.provide(Layer.mergeAll(NodeServices.layer, NodeHttpClient.layerUndici, emptyEnv)), |
| 382 | ), | 385 | ), |
| 383 | ); | 386 | ); |
| 384 | 387 | ||
| ... | @@ -424,7 +427,93 @@ describe("DesktopObservability", () => { | ... | @@ -424,7 +427,93 @@ describe("DesktopObservability", () => { |
| 424 | assert.lengthOf(record?.events ?? [], 0); | 427 | assert.lengthOf(record?.events ?? [], 0); |
| 425 | }).pipe( | 428 | }).pipe( |
| 426 | Effect.scoped, | 429 | Effect.scoped, |
| 427 | Effect.provide(Layer.mergeAll(NodeServices.layer, collectorLayer(requests))), | 430 | Effect.provide(Layer.mergeAll(NodeServices.layer, collectorLayer(requests), emptyEnv)), |
| 431 | ); | ||
| 432 | }); | ||
| 433 | |||
| 434 | it.effect("exports to an OTEL endpoint over Settings, with its own headers and protocol", () => { | ||
| 435 | const requests: Array<ExportedRequest> = []; | ||
| 436 | return Effect.gen(function* () { | ||
| 437 | const fileSystem = yield* FileSystem.FileSystem; | ||
| 438 | const baseDir = yield* fileSystem.makeTempDirectoryScoped({ | ||
| 439 | prefix: "t3-desktop-observability-test-", | ||
| 440 | }); | ||
| 441 | const environmentLayer = makeEnvironmentLayer(baseDir, true, { | ||
| 442 | T3CODE_OTLP_HEADERS: "x-scope=desktop", | ||
| 443 | }); | ||
| 444 | yield* writeObservabilitySettings(environmentLayer, { | ||
| 445 | otlpLogsUrl: "https://settings.example.com/v1/logs", | ||
| 446 | }); | ||
| 447 | |||
| 448 | yield* Effect.scoped( | ||
| 449 | Effect.logInfo("desktop otel export").pipe( | ||
| 450 | Effect.provide(DesktopObservability.layer.pipe(Layer.provideMerge(environmentLayer))), | ||
| 451 | ), | ||
| 452 | ); | ||
| 453 | |||
| 454 | assert.lengthOf(requests, 1); | ||
| 455 | const [request] = requests; | ||
| 456 | assert.strictEqual(request?.url, "https://collector.example.com/v1/logs"); | ||
| 457 | assert.strictEqual(request?.headers["x-otel"], "desktop"); | ||
| 458 | assert.strictEqual(request?.headers["x-scope"], undefined); | ||
| 459 | assert.strictEqual(request?.headers["content-type"], "application/json"); | ||
| 460 | }).pipe( | ||
| 461 | Effect.scoped, | ||
| 462 | Effect.provide( | ||
| 463 | Layer.mergeAll( | ||
| 464 | NodeServices.layer, | ||
| 465 | collectorLayer(requests), | ||
| 466 | ConfigProvider.layer( | ||
| 467 | ConfigProvider.fromEnv({ | ||
| 468 | env: { | ||
| 469 | OTEL_EXPORTER_OTLP_ENDPOINT: "https://collector.example.com", | ||
| 470 | OTEL_EXPORTER_OTLP_HEADERS: "x-otel=desktop", | ||
| 471 | OTEL_EXPORTER_OTLP_LOGS_PROTOCOL: "http/json", | ||
| 472 | }, | ||
| 473 | }), | ||
| 474 | ), | ||
| 475 | ), | ||
| 476 | ), | ||
| 477 | ); | ||
| 478 | }); | ||
| 479 | |||
| 480 | it.effect("exports nothing to Settings for logs an unusable OTEL endpoint claimed", () => { | ||
| 481 | const requests: Array<ExportedRequest> = []; | ||
| 482 | return Effect.gen(function* () { | ||
| 483 | const fileSystem = yield* FileSystem.FileSystem; | ||
| 484 | const baseDir = yield* fileSystem.makeTempDirectoryScoped({ | ||
| 485 | prefix: "t3-desktop-observability-test-", | ||
| 486 | }); | ||
| 487 | const environmentLayer = makeEnvironmentLayer(baseDir, true, { | ||
| 488 | T3CODE_OTLP_HEADERS: "x-scope=desktop", | ||
| 489 | }); | ||
| 490 | yield* writeObservabilitySettings(environmentLayer, { | ||
| 491 | otlpLogsUrl: "https://settings.example.com/v1/logs", | ||
| 492 | }); | ||
| 493 | |||
| 494 | yield* Effect.scoped( | ||
| 495 | Effect.logInfo("desktop otel off").pipe( | ||
| 496 | Effect.provide(DesktopObservability.layer.pipe(Layer.provideMerge(environmentLayer))), | ||
| 497 | ), | ||
| 498 | ); | ||
| 499 | |||
| 500 | assert.lengthOf(requests, 0); | ||
| 501 | }).pipe( | ||
| 502 | Effect.scoped, | ||
| 503 | Effect.provide( | ||
| 504 | Layer.mergeAll( | ||
| 505 | NodeServices.layer, | ||
| 506 | collectorLayer(requests), | ||
| 507 | ConfigProvider.layer( | ||
| 508 | ConfigProvider.fromEnv({ | ||
| 509 | env: { | ||
| 510 | OTEL_EXPORTER_OTLP_ENDPOINT: "https://collector.example.com", | ||
| 511 | OTEL_EXPORTER_OTLP_LOGS_PROTOCOL: "grpc", | ||
| 512 | }, | ||
| 513 | }), | ||
| 514 | ), | ||
| 515 | ), | ||
| 516 | ), | ||
| 428 | ); | 517 | ); |
| 429 | }); | 518 | }); |
| 430 | 519 | ||
| ... | @@ -495,7 +584,7 @@ describe("DesktopObservability", () => { | ... | @@ -495,7 +584,7 @@ describe("DesktopObservability", () => { |
| 495 | ); | 584 | ); |
| 496 | }).pipe( | 585 | }).pipe( |
| 497 | Effect.scoped, | 586 | Effect.scoped, |
| 498 | Effect.provide(Layer.mergeAll(NodeServices.layer, collectorLayer(requests))), | 587 | Effect.provide(Layer.mergeAll(NodeServices.layer, collectorLayer(requests), emptyEnv)), |
| 499 | ); | 588 | ); |
| 500 | }); | 589 | }); |
| 501 | 590 | ||
| ... | @@ -519,7 +608,7 @@ describe("DesktopObservability", () => { | ... | @@ -519,7 +608,7 @@ describe("DesktopObservability", () => { |
| 519 | assert.lengthOf(requests, 0); | 608 | assert.lengthOf(requests, 0); |
| 520 | }).pipe( | 609 | }).pipe( |
| 521 | Effect.scoped, | 610 | Effect.scoped, |
| 522 | Effect.provide(Layer.mergeAll(NodeServices.layer, collectorLayer(requests))), | 611 | Effect.provide(Layer.mergeAll(NodeServices.layer, collectorLayer(requests), emptyEnv)), |
| 523 | ); | 612 | ); |
| 524 | }); | 613 | }); |
| 525 | 614 |
apps/desktop/src/app/DesktopObservability.ts+45-19| ... | @@ -3,6 +3,7 @@ import { | ... | @@ -3,6 +3,7 @@ import { |
| 3 | makeLocalFileTracer, | 3 | makeLocalFileTracer, |
| 4 | makeTraceSink, | 4 | makeTraceSink, |
| 5 | otlpSerializationLayer, | 5 | otlpSerializationLayer, |
| 6 | type SignalExport, | ||
| 6 | } from "@t3tools/shared/observability"; | 7 | } from "@t3tools/shared/observability"; |
| 7 | import * as OtelEnvironment from "@t3tools/shared/otelEnvironment"; | 8 | import * as OtelEnvironment from "@t3tools/shared/otelEnvironment"; |
| 8 | import { | 9 | import { |
| ... | @@ -350,8 +351,10 @@ const readPersistedObservabilitySettings: Effect.Effect< | ... | @@ -350,8 +351,10 @@ const readPersistedObservabilitySettings: Effect.Effect< |
| 350 | }); | 351 | }); |
| 351 | 352 | ||
| 352 | /** | 353 | /** |
| 353 | * Settings is read once for every signal, so the main process cannot | 354 | * Resolved as the server resolves them, with persisted Settings as the |
| 354 | * resolve traces against one revision of the file and logs against another. | 355 | * fallback. Settings is read once for every signal, so the main process |
| 356 | * cannot resolve traces against one revision of the file and logs against | ||
| 357 | * another. | ||
| 355 | */ | 358 | */ |
| 356 | const resolveOtlpEndpoints = Effect.gen(function* () { | 359 | const resolveOtlpEndpoints = Effect.gen(function* () { |
| 357 | const otel = yield* OtelEnvironment.load; | 360 | const otel = yield* OtelEnvironment.load; |
| ... | @@ -367,10 +370,30 @@ const resolveOtlpEndpoints = Effect.gen(function* () { | ... | @@ -367,10 +370,30 @@ const resolveOtlpEndpoints = Effect.gen(function* () { |
| 367 | 370 | ||
| 368 | const environment = yield* DesktopEnvironment.DesktopEnvironment; | 371 | const environment = yield* DesktopEnvironment.DesktopEnvironment; |
| 369 | const persisted = yield* readPersistedObservabilitySettings; | 372 | const persisted = yield* readPersistedObservabilitySettings; |
| 373 | const signalExport: SignalExport = { | ||
| 374 | protocol: environment.otlpProtocol, | ||
| 375 | headers: Option.getOrUndefined(environment.otlpHeaders), | ||
| 376 | exportIntervalMs: environment.otlpExportIntervalMs, | ||
| 377 | }; | ||
| 370 | return { | 378 | return { |
| 371 | traces: Option.getOrUndefined(environment.otlpTracesUrl) ?? persisted.otlpTracesUrl, | 379 | traces: OtelEnvironment.resolveSignalEndpoint( |
| 372 | metrics: Option.getOrUndefined(environment.otlpMetricsUrl) ?? persisted.otlpMetricsUrl, | 380 | otel, |
| 373 | logs: Option.getOrUndefined(environment.otlpLogsUrl) ?? persisted.otlpLogsUrl, | 381 | "traces", |
| 382 | { url: Option.getOrUndefined(environment.otlpTracesUrl), export: signalExport }, | ||
| 383 | persisted.otlpTracesUrl, | ||
| 384 | ), | ||
| 385 | metrics: OtelEnvironment.resolveSignalEndpoint( | ||
| 386 | otel, | ||
| 387 | "metrics", | ||
| 388 | { url: Option.getOrUndefined(environment.otlpMetricsUrl), export: signalExport }, | ||
| 389 | persisted.otlpMetricsUrl, | ||
| 390 | ), | ||
| 391 | logs: OtelEnvironment.resolveSignalEndpoint( | ||
| 392 | otel, | ||
| 393 | "logs", | ||
| 394 | { url: Option.getOrUndefined(environment.otlpLogsUrl), export: signalExport }, | ||
| 395 | persisted.otlpLogsUrl, | ||
| 396 | ), | ||
| 374 | warnings: otel.warnings, | 397 | warnings: otel.warnings, |
| 375 | resourceAttributes: otel.resourceAttributes, | 398 | resourceAttributes: otel.resourceAttributes, |
| 376 | }; | 399 | }; |
| ... | @@ -602,8 +625,6 @@ const telemetryLayer = Layer.unwrap( | ... | @@ -602,8 +625,6 @@ const telemetryLayer = Layer.unwrap( |
| 602 | Effect.gen(function* () { | 625 | Effect.gen(function* () { |
| 603 | const environment = yield* DesktopEnvironment.DesktopEnvironment; | 626 | const environment = yield* DesktopEnvironment.DesktopEnvironment; |
| 604 | const endpoints = yield* resolveOtlpEndpoints; | 627 | const endpoints = yield* resolveOtlpEndpoints; |
| 605 | const headers = Option.getOrUndefined(environment.otlpHeaders); | ||
| 606 | const serializationLayer = otlpSerializationLayer(environment.otlpProtocol); | ||
| 607 | const resource = { | 628 | const resource = { |
| 608 | serviceName: "desktop", | 629 | serviceName: "desktop", |
| 609 | attributes: { | 630 | attributes: { |
| ... | @@ -629,14 +650,19 @@ const telemetryLayer = Layer.unwrap( | ... | @@ -629,14 +650,19 @@ const telemetryLayer = Layer.unwrap( |
| 629 | : [ | 650 | : [ |
| 630 | Logger.consolePretty(), | 651 | Logger.consolePretty(), |
| 631 | OtlpLogger.make({ | 652 | OtlpLogger.make({ |
| 632 | url: endpoints.logs, | 653 | url: endpoints.logs.url, |
| 633 | exportInterval: `${environment.otlpExportIntervalMs} millis`, | 654 | exportInterval: `${endpoints.logs.export.exportIntervalMs} millis`, |
| 634 | headers, | 655 | headers: endpoints.logs.export.headers, |
| 635 | resource, | 656 | resource, |
| 636 | }), | 657 | }), |
| 637 | ], | 658 | ], |
| 638 | { mergeWithExisting: false }, | 659 | { mergeWithExisting: false }, |
| 639 | ).pipe(Layer.provide(OtlpExporter.layerFlusher), Layer.provide(serializationLayer)); | 660 | ).pipe( |
| 661 | Layer.provide(OtlpExporter.layerFlusher), | ||
| 662 | Layer.provide( | ||
| 663 | otlpSerializationLayer(endpoints.logs?.export.protocol ?? environment.otlpProtocol), | ||
| 664 | ), | ||
| 665 | ); | ||
| 640 | 666 | ||
| 641 | const tracerLayer = Layer.unwrap( | 667 | const tracerLayer = Layer.unwrap( |
| 642 | Effect.gen(function* () { | 668 | Effect.gen(function* () { |
| ... | @@ -651,11 +677,11 @@ const telemetryLayer = Layer.unwrap( | ... | @@ -651,11 +677,11 @@ const telemetryLayer = Layer.unwrap( |
| 651 | endpoints.traces === undefined | 677 | endpoints.traces === undefined |
| 652 | ? undefined | 678 | ? undefined |
| 653 | : yield* OtlpTracer.make({ | 679 | : yield* OtlpTracer.make({ |
| 654 | url: endpoints.traces, | 680 | url: endpoints.traces.url, |
| 655 | exportInterval: `${environment.otlpExportIntervalMs} millis`, | 681 | exportInterval: `${endpoints.traces.export.exportIntervalMs} millis`, |
| 656 | headers, | 682 | headers: endpoints.traces.export.headers, |
| 657 | resource, | 683 | resource, |
| 658 | }).pipe(Effect.provide(serializationLayer)); | 684 | }).pipe(Effect.provide(otlpSerializationLayer(endpoints.traces.export.protocol))); |
| 659 | const tracer = yield* makeLocalFileTracer({ | 685 | const tracer = yield* makeLocalFileTracer({ |
| 660 | filePath: tracePath, | 686 | filePath: tracePath, |
| 661 | maxBytes: DESKTOP_LOG_FILE_MAX_BYTES, | 687 | maxBytes: DESKTOP_LOG_FILE_MAX_BYTES, |
| ... | @@ -679,11 +705,11 @@ const telemetryLayer = Layer.unwrap( | ... | @@ -679,11 +705,11 @@ const telemetryLayer = Layer.unwrap( |
| 679 | // endpoints.metrics === undefined | 705 | // endpoints.metrics === undefined |
| 680 | // ? Layer.empty | 706 | // ? Layer.empty |
| 681 | // : OtlpMetrics.layer({ | 707 | // : OtlpMetrics.layer({ |
| 682 | // url: endpoints.metrics, | 708 | // url: endpoints.metrics.url, |
| 683 | // exportInterval: `${environment.otlpExportIntervalMs} millis`, | 709 | // exportInterval: `${endpoints.metrics.export.exportIntervalMs} millis`, |
| 684 | // headers, | 710 | // headers: endpoints.metrics.export.headers, |
| 685 | // resource, | 711 | // resource, |
| 686 | // }).pipe(Layer.provide(serializationLayer)); | 712 | // }).pipe(Layer.provide(otlpSerializationLayer(endpoints.metrics.export.protocol))); |
| 687 | 713 | ||
| 688 | // Logged once the loggers above are installed, so the warnings use them. | 714 | // Logged once the loggers above are installed, so the warnings use them. |
| 689 | const otelWarningsLayer = Layer.effectDiscard( | 715 | const otelWarningsLayer = Layer.effectDiscard( |
apps/desktop/src/backend/DesktopBackendConfiguration.test.ts+73-3| ... | @@ -780,12 +780,11 @@ describe("DesktopBackendConfiguration", () => { | ... | @@ -780,12 +780,11 @@ describe("DesktopBackendConfiguration", () => { |
| 780 | const config = yield* configuration.resolveWsl({ port: 5050, distro: null }); | 780 | const config = yield* configuration.resolveWsl({ port: 5050, distro: null }); |
| 781 | 781 | ||
| 782 | // No settings.json exists here: the endpoints come from the desktop | 782 | // No settings.json exists here: the endpoints come from the desktop |
| 783 | // process's env, which a WSL child cannot inherit, so the bootstrap | 783 | // environment, and the bootstrap carries them for a WSL child that |
| 784 | // has to carry them or log export stays off inside the distro. | 784 | // lacks the variables. |
| 785 | assert.equal(config.bootstrap.otlpTracesUrl, "http://127.0.0.1:4318/v1/traces"); | 785 | assert.equal(config.bootstrap.otlpTracesUrl, "http://127.0.0.1:4318/v1/traces"); |
| 786 | assert.equal(config.bootstrap.otlpMetricsUrl, "http://127.0.0.1:4318/v1/metrics"); | 786 | assert.equal(config.bootstrap.otlpMetricsUrl, "http://127.0.0.1:4318/v1/metrics"); |
| 787 | assert.equal(config.bootstrap.otlpLogsUrl, "http://127.0.0.1:4318/v1/logs"); | 787 | assert.equal(config.bootstrap.otlpLogsUrl, "http://127.0.0.1:4318/v1/logs"); |
| 788 | assert.notInclude(config.env.WSLENV ?? "", "T3CODE_OTLP_LOGS_URL"); | ||
| 789 | }).pipe( | 788 | }).pipe( |
| 790 | Effect.provide( | 789 | Effect.provide( |
| 791 | DesktopBackendConfiguration.layer.pipe( | 790 | DesktopBackendConfiguration.layer.pipe( |
| ... | @@ -996,6 +995,73 @@ describe("DesktopBackendConfiguration", () => { | ... | @@ -996,6 +995,73 @@ describe("DesktopBackendConfiguration", () => { |
| 996 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), | 995 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), |
| 997 | ); | 996 | ); |
| 998 | 997 | ||
| 998 | it.effect( | ||
| 999 | "resolveWsl carries the standard OTLP endpoint, headers, and protocol into the distro", | ||
| 1000 | () => | ||
| 1001 | Effect.gen(function* () { | ||
| 1002 | const fileSystem = yield* FileSystem.FileSystem; | ||
| 1003 | const baseDir = yield* fileSystem.makeTempDirectoryScoped({ | ||
| 1004 | prefix: "t3-desktop-backend-config-test-", | ||
| 1005 | }); | ||
| 1006 | |||
| 1007 | const standard = { | ||
| 1008 | OTEL_EXPORTER_OTLP_ENDPOINT: "https://collector.example.com:4318/base?api_key=secret", | ||
| 1009 | OTEL_EXPORTER_OTLP_LOGS_HEADERS: "authorization=Bearer%20token", | ||
| 1010 | T3CODE_OTLP_TRACES_URL: "http://t3.example.com:4318/v1/traces", | ||
| 1011 | }; | ||
| 1012 | const previousWslEnv = process.env.WSLENV; | ||
| 1013 | // A developer's own OTLP variables would be forwarded too. | ||
| 1014 | const ambientOtel = Object.entries(process.env).filter( | ||
| 1015 | ([name]) => name.startsWith("OTEL_") || name.startsWith("T3CODE_OTLP_"), | ||
| 1016 | ); | ||
| 1017 | try { | ||
| 1018 | for (const [name] of ambientOtel) delete process.env[name]; | ||
| 1019 | delete process.env.WSLENV; | ||
| 1020 | Object.assign(process.env, standard); | ||
| 1021 | |||
| 1022 | yield* Effect.gen(function* () { | ||
| 1023 | const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration; | ||
| 1024 | const config = yield* configuration.resolveWsl({ port: 5050, distro: null }); | ||
| 1025 | |||
| 1026 | assert.equal( | ||
| 1027 | config.env.OTEL_EXPORTER_OTLP_ENDPOINT, | ||
| 1028 | "https://collector.example.com:4318/base?api_key=secret", | ||
| 1029 | ); | ||
| 1030 | assert.equal( | ||
| 1031 | config.env.OTEL_EXPORTER_OTLP_LOGS_HEADERS, | ||
| 1032 | "authorization=Bearer%20token", | ||
| 1033 | ); | ||
| 1034 | // Without a flag, WSL passes the values through untranslated. | ||
| 1035 | const wslEnv = (config.env.WSLENV ?? "").split(":"); | ||
| 1036 | assert.include(wslEnv, "OTEL_EXPORTER_OTLP_ENDPOINT"); | ||
| 1037 | assert.include(wslEnv, "OTEL_EXPORTER_OTLP_LOGS_HEADERS"); | ||
| 1038 | assert.equal(config.env.T3CODE_OTLP_TRACES_URL, "http://t3.example.com:4318/v1/traces"); | ||
| 1039 | assert.include(wslEnv, "T3CODE_OTLP_TRACES_URL"); | ||
| 1040 | }).pipe( | ||
| 1041 | Effect.provide( | ||
| 1042 | DesktopBackendConfiguration.layer.pipe( | ||
| 1043 | Layer.provideMerge(serverExposureLayer), | ||
| 1044 | Layer.provideMerge(DesktopAppSettings.layerTest()), | ||
| 1045 | Layer.provideMerge(DesktopWslServerTree.layerTest()), | ||
| 1046 | Layer.provideMerge( | ||
| 1047 | DesktopWslEnvironment.layerTest({ | ||
| 1048 | isAvailable: true, | ||
| 1049 | windowsToWslPath: () => Option.some("/mnt/c/repo/apps/server/src/index.ts"), | ||
| 1050 | getDistroIp: () => Option.some("172.27.0.99"), | ||
| 1051 | }), | ||
| 1052 | ), | ||
| 1053 | Layer.provideMerge(makeEnvironmentLayer(baseDir, { platform: "win32" })), | ||
| 1054 | ), | ||
| 1055 | ), | ||
| 1056 | ); | ||
| 1057 | } finally { | ||
| 1058 | for (const name of Object.keys(standard)) delete process.env[name]; | ||
| 1059 | restoreEnv("WSLENV", previousWslEnv); | ||
| 1060 | for (const [name, value] of ambientOtel) restoreEnv(name, value); | ||
| 1061 | } | ||
| 1062 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), | ||
| 1063 | ); | ||
| 1064 | |||
| 999 | it.effect("resolveWsl preserves existing WSLENV entries when forwarding backend secrets", () => | 1065 | it.effect("resolveWsl preserves existing WSLENV entries when forwarding backend secrets", () => |
| 1000 | Effect.gen(function* () { | 1066 | Effect.gen(function* () { |
| 1001 | const fileSystem = yield* FileSystem.FileSystem; | 1067 | const fileSystem = yield* FileSystem.FileSystem; |
| ... | @@ -1008,7 +1074,10 @@ describe("DesktopBackendConfiguration", () => { | ... | @@ -1008,7 +1074,10 @@ describe("DesktopBackendConfiguration", () => { |
| 1008 | const previousAnthropicKey = process.env.ANTHROPIC_API_KEY; | 1074 | const previousAnthropicKey = process.env.ANTHROPIC_API_KEY; |
| 1009 | const previousOtlpHeaders = process.env.T3CODE_OTLP_HEADERS; | 1075 | const previousOtlpHeaders = process.env.T3CODE_OTLP_HEADERS; |
| 1010 | const previousOtlpProtocol = process.env.T3CODE_OTLP_PROTOCOL; | 1076 | const previousOtlpProtocol = process.env.T3CODE_OTLP_PROTOCOL; |
| 1077 | // A developer's own OTEL_* variables would be forwarded too. | ||
| 1078 | const ambientOtel = Object.entries(process.env).filter(([name]) => name.startsWith("OTEL_")); | ||
| 1011 | try { | 1079 | try { |
| 1080 | for (const [name] of ambientOtel) delete process.env[name]; | ||
| 1012 | process.env.WSLENV = "GOPATH/p:OPENAI_API_KEY/u:EMPTY::AZURE_DEVOPS_EXT_PAT/u"; | 1081 | process.env.WSLENV = "GOPATH/p:OPENAI_API_KEY/u:EMPTY::AZURE_DEVOPS_EXT_PAT/u"; |
| 1013 | process.env.OPENAI_API_KEY = "openai-key"; | 1082 | process.env.OPENAI_API_KEY = "openai-key"; |
| 1014 | process.env.ANTHROPIC_API_KEY = "anthropic-key"; | 1083 | process.env.ANTHROPIC_API_KEY = "anthropic-key"; |
| ... | @@ -1065,6 +1134,7 @@ describe("DesktopBackendConfiguration", () => { | ... | @@ -1065,6 +1134,7 @@ describe("DesktopBackendConfiguration", () => { |
| 1065 | restoreEnv("ANTHROPIC_API_KEY", previousAnthropicKey); | 1134 | restoreEnv("ANTHROPIC_API_KEY", previousAnthropicKey); |
| 1066 | restoreEnv("T3CODE_OTLP_HEADERS", previousOtlpHeaders); | 1135 | restoreEnv("T3CODE_OTLP_HEADERS", previousOtlpHeaders); |
| 1067 | restoreEnv("T3CODE_OTLP_PROTOCOL", previousOtlpProtocol); | 1136 | restoreEnv("T3CODE_OTLP_PROTOCOL", previousOtlpProtocol); |
| 1137 | for (const [name, value] of ambientOtel) restoreEnv(name, value); | ||
| 1068 | } | 1138 | } |
| 1069 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), | 1139 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), |
| 1070 | ); | 1140 | ); |
apps/desktop/src/backend/DesktopBackendConfiguration.ts+27-13| ... | @@ -90,9 +90,8 @@ const DESKTOP_BACKEND_ENV_NAMES = [ | ... | @@ -90,9 +90,8 @@ const DESKTOP_BACKEND_ENV_NAMES = [ |
| 90 | ] as const; | 90 | ] as const; |
| 91 | 91 | ||
| 92 | // Env vars that the WSL backend needs but Windows process.env won't forward | 92 | // Env vars that the WSL backend needs but Windows process.env won't forward |
| 93 | // across the wsl.exe boundary without WSLENV. The dev-server URL is handled | 93 | // across the wsl.exe boundary without WSLENV. The dev-server URL travels as |
| 94 | // separately via a `--dev-url` CLI flag because WSLENV translation of | 94 | // the `--dev-url` CLI flag instead. |
| 95 | // URL-shaped values (colons / slashes) is unreliable. | ||
| 96 | const WSL_FORWARDED_ENV_NAMES = [ | 95 | const WSL_FORWARDED_ENV_NAMES = [ |
| 97 | "OPENAI_API_KEY", | 96 | "OPENAI_API_KEY", |
| 98 | "ANTHROPIC_API_KEY", | 97 | "ANTHROPIC_API_KEY", |
| ... | @@ -101,6 +100,24 @@ const WSL_FORWARDED_ENV_NAMES = [ | ... | @@ -101,6 +100,24 @@ const WSL_FORWARDED_ENV_NAMES = [ |
| 101 | "OTEL_SDK_DISABLED", | 100 | "OTEL_SDK_DISABLED", |
| 102 | "T3CODE_OTLP_HEADERS", | 101 | "T3CODE_OTLP_HEADERS", |
| 103 | "T3CODE_OTLP_PROTOCOL", | 102 | "T3CODE_OTLP_PROTOCOL", |
| 103 | // Forwarded without a WSLENV flag, so the values arrive untranslated. The | ||
| 104 | // server prefers an OTEL endpoint over the bootstrap envelope, so the T3 URLs | ||
| 105 | // travel as variables to keep winning inside the distro as they do on Windows. | ||
| 106 | "T3CODE_OTLP_TRACES_URL", | ||
| 107 | "T3CODE_OTLP_METRICS_URL", | ||
| 108 | "T3CODE_OTLP_LOGS_URL", | ||
| 109 | "OTEL_EXPORTER_OTLP_ENDPOINT", | ||
| 110 | "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", | ||
| 111 | "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", | ||
| 112 | "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT", | ||
| 113 | "OTEL_EXPORTER_OTLP_HEADERS", | ||
| 114 | "OTEL_EXPORTER_OTLP_TRACES_HEADERS", | ||
| 115 | "OTEL_EXPORTER_OTLP_METRICS_HEADERS", | ||
| 116 | "OTEL_EXPORTER_OTLP_LOGS_HEADERS", | ||
| 117 | "OTEL_EXPORTER_OTLP_PROTOCOL", | ||
| 118 | "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", | ||
| 119 | "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL", | ||
| 120 | "OTEL_EXPORTER_OTLP_LOGS_PROTOCOL", | ||
| 104 | ] as const; | 121 | ] as const; |
| 105 | 122 | ||
| 106 | const WSL_SERVER_SYSTEM_PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"; | 123 | const WSL_SERVER_SYSTEM_PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"; |
| ... | @@ -221,12 +238,11 @@ const readPersistedBackendObservabilitySettings = Effect.gen(function* () { | ... | @@ -221,12 +238,11 @@ const readPersistedBackendObservabilitySettings = Effect.gen(function* () { |
| 221 | }; | 238 | }; |
| 222 | }); | 239 | }); |
| 223 | 240 | ||
| 224 | // The bootstrap is the only channel that carries an OTLP endpoint to every | 241 | // The bootstrap carries the OTLP endpoints to every backend, including a WSL |
| 225 | // backend. A Windows-native child inherits the desktop process's env, but a | 242 | // child that lacks the variables. The T3 URLs also travel as variables in |
| 226 | // WSL child gets nothing across wsl.exe that WSLENV does not declare, and | 243 | // WSL_FORWARDED_ENV_NAMES so they outrank a forwarded OTEL endpoint. Env beats |
| 227 | // WSLENV translation of URL-shaped values is unreliable, so the endpoints are | 244 | // the persisted settings file, matching the precedence resolveServerConfig and |
| 228 | // deliberately not forwarded that way. Env beats the persisted settings file, | 245 | // DesktopObservability apply. |
| 229 | // matching the precedence resolveServerConfig and DesktopObservability apply. | ||
| 230 | const readBackendObservabilitySettings = Effect.gen(function* () { | 246 | const readBackendObservabilitySettings = Effect.gen(function* () { |
| 231 | const environment = yield* DesktopEnvironment.DesktopEnvironment; | 247 | const environment = yield* DesktopEnvironment.DesktopEnvironment; |
| 232 | const persisted = yield* readPersistedBackendObservabilitySettings; | 248 | const persisted = yield* readPersistedBackendObservabilitySettings; |
| ... | @@ -742,10 +758,8 @@ const resolveWslStartConfig = Effect.fn("desktop.backendConfiguration.resolveWsl | ... | @@ -742,10 +758,8 @@ const resolveWslStartConfig = Effect.fn("desktop.backendConfiguration.resolveWsl |
| 742 | }; | 758 | }; |
| 743 | 759 | ||
| 744 | // Forward the dev-server URL as an explicit CLI flag so the WSL backend's | 760 | // Forward the dev-server URL as an explicit CLI flag so the WSL backend's |
| 745 | // config resolution lands in dev/ instead of userdata/. Inheriting through | 761 | // config resolution lands in dev/ instead of userdata/. The packaged build |
| 746 | // WSLENV is unreliable in practice (URL-shaped values with colons / | 762 | // leaves devServerUrl as None. |
| 747 | // slashes get translated unpredictably depending on flags), and the | ||
| 748 | // packaged build leaves devServerUrl as None anyway. | ||
| 749 | const devUrlArgs = Option.match(environment.devServerUrl, { | 763 | const devUrlArgs = Option.match(environment.devServerUrl, { |
| 750 | onNone: () => [] as ReadonlyArray<string>, | 764 | onNone: () => [] as ReadonlyArray<string>, |
| 751 | onSome: (url) => ["--dev-url", url.href], | 765 | onSome: (url) => ["--dev-url", url.href], |
docs/operations/observability.md+12-11| ... | @@ -552,17 +552,18 @@ OTLP export: | ... | @@ -552,17 +552,18 @@ OTLP export: |
| 552 | `OTEL_EXPORTER_OTLP_HEADERS`: comma-separated `key=value` pairs with percent-encoded values. | 552 | `OTEL_EXPORTER_OTLP_HEADERS`: comma-separated `key=value` pairs with percent-encoded values. |
| 553 | - `T3CODE_OTLP_PROTOCOL`: `http/json` (default) or `http/protobuf` | 553 | - `T3CODE_OTLP_PROTOCOL`: `http/json` (default) or `http/protobuf` |
| 554 | 554 | ||
| 555 | The server also reads the standard `OTEL_EXPORTER_OTLP_{TRACES,METRICS,LOGS}_ENDPOINT` and generic | 555 | The server and the desktop app also read the standard |
| 556 | `OTEL_EXPORTER_OTLP_ENDPOINT` (with `/v1/traces`, `/v1/metrics`, or `/v1/logs` appended), for a | 556 | `OTEL_EXPORTER_OTLP_{TRACES,METRICS,LOGS}_ENDPOINT` and generic `OTEL_EXPORTER_OTLP_ENDPOINT` (with |
| 557 | collector expecting those instead. A non-blank `T3CODE_OTLP_*_URL` wins over either, and a | 557 | `/v1/traces`, `/v1/metrics`, or `/v1/logs` appended), for a collector expecting those instead. A |
| 558 | per-signal endpoint wins over the generic one for its signal. A blank value counts as unset. A | 558 | non-blank `T3CODE_OTLP_*_URL` wins over either, and a per-signal endpoint wins over the generic one |
| 559 | signal with an OTEL endpoint takes its headers from `OTEL_EXPORTER_OTLP_HEADERS` and its protocol | 559 | for its signal. A blank value counts as unset. A signal with an OTEL endpoint takes its headers from |
| 560 | from `OTEL_EXPORTER_OTLP_PROTOCOL` (default `http/protobuf`, read case-insensitively), and a | 560 | `OTEL_EXPORTER_OTLP_HEADERS` and its protocol from `OTEL_EXPORTER_OTLP_PROTOCOL` (default |
| 561 | per-signal `OTEL_EXPORTER_OTLP_{TRACES,METRICS,LOGS}_HEADERS` or `_PROTOCOL` wins over the generic | 561 | `http/protobuf`, read case-insensitively), and a per-signal |
| 562 | one for its signal. `T3CODE_OTLP_HEADERS` and `T3CODE_OTLP_PROTOCOL` never apply to it. An endpoint | 562 | `OTEL_EXPORTER_OTLP_{TRACES,METRICS,LOGS}_HEADERS` or `_PROTOCOL` wins over the generic one for its |
| 563 | that is not an `http` or `https` URL, a protocol other than `http/protobuf` or `http/json` such as | 563 | signal. `T3CODE_OTLP_HEADERS` and `T3CODE_OTLP_PROTOCOL` never apply to it. An endpoint that is not |
| 564 | `grpc`, or headers that are not `key=value` pairs with percent-encoded values turn that signal's | 564 | an `http` or `https` URL, a protocol other than `http/protobuf` or `http/json` such as `grpc`, or |
| 565 | export off with a startup warning, rather than sending it to the Settings endpoint. | 565 | headers that are not `key=value` pairs with percent-encoded values turn that signal's export off |
| 566 | with a startup warning, rather than sending it to the Settings endpoint. | ||
| 566 | 567 | ||
| 567 | If the OTLP URLs are unset, local tracing still works, metrics stay in-process only, and logs stay | 568 | If the OTLP URLs are unset, local tracing still works, metrics stay in-process only, and logs stay |
| 568 | on stdout only. | 569 | on stdout only. |