Skip to content

Commit

Permalink
fix(http-instrumentation): crash fix (#2009)
Browse files Browse the repository at this point in the history
Co-authored-by: Valentin Marchaud <contact@vmarchaud.fr>
  • Loading branch information
Nir Hadassi and vmarchaud authored Mar 12, 2021
1 parent cc9f1d2 commit d6e9654
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/opentelemetry-instrumentation-http/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
if (
component === 'https' &&
typeof options === 'object' &&
options?.constructor.name !== 'URL'
options?.constructor?.name !== 'URL'
) {
options = Object.assign({}, options);
instrumentation._setDefaultOptions(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,32 @@ describe('HttpsInstrumentation', () => {
}
});

it('should have 2 ended spans when provided "options" are an object without a constructor', async () => {
// Related issue: https://github.com/open-telemetry/opentelemetry-js/issues/2008
const testPath = '/outgoing/test';
const options = Object.create(null);
options.hostname = hostname;
options.port = serverPort;
options.path = pathname;
options.method = 'GET';

doNock(hostname, testPath, 200, 'Ok');

const promiseRequest = new Promise((resolve, _reject) => {
const req = https.request(options, (resp: http.IncomingMessage) => {
resp.on('data', () => {});
resp.on('end', () => {
resolve({});
});
});
return req.end();
});

await promiseRequest;
const spans = memoryExporter.getFinishedSpans();
assert.strictEqual(spans.length, 2);
});

it('should have 1 ended span when response.end throw an exception', async () => {
const testPath = '/outgoing/rootSpan/childs/1';
doNock(hostname, testPath, 400, 'Not Ok');
Expand Down

0 comments on commit d6e9654

Please sign in to comment.