Wire telemetry in main and store anonymous ID in state dir
- move `AnalyticsServiceLayerLive` from CLI runtime setup into `main` server layer - persist telemetry `anonymous-id` under configured `stateDir` instead of home directory - add `FetchHttpClient.layer` to `main.test.ts` test layer wiring
This commit is contained in:
1 parent
d5d88270f0
commit
477b4f9d0e
4 files changed
+7
-3
No files matched your search
@@ -9,12 +9,10 @@ import { Command } from "effect/unstable/cli";
|
||||
import { version } from "../package.json" with { type: "json" };
|
||||
import { ServerLive } from "./wsServer";
|
||||
import { NetService } from "@t3tools/shared/Net";
|
||||
import { AnalyticsServiceLayerLive } from "./telemetry/Layers/AnalyticsService";
|
||||
import { FetchHttpClient } from "effect/unstable/http";
|
||||
|
||||
const RuntimeLayer = Layer.empty.pipe(
|
||||
Layer.provideMerge(CliConfig.layer),
|
||||
Layer.provideMerge(AnalyticsServiceLayerLive),
|
||||
Layer.provideMerge(ServerLive),
|
||||
Layer.provideMerge(OpenLive),
|
||||
Layer.provideMerge(NetService.layer),
|
||||
|
||||
@@ -5,6 +5,7 @@ import * as ConfigProvider from "effect/ConfigProvider";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Command from "effect/unstable/cli/Command";
|
||||
import { FetchHttpClient } from "effect/unstable/http";
|
||||
import { beforeEach } from "vitest";
|
||||
import { NetService } from "@t3tools/shared/Net";
|
||||
|
||||
@@ -52,6 +53,7 @@ const testLayer = Layer.mergeAll(
|
||||
record: () => Effect.void,
|
||||
flush: Effect.void,
|
||||
}),
|
||||
FetchHttpClient.layer,
|
||||
NodeServices.layer,
|
||||
);
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import { makeServerProviderLayer, makeServerRuntimeServicesLayer } from "./serve
|
||||
import { ProviderHealthLive } from "./provider/Layers/ProviderHealth";
|
||||
import { Server } from "./wsServer";
|
||||
import { ServerLoggerLive } from "./serverLogger";
|
||||
import { AnalyticsServiceLayerLive } from "./telemetry/Layers/AnalyticsService";
|
||||
|
||||
export class StartupError extends Data.TaggedError("StartupError")<{
|
||||
readonly message: string;
|
||||
@@ -197,6 +198,7 @@ const LayerLive = (input: CliInput) =>
|
||||
Layer.provideMerge(ProviderHealthLive),
|
||||
Layer.provideMerge(SqlitePersistence.layerConfig),
|
||||
Layer.provideMerge(ServerLoggerLive),
|
||||
Layer.provideMerge(AnalyticsServiceLayerLive),
|
||||
Layer.provideMerge(ServerConfigLive(input)),
|
||||
);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Effect, FileSystem, Path, Random, Schema } from "effect";
|
||||
import * as Crypto from "node:crypto";
|
||||
import { homedir } from "node:os";
|
||||
import { ServerConfig } from "../config";
|
||||
|
||||
const CodexAuthJsonSchema = Schema.Struct({
|
||||
tokens: Schema.Struct({
|
||||
@@ -39,8 +40,9 @@ const getCodexAccountId = Effect.gen(function* () {
|
||||
const upsertAnonymousId = Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const serverConfig = yield* ServerConfig;
|
||||
|
||||
const anonymousIdPath = path.join(homedir(), ".t3", "telemetry", "anonymous-id");
|
||||
const anonymousIdPath = path.join(serverConfig.stateDir, "anonymous-id");
|
||||
const anonymousId = yield* fileSystem.readFileString(anonymousIdPath).pipe(
|
||||
Effect.catch(() =>
|
||||
Effect.gen(function* () {
|
||||
|
||||
Reference in new issue
Block a user