Skip to content

fix: Send headers for node #2637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 3, 2020
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott
- [react] feat: Add @sentry/react package (#2631)

## 5.16.1

- [node] fix: Requests to old `/store` endpoint need the `x-sentry-auth` header in node (#2637)

## 5.16.0

*If you are a `@sentry/apm` and did manual instrumentation using `hub.startSpan` please be aware of the changes we did
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ export class API {

/**
* Returns an object that can be used in request headers.
*
* @deprecated in favor of `getStoreEndpointWithUrlEncodedAuth` and `getEnvelopeEndpointWithUrlEncodedAuth`.
* This is needed for node and the old /store endpoint in sentry
*/
public getRequestHeaders(clientName: string, clientVersion: string): { [key: string]: string } {
const dsn = this._dsnObject;
Expand Down
11 changes: 5 additions & 6 deletions packages/node/src/transports/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as http from 'http';
import * as https from 'https';
import * as url from 'url';

// import { SDK_NAME, SDK_VERSION } from '../version';
import { SDK_NAME, SDK_VERSION } from '../version';

/**
* Internal used interface for typescript.
Expand Down Expand Up @@ -59,14 +59,13 @@ export abstract class BaseTransport implements Transport {
/** Returns a build request option object used by request */
protected _getRequestOptions(uri: url.URL): http.RequestOptions | https.RequestOptions {
const headers = {
// The auth headers are not included because auth is done via query string to match @sentry/browser.
//
// ...this._api.getRequestHeaders(SDK_NAME, SDK_VERSION)
...this._api.getRequestHeaders(SDK_NAME, SDK_VERSION),
...this.options.headers,
};
const { hostname, pathname, port, protocol, search } = uri;
const { hostname, pathname, port, protocol } = uri;
// See https://github.com/nodejs/node/blob/38146e717fed2fabe3aacb6540d839475e0ce1c6/lib/internal/url.js#L1268-L1290
const path = `${pathname}${search}`;
// We ignore the query string on purpose
const path = `${pathname}`;

return {
agent: this.client,
Expand Down
4 changes: 2 additions & 2 deletions packages/node/test/transports/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { HTTPTransport } from '../../src/transports/http';

const mockSetEncoding = jest.fn();
const dsn = 'http://[email protected]:8989/mysubpath/50622';
const transportPath = '/mysubpath/api/50622/store/?sentry_key=9e9fd4523d784609a5fc0ebb1080592f&sentry_version=7';
const transportPath = '/mysubpath/api/50622/store/';
let mockReturnCode = 200;
let mockHeaders = {};

Expand All @@ -28,7 +28,7 @@ function createTransport(options: TransportOptions): HTTPTransport {
}

function assertBasicOptions(options: any): void {
expect(options.headers).not.toContain('X-Sentry-Auth'); // auth is part of the query string
expect(options.headers['X-Sentry-Auth']).toBeTruthy();
expect(options.port).toEqual('8989');
expect(options.path).toEqual(transportPath);
expect(options.hostname).toEqual('sentry.io');
Expand Down
4 changes: 2 additions & 2 deletions packages/node/test/transports/https.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { HTTPSTransport } from '../../src/transports/https';

const mockSetEncoding = jest.fn();
const dsn = 'https://[email protected]:8989/mysubpath/50622';
const transportPath = '/mysubpath/api/50622/store/?sentry_key=9e9fd4523d784609a5fc0ebb1080592f&sentry_version=7';
const transportPath = '/mysubpath/api/50622/store/';
let mockReturnCode = 200;
let mockHeaders = {};

Expand Down Expand Up @@ -34,7 +34,7 @@ function createTransport(options: TransportOptions): HTTPSTransport {
}

function assertBasicOptions(options: any): void {
expect(options.headers).not.toContain('X-Sentry-Auth'); // auth is part of the query string
expect(options.headers['X-Sentry-Auth']).toBeTruthy();
expect(options.port).toEqual('8989');
expect(options.path).toEqual(transportPath);
expect(options.hostname).toEqual('sentry.io');
Expand Down