@opentelemetry/instrumentation-restify
Advanced tools
Comparing version 0.31.0 to 0.32.0
@@ -5,2 +5,3 @@ import { RestifyInstrumentation } from './instrumentation'; | ||
export * from './enums/AttributeNames'; | ||
export * from './types'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -32,2 +32,3 @@ "use strict"; | ||
__exportStar(require("./enums/AttributeNames"), exports); | ||
__exportStar(require("./types"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -1,6 +0,9 @@ | ||
import { InstrumentationBase, InstrumentationConfig, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation'; | ||
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation'; | ||
import type { RestifyInstrumentationConfig } from './types'; | ||
export declare class RestifyInstrumentation extends InstrumentationBase<any> { | ||
constructor(config?: InstrumentationConfig); | ||
constructor(config?: RestifyInstrumentationConfig); | ||
private _moduleVersion?; | ||
private _isDisabled; | ||
setConfig(config?: RestifyInstrumentationConfig): void; | ||
getConfig(): RestifyInstrumentationConfig; | ||
init(): InstrumentationNodeModuleDefinition<any>; | ||
@@ -7,0 +10,0 @@ private _middlewarePatcher; |
@@ -20,3 +20,3 @@ "use strict"; | ||
const api = require("@opentelemetry/api"); | ||
const internal_types_1 = require("./internal-types"); | ||
const types_1 = require("./types"); | ||
const AttributeNames = require("./enums/AttributeNames"); | ||
@@ -32,5 +32,11 @@ const version_1 = require("./version"); | ||
constructor(config = {}) { | ||
super(`@opentelemetry/instrumentation-${constants.MODULE_NAME}`, version_1.VERSION); | ||
super(`@opentelemetry/instrumentation-${constants.MODULE_NAME}`, version_1.VERSION, Object.assign({}, config)); | ||
this._isDisabled = false; | ||
} | ||
setConfig(config = {}) { | ||
this._config = Object.assign({}, config); | ||
} | ||
getConfig() { | ||
return this._config; | ||
} | ||
init() { | ||
@@ -76,3 +82,3 @@ const module = new instrumentation_1.InstrumentationNodeModuleDefinition(constants.MODULE_NAME, constants.SUPPORTED_VERSIONS, (moduleExports, moduleVersion) => { | ||
return function (...handler) { | ||
return original.call(this, instrumentation._handlerPatcher({ type: internal_types_1.LayerType.MIDDLEWARE, methodName }, handler)); | ||
return original.call(this, instrumentation._handlerPatcher({ type: types_1.LayerType.MIDDLEWARE, methodName }, handler)); | ||
}; | ||
@@ -83,3 +89,3 @@ } | ||
return function (path, ...handler) { | ||
return original.call(this, path, ...instrumentation._handlerPatcher({ type: internal_types_1.LayerType.REQUEST_HANDLER, path, methodName }, handler)); | ||
return original.call(this, path, ...instrumentation._handlerPatcher({ type: types_1.LayerType.REQUEST_HANDLER, path, methodName }, handler)); | ||
}; | ||
@@ -107,3 +113,3 @@ } | ||
const fnName = handler.name || undefined; | ||
const spanName = metadata.type === internal_types_1.LayerType.REQUEST_HANDLER | ||
const spanName = metadata.type === types_1.LayerType.REQUEST_HANDLER | ||
? `request handler - ${route}` | ||
@@ -121,2 +127,16 @@ : `middleware - ${fnName || 'anonymous'}`; | ||
}, api.context.active()); | ||
const instrumentation = this; | ||
const requestHook = instrumentation.getConfig().requestHook; | ||
if (requestHook) { | ||
instrumentation_1.safeExecuteInTheMiddle(() => { | ||
return requestHook(span, { | ||
request: req, | ||
layerType: metadata.type, | ||
}); | ||
}, e => { | ||
if (e) { | ||
instrumentation._diag.error('request hook failed', e); | ||
} | ||
}, true); | ||
} | ||
const patchedNext = (err) => { | ||
@@ -123,0 +143,0 @@ span.end(); |
import { Span } from '@opentelemetry/api'; | ||
import type * as restify from 'restify'; | ||
export declare enum LayerType { | ||
MIDDLEWARE = "middleware", | ||
REQUEST_HANDLER = "request_handler" | ||
} | ||
import { LayerType } from './types'; | ||
declare interface RequestWithRoute extends restify.Request { | ||
@@ -8,0 +5,0 @@ route: { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LayerType = void 0; | ||
var LayerType; | ||
(function (LayerType) { | ||
LayerType["MIDDLEWARE"] = "middleware"; | ||
LayerType["REQUEST_HANDLER"] = "request_handler"; | ||
})(LayerType = exports.LayerType || (exports.LayerType = {})); | ||
//# sourceMappingURL=internal-types.js.map |
@@ -1,2 +0,2 @@ | ||
export declare const VERSION = "0.31.0"; | ||
export declare const VERSION = "0.32.0"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -20,3 +20,3 @@ "use strict"; | ||
// this is autogenerated file, see scripts/version-update.js | ||
exports.VERSION = '0.31.0'; | ||
exports.VERSION = '0.32.0'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@opentelemetry/instrumentation-restify", | ||
"version": "0.31.0", | ||
"version": "0.32.0", | ||
"description": "OpenTelemetry restify automatic instrumentation package", | ||
@@ -73,3 +73,3 @@ "main": "build/src/index.js", | ||
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-restify#readme", | ||
"gitHead": "59fa57cfd0dff4ae0e6f3833dff73c55dfd79ee5" | ||
"gitHead": "8472e8273d14993a13f921b6f8173b20fb37a383" | ||
} |
@@ -44,2 +44,23 @@ # OpenTelemetry Restify Instrumentation for Node.js | ||
## Restify Instrumentation Options | ||
| Options | Type | Example | Description | | ||
| `requestHook` | `RestifyCustomAttributeFunction` | `(span, requestInfo) => {}` | Function for adding custom attributes to restify requests. Receives params: `Span, RestifyRequestInfo`. | | ||
### Using `requestHook` | ||
Instrumentation configuration accepts a custom "hook" function which will be called for every instrumented restify request. Custom attributes can be set on the span or run any custom logic per request. | ||
```javascript | ||
import { RestifyInstrumentation } from "@opentelemetry/instrumentation-restify" | ||
const restifyInstrumentation = new RestifyInstrumentation({ | ||
requestHook: function (span: Span, info: RestifyRequestInfo) { | ||
span.setAttribute( | ||
'http.method', | ||
info.request.method, | ||
) | ||
} | ||
}); | ||
``` | ||
## Useful links | ||
@@ -46,0 +67,0 @@ |
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
43671
27
427
80