Skip to content

Commit

Permalink
chore: add dd-trace (#190)
Browse files Browse the repository at this point in the history
## Motivation

We're collecting logs, but we'd like better observability for the relay
using dd-trace.

## Change Summary

Configure and enable Datadog tracing for the auth relay.

## Merge Checklist

_Choose all relevant options below by adding an `x` now or at any time
before submitting for review_

- [x] PR title adheres to the [conventional
commits](https://www.conventionalcommits.org/en/v1.0.0/) standard
- [x] PR has a changeset
- [x] PR has been tagged with a change label(s) (i.e. documentation,
feature, bugfix, or chore)
- [x] PR includes documentation if necessary
- [x] All commits have been signed
  • Loading branch information
horsefacts committed Aug 14, 2024
1 parent fb16a2c commit c4b36cf
Show file tree
Hide file tree
Showing 7 changed files with 376 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-laws-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@farcaster/auth-relay": minor
---

chore: add dd-trace
1 change: 1 addition & 0 deletions apps/relay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@fastify/cors": "^8.4.2",
"@fastify/rate-limit": "^9.0.1",
"axios": "^1.7.4",
"dd-trace": "^5.21.0",
"dotenv": "^16.3.1",
"ethers": "^6.0.8",
"fastify": "^4.24.3",
Expand Down
1 change: 1 addition & 0 deletions apps/relay/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import tracing from "./tracing";
import { RelayServer } from "./server";
import { CHANNEL_TTL, REDIS_URL, RELAY_SERVER_HOST, RELAY_SERVER_PORT } from "./env";

Expand Down
3 changes: 3 additions & 0 deletions apps/relay/src/env.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import "dotenv/config";

export const ENVIRONMENT = process.env["ENVIRONMENT"] || process.env["DD_ENV"] || "dev";
export const SERVICE = process.env["DD_SERVICE"] || "auth-relay";

export const LOG_LEVEL = process.env["LOG_LEVEL"] || "warn";

export const CHANNEL_TTL = Number(process.env["CHANNEL_TTL"] || "3600");
Expand Down
49 changes: 49 additions & 0 deletions apps/relay/src/tracing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import tracer from "dd-trace";
import { ENVIRONMENT, SERVICE } from "./env";

tracer.init({
env: ENVIRONMENT,
// Service name that appears in the Datadog UI
service: SERVICE,
// Include trace ID in log messages
logInjection: ENVIRONMENT !== "test",
// Collect metrics on NodeJS CPU, memory, heap, event loop delay, GC events, etc.
// See https://docs.datadoghq.com/tracing/runtime_metrics/nodejs#data-collected
// for a list of statsd metrics.
runtimeMetrics: ENVIRONMENT !== "test",
// Log configuration on startup
startupLogs: ENVIRONMENT === "prod",
});

tracer.use("fastify", {
enabled: true,
service: SERVICE,
blocklist: ["/healthcheck"],
});

tracer.use("ioredis", {
enabled: true,
service: SERVICE,
});

tracer.use("redis", {
enabled: true,
service: SERVICE,
});

tracer.use("http", {
enabled: true,
service: SERVICE,
});

tracer.use("http2", {
enabled: true,
service: SERVICE,
});

tracer.use("net", {
enabled: true,
service: SERVICE,
});

export default tracer;
1 change: 0 additions & 1 deletion test/client/src/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
import { JsonRpcProvider } from "ethers";
import { RelayServer } from "../../../apps/relay/src/server";
import { createAppClient, createWalletClient } from "../../../packages/auth-client/src/clients";
import { viemConnector } from "../../../packages/auth-client/src/clients/ethereum/viemConnector";
Expand Down
Loading

0 comments on commit c4b36cf

Please sign in to comment.