Registry / devops / zipkin-axios

zipkin-axios

JSON →
library0.2.4jsnpmunverified

Instrumentation wrapper for the axios HTTP client, enabling distributed tracing via Zipkin. This package is a maintained fork of zipkin-instrumentation-axios (which is no longer maintained). Current version 0.2.4 stable. Requires zipkin >= 0.15.0 as a peer dependency. Primary differentiator: provides a simple wrapAxios function returning a traced axios instance, compatible with browser and Node.js environments.

npm install zipkin-axios
INSTALL
IMPORT
SIG · ZIPKIN-AXIOS
Z
zipkin-axios
devopsjavascriptv0.2.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

wrapAxios
import wrapAxios from 'zipkin-axios'
const { wrapAxios } = require('zipkin-axios')
Default export only; named export not available. CommonJS users must use `require('zipkin-axios').default` or the pattern shown.
zipkin-axios
const wrapAxios = require('zipkin-axios')
const wrapAxios = require('zipkin-axios').default
The CJS module assigns the default export to module.exports; using .default is unnecessary.
zipkin-axios (type import)
import wrapAxios from 'zipkin-axios'
import { wrapAxios } from 'zipkin-axios'
No named exports available.

Shows how to wrap an axios instance with Zipkin tracing and make a traced GET request.

const axios = require('axios'); const wrapAxios = require('zipkin-axios'); const { HttpLogger } = require('zipkin-transport-http'); const { Tracer, ExplicitContext, BatchRecorder } = require('zipkin'); const ctxImpl = new ExplicitContext(); const recorder = new BatchRecorder({ logger: new HttpLogger({ endpoint: `http://localhost:9411/api/v1/spans` }) }); const tracer = new Tracer({ ctxImpl, recorder }); const zipkinAxios = wrapAxios(axios, { tracer, serviceName: 'myService' }); zipkinAxios.get('http://another-service/foo') .then(result => console.log(result.data)) .catch(e => console.error(e));
Debug
Known issues
gotchawrapAxios mutates the original axios instance; create a copy if the original needs to remain untraced.
fix
Use axios.create() to get a new instance before passing to wrapAxios.
affects: >=0.0.0
gotchaThe package does not ship TypeScript definitions; users must create custom typings or use @types/zipkin-axios if available.
fix
Add a .d.ts file: declare module 'zipkin-axios' { function wrapAxios(axios: any, options: any): any; export default wrapAxios; }
affects: >=0.0.0
deprecatedThe original package zipkin-instrumentation-axios is deprecated; this fork is the recommended replacement.
fix
Migrate to zipkin-axios by replacing imports.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: wrapAxios is not a function
Using named import { wrapAxios } instead of default import in ESM.
fix
Change to `import wrapAxios from 'zipkin-axios'` or use `const wrapAxios = require('zipkin-axios')` in CJS.
Module not found: Can't resolve 'zipkin-axios'
Package not installed or missing peer dependency zipkin.
fix
Run `npm install --save zipkin-axios zipkin` to install both.
Upgrade
Version history
0.2.4latest on npm
Audit
Dependencies
zipkinrequiredpeer dependency for tracer and context
Agent activity
33 hits · last 30 days
node
30
Resources
zipkin-axios — npm install zipkin-axios · libregistry