Skip to content

Commit ef1c71c

Browse files
authored
Merge branch 'main' into fix/opencode-v2-serve-ready-line
2 parents 7ed1560 + 6530de0 commit ef1c71c

112 files changed

Lines changed: 2913 additions & 372 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/triage/PLAYBOOK.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ different code depending on it:
5959

6060
Then work from evidence, not assumption. In rough order of value:
6161

62-
- The server log and the trace file (`server.trace.ndjson`) around the time of the
63-
problem. Recent failures usually leave a trail here.
62+
- The trace file (`server.trace.ndjson`) around the time of the problem, plus the
63+
service log or desktop backend logs from the context file if they exist. Recent
64+
failures usually leave a trail here.
6465
- The provider event log, for problems with claude/codex/cursor sessions.
6566
- The SQLite database. Read it freely, but only write when a write is necessary
6667
to fix the problem the user described, and get their explicit permission

‎apps/desktop/src/app/DesktopObservability.test.ts‎

Lines changed: 140 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ const collectorLayer = (requests: Array<ExportedRequest>) =>
9393
),
9494
);
9595

96+
// A developer's own OTEL_* variables would otherwise pick the endpoints.
97+
const emptyEnv = ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} }));
98+
9699
const encodeObservabilitySettingsFile = Schema.encodeSync(
97100
Schema.fromJsonString(
98101
Schema.Struct({ observability: Schema.Record(Schema.String, Schema.String) }),
@@ -182,7 +185,7 @@ describe("DesktopObservability", () => {
182185
assert.isFalse(yield* fileSystem.exists(logPath));
183186
}).pipe(
184187
Effect.scoped,
185-
Effect.provide(Layer.mergeAll(NodeServices.layer, NodeHttpClient.layerUndici)),
188+
Effect.provide(Layer.mergeAll(NodeServices.layer, NodeHttpClient.layerUndici, emptyEnv)),
186189
),
187190
);
188191

@@ -260,7 +263,7 @@ describe("DesktopObservability", () => {
260263
);
261264
}).pipe(
262265
Effect.scoped,
263-
Effect.provide(Layer.mergeAll(NodeServices.layer, NodeHttpClient.layerUndici)),
266+
Effect.provide(Layer.mergeAll(NodeServices.layer, NodeHttpClient.layerUndici, emptyEnv)),
264267
),
265268
);
266269

@@ -300,7 +303,7 @@ describe("DesktopObservability", () => {
300303
assert.equal(records.at(-1)?.annotations.details, "code=1");
301304
}).pipe(
302305
Effect.scoped,
303-
Effect.provide(Layer.mergeAll(NodeServices.layer, NodeHttpClient.layerUndici)),
306+
Effect.provide(Layer.mergeAll(NodeServices.layer, NodeHttpClient.layerUndici, emptyEnv)),
304307
),
305308
);
306309

@@ -344,7 +347,7 @@ describe("DesktopObservability", () => {
344347
assert.isFalse(text.includes("y"));
345348
}).pipe(
346349
Effect.scoped,
347-
Effect.provide(Layer.mergeAll(NodeServices.layer, NodeHttpClient.layerUndici)),
350+
Effect.provide(Layer.mergeAll(NodeServices.layer, NodeHttpClient.layerUndici, emptyEnv)),
348351
),
349352
);
350353

@@ -378,7 +381,7 @@ describe("DesktopObservability", () => {
378381
assert.equal(lines.length, 258);
379382
}).pipe(
380383
Effect.scoped,
381-
Effect.provide(Layer.mergeAll(NodeServices.layer, NodeHttpClient.layerUndici)),
384+
Effect.provide(Layer.mergeAll(NodeServices.layer, NodeHttpClient.layerUndici, emptyEnv)),
382385
),
383386
);
384387

@@ -424,7 +427,136 @@ describe("DesktopObservability", () => {
424427
assert.lengthOf(record?.events ?? [], 0);
425428
}).pipe(
426429
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("keeps its service name while OTEL resource attributes add dimensions", () => {
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_LOGS_URL: "https://collector.example.com/v1/logs",
489+
});
490+
491+
yield* Effect.scoped(
492+
Effect.logInfo("desktop service name").pipe(
493+
Effect.provide(DesktopObservability.layer.pipe(Layer.provideMerge(environmentLayer))),
494+
),
495+
);
496+
497+
assert.lengthOf(requests, 1);
498+
const body = requests[0]?.body ?? "";
499+
assert.include(body, '"stringValue":"t3code-desktop"');
500+
assert.include(body, "deployment.environment.name");
501+
assert.include(body, '"key":"service.namespace","value":{"stringValue":"t3code"}');
502+
assert.notInclude(body, "renamed");
503+
}).pipe(
504+
Effect.scoped,
505+
Effect.provide(
506+
Layer.mergeAll(
507+
NodeServices.layer,
508+
collectorLayer(requests),
509+
ConfigProvider.layer(
510+
ConfigProvider.fromEnv({
511+
env: {
512+
OTEL_SERVICE_NAME: "renamed",
513+
OTEL_RESOURCE_ATTRIBUTES:
514+
"service.name=renamed,service.namespace=renamed,deployment.environment.name=development",
515+
},
516+
}),
517+
),
518+
),
519+
),
520+
);
521+
});
522+
523+
it.effect("exports nothing to Settings for logs an unusable OTEL endpoint claimed", () => {
524+
const requests: Array<ExportedRequest> = [];
525+
return Effect.gen(function* () {
526+
const fileSystem = yield* FileSystem.FileSystem;
527+
const baseDir = yield* fileSystem.makeTempDirectoryScoped({
528+
prefix: "t3-desktop-observability-test-",
529+
});
530+
const environmentLayer = makeEnvironmentLayer(baseDir, true, {
531+
T3CODE_OTLP_HEADERS: "x-scope=desktop",
532+
});
533+
yield* writeObservabilitySettings(environmentLayer, {
534+
otlpLogsUrl: "https://settings.example.com/v1/logs",
535+
});
536+
537+
yield* Effect.scoped(
538+
Effect.logInfo("desktop otel off").pipe(
539+
Effect.provide(DesktopObservability.layer.pipe(Layer.provideMerge(environmentLayer))),
540+
),
541+
);
542+
543+
assert.lengthOf(requests, 0);
544+
}).pipe(
545+
Effect.scoped,
546+
Effect.provide(
547+
Layer.mergeAll(
548+
NodeServices.layer,
549+
collectorLayer(requests),
550+
ConfigProvider.layer(
551+
ConfigProvider.fromEnv({
552+
env: {
553+
OTEL_EXPORTER_OTLP_ENDPOINT: "https://collector.example.com",
554+
OTEL_EXPORTER_OTLP_LOGS_PROTOCOL: "grpc",
555+
},
556+
}),
557+
),
558+
),
559+
),
428560
);
429561
});
430562

@@ -495,7 +627,7 @@ describe("DesktopObservability", () => {
495627
);
496628
}).pipe(
497629
Effect.scoped,
498-
Effect.provide(Layer.mergeAll(NodeServices.layer, collectorLayer(requests))),
630+
Effect.provide(Layer.mergeAll(NodeServices.layer, collectorLayer(requests), emptyEnv)),
499631
);
500632
});
501633

@@ -519,7 +651,7 @@ describe("DesktopObservability", () => {
519651
assert.lengthOf(requests, 0);
520652
}).pipe(
521653
Effect.scoped,
522-
Effect.provide(Layer.mergeAll(NodeServices.layer, collectorLayer(requests))),
654+
Effect.provide(Layer.mergeAll(NodeServices.layer, collectorLayer(requests), emptyEnv)),
523655
);
524656
});
525657

‎apps/desktop/src/app/DesktopObservability.ts‎

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
makeLocalFileTracer,
44
makeTraceSink,
55
otlpSerializationLayer,
6+
type SignalExport,
67
} from "@t3tools/shared/observability";
78
import * as OtelEnvironment from "@t3tools/shared/otelEnvironment";
89
import {
@@ -350,8 +351,10 @@ const readPersistedObservabilitySettings: Effect.Effect<
350351
});
351352

352353
/**
353-
* Settings is read once for every signal, so the main process cannot
354-
* resolve traces against one revision of the file and logs against another.
354+
* Resolved as the server resolves them, with persisted Settings as the
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.
355358
*/
356359
const resolveOtlpEndpoints = Effect.gen(function* () {
357360
const otel = yield* OtelEnvironment.load;
@@ -367,10 +370,30 @@ const resolveOtlpEndpoints = Effect.gen(function* () {
367370

368371
const environment = yield* DesktopEnvironment.DesktopEnvironment;
369372
const persisted = yield* readPersistedObservabilitySettings;
373+
const signalExport: SignalExport = {
374+
protocol: environment.otlpProtocol,
375+
headers: Option.getOrUndefined(environment.otlpHeaders),
376+
exportIntervalMs: environment.otlpExportIntervalMs,
377+
};
370378
return {
371-
traces: Option.getOrUndefined(environment.otlpTracesUrl) ?? persisted.otlpTracesUrl,
372-
metrics: Option.getOrUndefined(environment.otlpMetricsUrl) ?? persisted.otlpMetricsUrl,
373-
logs: Option.getOrUndefined(environment.otlpLogsUrl) ?? persisted.otlpLogsUrl,
379+
traces: OtelEnvironment.resolveSignalEndpoint(
380+
otel,
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+
),
374397
warnings: otel.warnings,
375398
resourceAttributes: otel.resourceAttributes,
376399
};
@@ -602,11 +625,10 @@ const telemetryLayer = Layer.unwrap(
602625
Effect.gen(function* () {
603626
const environment = yield* DesktopEnvironment.DesktopEnvironment;
604627
const endpoints = yield* resolveOtlpEndpoints;
605-
const headers = Option.getOrUndefined(environment.otlpHeaders);
606-
const serializationLayer = otlpSerializationLayer(environment.otlpProtocol);
607628
const resource = {
608-
serviceName: "desktop",
629+
serviceName: "t3code-desktop",
609630
attributes: {
631+
"service.namespace": "t3code",
610632
"service.runtime": "desktop",
611633
"service.mode": environment.isDevelopment ? "development" : "packaged",
612634
},
@@ -629,14 +651,19 @@ const telemetryLayer = Layer.unwrap(
629651
: [
630652
Logger.consolePretty(),
631653
OtlpLogger.make({
632-
url: endpoints.logs,
633-
exportInterval: `${environment.otlpExportIntervalMs} millis`,
634-
headers,
654+
url: endpoints.logs.url,
655+
exportInterval: `${endpoints.logs.export.exportIntervalMs} millis`,
656+
headers: endpoints.logs.export.headers,
635657
resource,
636658
}),
637659
],
638660
{ mergeWithExisting: false },
639-
).pipe(Layer.provide(OtlpExporter.layerFlusher), Layer.provide(serializationLayer));
661+
).pipe(
662+
Layer.provide(OtlpExporter.layerFlusher),
663+
Layer.provide(
664+
otlpSerializationLayer(endpoints.logs?.export.protocol ?? environment.otlpProtocol),
665+
),
666+
);
640667

641668
const tracerLayer = Layer.unwrap(
642669
Effect.gen(function* () {
@@ -651,11 +678,11 @@ const telemetryLayer = Layer.unwrap(
651678
endpoints.traces === undefined
652679
? undefined
653680
: yield* OtlpTracer.make({
654-
url: endpoints.traces,
655-
exportInterval: `${environment.otlpExportIntervalMs} millis`,
656-
headers,
681+
url: endpoints.traces.url,
682+
exportInterval: `${endpoints.traces.export.exportIntervalMs} millis`,
683+
headers: endpoints.traces.export.headers,
657684
resource,
658-
}).pipe(Effect.provide(serializationLayer));
685+
}).pipe(Effect.provide(otlpSerializationLayer(endpoints.traces.export.protocol)));
659686
const tracer = yield* makeLocalFileTracer({
660687
filePath: tracePath,
661688
maxBytes: DESKTOP_LOG_FILE_MAX_BYTES,
@@ -679,11 +706,11 @@ const telemetryLayer = Layer.unwrap(
679706
// endpoints.metrics === undefined
680707
// ? Layer.empty
681708
// : OtlpMetrics.layer({
682-
// url: endpoints.metrics,
683-
// exportInterval: `${environment.otlpExportIntervalMs} millis`,
684-
// headers,
709+
// url: endpoints.metrics.url,
710+
// exportInterval: `${endpoints.metrics.export.exportIntervalMs} millis`,
711+
// headers: endpoints.metrics.export.headers,
685712
// resource,
686-
// }).pipe(Layer.provide(serializationLayer));
713+
// }).pipe(Layer.provide(otlpSerializationLayer(endpoints.metrics.export.protocol)));
687714

688715
// Logged once the loggers above are installed, so the warnings use them.
689716
const otelWarningsLayer = Layer.effectDiscard(

0 commit comments

Comments
 (0)