-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add URL container support to Node.JS transports #3612
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
kamilogorek
merged 10 commits into
getsentry:master
from
1999:dsorin/DAC-XXX-add-url-container
Jun 7, 2021
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
870ea93
Add URL container support
1999 b14ba47
Merge branch 'master' into dsorin/DAC-XXX-add-url-container
1999 277fc58
Merge branch 'master' into dsorin/DAC-XXX-add-url-container
1999 dd14cfd
Merge branch 'master' into dsorin/DAC-XXX-add-url-container
1999 e4c3aa1
Replace URLContainer with URLParser
1999 932a95a
Merge branch 'master' into dsorin/DAC-XXX-add-url-container
kamilogorek 6f3fd70
Merge branch 'master' into dsorin/DAC-XXX-add-url-container
1999 e0a1d04
Make URLParser required with default value to avoid breaking changes …
1999 e1121e5
Update test suite name
1999 f8016cf
Merge branch 'master' into dsorin/DAC-XXX-add-url-container
kamilogorek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { SentryError } from '@sentry/utils'; | ||
|
|
||
| import { CustomUrlTransport, NoUrlTransport } from './transports'; | ||
|
|
||
| describe('Custom transport', () => { | ||
| describe('url container support', () => { | ||
| const noop = () => null; | ||
| const sampleDsn = 'https://[email protected]/path/1'; | ||
|
|
||
| test("reject with SentryError when a transport doesn't define a URL container", () => { | ||
| const transport = new NoUrlTransport({ | ||
| dsn: sampleDsn, | ||
| }); | ||
|
|
||
| return expect(transport.sendEvent({})).rejects.toEqual(new SentryError('No URL parser configured')); | ||
| }); | ||
|
|
||
| test('use URL property constructor for sendEvent() method', async () => { | ||
| const urlParser = jest.fn(); | ||
| const transport = new CustomUrlTransport({ dsn: sampleDsn }, urlParser); | ||
| await transport.sendEvent({}).catch(noop); | ||
|
|
||
| expect(urlParser).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('use URL property constructor for sendSession() method', async () => { | ||
| const urlParser = jest.fn(); | ||
| const transport = new CustomUrlTransport({ dsn: sampleDsn }, urlParser); | ||
| await transport.sendSession({ aggregates: [] }).then(noop, noop); | ||
|
|
||
| expect(urlParser).toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { eventToSentryRequest } from '@sentry/core'; | ||
| import { Event, Response, TransportOptions } from '@sentry/types'; | ||
| import * as http from 'http'; | ||
|
|
||
| import { BaseTransport, HTTPTransport } from '../../../src/transports'; | ||
| import { UrlParser } from '../../../src/transports/base'; | ||
|
|
||
| export class CustomUrlTransport extends HTTPTransport { | ||
| public constructor(public options: TransportOptions, urlParser: UrlParser) { | ||
| super(options); | ||
| this.urlParser = urlParser; | ||
| } | ||
| } | ||
|
|
||
| export class NoUrlTransport extends BaseTransport { | ||
| public constructor(public options: TransportOptions) { | ||
| super(options); | ||
|
|
||
| const proxy = this._getProxy('http'); | ||
| this.module = http; | ||
| this.client = proxy | ||
| ? (new (require('https-proxy-agent'))(proxy) as http.Agent) | ||
| : new http.Agent({ keepAlive: false, maxSockets: 30, timeout: 2000 }); | ||
| } | ||
|
|
||
| public sendEvent(event: Event): Promise<Response> { | ||
| return this._send(eventToSentryRequest(event, this._api), event); | ||
| } | ||
|
|
||
| public sendSession(): Promise<Response> { | ||
| throw new Error('NOT_NEEDED'); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we actually make this non-optional, and move the default
utl => new URL(url)here? Otherwise it may be a breaking change for people using custom transports.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kamilogorek before I jump into this rabbit hole, is this what you mean?
I also feel like URL parser can belong as an (optional) option in TransportOptions. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly that. Tbh I don't see anyone ever wanting to override this other than use cases like yours, where completely custom transport is required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kamilogorek gotcha, done.