https://github.com/pthm/superagent-opentracing
Opentracing instrumentation for superagent requests
https://github.com/pthm/superagent-opentracing
Last synced: 8 months ago
JSON representation
Opentracing instrumentation for superagent requests
- Host: GitHub
- URL: https://github.com/pthm/superagent-opentracing
- Owner: pthm
- License: mit
- Created: 2018-03-28T23:08:26.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-28T23:28:47.000Z (about 8 years ago)
- Last Synced: 2025-09-16T10:08:36.428Z (9 months ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/superagent-opentracing
- Size: 6.84 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# superagent-opentracing
Opentracing instrumentation for superagent requests
## Installation
```bash
npm install -g superagent-opentracing
```
## Usage
By default the `globalTracer` is used for all requests, headers are injected into all requests for extraction by other services. This library does not handle extraction.
### Standalone tracing
```typescript
const tracing = require('superagent-opentracing');
const request = require('superagent');
request.get('http://google.com')
.use(tracing())
.end((response) => {
console.log('Response', response);
});
```
### Trace as child
```typescript
const tracing = require('superagent-opentracing');
const request = require('superagent');
const opentracing = require('opentracing');
const tracer = opentracing.globalTracer();
const span = tracer.startSpan('some.request');
request.get('http://google.com')
.use(tracing(span))
.end((err, response) => {
console.log('Response', response);
if(err){
span.setTag(opentracing.Tags.ERROR, true);
span.log({'event': 'error', 'error.object': err, 'message': err.message, 'stack': err.stack});
}
span.finish();
})
```