sentry-javascript: @sentry/bun causes AWS-S3 jsv3 SDK to fail

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/bun

SDK Version

7.80.1

Framework Version

Bun 1.0.11

Link to Sentry event

No response

SDK Setup

import * as Sentry from '@sentry/bun';

Sentry.init({
  dsn: 'https:/{DSN}.ingest.sentry.io/4506217287778304',
  tracesSampleRate: 1.0,
});

Steps to Reproduce

import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3';
import { db } from './db';

if (!process.env.S3_ACCESS_KEY_ID) {
  throw new Error('Missing S3_ACCESS_KEY_ID');
}

if (!process.env.S3_SECRET_ACCESS_KEY) {
  throw new Error('Missing S3_SECRET_ACCESS_KEY');
}

if (!process.env.S3_ENDPOINT) {
  throw new Error('Missing S3_ENDPOINT');
}

if (!process.env.S3_IMAGES_BUCKET) {
  throw new Error('Missing S3_IMAGES_BUCKET');
}

if (!process.env.S3_PUBLIC_URL) {
  throw new Error('Missing S3_PUBLIC_URL');
}

const S3 = new S3Client({
  region: 'auto',
  endpoint: process.env.S3_ENDPOINT,
  credentials: {
    accessKeyId: process.env.S3_ACCESS_KEY_ID,
    secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
  },
  forcePathStyle: false,
});

export async function uploadImageToR2(imageURL: string, messageId: string) {
  const response = await fetch(imageURL);
  const arrayBuffer = await response.arrayBuffer();
  const imageBuffer = Buffer.from(arrayBuffer);

  const uploadCommand = new PutObjectCommand({
    Bucket: process.env.S3_IMAGES_BUCKET,
    Key: messageId + '.png',
    Body: imageBuffer,
    ContentType: 'image/png',
  });

  const uploadResponse = await S3.send(uploadCommand);

  if (uploadResponse.$metadata.httpStatusCode != 200) {
    throw new Error('Failed to upload image to S3');
  }

  await db.message.update({
    where: {
      id: messageId,
    },
    data: {
      content: `${process.env.S3_PUBLIC_URL}/${messageId}.png`,
    },
  });
}

With @sentry/bun installed S3.send() just hangs (no errors, no timeouts) inside this exported async function (but works when executed on globa/root scope.

Expected Result

S3 send should execute normally

Actual Result

n/a

About this issue

  • Original URL
  • State: open
  • Created 8 months ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Let us know if this ends up being a bug in bun. it might be

yes @r614 this is a bug with Bun - I recommend you follow up with them.

ref https://github.com/getsentry/sentry-javascript/issues/9516#issuecomment-1828252163

Looks like simliar error: #9547

Only:

Sentry.init({
  dsn: 'https:/{DSN}.ingest.sentry.io/4506217287778304',
  tracesSampleRate: 1.0,
  ...
  enabled: false,
});

Help the problem 🗡️

if i filter out Http, the request is successful.

Sentry.init({
  dsn: <dsn>,
  tracesSampleRate: 1.0,
  debug: true,
  integrations: (int) =>
    int.filter((i) => !["BunServer", "Http"].includes(i.name)),
});

Continuing our thread here. Running with node doesn’t work:

Ah yeah it won’t 🤦‍♂️ - sorry that’s on me, we rely on the Bun global for metadata. If you shim the Bun global via globalThis.Bun = ... and run with Node, do you see a problem?

2nd thing we can try. If you filter out the BunServer, do you still see freezes?

Sentry.init({
  // ... your config
  // filter out default BunServer integration
  integrations: (int) => int.filter(i => i.name !== 'BunServer'),
});

You can also try filtering out Http integration via adjusting the conditional. Does that help?

Thanks for your patience and helping debug!

Hi @DeveloperHarris, we’re going to backlog this. Unfortunately we don’t have the bandwidth to look at this at the moment but we’ll get to it eventually. Sorry for the inconvenience!