@opentelemetry/instrumentation-koa
Advanced tools
Comparing version 0.41.0 to 0.42.0
@@ -38,3 +38,3 @@ "use strict"; | ||
init() { | ||
return new instrumentation_1.InstrumentationNodeModuleDefinition('koa', ['^2.0.0'], (module) => { | ||
return new instrumentation_1.InstrumentationNodeModuleDefinition('koa', ['>=2.0.0 <3'], (module) => { | ||
const moduleExports = module[Symbol.toStringTag] === 'Module' | ||
@@ -41,0 +41,0 @@ ? module.default // ESM |
/// <reference types="koa__router" /> | ||
import type { Middleware, DefaultState } from 'koa'; | ||
import { KoaContext } from './types'; | ||
import type { Middleware, ParameterizedContext, DefaultState } from 'koa'; | ||
import type * as Router from '@koa/router'; | ||
export declare type KoaContext = ParameterizedContext<DefaultState, Router.RouterParamContext>; | ||
export declare type KoaMiddleware = Middleware<DefaultState, KoaContext> & { | ||
@@ -6,0 +6,0 @@ router?: Router; |
@@ -1,4 +0,1 @@ | ||
/// <reference types="koa__router" /> | ||
import type { Middleware, ParameterizedContext, DefaultState } from 'koa'; | ||
import type { RouterParamContext } from '@koa/router'; | ||
import { Span } from '@opentelemetry/api'; | ||
@@ -10,6 +7,26 @@ import { InstrumentationConfig } from '@opentelemetry/instrumentation'; | ||
} | ||
export declare type KoaContext = ParameterizedContext<DefaultState, RouterParamContext>; | ||
export declare type KoaRequestInfo = { | ||
context: KoaContext; | ||
middlewareLayer: Middleware<DefaultState, KoaContext>; | ||
/** | ||
* Information about the current Koa middleware layer | ||
* The middleware layer type is any by default. | ||
* One can install koa types packages `@types/koa` and `@types/koa__router` | ||
* with compatible versions to the koa version used in the project | ||
* to get more specific types for the middleware layer property. | ||
* | ||
* Example use in a custom attribute function: | ||
* ```ts | ||
* import type { Middleware, ParameterizedContext, DefaultState } from 'koa'; | ||
* import type { RouterParamContext } from '@koa/router'; | ||
* | ||
* type KoaContext = ParameterizedContext<DefaultState, RouterParamContext>; | ||
* type KoaMiddleware = Middleware<DefaultState, KoaContext>; | ||
* | ||
* const koaConfig: KoaInstrumentationConfig<KoaContext, KoaMiddleware> = { | ||
* requestHook: (span: Span, info: KoaRequestInfo<KoaContext, KoaMiddleware>) => { | ||
* // custom typescript code that can access the typed into.middlewareLayer and info.context | ||
* } | ||
* | ||
*/ | ||
export declare type KoaRequestInfo<KoaContextType = any, KoaMiddlewareType = any> = { | ||
context: KoaContextType; | ||
middlewareLayer: KoaMiddlewareType; | ||
layerType: KoaLayerType; | ||
@@ -22,4 +39,4 @@ }; | ||
*/ | ||
export interface KoaRequestCustomAttributeFunction { | ||
(span: Span, info: KoaRequestInfo): void; | ||
export interface KoaRequestCustomAttributeFunction<KoaContextType = any, KoaMiddlewareType = any> { | ||
(span: Span, info: KoaRequestInfo<KoaContextType, KoaMiddlewareType>): void; | ||
} | ||
@@ -29,8 +46,8 @@ /** | ||
*/ | ||
export interface KoaInstrumentationConfig extends InstrumentationConfig { | ||
export interface KoaInstrumentationConfig<KoaContextType = any, KoaMiddlewareType = any> extends InstrumentationConfig { | ||
/** Ignore specific layers based on their type */ | ||
ignoreLayersType?: KoaLayerType[]; | ||
/** Function for adding custom attributes to each middleware layer span */ | ||
requestHook?: KoaRequestCustomAttributeFunction; | ||
requestHook?: KoaRequestCustomAttributeFunction<KoaContextType, KoaMiddlewareType>; | ||
} | ||
//# sourceMappingURL=types.d.ts.map |
@@ -1,3 +0,3 @@ | ||
import { KoaContext, KoaLayerType, KoaInstrumentationConfig } from './types'; | ||
import { KoaMiddleware } from './internal-types'; | ||
import { KoaLayerType, KoaInstrumentationConfig } from './types'; | ||
import { KoaContext, KoaMiddleware } from './internal-types'; | ||
import { Attributes } from '@opentelemetry/api'; | ||
@@ -14,3 +14,3 @@ export declare const getMiddlewareMetadata: (context: KoaContext, layer: KoaMiddleware, isRouter: boolean, layerPath?: string | RegExp | undefined) => { | ||
*/ | ||
export declare const isLayerIgnored: (type: KoaLayerType, config?: KoaInstrumentationConfig | undefined) => boolean; | ||
export declare const isLayerIgnored: (type: KoaLayerType, config?: KoaInstrumentationConfig<any, any> | undefined) => boolean; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -1,3 +0,3 @@ | ||
export declare const PACKAGE_VERSION = "0.41.0"; | ||
export declare const PACKAGE_VERSION = "0.42.0"; | ||
export declare const PACKAGE_NAME = "@opentelemetry/instrumentation-koa"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -20,4 +20,4 @@ "use strict"; | ||
// this is autogenerated file, see scripts/version-update.js | ||
exports.PACKAGE_VERSION = '0.41.0'; | ||
exports.PACKAGE_VERSION = '0.42.0'; | ||
exports.PACKAGE_NAME = '@opentelemetry/instrumentation-koa'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@opentelemetry/instrumentation-koa", | ||
"version": "0.41.0", | ||
"version": "0.42.0", | ||
"description": "OpenTelemetry instrumentation for `koa` http web application framework", | ||
@@ -15,2 +15,3 @@ "main": "build/src/index.js", | ||
"lint:fix": "eslint . --ext .ts --fix", | ||
"lint:readme": "node ../../../scripts/lint-readme.js", | ||
"precompile": "tsc --version && lerna run version:update --scope @opentelemetry/instrumentation-koa --include-dependencies", | ||
@@ -56,2 +57,4 @@ "prewatch": "npm run precompile", | ||
"@opentelemetry/sdk-trace-node": "^1.8.0", | ||
"@types/koa": "2.15.0", | ||
"@types/koa__router": "12.0.4", | ||
"@types/mocha": "7.0.2", | ||
@@ -72,8 +75,6 @@ "@types/node": "18.6.5", | ||
"@opentelemetry/instrumentation": "^0.52.0", | ||
"@opentelemetry/semantic-conventions": "^1.22.0", | ||
"@types/koa": "2.14.0", | ||
"@types/koa__router": "12.0.3" | ||
"@opentelemetry/semantic-conventions": "^1.22.0" | ||
}, | ||
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-koa#readme", | ||
"gitHead": "0af1b70f7c3c9763c85ac51fa5e334c1e1512020" | ||
"gitHead": "ad8436d6a4174f2288cb939080cd4e74da94b0d7" | ||
} |
@@ -10,2 +10,4 @@ # OpenTelemetry Koa Instrumentation for Node.js | ||
Compatible with OpenTelemetry JS API and SDK `1.0+`. | ||
## Status | ||
@@ -25,4 +27,4 @@ | ||
- `koa`: `^2.0.0` | ||
- `@koa/router`: `>=8` | ||
- [`koa`](https://www.npmjs.com/package/koa) versions `>=2.0.0 <3` | ||
- [`@koa/router`](https://www.npmjs.com/package/@koa/router) versions `>=8.0.0` | ||
@@ -68,7 +70,14 @@ ## Usage | ||
```javascript | ||
NOTE: `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: | ||
```typescript | ||
import { KoaInstrumentation } from "@opentelemetry/instrumentation-koa" | ||
import type { Middleware, ParameterizedContext, DefaultState } from 'koa'; | ||
import type { RouterParamContext } from '@koa/router'; | ||
type KoaContext = ParameterizedContext<DefaultState, RouterParamContext>; | ||
type KoaMiddleware = Middleware<DefaultState, KoaContext>; | ||
const koaInstrumentation = new KoaInstrumentation({ | ||
requestHook: function (span: Span, info: KoaRequestInfo) { | ||
requestHook: function (span: Span, info: KoaRequestInfo<KoaContext, KoaMiddleware>) { | ||
span.setAttribute( | ||
@@ -75,0 +84,0 @@ 'http.method', |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61375
4
427
107
20
- Removed@types/koa@2.14.0
- Removed@types/koa__router@12.0.3
- Removed@types/accepts@1.3.7(transitive)
- Removed@types/body-parser@1.19.5(transitive)
- Removed@types/connect@3.4.38(transitive)
- Removed@types/content-disposition@0.5.8(transitive)
- Removed@types/cookies@0.9.0(transitive)
- Removed@types/express@4.17.21(transitive)
- Removed@types/express-serve-static-core@4.19.5(transitive)
- Removed@types/http-assert@1.5.5(transitive)
- Removed@types/http-errors@2.0.4(transitive)
- Removed@types/keygrip@1.0.6(transitive)
- Removed@types/koa@2.14.0(transitive)
- Removed@types/koa-compose@3.2.8(transitive)
- Removed@types/koa__router@12.0.3(transitive)
- Removed@types/mime@1.3.5(transitive)
- Removed@types/node@22.5.4(transitive)
- Removed@types/qs@6.9.15(transitive)
- Removed@types/range-parser@1.2.7(transitive)
- Removed@types/send@0.17.4(transitive)
- Removed@types/serve-static@1.15.7(transitive)
- Removedundici-types@6.19.8(transitive)