Skip to content

Using Sentry breaks S3 put via @aws-sdk #16477

Description

@ortutay

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

^9.25.1

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

No response

Steps to Reproduce

I am using this function to put onto s3:

export const s3put = async (key, val, options) => {
  const { acl, contentType } = options || {};
  const params = {
    Bucket: bucket,
    Key: key,
    Body: val,
    ContentType: contentType,
    ACL: acl,
  };

  try {
    await s3.send(new PutObjectCommand(params));
  } catch (e) {
    console.error('s3put got error:', e, params);
    throw e;
  }
  const url = s3url(key);
  return url;
};

Without Sentry, it works fine.

My Sentry instrument.js file is:

import * as Sentry_ from '@sentry/node';
export const Sentry = Sentry_;

if (process.env.ENV == 'prod') {
  Sentry.init({
    dsn: '...',
    sendDefaultPii: true,
  });
}

Expected Result

It should upload to s3

Actual Result

When I add Sentry instrumentation, I get this error:

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ClientRequest.setHeader (node:_http_outgoing:699:11)
    at SentryHttpInstrumentation._onOutgoingRequestCreated (/app/node_modules/@sentry/node/src/integrations/http/SentryHttpInstrumentation.ts:265:15)
    at onHttpClientRequestCreated (/app/node_modules/@sentry/node/src/integrations/http/SentryHttpInstrumentation.ts:167:12)
    at Channel.publish (node:diagnostics_channel:150:9)
    at new ClientRequest (node:_http_client:384:35)
    at request (node:https:381:10)
    at /app/node_modules/@smithy/node-http-handler/dist-cjs/index.js:366:19
    at new Promise (<anonymous>)
    at _NodeHttpHandler.handle (/app/node_modules/@smithy/node-http-handler/dist-cjs/index.js:300:12)
    at async /app/node_modules/@aws-sdk/middleware-flexible-checksums/dist-cjs/index.js:456:18 {
  code: 'ERR_HTTP_HEADERS_SENT'
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions