Skip to content

Commit 2a44c7c

Browse files
author
Peter Marton
committed
fix(instrumentation/https): add https instrumentation
1 parent 8795641 commit 2a44c7c

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Create a new Tracer and instrument modules.
7575

7676
## Instrumentations
7777

78-
- [http](https://nodejs.org/api/http.html)
78+
- [http, https](https://nodejs.org/api/http.html)
7979
- [express](https://expressjs.com/)
8080
- [MongoDB](https://www.npmjs.com/package/mongodb-core)
8181
- [PostgreSQL](https://www.npmjs.com/package/pg)

src/instrumentation/httpClient.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function patchHttp (http, tracer) {
6767
_.isUndefined
6868
)
6969

70-
if (res.statusCode >= 400) {
70+
if (res.statusCode > 399) {
7171
span.setTag(opentracing.Tags.ERROR, true)
7272
}
7373

src/instrumentation/httpsClient.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict'
2+
3+
const httpClient = require('./httpClient')
4+
5+
module.exports = {
6+
module: 'https',
7+
OPERATION_NAME: httpClient.OPERATION_NAME,
8+
patch: (https, tracer) => httpClient.patch(https, tracer),
9+
unpatch: (https) => httpClient.unpatch(https)
10+
}

src/instrumentation/index.js

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

910
module.exports = [
1011
express,
1112
expressError,
1213
httpClient,
14+
httpsClient,
1315
mongodbCore,
1416
pg
1517
]

src/tracer.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { expect } = require('chai')
44
const jaeger = require('jaeger-client')
55
const Tracer = require('./tracer')
66
const instrumentationExpress = require('./instrumentation/express')
7+
const instrumentationHTTPClient = require('./instrumentation/httpClient')
78

89
describe('Tracer', () => {
910
let tracer
@@ -27,15 +28,22 @@ describe('Tracer', () => {
2728

2829
it('should hook require and apply instrumentation', function () {
2930
this.sandbox.spy(instrumentationExpress, 'patch')
31+
this.sandbox.spy(instrumentationHTTPClient, 'patch')
3032

3133
tracer = new Tracer({
3234
serviceName: 'my-service'
3335
})
3436

3537
// eslint-disable-next-line
3638
const express = require('express')
39+
// eslint-disable-next-line
40+
const http = require('http')
41+
// eslint-disable-next-line
42+
const https = require('https')
3743

3844
expect(instrumentationExpress.patch).to.be.calledWith(express, tracer._tracer)
45+
expect(instrumentationHTTPClient.patch).to.be.calledWith(http, tracer._tracer)
46+
expect(instrumentationHTTPClient.patch).to.be.calledWith(https, tracer._tracer)
3947
})
4048

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

0 commit comments

Comments
 (0)