Skip to content

Commit

Permalink
chore(instrumentation-nestjs-core): use strings exported for attribut…
Browse files Browse the repository at this point in the history
…es (#2193)

Refs: #2025
Signed-off-by: maryliag <marylia.gutierrez@grafana.com>
  • Loading branch information
maryliag committed May 14, 2024
1 parent 025abda commit 7795ff6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 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.

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"
},
"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

0 comments on commit 7795ff6

Please sign in to comment.