Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use openapi format for endpoint uris #98

Merged
merged 1 commit into from
Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/plugins/ExpressPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ class ExpressPlugin implements SwPlugin {

router.handle = function (req: Request, res: ServerResponse, next: any) {
const carrier = ContextCarrier.from((req as any).headers || {});
const operation = (req.originalUrl || req.url || '/').replace(/\?.*/g, '');
const span = ignoreHttpMethodCheck(req.method ?? 'GET')
const reqMethod = req.method ?? 'GET';
const operation = reqMethod + ':' + (req.originalUrl || req.url || '/').replace(/\?.*/g, '');
const span = ignoreHttpMethodCheck(reqMethod)
? DummySpan.create()
: ContextManager.current.newEntrySpan(operation, carrier, [Component.HTTP_SERVER, Component.EXPRESS]);

Expand Down
5 changes: 3 additions & 2 deletions src/plugins/HttpPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ class HttpPlugin implements SwPlugin {

function _sw_request(this: any, req: IncomingMessage, res: ServerResponse, ...reqArgs: any[]) {
const carrier = ContextCarrier.from((req as any).headers || {});
const operation = (req.url || '/').replace(/\?.*/g, '');
const span = ignoreHttpMethodCheck(req.method ?? 'GET')
const reqMethod = req.method ?? 'GET';
const operation = reqMethod + ':' + (req.url || '/').replace(/\?.*/g, '');
const span = ignoreHttpMethodCheck(reqMethod)
? DummySpan.create()
: ContextManager.current.newEntrySpan(operation, carrier);

Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/axios/expected.data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ segmentItems:
value: '200'
- key: http.status.msg
value: OK
- operationName: /axios
- operationName: GET:/axios
operationId: 0
parentSpanId: -1
spanId: 0
Expand Down Expand Up @@ -97,7 +97,7 @@ segmentItems:
spanType: Exit
peer: server:5000
skipAnalysis: false
- operationName: /axios
- operationName: GET:/axios
operationId: 0
parentSpanId: -1
spanId: 0
Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/express/expected.data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ segmentItems:
segments:
- segmentId: not null
spans:
- operationName: /express
- operationName: GET:/express
operationId: 0
parentSpanId: -1
spanId: 0
Expand Down Expand Up @@ -77,7 +77,7 @@ segmentItems:
segments:
- segmentId: not null
spans:
- operationName: /test/express
- operationName: GET:/test/express
operationId: 0
parentSpanId: -1
spanId: 0
Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/http/expected.data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ segmentItems:
segments:
- segmentId: not null
spans:
- operationName: /test
- operationName: GET:/test
operationId: 0
parentSpanId: -1
spanId: 0
Expand Down Expand Up @@ -77,7 +77,7 @@ segmentItems:
segments:
- segmentId: not null
spans:
- operationName: /test
- operationName: GET:/test
operationId: 0
parentSpanId: -1
spanId: 0
Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/ioredis/expected.data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ segmentItems:
tags:
- { key: db.type, value: Redis }
- { key: db.instance, value: "0" }
- operationName: /ioredis
- operationName: GET:/ioredis
operationId: 0
parentSpanId: -1
spanId: 0
Expand Down Expand Up @@ -96,7 +96,7 @@ segmentItems:
segments:
- segmentId: not null
spans:
- operationName: /ioredis
- operationName: GET:/ioredis
operationId: 0
parentSpanId: -1
spanId: 0
Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/mongodb/expected.data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ segmentItems:
- { key: db.type, value: MongoDB }
- { key: db.instance, value: admin }
- { key: db.statement, value: docs.findOne() }
- operationName: /mongo
- operationName: GET:/mongo
operationId: 0
parentSpanId: -1
spanId: 0
Expand Down Expand Up @@ -82,7 +82,7 @@ segmentItems:
segments:
- segmentId: not null
spans:
- operationName: /mongo
- operationName: GET:/mongo
operationId: 0
parentSpanId: -1
spanId: 0
Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/mongoose/expected.data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ segmentItems:
- { key: db.type, value: MongoDB }
- { key: db.instance, value: admin }
- { key: db.statement, value: 'tests.find({})' }
- operationName: /mongoose
- operationName: GET:/mongoose
operationId: 0
parentSpanId: -1
spanId: 0
Expand Down Expand Up @@ -96,7 +96,7 @@ segmentItems:
segments:
- segmentId: not null
spans:
- operationName: /mongoose
- operationName: GET:/mongoose
operationId: 0
parentSpanId: -1
spanId: 0
Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/mysql/expected.data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ segmentItems:
value: test
- key: db.statement
value: SELECT * FROM `user` WHERE `name` = "u1"
- operationName: /mysql
- operationName: GET:/mysql
operationId: 0
parentSpanId: -1
spanId: 0
Expand Down Expand Up @@ -75,7 +75,7 @@ segmentItems:
segments:
- segmentId: not null
spans:
- operationName: /mysql
- operationName: GET:/mysql
operationId: 0
parentSpanId: -1
spanId: 0
Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/mysql2/expected.data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ segmentItems:
value: test
- key: db.statement
value: SELECT * FROM `user` WHERE `name` = "u1"
- operationName: /mysql
- operationName: GET:/mysql
operationId: 0
parentSpanId: -1
spanId: 0
Expand Down Expand Up @@ -75,7 +75,7 @@ segmentItems:
segments:
- segmentId: not null
spans:
- operationName: /mysql
- operationName: GET:/mysql
operationId: 0
parentSpanId: -1
spanId: 0
Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/pg/expected.data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ segmentItems:
- { key: db.type, value: PostgreSQL }
- { key: db.instance, value: test }
- { key: db.statement, value: SELECT * FROM "user" where name = 'u1' }
- operationName: /postgres
- operationName: GET:/postgres
operationId: 0
parentSpanId: -1
spanId: 0
Expand Down Expand Up @@ -67,7 +67,7 @@ segmentItems:
segments:
- segmentId: not null
spans:
- operationName: /postgres
- operationName: GET:/postgres
operationId: 0
parentSpanId: -1
spanId: 0
Expand Down