-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(restify): add requestHook support (#1312)
* feat(restify): add requestHook support The `requestHook` config option allows custom span handling per request layer. * fix(restify): pass config to super class As mentioned in the review, pass the instrumentation config to the parent class. That way the config is also stored when given to the initializer, rather only when using the `setConfig` function. * fix(restify): fix comment referencing restify type Update comment to reference to correct type from the `@types/restify` package. * fix(restify): import missing Span type Add the missing import reported by the linter. * fix(restify): fix issues reported by linter * fix(restify): fix comment referencing restify type Mention the package name exactly. * fix(restify): fix comment referencing restify type Co-authored-by: Amir Blum <amirgiraffe@gmail.com> * fix(restify): add missing import in restify test * feat(restify): add layer argument to requestHook Add the layerType argument to the requestHook function. This is like the following PR but for restify: #1226 Move the LayerType from internal-types to types, because it's now used in a function used by users of the instrumentation package. Co-authored-by: Amir Blum <amirgiraffe@gmail.com>
- Loading branch information
Showing
6 changed files
with
187 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
plugins/node/opentelemetry-instrumentation-restify/src/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { Span } from '@opentelemetry/api'; | ||
import { InstrumentationConfig } from '@opentelemetry/instrumentation'; | ||
|
||
export enum LayerType { | ||
MIDDLEWARE = 'middleware', | ||
REQUEST_HANDLER = 'request_handler', | ||
} | ||
|
||
export interface RestifyRequestInfo { | ||
request: any; // Request type from @types/restify package | ||
layerType: LayerType; | ||
} | ||
|
||
/** | ||
* Function that can be used to add custom attributes to the current span | ||
* @param span - The restify handler span. | ||
* @param info - The restify request info object. | ||
*/ | ||
export interface RestifyCustomAttributeFunction { | ||
(span: Span, info: RestifyRequestInfo): void; | ||
} | ||
|
||
/** | ||
* Options available for the restify Instrumentation | ||
*/ | ||
export interface RestifyInstrumentationConfig extends InstrumentationConfig { | ||
/** Function for adding custom attributes to each handler span */ | ||
requestHook?: RestifyCustomAttributeFunction; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters