Skip to content

Commit 79ef8fb

Browse files
author
Peter Marton
committed
fix(instrumentation/https): removed unnecessary instrumentation, https uses http in the background
1 parent d66acb1 commit 79ef8fb

File tree

6 files changed

+21
-76
lines changed

6 files changed

+21
-76
lines changed

Diff for: src/instrumentation/httpClient.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,7 @@ function extractUrl (options) {
2323
})
2424
}
2525

26-
function unpatchHttp (http) {
27-
shimmer.unwrap(http, 'request')
28-
29-
if (semver.satisfies(process.version, '>=8.0.0')) {
30-
shimmer.unwrap(http, 'get')
31-
}
32-
}
33-
34-
function patchHttp (http, tracer) {
26+
function patch (http, tracer) {
3527
shimmer.wrap(http, 'request', (request) => makeRequestTrace(request))
3628

3729
if (semver.satisfies(process.version, '>=8.0.0')) {
@@ -99,9 +91,17 @@ function patchHttp (http, tracer) {
9991
}
10092
}
10193

94+
function unpatch (http) {
95+
shimmer.unwrap(http, 'request')
96+
97+
if (semver.satisfies(process.version, '>=8.0.0')) {
98+
shimmer.unwrap(http, 'get')
99+
}
100+
}
101+
102102
module.exports = {
103103
module: 'http',
104104
OPERATION_NAME,
105-
patch: patchHttp,
106-
unpatch: unpatchHttp
105+
patch,
106+
unpatch
107107
}

Diff for: src/instrumentation/httpClient.spec.js

+10-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22

33
const http = require('http')
4-
const https = require('https')
54
const request = require('request-promise-native')
65
const nock = require('nock')
76
const { expect } = require('chai')
@@ -24,15 +23,10 @@ describe('instrumentation: httpClient', () => {
2423
this.sandbox.stub(cls, 'startChildSpan').callsFake(() => mockChildSpan)
2524

2625
instrumentation.patch(http, tracer)
27-
instrumentation.patch(https, tracer)
28-
29-
nock.disableNetConnect()
3026
})
3127

3228
afterEach(() => {
3329
instrumentation.unpatch(http)
34-
instrumentation.unpatch(https)
35-
nock.enableNetConnect()
3630
nock.cleanAll()
3731
})
3832

@@ -53,39 +47,38 @@ describe('instrumentation: httpClient', () => {
5347
})
5448
})
5549

56-
it('should start and finish span with https', () => {
57-
nock('https://risingstack.com')
58-
.get('/')
59-
.reply(200)
50+
it('should start and finish span with https', () =>
51+
// WARNING: nock doesn't work well with https instrumentation
52+
// create real request
6053

61-
return request('https://risingstack.com')
54+
request('https://risingstack.com')
6255
.then(() => {
6356
expect(cls.startChildSpan).to.be.calledWith(tracer, instrumentation.OPERATION_NAME)
64-
expect(mockChildSpan.setTag).to.have.calledWith(Tags.HTTP_URL, 'http://risingstack.com:443')
57+
expect(mockChildSpan.setTag).to.have.calledWith(Tags.HTTP_URL, 'https://risingstack.com:443')
6558
expect(mockChildSpan.setTag).to.have.calledWith(Tags.HTTP_METHOD, 'GET')
6659
expect(mockChildSpan.setTag).to.have.calledWith(Tags.SPAN_KIND_RPC_CLIENT, true)
6760
expect(mockChildSpan.setTag).to.have.calledWith(Tags.HTTP_STATUS_CODE, 200)
6861
expect(mockChildSpan.finish).to.have.callCount(1)
6962
})
70-
})
63+
)
7164

7265
it('should flag wrong status codes as error', () => {
73-
nock('https://risingstack.com')
66+
nock('http://risingstack.com')
7467
.get('/')
7568
.reply(400)
7669

77-
return request('https://risingstack.com')
70+
return request('http://risingstack.com')
7871
.catch(() => {
7972
expect(mockChildSpan.setTag).to.be.calledWith(Tags.ERROR, true)
8073
})
8174
})
8275

8376
it('should flag error', () => {
84-
nock('https://risingstack.com')
77+
nock('http://risingstack.com')
8578
.get('/')
8679
.replyWithError('My Error')
8780

88-
return request('https://risingstack.com')
81+
return request('http://risingstack.com')
8982
.catch((err) => {
9083
expect(mockChildSpan.setTag).to.be.calledWith(Tags.ERROR, true)
9184
expect(mockChildSpan.log).to.be.calledWith({

Diff for: src/instrumentation/httpsClient.js

-10
This file was deleted.

Diff for: src/instrumentation/httpsClient.spec.js

-35
This file was deleted.

Diff for: src/instrumentation/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
const express = require('./express')
44
const expressError = require('./expressError')
55
const httpClient = require('./httpClient')
6-
const httpsClient = require('./httpsClient')
76
const mongodbCore = require('./mongodbCore')
87
const pg = require('./pg')
98

109
module.exports = [
1110
express,
1211
expressError,
1312
httpClient,
14-
httpsClient,
1513
mongodbCore,
1614
pg
1715
]

Diff for: src/tracer.spec.js

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ describe('Tracer', () => {
4343

4444
expect(instrumentationExpress.patch).to.be.calledWith(express, tracer._tracer)
4545
expect(instrumentationHTTPClient.patch).to.be.calledWith(http, tracer._tracer)
46-
expect(instrumentationHTTPClient.patch).to.be.calledWith(https, tracer._tracer)
4746
})
4847

4948
it('should not apply instrumentation for not supported version', function () {

0 commit comments

Comments
 (0)