Skip to content

Commit

Permalink
fix(instrumentation-express)!: remove @types/express from dependenc…
Browse files Browse the repository at this point in the history
…ies (#1804)

Closes: #1787
  • Loading branch information
david-luna committed Dec 7, 2023
1 parent bcf3501 commit 86a21d7
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions plugins/node/opentelemetry-instrumentation-express/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ Express instrumentation has few options available to choose from. You can set th
- `info: ExpressRequestInfo` containing the incoming Express.js request, the current route handler creating a span and `ExpressLayerType` - the type of the handling layer.
- `defaultName: string` - original name proposed by the instrumentation.

`requestHook` is invoked with 2 arguments:

- `span: Span` - the span associated with the express request.
- `info: ExpressRequestInfo` containing the incoming Express.js request, the current route handler creating a span and `ExpressLayerType` - the type of the handling layer.

NOTE: `ExpressRequestInfo.request` is typed as `any`. If you want type support make sure you have `@types/express` installed then you can use `ExpressRequestInfo<express.Request>`

#### Ignore a whole Express route

In order to ignore whole traces that represent a given Express route, use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@opentelemetry/context-async-hooks": "^1.8.0",
"@opentelemetry/sdk-trace-base": "^1.8.0",
"@opentelemetry/sdk-trace-node": "^1.8.0",
"@types/express": "4.17.18",
"@types/mocha": "7.0.2",
"@types/node": "18.6.5",
"@types/sinon": "10.0.18",
Expand All @@ -64,8 +65,7 @@
"dependencies": {
"@opentelemetry/core": "^1.8.0",
"@opentelemetry/instrumentation": "^0.45.1",
"@opentelemetry/semantic-conventions": "^1.0.0",
"@types/express": "4.17.18"
"@opentelemetry/semantic-conventions": "^1.0.0"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-express#readme"
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
trace,
context,
diag,
SpanAttributes,
Attributes,
SpanStatusCode,
} from '@opentelemetry/api';
import type * as express from 'express';
Expand Down Expand Up @@ -199,7 +199,7 @@ export class ExpressInstrumentation extends InstrumentationBase<
.filter(path => path !== '/' && path !== '/*')
.join('');

const attributes: SpanAttributes = {
const attributes: Attributes = {
[SemanticAttributes.HTTP_ROUTE]: route.length > 0 ? route : '/',
};
const metadata = getLayerMetadata(layer, layerPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import type { Request } from 'express';
import { SpanAttributes } from '@opentelemetry/api';
import { Attributes } from '@opentelemetry/api';

/**
* This symbol is used to mark express layer as being already instrumented
Expand Down Expand Up @@ -67,6 +67,6 @@ export type ExpressLayer = {
};

export type LayerMetadata = {
attributes: SpanAttributes;
attributes: Attributes;
name: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* limitations under the License.
*/

import type { Request } from 'express';
import { Span } from '@opentelemetry/api';
import { InstrumentationConfig } from '@opentelemetry/instrumentation';
import { ExpressLayerType } from './enums/ExpressLayerType';

export type IgnoreMatcher = string | RegExp | ((name: string) => boolean);

export type ExpressRequestInfo = {
request: Request;
export type ExpressRequestInfo<T = any> = {
/** An express request object */
request: T;
route: string;
layerType: ExpressLayerType;
};
Expand All @@ -47,7 +47,7 @@ export interface ExpressRequestCustomAttributeFunction {
}

/**
* Options available for the Express Instrumentation (see [documentation](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-Instrumentation-express#express-Instrumentation-options))
* Options available for the Express Instrumentation (see [documentation](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-express#express-instrumentation-options))
*/
export interface ExpressInstrumentationConfig extends InstrumentationConfig {
/** Ignore specific based on their name */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { SpanAttributes } from '@opentelemetry/api';
import { Attributes } from '@opentelemetry/api';
import { IgnoreMatcher, ExpressInstrumentationConfig } from './types';
import { ExpressLayerType } from './enums/ExpressLayerType';
import { AttributeNames } from './enums/AttributeNames';
Expand Down Expand Up @@ -49,7 +49,7 @@ export const getLayerMetadata = (
layer: ExpressLayer,
layerPath?: string
): {
attributes: SpanAttributes;
attributes: Attributes;
name: string;
} => {
if (layer.name === 'router') {
Expand Down

0 comments on commit 86a21d7

Please sign in to comment.