Skip to content

Commit 61088a7

Browse files
committed
chore: lint files
1 parent 95dfd78 commit 61088a7

File tree

4 files changed

+60
-43
lines changed

4 files changed

+60
-43
lines changed

packages/opentelemetry-plugin-express/src/express.ts

+35-23
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { BasePlugin } from '@opentelemetry/core';
1818
import { Attributes } from '@opentelemetry/types';
1919
import * as express from 'express';
20-
import * as core from "express-serve-static-core";
20+
import * as core from 'express-serve-static-core';
2121
import * as shimmer from 'shimmer';
2222
import {
2323
ExpressLayer,
@@ -26,13 +26,9 @@ import {
2626
PatchedRequest,
2727
Parameters,
2828
PathParams,
29-
_MIDDLEWARES_STORE_PROPERTY
29+
_MIDDLEWARES_STORE_PROPERTY,
3030
} from './types';
31-
import {
32-
getLayerMetadata,
33-
storeLayerPath,
34-
patchEnd,
35-
} from './utils'
31+
import { getLayerMetadata, storeLayerPath, patchEnd } from './utils';
3632
import { VERSION } from './version';
3733

3834
/**
@@ -59,7 +55,8 @@ export class ExpressPlugin extends BasePlugin<typeof express> {
5955
if (this._moduleExports === undefined || this._moduleExports === null) {
6056
return this._moduleExports;
6157
}
62-
const routerProto = (this._moduleExports.Router as unknown) as express.Router;
58+
const routerProto = (this._moduleExports
59+
.Router as unknown) as express.Router;
6360

6461
this._logger.debug('patching express.Router.prototype.route');
6562
shimmer.wrap(routerProto, 'route', this._getRoutePatch.bind(this));
@@ -68,52 +65,67 @@ export class ExpressPlugin extends BasePlugin<typeof express> {
6865
shimmer.wrap(routerProto, 'use', this._getRouterUsePatch.bind(this));
6966

7067
this._logger.debug('patching express.Application.use');
71-
shimmer.wrap(this._moduleExports.application, 'use', this._getAppUsePatch.bind(this));
68+
shimmer.wrap(
69+
this._moduleExports.application,
70+
'use',
71+
this._getAppUsePatch.bind(this)
72+
);
7273

7374
return this._moduleExports;
7475
}
7576

7677
/**
7778
* Get the patch for Router.route function
78-
* @param original
79+
* @param original
7980
*/
80-
private _getRoutePatch (original: (path: PathParams) => express.IRoute) {
81-
const plugin = this
81+
private _getRoutePatch(original: (path: PathParams) => express.IRoute) {
82+
const plugin = this;
8283
return function route_trace(
8384
this: ExpressRouter,
8485
...args: Parameters<typeof original>
8586
) {
8687
const route = original.apply(this, args);
8788
const layer = this.stack[this.stack.length - 1] as ExpressLayer;
88-
plugin._applyPatch(layer, typeof args[0] === 'string' ? args[0] : undefined);
89+
plugin._applyPatch(
90+
layer,
91+
typeof args[0] === 'string' ? args[0] : undefined
92+
);
8993
return route;
9094
};
9195
}
9296

9397
/**
9498
* Get the patch for Router.use function
95-
* @param original
99+
* @param original
96100
*/
97-
private _getRouterUsePatch (original: express.IRouterHandler<express.Router> & express.IRouterMatcher<express.Router>) {
98-
const plugin = this
101+
private _getRouterUsePatch(
102+
original: express.IRouterHandler<express.Router> &
103+
express.IRouterMatcher<express.Router>
104+
) {
105+
const plugin = this;
99106
return function use(
100107
this: express.Application,
101108
...args: Parameters<typeof original>
102109
) {
103110
const route = original.apply(this, args);
104111
const layer = this.stack[this.stack.length - 1] as ExpressLayer;
105-
plugin._applyPatch(layer, typeof args[0] === 'string' ? args[0] : undefined);
112+
plugin._applyPatch(
113+
layer,
114+
typeof args[0] === 'string' ? args[0] : undefined
115+
);
106116
return route;
107117
// tslint:disable-next-line:no-any
108-
} as any
118+
} as any;
109119
}
110120

111121
/**
112122
* Get the patch for Application.use function
113-
* @param original
123+
* @param original
114124
*/
115-
private _getAppUsePatch (original: core.ApplicationRequestHandler<express.Application>) {
116-
const plugin = this
125+
private _getAppUsePatch(
126+
original: core.ApplicationRequestHandler<express.Application>
127+
) {
128+
const plugin = this;
117129
return function use(
118130
this: { _router: ExpressRouter },
119131
...args: Parameters<typeof original>
@@ -157,8 +169,8 @@ export class ExpressPlugin extends BasePlugin<typeof express> {
157169
[AttributeNames.COMPONENT]: plugin._COMPONENT,
158170
[AttributeNames.HTTP_ROUTE]: route.length > 0 ? route : undefined,
159171
};
160-
const metadata = getLayerMetadata(layer, layerPath)
161-
172+
const metadata = getLayerMetadata(layer, layerPath);
173+
162174
const span = plugin._tracer.startSpan(metadata.name, {
163175
parent: plugin._tracer.getCurrentSpan(),
164176
attributes: Object.assign(attributes, metadata.attributes),

packages/opentelemetry-plugin-express/src/types.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
import { kLayerPatched } from './express';
1818
import { Request } from 'express';
1919

20-
export const _MIDDLEWARES_STORE_PROPERTY = '__ot_middlewares'
20+
export const _MIDDLEWARES_STORE_PROPERTY = '__ot_middlewares';
2121

2222
export type Parameters<T> = T extends (...args: infer T) => any ? T : unknown[];
23-
export type PatchedRequest = { [_MIDDLEWARES_STORE_PROPERTY]?: string[] } & Request;
23+
export type PatchedRequest = {
24+
[_MIDDLEWARES_STORE_PROPERTY]?: string[];
25+
} & Request;
2426
export type PathParams = string | RegExp | Array<string | RegExp>;
2527

2628
// https://github.com/expressjs/express/blob/master/lib/router/index.js#L53
@@ -54,5 +56,5 @@ export enum AttributeNames {
5456
export enum ExpressLayerType {
5557
ROUTER = 'router',
5658
MIDDLEWARE = 'middleware',
57-
REQUEST_HANDLER = 'request_handler'
59+
REQUEST_HANDLER = 'request_handler',
5860
}

packages/opentelemetry-plugin-express/src/utils.ts

+19-16
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
AttributeNames,
2121
PatchedRequest,
2222
_MIDDLEWARES_STORE_PROPERTY,
23-
ExpressLayerType
23+
ExpressLayerType,
2424
} from './types';
2525

2626
/**
@@ -37,42 +37,45 @@ export const storeLayerPath = (request: PatchedRequest, value?: string) => {
3737
}
3838
if (value === undefined) return;
3939
(request[_MIDDLEWARES_STORE_PROPERTY] as string[]).push(value);
40-
}
40+
};
4141

4242
/**
4343
* Parse express layer context to retrieve a name and attributes.
4444
* @param layer Express layer
4545
* @param [layerPath] if present, the path on which the layer has been mounted
4646
*/
47-
export const getLayerMetadata = (layer: ExpressLayer, layerPath?: string): {
48-
attributes: Attributes,
49-
name: string
47+
export const getLayerMetadata = (
48+
layer: ExpressLayer,
49+
layerPath?: string
50+
): {
51+
attributes: Attributes;
52+
name: string;
5053
} => {
5154
if (layer.name === 'router') {
5255
return {
5356
attributes: {
5457
[AttributeNames.EXPRESS_NAME]: layerPath,
55-
[AttributeNames.EXPRESS_TYPE]: ExpressLayerType.ROUTER
58+
[AttributeNames.EXPRESS_TYPE]: ExpressLayerType.ROUTER,
5659
},
57-
name: `router - ${layerPath}`
58-
}
60+
name: `router - ${layerPath}`,
61+
};
5962
} else if (layer.name === 'bound dispatch') {
6063
return {
6164
attributes: {
62-
[AttributeNames.EXPRESS_TYPE]: ExpressLayerType.REQUEST_HANDLER
65+
[AttributeNames.EXPRESS_TYPE]: ExpressLayerType.REQUEST_HANDLER,
6366
},
64-
name: 'request handler'
65-
}
67+
name: 'request handler',
68+
};
6669
} else {
6770
return {
6871
attributes: {
6972
[AttributeNames.EXPRESS_NAME]: layer.name,
70-
[AttributeNames.EXPRESS_TYPE]: ExpressLayerType.MIDDLEWARE
73+
[AttributeNames.EXPRESS_TYPE]: ExpressLayerType.MIDDLEWARE,
7174
},
72-
name: `middleware - ${layer.name}`
73-
}
75+
name: `middleware - ${layer.name}`,
76+
};
7477
}
75-
}
78+
};
7679

7780
/**
7881
* Ends a created span.
@@ -95,4 +98,4 @@ export const patchEnd = (span: Span, resultHandler: Function): Function => {
9598
span.end();
9699
return resultHandler.apply(this, args);
97100
};
98-
}
101+
};

packages/opentelemetry-plugin-http/src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -451,5 +451,5 @@ export const getIncomingRequestAttributesOnResponse = (
451451
if (route !== undefined) {
452452
attributes[AttributeNames.HTTP_ROUTE] = route;
453453
}
454-
return attributes;
454+
return attributes;
455455
};

0 commit comments

Comments
 (0)