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-hapi): use exported strings for attributes #2190

Merged
merged 14 commits into from
May 15, 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
19 changes: 2 additions & 17 deletions package-lock.json

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

11 changes: 11 additions & 0 deletions plugins/node/opentelemetry-instrumentation-hapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ The dev dependency of `@hapi/[email protected]` is required to force the compatible t

This package provides automatic tracing for hapi server routes and [request lifecycle](https://github.com/hapijs/hapi/blob/master/API.md#request-lifecycle) extensions defined either directly or via a Hapi plugin.

## 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)

trentm marked this conversation as resolved.
Show resolved Hide resolved
Attributes collected:

| Attribute | Short Description |
|---------------------|----------------------------------------------------|
| `http.method` | HTTP method |
| `http.route` | Route assigned to handler. Ex: `/users/:id` |

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"dependencies": {
"@opentelemetry/core": "^1.8.0",
"@opentelemetry/instrumentation": "^0.51.0",
"@opentelemetry/semantic-conventions": "^1.0.0"
"@opentelemetry/semantic-conventions": "^1.22.0"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-hapi#readme"
}
13 changes: 8 additions & 5 deletions plugins/node/opentelemetry-instrumentation-hapi/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
*/

import { SpanAttributes } from '@opentelemetry/api';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import {
SEMATTRS_HTTP_METHOD,
SEMATTRS_HTTP_ROUTE,
} from '@opentelemetry/semantic-conventions';
import type * as Hapi from '@hapi/hapi';
import {
HapiLayerType,
Expand Down Expand Up @@ -77,8 +80,8 @@ export const getRouteMetadata = (
if (pluginName) {
return {
attributes: {
[SemanticAttributes.HTTP_ROUTE]: route.path,
[SemanticAttributes.HTTP_METHOD]: route.method,
[SEMATTRS_HTTP_ROUTE]: route.path,
[SEMATTRS_HTTP_METHOD]: route.method,
[AttributeNames.HAPI_TYPE]: HapiLayerType.PLUGIN,
[AttributeNames.PLUGIN_NAME]: pluginName,
},
Expand All @@ -87,8 +90,8 @@ export const getRouteMetadata = (
}
return {
attributes: {
[SemanticAttributes.HTTP_ROUTE]: route.path,
[SemanticAttributes.HTTP_METHOD]: route.method,
[SEMATTRS_HTTP_ROUTE]: route.path,
[SEMATTRS_HTTP_METHOD]: route.method,
[AttributeNames.HAPI_TYPE]: HapiLayerType.ROUTER,
},
name: `route - ${route.path}`,
Expand Down
Loading