-
Notifications
You must be signed in to change notification settings - Fork 620
feat(instrumentation-hapi): support migration to stable HTTP semconv, v1.23.1 #2863
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
Merged
trentm
merged 7 commits into
open-telemetry:main
from
trentm:trentm-http-semconv-migration-hapi
Jun 2, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
67d7102
feat(instrumentation-hapi): support migration to stable HTTP semconv,…
trentm adf2525
Merge branch 'main' into trentm-http-semconv-migration-hapi
trentm 3ac945d
lint:fix
trentm 5a93d9d
Merge branch 'main' into trentm-http-semconv-migration-hapi
trentm 8d4865e
fix typo: http/dup is the token to use
trentm f256718
Merge branch 'main' into trentm-http-semconv-migration-hapi
trentm 44c6f88
Merge branch 'main' into trentm-http-semconv-migration-hapi
trentm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,7 +60,7 @@ hapiInstrumentation.setTracerProvider(provider); | |
|
|
||
| See [examples/hapi](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/examples/hapi) for a short example using Hapi | ||
|
|
||
| <!-- | ||
| <!-- | ||
| The dev dependency of `@hapi/[email protected]` is required to force the compatible type declarations. See: https://github.com/hapijs/hapi/issues/4240 | ||
| --> | ||
|
|
||
|
|
@@ -70,14 +70,24 @@ This package provides automatic tracing for hapi server routes and [request life | |
|
|
||
| ## 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) | ||
| Prior to version `0.48.0`, this instrumentation created spans targeting an experimental semantic convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md). | ||
|
|
||
| Attributes collected: | ||
| HTTP semantic conventions (semconv) were stabilized in v1.23.0, and a [migration process](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/non-normative/http-migration.md#http-semantic-convention-stability-migration) was defined. `instrumentation-hapi` versions 0.48.0 and later include support for migrating to stable HTTP semantic conventions, as described below. The intent is to provide an approximate 6 month time window for users of this instrumentation to migrate to the new HTTP semconv, after which a new minor version will use the *new* semconv by default and drop support for the old semconv. See the [HTTP semconv migration plan for OpenTelemetry JS instrumentations](https://github.com/open-telemetry/opentelemetry-js/issues/5646). | ||
|
|
||
| | Attribute | Short Description | | ||
| |---------------------|----------------------------------------------------| | ||
| | `http.method` | HTTP method | | ||
| | `http.route` | Route assigned to handler. Ex: `/users/:id` | | ||
| To select which semconv version(s) is emitted from this instrumentation, use the `OTEL_SEMCONV_STABILITY_OPT_IN` environment variable. | ||
|
|
||
| - `http`: emit the new (stable) v1.23.0+ semantics | ||
| - `http/dup`: emit **both** the old v1.7.0 and the new (stable) v1.23.0+ semantics | ||
| - By default, if `OTEL_SEMCONV_STABILITY_OPT_IN` includes neither of the above tokens, the old v1.7.0 semconv is used. | ||
|
|
||
| ### Attributes collected | ||
|
|
||
| The following semconv attributes are collected on hapi route spans: | ||
|
|
||
| | v1.7.0 semconv | v1.23.0 semconv | Notes | | ||
| | -------------- | --------------------- | ----- | | ||
| | `http.method` | `http.request.method` | HTTP request method | | ||
| | `http.route` | `http.route` (same) | Route assigned to handler. Ex: `/users/:id` | | ||
|
|
||
| ## Useful links | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
plugins/node/opentelemetry-instrumentation-hapi/src/semconv.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /* | ||
| * This file contains a copy of unstable semantic convention definitions | ||
| * used by this package. | ||
| * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv | ||
| */ | ||
|
|
||
| /** | ||
| * Deprecated, use `http.request.method` instead. | ||
| * | ||
| * @example GET | ||
| * @example POST | ||
| * @example HEAD | ||
| * | ||
| * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. | ||
| * | ||
| * @deprecated Replaced by `http.request.method`. | ||
| */ | ||
| export const ATTR_HTTP_METHOD = 'http.method' as const; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
plugins/node/opentelemetry-instrumentation-hapi/test/fixtures/use-hapi.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| const { createTestNodeSdk } = require('@opentelemetry/contrib-test-utils'); | ||
|
|
||
| const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http'); | ||
| const { HapiInstrumentation } = require('../../build/src/index.js'); | ||
|
|
||
| const sdk = createTestNodeSdk({ | ||
| serviceName: 'use-hapi', | ||
| instrumentations: [ | ||
| new HttpInstrumentation(), | ||
| new HapiInstrumentation() | ||
| ] | ||
| }) | ||
| sdk.start(); | ||
|
|
||
| const Hapi = require('@hapi/hapi'); | ||
| const http = require('http'); | ||
|
|
||
| async function main() { | ||
| // Start a Hapi server. | ||
| const server = new Hapi.Server({ | ||
| port: 0, | ||
| host: 'localhost' | ||
| }); | ||
|
|
||
| server.route({ | ||
| method: 'GET', | ||
| path: '/route/{param}', | ||
| handler: function() { | ||
| return { hello: 'world' }; | ||
| } | ||
| }); | ||
|
|
||
| await server.start(); | ||
|
|
||
| // Make a single request to it. | ||
| await new Promise(resolve => { | ||
| http.get(`http://${server.info.host}:${server.info.port}/route/test`, (res) => { | ||
| res.resume(); | ||
| res.on('end', () => { | ||
| resolve(); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| await server.stop(); | ||
| await sdk.shutdown(); | ||
| } | ||
|
|
||
| main(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,7 +57,7 @@ await new Promise(resolve => { | |
| res.on('end', () => { | ||
| resolve(); | ||
| }); | ||
| }) | ||
| }); | ||
| }); | ||
|
|
||
| await server.stop(); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.