Skip to content

Commit

Permalink
posthog logs (#2389)
Browse files Browse the repository at this point in the history
  • Loading branch information
chitalian authored Aug 6, 2024
1 parent 098c859 commit eb4f1b7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
33 changes: 31 additions & 2 deletions valhalla/jawn/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { initLogs } from "./utils/injectLogs";
import { initSentry } from "./utils/injectSentry";
import { startConsumers } from "./workers/consumerInterface";
import { unauthorizedCacheMiddleware } from "./middleware/unauthorizedCache";
import { postHogClient } from "./lib/clients/postHogClient";
import { uuid } from "uuidv4";

export const ENVIRONMENT: "production" | "development" = (process.env
.VERCEL_ENV ?? "development") as any;
Expand Down Expand Up @@ -61,11 +63,38 @@ const KAFKA_ENABLED = (KAFKA_CREDS?.KAFKA_ENABLED ?? "false") === "true";

if (KAFKA_ENABLED) {
startConsumers({
dlqCount: DLQ_WORKER_COUNT,
normalCount: NORMAL_WORKER_COUNT,
dlqCount: 0,
normalCount: 0,
});
}

app.use((req, res, next) => {
const start = Date.now();

const captureRequest = () => {
const duration = Date.now() - start;
try {
postHogClient?.capture({
distinctId: uuid(),
event: "jawn_http_request",
properties: {
method: req.method,
url: req.originalUrl,
status: res.statusCode,
duration: duration,
userAgent: req.headers["user-agent"],
},
});
} catch (error) {
console.error("Failed to capture request in PostHog:", error);
}
};

res.on("finish", captureRequest);

next();
});

app.get("/healthcheck", (req, res) => {
res.json({
status: "healthy :)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function recursivelyConsolidateAnthropicListForClaude3(delta: any[]): any {
function recursivelyConsolidateAnthropic(body: any, delta: any): any {
Object.keys(delta).forEach((key) => {
if (key === "stop_reason") {
console.log("Stop Reason", delta[key]);
// console.log("Stop Reason", delta[key]);
}
if (key === "delta") {
} else if (key === "type") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { consolidateTextFields } from "./responseParserHelpers";
export function recursivelyConsolidateAnthropic(body: any, delta: any): any {
Object.keys(delta).forEach((key) => {
if (key === "stop_reason") {
console.log("Stop Reason", delta[key]);
// console.log("Stop Reason", delta[key]);
}
if (key === "delta") {
console.log("Delta", delta[key]);
Expand Down

0 comments on commit eb4f1b7

Please sign in to comment.