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(instrumentation-nestjs-core): use strings exported for attributes #2193

Merged
merged 3 commits into from
May 14, 2024
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
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.

30 changes: 17 additions & 13 deletions plugins/node/opentelemetry-instrumentation-nestjs-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,23 @@ registerInstrumentations({
`<ControllerName>.<memberName>` | `request_context` | Traces the whole request context. | `http.*`, `nestjs.callback`
`<memberName>` | `handler` | Traces the work of a specific controller member function. | `nestjs.callback`

### Attributes

| Name | Description
| ---- | ----
| `component`* | "@nestjs/core"
| `nestjs.version`* | Version of instrumented `@nestjs/core` package
| `nestjs.type`* | See [NestType](./src/enums/NestType.ts)
| `nestjs.module` | Nest module class name
| `nestjs.controller` | Nest controller class name
| `nestjs.callback` | The function name of the member in the controller
| `http.method` | HTTP method
| `http.url` | Full request URL
| `http.route` | Route assigned to handler. Ex: `/users/:id`
## Semantic Conventions

This package uses `@opentelemetry/semantic-conventions` version `1.22+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md)

Attributes collected:

| Attribute | Short Description |
|---------------------|----------------------------------------------------|
| `component`* | "@nestjs/core" |
| `nestjs.version`* | Version of instrumented `@nestjs/core` package |
| `nestjs.type`* | See [NestType](./src/enums/NestType.ts) |
| `nestjs.module` | Nest module class name |
| `nestjs.controller` | Nest controller class name |
| `nestjs.callback` | The function name of the member in the controller |
| `http.method` | HTTP method |
| `http.url` | Full request URL |
| `http.route` | Route assigned to handler. Ex: `/users/:id` |

\* included in all of the spans.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"dependencies": {
"@opentelemetry/instrumentation": "^0.51.0",
"@opentelemetry/semantic-conventions": "^1.0.0"
"@opentelemetry/semantic-conventions": "^1.23.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
"@opentelemetry/semantic-conventions": "^1.23.0"
"@opentelemetry/semantic-conventions": "^1.22.0"

},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-nestjs-core#readme"
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ import {
import type { NestFactory } from '@nestjs/core/nest-factory.js';
import type { RouterExecutionContext } from '@nestjs/core/router/router-execution-context.js';
import type { Controller } from '@nestjs/common/interfaces';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import {
SEMATTRS_HTTP_METHOD,
SEMATTRS_HTTP_ROUTE,
SEMATTRS_HTTP_URL,
} from '@opentelemetry/semantic-conventions';
import { VERSION } from './version';
import { AttributeNames, NestType } from './enums';

Expand Down Expand Up @@ -168,9 +172,9 @@ function createWrapCreateHandler(tracer: api.Tracer, moduleVersion?: string) {
...Instrumentation.COMMON_ATTRIBUTES,
[AttributeNames.VERSION]: moduleVersion,
[AttributeNames.TYPE]: NestType.REQUEST_CONTEXT,
[SemanticAttributes.HTTP_METHOD]: req.method,
[SemanticAttributes.HTTP_URL]: req.originalUrl || req.url,
[SemanticAttributes.HTTP_ROUTE]:
[SEMATTRS_HTTP_METHOD]: req.method,
[SEMATTRS_HTTP_URL]: req.originalUrl || req.url,
[SEMATTRS_HTTP_ROUTE]:
req.route?.path || req.routeOptions?.url || req.routerPath,
[AttributeNames.CONTROLLER]: instanceName,
[AttributeNames.CALLBACK]: callbackName,
Expand Down
Loading