{"name":"@opentelemetry/context-async-hooks","version":"2.0.0-dev.0","keywords":["opentelemetry","nodejs","tracing","profiling","metrics","stats"],"author":{"name":"OpenTelemetry Authors"},"license":"Apache-2.0","_id":"@opentelemetry/context-async-hooks@2.0.0-dev.0","homepage":"https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-context-async-hooks","bugs":{"url":"https://github.com/open-telemetry/opentelemetry-js/issues"},"dist":{"shasum":"1b4d011c7e74b5fe647c3d06254c7a893a30f79e","tarball":"http://registry-npm.ywwl.com/@opentelemetry/context-async-hooks/download/@opentelemetry/context-async-hooks-2.0.0-dev.0.tgz","fileCount":18,"integrity":"sha512-5myaYGXVBVIP4wZVoUpMcI80+Wn4sG64kuwc3OO2LVi4jZxMv/hKZA7IO8WvgQMP9gHSWDSS4FN2VXuOyoYmcw==","signatures":[{"sig":"MEQCIDZQeIYGqoEMo/OCPkWLEVWba48aTYEEgi/Wb6nNs8HFAiAUwE8bRlNkkvIoQECTxoRtQUdcwvEMgrRlNzHGilnxUw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@opentelemetry%2fcontext-async-hooks@2.0.0-dev.0","provenance":{"predicateType":"https://slsa.dev/provenance/v0.2"}},"unpackedSize":59162,"size":13663,"noattachment":false,"key":"/@opentelemetry/context-async-hooks/-/@opentelemetry/context-async-hooks-2.0.0-dev.0.tgz"},"main":"build/src/index.js","types":"build/src/index.d.ts","engines":{"node":"^18.19.0 || >=20.6.0"},"gitHead":"544c40984797dd2e2cccb92cce0e88b30f235b02","scripts":{"tdd":"npm run test -- --watch-extensions ts --watch","lint":"eslint . --ext .ts","test":"nyc mocha 'test/**/*.test.ts'","clean":"tsc --build --clean","compile":"tsc --build","version":"node ../../scripts/version-update.js","lint:fix":"eslint . --ext .ts --fix","prewatch":"npm run precompile","precompile":"cross-var lerna run version --scope $npm_package_name --include-dependencies","align-api-deps":"node ../../scripts/align-api-deps.js","peer-api-check":"node ../../scripts/peer-api-check.js","prepublishOnly":"npm run compile"},"_npmUser":{"name":"dyladan","email":"dyladan@gmail.com"},"repository":{"url":"git+https://github.com/open-telemetry/opentelemetry-js.git","type":"git"},"_npmVersion":"lerna/6.6.2/node@v18.20.6+x64 (linux)","description":"OpenTelemetry AsyncHooks-based Context Manager","directories":{},"sideEffects":false,"_nodeVersion":"18.20.6","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"17.1.0","lerna":"6.6.2","mocha":"11.1.0","cross-var":"1.1.0","typescript":"5.0.4","@types/node":"18.6.5","@types/mocha":"10.0.10","@opentelemetry/api":">=1.0.0 <1.10.0"},"peerDependencies":{"@opentelemetry/api":">=1.0.0 <1.10.0"},"_npmOperationalInternal":{"tmp":"tmp/context-async-hooks_2.0.0-dev.0_1740420118525_0.8273362600143388","host":"s3://npm-registry-packages-npm-production"},"readme":"# OpenTelemetry async_hooks-based Context Managers\n\n[![NPM Published Version][npm-img]][npm-url]\n[![Apache License][license-image]][license-image]\n\nThis package provides two [`ContextManager`](https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_api.ContextManager.html) implementations built on APIs from Node.js's [`async_hooks`][async-hooks-doc] module. If you're looking for a `ContextManager` to use in browser environments, consider [opentelemetry-context-zone](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-context-zone) or [opentelemetry-context-zone-peer-dep](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-context-zone-peer-dep).\n\nThe definition of the `ContextManager` interface and the problem it solves can be found [here][def-context-manager].\n\n## API\n\nTwo `ContextManager` implementations are exported:\n\n- `AsyncLocalStorageContextManager`, based on [`AsyncLocalStorage`](https://nodejs.org/api/async_context.html#class-asynclocalstorage)\n- `AsyncHooksContextManager`, based on [`AsyncHook`](https://nodejs.org/api/async_hooks.html#async_hooks_class_asynchook)\n\nThe former should be preferred over the latter as its implementation is substantially simpler than the latter's, and according to [Node.js docs](https://github.com/nodejs/node/blame/v17.1.0/doc/api/async_context.md#L42-L45),\n\n> While you can create your own implementation [of `AsyncLocalStorage`] on top of [`AsyncHook`], `AsyncLocalStorage` should be preferred as it is a performant and memory safe implementation that involves significant optimizations that are non-obvious to implement.\n\n`AsyncLocalStorage` is available in node `^12.17.0 || >= 13.10.0`, however `AsyncLocalStorageContextManager` is not enabled by default for node `<14.8.0` because of some important bugfixes which were introduced in `v14.8.0` (e.g., [nodejs/node#34573](https://github.com/nodejs/node/pull/34573)).\n\n## Limitations\n\nIt's possible that this package won't track context perfectly when used with certain packages. In particular, it inherits any bugs present in async_hooks. See [here][pkgs-that-break-ah] for known issues.\n\nasync_hooks is still seeing significant correctness and performance fixes, it's recommended to run the latest Node.js LTS release to benefit from said fixes.\n\n## Prior art\n\nContext propagation is a big subject when talking about tracing in Node.js. If you want more information about it here are some resources:\n\n- <https://www.npmjs.com/package/continuation-local-storage> (which was the old way of doing context propagation)\n- Datadog's own implementation for their JavaScript tracer: [here][dd-js-tracer-scope]\n- OpenTracing implementation: [here][opentracing-scope]\n- Discussion about context propagation by the Node.js Diagnostics Working Group: [here][diag-team-scope-discussion]\n\n## Useful links\n\n- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>\n- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>\n- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]\n\n## License\n\nApache 2.0 - See [LICENSE][license-url] for more information.\n\n[discussions-url]: https://github.com/open-telemetry/opentelemetry-js/discussions\n[license-url]: https://github.com/open-telemetry/opentelemetry-js/blob/main/LICENSE\n[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat\n[async-hooks-doc]: http://nodejs.org/dist/latest/docs/api/async_hooks.html\n[def-context-manager]: https://opentelemetry.io/docs/instrumentation/js/api/context/#context-manager\n[dd-js-tracer-scope]: https://github.com/DataDog/dd-trace-js/blob/master/packages/dd-trace/src/scope.js\n[opentracing-scope]: https://github.com/opentracing/opentracing-javascript/pull/113\n[diag-team-scope-discussion]: https://github.com/nodejs/diagnostics/issues/300\n[pkgs-that-break-ah]: https://github.com/nodejs/diagnostics/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Aasync-continuity\n[npm-url]: https://www.npmjs.com/package/@opentelemetry/context-async-hooks\n[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fcontext-async-hooks.svg\n","publish_time":1740420118793,"maintainers":[{"name":"bogdandrutu","email":"bogdandrutu@gmail.com"},{"name":"dyladan","email":"dyladan@gmail.com"},{"name":"pichlermarc","email":"marc.pichler@dynatrace.com"}],"_cnpm_publish_time":1740420118793,"dist-tags":{"canary":"3.0.0-rc.0","latest":"3.1.0","next":"1.8.0"}}