{"name":"@opentelemetry/instrumentation-koa","version":"0.52.0","keywords":["instrumentation","koa","nodejs","opentelemetry","plugin","profiling","tracing"],"author":"OpenTelemetry Authors","license":"Apache-2.0","_id":"@opentelemetry/instrumentation-koa@0.52.0","maintainers":[{"name":"dyladan","email":"dyladan@gmail.com"},{"name":"pichlermarc","email":"marc.pichler@dynatrace.com"}],"homepage":"https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-koa#readme","dist":{"shasum":"7266785ea85334366c3e50dc2b45468df438eb3f","tarball":"http://registry-npm.ywwl.com/@opentelemetry/instrumentation-koa/download/@opentelemetry/instrumentation-koa-0.52.0.tgz","fileCount":24,"integrity":"sha512-JJSBYLDx/mNSy8Ibi/uQixu2rH0bZODJa8/cz04hEhRaiZQoeJ5UrOhO/mS87IdgVsHrnBOsZ6vDu09znupyuA==","signatures":[{"sig":"MEUCIHKr6BSFzEmh4gtZ1SPFmjlPPRYFw/3tpNqrcZnLe7/KAiEA0Dh0fFj5OvyQ7ogapwEoOGRV01duhb7vfS0jhATVloI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@opentelemetry%2finstrumentation-koa@0.52.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":60648,"size":14373,"noattachment":false,"key":"/@opentelemetry/instrumentation-koa/-/@opentelemetry/instrumentation-koa-0.52.0.tgz"},"main":"build/src/index.js","types":"build/src/index.d.ts","engines":{"node":"^18.19.0 || >=20.6.0"},"gitHead":"0a45ac1b951d2acd2e40834e7ae012c04820faec","scripts":{"tdd":"npm run test -- --watch-extensions ts --watch","lint":"eslint . --ext=ts,js,mjs","test":"nyc --no-clean mocha 'test/**/*.ts'","clean":"rimraf build/*","watch":"tsc -w","compile":"tsc -p .","lint:fix":"eslint . --ext=ts,js,mjs --fix","lint:readme":"node ../../scripts/lint-readme.js","prepublishOnly":"npm run compile","version:update":"node ../../scripts/version-update.js","test-all-versions":"tav","test-merge-coverage":"nyc merge .nyc_output coverage/coverage-final.json","compile:with-dependencies":"nx run-many -t compile -p @opentelemetry/instrumentation-koa"},"_npmUser":{"name":"dyladan","email":"dyladan@gmail.com"},"repository":{"url":"https://github.com/open-telemetry/opentelemetry-js-contrib.git","type":"git","directory":"packages/instrumentation-koa"},"_npmVersion":"lerna/8.2.3/node@v18.20.8+x64 (linux)","description":"OpenTelemetry instrumentation for `koa` http web application framework","directories":{},"_nodeVersion":"18.20.8","dependencies":{"@opentelemetry/core":"^2.0.0","@opentelemetry/instrumentation":"^0.204.0","@opentelemetry/semantic-conventions":"^1.27.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"koa":"2.16.1","nyc":"17.1.0","sinon":"15.2.0","rimraf":"5.0.10","semver":"7.7.2","@types/koa":"2.15.0","typescript":"5.0.4","@koa/router":"14.0.0","@types/node":"18.18.14","@types/mocha":"10.0.10","@types/sinon":"17.0.4","test-all-versions":"6.1.0","@opentelemetry/api":"^1.3.0","@types/koa__router":"12.0.4","@opentelemetry/sdk-trace-base":"^2.0.0","@opentelemetry/sdk-trace-node":"^2.0.0","@opentelemetry/contrib-test-utils":"^0.50.0","@opentelemetry/context-async-hooks":"^2.0.0","@opentelemetry/instrumentation-http":"^0.204.0"},"peerDependencies":{"@opentelemetry/api":"^1.3.0"},"_npmOperationalInternal":{"tmp":"tmp/instrumentation-koa_0.52.0_1757341941035_0.8219096745641468","host":"s3://npm-registry-packages-npm-production"},"readme":"# OpenTelemetry Koa Instrumentation for Node.js\n\n[![NPM Published Version][npm-img]][npm-url]\n[![Apache License][license-image]][license-image]\n\nThis module provides automatic instrumentation for the [Koa](https://github.com/koajs/koa) module.\n\nIf total installation size is not constrained, it is recommended to use the [`@opentelemetry/auto-instrumentations-node`](https://www.npmjs.com/package/@opentelemetry/auto-instrumentations-node) bundle with [@opentelemetry/sdk-node](https://www.npmjs.com/package/@opentelemetry/sdk-node) for the most seamless instrumentation experience.\n\nCompatible with OpenTelemetry JS API and SDK `1.0+`.\n\n## Status\n\n| Maturity                                           | [Component Owner](../../.github/component_owners.yml) | Compatibility         |\n|----------------------------------------------------|-------------------------------------------------------|-----------------------|\n| [Unmaintained](../../CONTRIBUTING.md#unmaintained) | N/A                                                   | API 1.0+<br/>SDK 1.0+ |\n\n## Installation\n\n```bash\nnpm install --save @opentelemetry/instrumentation-koa\n```\n\n### Supported Versions\n\n- [`koa`](https://www.npmjs.com/package/koa) versions `>=2.0.0 <4`\n- [`@koa/router`](https://www.npmjs.com/package/@koa/router) versions `>=8.0.0`\n\n## Usage\n\nOpenTelemetry Koa Instrumentation allows the user to automatically collect trace data and export them to their backend of choice, to give observability to distributed systems.\n\n```js\nconst { NodeSDK } = require('@opentelemetry/sdk-node');\nconst { KoaInstrumentation } = require('@opentelemetry/instrumentation-koa');\n\nconst sdk = new NodeSDK({\n  instrumentations: [\n    new KoaInstrumentation(),\n  ],\n});\nsdk.start();\nprocess.once('beforeExit', async () => { await sdk.shutdown(); });\n```\n\nSee [`examples/koa`](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/examples/koa) for a short example using both Koa and @koa/router.\n\nNote that generator-based middleware are deprecated and won't be instrumented.\n\n### Koa Instrumentation Options\n\n| Options            | Type                                | Example              | Description                                                                                              |\n| ------------------ | ----------------------------------- | -------------------- | -------------------------------------------------------------------------------------------------------- |\n| `ignoreLayersType` | `KoaLayerType[]`                    | `['middleware']`     | Ignore layers of specified type.                                                                         |\n| `requestHook`      | `KoaRequestCustomAttributeFunction` | `(span, info) => {}` | Function for adding custom attributes to Koa middleware layers. Receives params: `Span, KoaRequestInfo`. |\n\n`ignoreLayersType` accepts an array of `KoaLayerType` which can take the following string values:\n\n- `router`,\n- `middleware`.\n\n#### Using `requestHook`\n\nInstrumentation configuration accepts a custom \"hook\" function which will be called for every instrumented Koa middleware layer involved in a request. Custom attributes can be set on the span or run any custom logic per layer.\n\nNOTE: `KoaRequestInfo.context` and `KoaRequestInfo.middlewareLayer` are typed as `any`. If you want type support make sure you have `@types/koa` and `@types/koa__router` installed then you can use the following type definitions:\n\n```typescript\nimport { KoaInstrumentation } from \"@opentelemetry/instrumentation-koa\"\nimport type { Middleware, ParameterizedContext, DefaultState } from 'koa';\nimport type { RouterParamContext } from '@koa/router';\n\ntype KoaContext = ParameterizedContext<DefaultState, RouterParamContext>;\ntype KoaMiddleware = Middleware<DefaultState, KoaContext>;\n\nconst koaInstrumentation = new KoaInstrumentation({\n  requestHook: function (span: Span, info: KoaRequestInfo<KoaContext, KoaMiddleware>) {\n    span.setAttribute(\n      'http.method',\n      info.context.request.method\n    )\n  }\n});\n```\n\n## Koa Packages\n\nThis package provides automatic tracing for middleware added using either the core [`koa`](https://github.com/koajs/koa) package or the [`@koa/router`](https://github.com/koajs/router) package.\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-contrib/blob/main/LICENSE\n[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat\n[npm-url]: https://www.npmjs.com/package/@opentelemetry/instrumentation-koa\n[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Finstrumentation-koa.svg\n","publish_time":1757341941246,"_cnpm_publish_time":1757341941246,"dist-tags":{"latest":"0.73.0"}}