Skip to content
Open
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
2 changes: 1 addition & 1 deletion sdk_contrib/fetch/lib/fetch_p.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function enableCapture(baseFetchFunction, requestClass, downstreamXRayEnabled, s
const thisDownstreamXRayEnabled = !!downstreamXRayEnabled;
const thisSubsegmentCallback = subsegmentCallback;
// Standardize request information
const request = typeof args[0] === 'object' ?
const request = (args[0] instanceof requestClass && args.length === 1) ?
args[0] :
new requestClass(...args);

Expand Down
20 changes: 20 additions & 0 deletions sdk_contrib/fetch/test/integration/fetch_p.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,26 @@ describe('Integration tests', function () {
stubClose.should.have.been.calledOnce;
});

it('works with stringifyable objects', async function () {
const spyCallback = sandbox.spy();
const fetch = captureFetchGlobal(true, spyCallback);
const response = await fetch(new URL(goodUrl), {
headers: {
'foo': 'bar'
}
});
response.status.should.equal(200);
receivedHeaders.should.to.have.property('x-amzn-trace-id');
receivedHeaders.should.to.have.property('foo', 'bar');
(await response.text()).should.contain('Example');
stubIsAutomaticMode.should.have.been.called;
stubAddNewSubsegment.should.have.been.calledOnce;
stubResolveSegment.should.have.been.calledOnce;
stubAddFetchRequestData.should.have.been.calledOnce;
stubAddErrorFlag.should.not.have.been.calledOnce;
stubClose.should.have.been.calledOnce;
});

it('sets error flag on failed fetch when global fetch exists', async function () {
const spyCallback = sandbox.spy();
const fetch = captureFetchGlobal(true, spyCallback);
Expand Down
4 changes: 2 additions & 2 deletions sdk_contrib/fetch/test/unit/fetch_p.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ describe('Unit tests', function () {

it('short circuits if headers include trace ID', async function () {
const activeFetch = captureFetch(true);
const request = new fetchModule.Request('https://www.foo.com', {
const request = new FetchRequest('https://www.foo.com', {
headers: {
'X-Amzn-Trace-Id': '12345'
}
});
await activeFetch(request);
stubFetch.should.have.been.calledOnceWith(request);
stubFetch.should.have.been.calledOnceWith(sinon.match({ url: 'https://www.foo.com/'}));
stubResolveSegment.should.not.have.been.called;
});

Expand Down