Skip to content

Commit

Permalink
fix(instrumentation): collect timings for non flowing response streams
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Marton committed Sep 7, 2017
1 parent b68e72b commit 04be8fe
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ curl http://localhost:3000
open http://localhost:16686
```

![Jaeger Node.js tracing](https://user-images.githubusercontent.com/1764512/26843812-c3198758-4af1-11e7-8aa3-1da55d9e58b6.png)
![Jaeger Node.js tracing](images/distributed_tracing.png)

## HTTP timings

You can enable it with the `httpTimings: true`

![HTTP timings](https://user-images.githubusercontent.com/1764512/30158154-92be25ca-93c4-11e7-9679-0d71ea3b8230.png)
![HTTP timings](images/http_timings.png)

## Debug

Expand Down
5 changes: 4 additions & 1 deletion example/server1.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ const tracer = new jaeger.Tracer('my-server-1', reporter, sampler, {
}
})
// eslint-disable-next-line
const instrument = new Instrument({ tracers: [tracer] })
const instrument = new Instrument({
tracers: [tracer],
httpTimings: true
})

// eslint-disable-next-line
const http = require('http')
Expand Down
Binary file added images/distributed_tracing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/http_timings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 10 additions & 10 deletions src/instrumentation/httpClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,17 @@ function patch (http, tracers, { httpTimings } = {}) {

timings.begin = Date.now()

const req = request.call(this, options, (res) => {
function finish () {
if (httpTimings) {
timings.end = Date.now()
addTimings(tracers, spans, timings)
}

spans.forEach((span) => span.finish())
isFinish = true
function finish () {
if (httpTimings) {
timings.end = Date.now()
addTimings(tracers, spans, timings)
}

spans.forEach((span) => span.finish())
isFinish = true
}

const req = request.call(this, options, (res) => {
if (res.statusCode > 399) {
spans.forEach((span) => span.setTag(Tags.ERROR, true))

Expand Down Expand Up @@ -188,7 +188,7 @@ function patch (http, tracers, { httpTimings } = {}) {
socket.on('close', () => {
// End event is not emitted when stream is not consumed fully
if (!isFinish) {
spans.forEach((span) => span.finish())
finish()
}
})
})
Expand Down

0 comments on commit 04be8fe

Please sign in to comment.