Skip to content

Commit 527fbda

Browse files
committed
add tracing
1 parent 1aedac6 commit 527fbda

File tree

8 files changed

+98
-22
lines changed

8 files changed

+98
-22
lines changed

apps/server-new/.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ PRIVY_APP_SECRET=your_privy_app_secret
1010

1111
# Hypergraph Configuration
1212
HYPERGRAPH_CHAIN=geo-testnet
13-
HYPERGRAPH_RPC_URL=
13+
HYPERGRAPH_RPC_URL=
14+
15+
# Honeycomb Configuration
16+
HONEYCOMB_API_KEY=

apps/server-new/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"prebuild": "prisma generate"
1717
},
1818
"dependencies": {
19+
"@effect/opentelemetry": "^0.56.0",
1920
"@effect/platform": "^0.90.0",
2021
"@effect/platform-node": "^0.94.0",
2122
"@graphprotocol/hypergraph": "workspace:*",
@@ -28,8 +29,8 @@
2829
"@types/cors": "^2.8.17",
2930
"@types/node": "^24.1.0",
3031
"prisma": "^6.7.0",
31-
"tsx": "^4.19.0",
3232
"tsup": "^8.4.0",
33+
"tsx": "^4.19.0",
3334
"typescript": "^5.8.3",
3435
"vitest": "^3.2.4"
3536
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Config } from 'effect';
2+
3+
/**
4+
* Honeycomb configuration
5+
*/
6+
export const honeycombApiKeyConfig = Config.redacted('HONEYCOMB_API_KEY').pipe(Config.option);

apps/server-new/src/config/privy.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Config, Effect } from 'effect';
2-
import { PrivyConfigError } from '../http/errors.js';
1+
import { Config } from 'effect';
32

43
/**
54
* Privy configuration
@@ -10,16 +9,7 @@ export const privyAppSecretConfig = Config.redacted('PRIVY_APP_SECRET');
109
/**
1110
* Load and validate Privy configuration
1211
*/
13-
export const privyConfig = Effect.fn(function* () {
14-
const appId = yield* privyAppIdConfig;
15-
const appSecret = yield* privyAppSecretConfig;
16-
17-
if (!appId || !appSecret) {
18-
return yield* Effect.fail(new PrivyConfigError({ message: 'Missing Privy configuration' }));
19-
}
20-
21-
return {
22-
appId,
23-
appSecret,
24-
};
12+
export const privyConfig = Config.all({
13+
appId: privyAppIdConfig,
14+
appSecret: privyAppSecretConfig,
2515
});

apps/server-new/src/http/handlers.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,15 @@ const ConnectGroupLive = HttpApiBuilder.group(Api.hypergraphApi, 'Connect', (han
8080
*/
8181
const IdentityGroupLive = HttpApiBuilder.group(Api.hypergraphApi, 'Identity', (handlers) => {
8282
return handlers
83-
.handle('getWhoami', () => Effect.succeed('Hypergraph Server v2'))
83+
.handle(
84+
'getWhoami',
85+
Effect.fn(function* () {
86+
yield* Effect.log('Getting whoami');
87+
yield* Effect.sleep('1 second').pipe(Effect.withSpan('sleeping'));
88+
yield* Effect.sleep('2 second').pipe(Effect.withSpan('sleeping again'));
89+
return 'Hypergraph Server v3';
90+
}),
91+
)
8492
.handle(
8593
'getConnectIdentity',
8694
Effect.fn(function* ({ urlParams }) {

apps/server-new/src/index.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
1-
import { NodeRuntime } from '@effect/platform-node';
2-
import { Layer } from 'effect';
1+
import * as Otlp from '@effect/opentelemetry/Otlp';
2+
import { FetchHttpClient, PlatformConfigProvider } from '@effect/platform';
3+
import { NodeContext, NodeRuntime } from '@effect/platform-node';
4+
import { Effect, Layer, Logger, Option, Redacted } from 'effect';
5+
import * as Config from './config/honeycomb.ts';
36
import { server } from './server.ts';
47

5-
NodeRuntime.runMain(Layer.launch(server));
8+
const Observability = Layer.unwrapEffect(
9+
Effect.gen(function* () {
10+
const apiKey = yield* Config.honeycombApiKeyConfig;
11+
if (Option.isNone(apiKey)) {
12+
return Layer.empty;
13+
}
14+
15+
return Otlp.layer({
16+
baseUrl: 'https://api.honeycomb.io',
17+
headers: {
18+
'x-honeycomb-team': Redacted.value(apiKey.value),
19+
},
20+
resource: {
21+
serviceName: 'hypergraph-server',
22+
},
23+
}).pipe(Layer.provide(FetchHttpClient.layer));
24+
}),
25+
);
26+
27+
const layer = server.pipe(
28+
Layer.provide(Logger.structured),
29+
Layer.provide(Observability),
30+
Layer.provide(PlatformConfigProvider.layerDotEnvAdd('.env')),
31+
Layer.provide(NodeContext.layer),
32+
);
33+
34+
NodeRuntime.runMain(Layer.launch(layer), {
35+
disablePrettyLogger: true,
36+
});

apps/server-new/src/services/auth.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ export const AuthService = Context.GenericTag<AuthService>('AuthService');
2020
* Auth service implementation
2121
*/
2222
export const makeAuthService = Effect.fn(function* () {
23-
const config = yield* Config.privyConfig();
24-
23+
const config = yield* Config.privyConfig;
2524
const privy = new PrivyClient(config.appId, Redacted.value(config.appSecret));
2625

2726
const verifyAuthToken = Effect.fn(function* (token: string) {

pnpm-lock.yaml

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)