Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix: remove sentry instrumentation (#918)

Max Deichmann4869e8a09301
diff --git a/src/features/public-api/server/apiAuth.ts b/src/features/public-api/server/apiAuth.ts
index 643b696fdd..100a863420 100644
--- a/src/features/public-api/server/apiAuth.ts
+++ b/src/features/public-api/server/apiAuth.ts
@@ -5,7 +5,6 @@ import {
} from "@/src/features/public-api/lib/apiKeys";
import { type ApiAccessScope } from "@/src/features/public-api/server/types";
import { prisma } from "@/src/server/db";
-import { instrumentAsync } from "@/src/utils/instrumentation";
export type AuthHeaderVerificationResult =
| {
@@ -20,93 +19,85 @@ export type AuthHeaderVerificationResult =
export async function verifyAuthHeaderAndReturnScope(
authHeader: string | undefined,
): Promise<AuthHeaderVerificationResult> {
- return instrumentAsync(
- { name: "verifyAuthHeaderAndReturnScope" },
- async () => {
- if (!authHeader) {
- console.error("No authorization header");
- return {
- validKey: false,
- error: "No authorization header",
- };
- }
+ if (!authHeader) {
+ console.error("No authorization header");
+ return {
+ validKey: false,
+ error: "No authorization header",
+ };
+ }
- try {
- // Basic auth, full scope, needs secret key and public key
- if (authHeader.startsWith("Basic ")) {
- const { username: publicKey, password: secretKey } =
- extractBasicAuthCredentials(authHeader);
+ try {
+ // Basic auth, full scope, needs secret key and public key
+ if (authHeader.startsWith("Basic ")) {
+ const { username: publicKey, password: secretKey } =
+ extractBasicAuthCredentials(authHeader);
- const salt = env.SALT;
- const hashFromProvidedKey = createShaHash(secretKey, salt);
- const apiKey = await prisma.apiKey.findUnique({
- where: { fastHashedSecretKey: hashFromProvidedKey },
- });
- let projectId = apiKey?.projectId;
+ const salt = env.SALT;
+ const hashFromProvidedKey = createShaHash(secretKey, salt);
+ const apiKey = await prisma.apiKey.findUnique({
+ where: { fastHashedSecretKey: hashFromProvidedKey },
+ });
+ let projectId = apiKey?.projectId;
- if (!apiKey || !apiKey.fastHashedSecretKey) {
- const dbKey = await findDbKeyOrThrow(publicKey);
- const isValid = await verifySecretKey(
- secretKey,
- dbKey.hashedSecretKey,
- );
+ if (!apiKey || !apiKey.fastHashedSecretKey) {
+ const dbKey = await findDbKeyOrThrow(publicKey);
+ const isValid = await verifySecretKey(secretKey, dbKey.hashedSecretKey);
- if (!isValid) {
- console.log("Old key is invalid", publicKey);
- throw new Error("Invalid credentials");
- }
+ if (!isValid) {
+ console.log("Old key is invalid", publicKey);
+ throw new Error("Invalid credentials");
+ }
- const shaKey = createShaHash(secretKey, salt);
+ const shaKey = createShaHash(secretKey, salt);
- await prisma.apiKey.update({
- where: { publicKey },
- data: {
- fastHashedSecretKey: shaKey,
- },
- });
- projectId = dbKey.projectId;
- }
+ await prisma.apiKey.update({
+ where: { publicKey },
+ data: {
+ fastHashedSecretKey: shaKey,
+ },
+ });
+ projectId = dbKey.projectId;
+ }
- if (!projectId) {
- console.log("No project id found for key", publicKey);
- throw new Error("Invalid credentials");
- }
+ if (!projectId) {
+ console.log("No project id found for key", publicKey);
+ throw new Error("Invalid credentials");
+ }
- return {
- validKey: true,
- scope: {
- projectId: projectId,
- accessLevel: "all",
- },
- };
- }
- // Bearer auth, limited scope, only needs public key
- if (authHeader.startsWith("Bearer ")) {
- const publicKey = authHeader.replace("Bearer ", "");
+ return {
+ validKey: true,
+ scope: {
+ projectId: projectId,
+ accessLevel: "all",
+ },
+ };
+ }
+ // Bearer auth, limited scope, only needs public key
+ if (authHeader.startsWith("Bearer ")) {
+ const publicKey = authHeader.replace("Bearer ", "");
- const dbKey = await findDbKeyOrThrow(publicKey);
+ const dbKey = await findDbKeyOrThrow(publicKey);
- return {
- validKey: true,
- scope: {
- projectId: dbKey.projectId,
- accessLevel: "scores",
- },
- };
- }
- } catch (error: unknown) {
- console.error("Error verifying auth header: ", error);
- return {
- validKey: false,
- error: error instanceof Error ? error.message : "Authorization error",
- };
- }
return {
- validKey: false,
- error: "Invalid authorization header",
+ validKey: true,
+ scope: {
+ projectId: dbKey.projectId,
+ accessLevel: "scores",
+ },
};
- },
- );
+ }
+ } catch (error: unknown) {
+ console.error("Error verifying auth header: ", error);
+ return {
+ validKey: false,
+ error: error instanceof Error ? error.message : "Authorization error",
+ };
+ }
+ return {
+ validKey: false,
+ error: "Invalid authorization header",
+ };
}
function extractBasicAuthCredentials(basicAuthHeader: string): {
diff --git a/src/server/api/routers/traces.ts b/src/server/api/routers/traces.ts
index 33bcc9e2f0..f3e2dfc49f 100644
--- a/src/server/api/routers/traces.ts
+++ b/src/server/api/routers/traces.ts
@@ -23,7 +23,6 @@ import { TRPCError } from "@trpc/server";
import { orderBy } from "@/src/server/api/interfaces/orderBy";
import { orderByToPrismaSql } from "@/src/features/orderBy/server/orderByToPrisma";
import { type Sql } from "@prisma/client/runtime/library";
-import { instrumentAsync } from "@/src/utils/instrumentation";
const TraceFilterOptions = z.object({
projectId: z.string(), // Required for protectedProjectProcedure
@@ -91,21 +90,17 @@ export const traceRouter = createTRPCRouter({
orderByCondition,
);
- const traces = await instrumentAsync(
- { name: "get-all-traces" },
- async () =>
- await ctx.prisma.$queryRaw<
- Array<
- Trace & {
- promptTokens: number;
- completionTokens: number;
- totalTokens: number;
- totalCount: number;
- latency: number | null;
- }
- >
- >(tracesQuery),
- );
+ const traces = await ctx.prisma.$queryRaw<
+ Array<
+ Trace & {
+ promptTokens: number;
+ completionTokens: number;
+ totalTokens: number;
+ totalCount: number;
+ latency: number | null;
+ }
+ >
+ >(tracesQuery);
const countQyery = createTracesQuery(
Prisma.sql`count(*)`,
@@ -118,11 +113,8 @@ export const traceRouter = createTRPCRouter({
Prisma.empty,
);
- const totalTraces = await instrumentAsync(
- { name: "get-total-traces" },
- async () =>
- await ctx.prisma.$queryRaw<Array<{ count: bigint }>>(countQyery),
- );
+ const totalTraces =
+ await ctx.prisma.$queryRaw<Array<{ count: bigint }>>(countQyery);
// get scores for each trace individually to increase
// performance of the query above