Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat(@opentelemetry-instrumentation-fetch): support reading response …
…body from the hook applyCustomAttributesOnSpan
  • Loading branch information
echoontheway committed Sep 26, 2021
commit 7f90bf462d1e3d82e8d2306838a3c0984f33c34a
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,15 @@ export class FetchInstrumentation extends InstrumentationBase<
): void {
try {
const resClone = response.clone();
const resClone4Hook = response.clone();
const body = resClone.body;
if (body) {
const reader = body.getReader();
const read = (): void => {
reader.read().then(
({ done }) => {
if (done) {
endSpanOnSuccess(span, response);
endSpanOnSuccess(span, resClone4Hook);
} else {
read();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,22 @@ describe('fetch', () => {

prepare(url, applyCustomAttributes);
});

it('get response body from callback arguments response', done => {
const applyCustomAttributes: FetchCustomAttributeFunction = async (
span,
request,
response
) => {
if(response instanceof Response ){
const rsp = await response.json();
assert.deepStrictEqual(rsp.args, {});
done();
}
};

prepare(url, applyCustomAttributes);
});
});

describe('when url is ignored', () => {
Expand Down