sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

Add custom HTTPHeaders in URLRequest

Open n1tesh-airtel opened this issue 2 years ago • 9 comments

Problem Statement

Please add functionality to provide custom headers in all URLRequest.

n1tesh-airtel avatar May 22 '23 14:05 n1tesh-airtel

The SDK should already add headers for failed HTTP requests here https://github.com/getsentry/sentry-cocoa/blob/2af280d3fd36a58915d26a619323499f72757fbc/Sources/Sentry/SentryNetworkTracker.m#L375-L379

Where exactly would you like to add custom headers? Would you like to see them as well for spans and breadcrumbs?

philipphofmann avatar May 22 '23 14:05 philipphofmann

@philipphofmann how can we add headers to that request? Need to add this in all urlrequests.

Example need to do here https://github.com/getsentry/sentry-cocoa/blob/2af280d3fd36a58915d26a619323499f72757fbc/Sources/Sentry/SentryNSURLRequest.m#L80-L84

n1tesh-airtel avatar May 22 '23 14:05 n1tesh-airtel

Hello @n1tesh-airtel currently its not possible to modify sentry requests.

brustolin avatar May 22 '23 18:05 brustolin

@n1tesh-airtel, can you please elaborate on why you need to add headers to these requests?

philipphofmann avatar May 23 '23 06:05 philipphofmann

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Jun 14 '23 00:06 github-actions[bot]

I'd also benefit from the ability to add custom headers.

Usecase: we host our own Sentry instance and it's hidden behind a proxy. This proxy expects some client-related headers to be passed with every request. I think this is a rather common use case for the self-hosted Sentry instances.

siejkowski avatar Jan 09 '24 16:01 siejkowski

Our JavaScript SDK allows you to set custom headers with the transport options

Sentry.init({
  transport: Sentry.makeBrowserOfflineTransport(Sentry.makeFetchTransport),
  transportOptions: {
    headers: {
      key: 'value'
    }
  }
})

The Cocoa SDK transport is not public yet. On Java, you can achieve this by implementing a custom transport. We can implement this feature, but I can't give you an ETA.

philipphofmann avatar Jan 10 '24 10:01 philipphofmann

I have the same issue as @siejkowski and would benefit from sentry-cocoa's ability to attach custom headers. I have been stuck on sentry-cocoa v4.4.1 for years because the ability to customize the headers using beforeSendRequest was removed in 5.x. Apologies if I am misunderstanding the documentation, but it seems like there is no way to communicate with a self-hosted Sentry server that requires custom headers using sentry-cocoa. Is this correct?

lillymaxwell avatar Mar 27 '24 20:03 lillymaxwell

but it seems like there is no way to communicate with a self-hosted Sentry server that requires custom headers using sentry-cocoa. Is this correct?

@lillymaxwell, yes, sadly, that's correct.

philipphofmann avatar Mar 28 '24 12:03 philipphofmann