Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 8 additions & 31 deletions valhalla/jawn/src/lib/handlers/LoggingHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
COST_PRECISION_MULTIPLIER,
modelCost,
} from "@helicone-package/cost/costCalc";
import { normalizeTier } from "../utils/tiers";
import { atLeastZero } from "../utils/helicone_math";

type S3Record = {
Expand All @@ -36,7 +35,6 @@ type S3Record = {
requestBody: string;
responseBody: string;
assets: Map<string, string>;
tier: string;
};

export type BatchPayload = {
Expand Down Expand Up @@ -244,18 +242,13 @@ export class LoggingHandler extends AbstractLogHandler {
s3Record.organizationId
);

// Get tier information from context (stored in s3Record)
const tags: Record<string, string> = {};
tags.tier = normalizeTier(s3Record.tier);

// Upload request and response body with tier tag
// Upload request and response body
const uploadRes = await this.s3Client.store(
key,
JSON.stringify({
request: s3Record.requestBody,
response: s3Record.responseBody,
}),
tags
})
);

if (uploadRes.error) {
Expand All @@ -269,8 +262,7 @@ export class LoggingHandler extends AbstractLogHandler {
const imageUploadRes = await this.storeRequestResponseImage(
s3Record.organizationId,
s3Record.requestId,
s3Record.assets,
s3Record.tier
s3Record.assets
);

if (imageUploadRes.error) {
Expand All @@ -293,18 +285,11 @@ export class LoggingHandler extends AbstractLogHandler {
private async storeRequestResponseImage(
organizationId: string,
requestId: string,
assets: Map<string, string>,
tier: string
assets: Map<string, string>
): PromiseGenericResult<string> {
const uploadPromises: Promise<void>[] = Array.from(assets.entries()).map(
([assetId, imageUrl]) =>
this.handleImageUpload(
assetId,
imageUrl,
requestId,
organizationId,
tier
)
this.handleImageUpload(assetId, imageUrl, requestId, organizationId)
);

await Promise.allSettled(uploadPromises);
Expand All @@ -330,14 +315,9 @@ export class LoggingHandler extends AbstractLogHandler {
assetId: string,
imageUrl: string,
requestId: string,
organizationId: string,
tier: string
organizationId: string
): Promise<void> {
try {
// Prepare tags
const tags: Record<string, string> = {};
tags.tier = normalizeTier(tier);

if (this.isBase64Image(imageUrl)) {
const [assetType, base64Data] = this.extractBase64Data(imageUrl);
const buffer = Buffer.from(base64Data, "base64");
Expand All @@ -346,8 +326,7 @@ export class LoggingHandler extends AbstractLogHandler {
assetType,
requestId,
organizationId,
assetId,
tags
assetId
);
} else {
const response = await fetch(imageUrl, {
Expand All @@ -363,8 +342,7 @@ export class LoggingHandler extends AbstractLogHandler {
blob,
requestId,
organizationId,
assetId,
tags
assetId
);
}
} catch (error) {
Expand Down Expand Up @@ -441,7 +419,6 @@ export class LoggingHandler extends AbstractLogHandler {
requestBody: context.processedLog.request.body,
responseBody: context.processedLog.response.body,
assets: assets ?? new Map(),
tier: orgParams.tier,
};

return s3Record;
Expand Down
46 changes: 10 additions & 36 deletions valhalla/jawn/src/lib/shared/db/s3Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
DeleteObjectCommand,
GetObjectCommand,
PutObjectCommand,
PutObjectCommandInput,
} from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
import {
Expand Down Expand Up @@ -187,19 +186,17 @@ export class S3Client {
assetType: string,
requestId: string,
orgId: string,
assetId: string,
tags?: Record<string, string>
assetId: string
): PromiseGenericResult<string> {
const key = this.getRequestResponseImageUrl(requestId, orgId, assetId);
return await this.uploadToS3(key, buffer, assetType, tags);
return await this.uploadToS3(key, buffer, assetType);
}

async uploadImageToS3(
image: Blob,
requestId: string,
orgId: string,
assetId: string,
tags?: Record<string, string>
assetId: string
): Promise<Result<string, string>> {
const uploadUrl = this.getRequestResponseImageUrl(
requestId,
Expand All @@ -210,8 +207,7 @@ export class S3Client {
return await this.uploadToS3(
uploadUrl,
await image.arrayBuffer(),
image.type,
tags
image.type
);
}

Expand Down Expand Up @@ -259,27 +255,15 @@ export class S3Client {
async uploadToS3(
key: string,
body: ArrayBuffer | Buffer,
contentType: string,
tags?: Record<string, string>
contentType: string
): Promise<Result<string, string>> {
return await putLimiter.schedule(async () => {
const commandOptions: PutObjectCommandInput = {
const command = new PutObjectCommand({
Bucket: this.bucketName,
Key: key,
Body: new Uint8Array(body),
ContentType: contentType,
};

// Add tags if provided
if (tags && Object.keys(tags).length > 0) {
const tagsAsQueryParams = new URLSearchParams();
for (const [tagKey, value] of Object.entries(tags)) {
tagsAsQueryParams.set(tagKey, value);
}
commandOptions.Tagging = tagsAsQueryParams.toString();
}

const command = new PutObjectCommand(commandOptions);
});

try {
const response = await this.awsClient.send(command);
Expand Down Expand Up @@ -317,24 +301,14 @@ export class S3Client {
ContentType: "application/json",
});
} else {
const commandOptions: PutObjectCommandInput = {
command = new PutObjectCommand({
Bucket: this.bucketName,
Key: key,
Body: compressedValue.data,
ContentEncoding: "gzip",
ContentType: "application/json",
};

// Add tags if provided
if (tags && Object.keys(tags).length > 0) {
const tagsAsQueryParams = new URLSearchParams();
for (const [tagKey, value] of Object.entries(tags)) {
tagsAsQueryParams.set(tagKey, value);
}
commandOptions.Tagging = tagsAsQueryParams.toString();
}

command = new PutObjectCommand(commandOptions);
Metadata: tags,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Critical bug: tags parameter may be undefined here since calling methods no longer pass it, but it's still being used in Metadata

Suggested change
Metadata: tags,
Metadata: tags || {},

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just what it was before i'd changed anything so its fine, https://github.com/Helicone/helicone/blob/21b649fdb1465d3b766e9b3ff851242f2cfd6a7b/valhalla/jawn/src/lib/shared/db/s3Client.ts

i also tested locally and this still logs fine (and made sure it was going into this else)

});
}

const response = await this.awsClient.send(command);
Expand Down
4 changes: 0 additions & 4 deletions valhalla/jawn/src/lib/utils/tiers.ts

This file was deleted.

29 changes: 2 additions & 27 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9164,12 +9164,7 @@ d3-array@^2.5.0:
dependencies:
internmap "^1.0.0"

"d3-color@1 - 2":
version "2.0.0"
resolved "https://registry.yarnpkg.com/d3-color/-/d3-color-2.0.0.tgz#8d625cab42ed9b8f601a1760a389f7ea9189d62e"
integrity sha512-SPXi0TSKPD4g9tw0NMZFnR95XVgUZiBH+uUTqQuDu1OsE2zomHU7ho0FISciaPvosimixwHFl3WHLGabv6dDgQ==

"d3-color@1 - 3":
"d3-color@1 - 2", "d3-color@1 - 3", d3-color@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/d3-color/-/d3-color-3.1.0.tgz#395b2833dfac71507f12ac2f7af23bf819de24e2"
integrity sha512-zg/chbXyeBtMQ1LbD/WSoW2DpC3I0mpmPdW+ynRTj/x2DAWYrIY7qeZIHidozwV24m4iavr15lNwIwLxRmOxhA==
Expand Down Expand Up @@ -18852,27 +18847,7 @@ write-file-atomic@^5.0.1:
imurmurhash "^0.1.4"
signal-exit "^4.0.1"

ws@8.13.0:
version "8.13.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0"
integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==

ws@8.17.1:
version "8.17.1"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.17.1.tgz#9293da530bb548febc95371d90f9c878727d919b"
integrity sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==

ws@8.18.0:
version "8.18.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.18.0.tgz#0d7505a6eafe2b0e712d232b42279f53bc289bbc"
integrity sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==

ws@^7.3.1:
version "7.5.10"
resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.10.tgz#58b5c20dc281633f6c19113f39b349bd8bd558d9"
integrity sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==

ws@^8, ws@^8.12.0, ws@^8.18.2:
ws@8.13.0, ws@8.17.1, ws@8.18.0, ws@^7.3.1, ws@^8, ws@^8.12.0, ws@^8.17.1, ws@^8.18.2:
version "8.18.3"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.18.3.tgz#b56b88abffde62791c639170400c93dcb0c95472"
integrity sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==
Expand Down
Loading