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

fix: update hapi bindings to v21 #1491

Closed
wants to merge 1 commit into from

Conversation

toddtarsi
Copy link
Contributor

@toddtarsi toddtarsi commented May 9, 2023

Which problem is this PR solving?

Short description of the changes

  • Change compat to v21 and up and change the type libraries to use hapi internal

@toddtarsi toddtarsi requested a review from a team May 9, 2023 14:18
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented May 9, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: toddtarsi / name: Todd Tarsi (41a45e5)

@toddtarsi toddtarsi changed the title update hapi bindings to v21 [fix] update hapi bindings to v21 May 9, 2023
@toddtarsi toddtarsi changed the title [fix] update hapi bindings to v21 fix: update hapi bindings to v21 May 9, 2023
@toddtarsi toddtarsi force-pushed the update-hapi-to-v21 branch from 41a45e5 to b85f015 Compare May 9, 2023 14:29
@@ -57,11 +57,15 @@ export class HapiInstrumentation extends InstrumentationBase {
protected init() {
return new InstrumentationNodeModuleDefinition<typeof Hapi>(
HapiComponentName,
['>=17 <21'],
['>=21'],
Copy link
Member

Choose a reason for hiding this comment

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

I guess the desupport of hapi 17 to 20 should be mentioned somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lol thats fair. I honestly don't know if we can't keep the support. Problem is not knowing isn't very useful.

Copy link
Member

Choose a reason for hiding this comment

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

Some instrumentations have tests for more versions via test all versions. I never used it by myself so can't provide a lot details. e.g. here is a config file holding a version list.
There are also github actions. e.g. here

But not sure if you are willing to take the task to setup tav for hapi.

Copy link
Member

Choose a reason for hiding this comment

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

>=21 is also quite the promise. Can we be sure 22, 23, 30, 50 are all supported?

@Towerism
Copy link

Towerism commented May 9, 2023

Firstly, thank you @toddtarsi!

I ran npm run compile so I could test this in our own project. However, it errored. Here is the output:

npm run compile

> @opentelemetry/instrumentation-hapi@0.31.2 precompile
> tsc --version && lerna run version:update --scope @opentelemetry/instrumentation-hapi --include-dependencies

Version 4.4.4
lerna notice cli v5.5.2
lerna info versioning independent
lerna notice filter including "@opentelemetry/instrumentation-hapi"
lerna notice filter including dependencies
lerna info filter [ '@opentelemetry/instrumentation-hapi' ]
lerna info Executing command in 1 package: "npm run version:update"
lerna info run Ran npm script 'version:update' in '@opentelemetry/instrumentation-hapi' in 1.2s:

> @opentelemetry/instrumentation-hapi@0.31.2 version:update
> node ../../../scripts/version-update.js

lerna success run Ran npm script 'version:update' in 1 package in 1.2s:
lerna success - @opentelemetry/instrumentation-hapi

> @opentelemetry/instrumentation-hapi@0.31.2 compile
> tsc -p .

node_modules/@hapi/hapi/lib/types/route.d.ts:2:68 - error TS2307: Cannot find module 'joi' or its corresponding type declarations.

2 import { ObjectSchema, ValidationOptions, SchemaMap, Schema } from 'joi';
                                                                     ~~~~~

node_modules/@hapi/hapi/lib/types/server/server.d.ts:4:22 - error TS2307: Cannot find module 'joi' or its corresponding type declarations.

4 import { Root } from 'joi';
                       ~~~~~


Found 2 errors.

@toddtarsi
Copy link
Contributor Author

Just noting, I was looking at it this weekend and I definitely just need to do the taz thing. Without that up, I am just going in circles a bit, sorry all!

@github-actions
Copy link
Contributor

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Jul 31, 2023
@IAmVisco
Copy link

IAmVisco commented Aug 1, 2023

@toddtarsi sorry to bother, are you planning on finishing this one? I was working on something of my own and noticed that installing open-telemetry would downgrade hapi to v20. I can pick it up and take a look.

@toddtarsi
Copy link
Contributor Author

@IAmVisco - Nah. I'm not sure what the taz stuff is tbh.

@IAmVisco
Copy link

IAmVisco commented Aug 1, 2023

@IAmVisco - Nah. I'm not sure what the taz stuff is tbh.

Sorry, mind linking what taz is? I don't see anything in the PR and you mentioned it first in your earlier comment.

@toddtarsi
Copy link
Contributor Author

@IAmVisco - Nah. I'm not sure what the taz stuff is tbh.

Sorry, mind linking what taz is? I don't see anything in the PR and you mentioned it first in your earlier comment.

#1491 (comment)

@IAmVisco
Copy link

IAmVisco commented Aug 1, 2023

@toddtarsi Just tested some stuff locally - if you do npm i -D joi (it comes with types already) and lower >=21 to just >=17 (hapi site still supports v17) it should work fine. Mind giving it a try? If all else fails I will fork and fiddle with it in my own PR tomorrow-ish. Cheers!

P.S. I don't see any issues with TAV on the first glance, but might be wrong.

@github-actions github-actions bot removed the stale label Aug 7, 2023
@mjsalinger
Copy link

Is there any chance this can get released?

@arimus
Copy link

arimus commented Nov 5, 2023

Looks like 2 tests failing. My guess it that this needs to be fixed, but also that there may need to be a new major or minor version to release a new version that depends on Hapi 21. One build can not unfortunately easily work for multiple versions of Hapi without a lot of casting to essentially using un-typed JS to get the job done, so not sure how TAV applies here.

Trying to debug the errors, but the monkey patching is a little complicated.

  23 passing (262ms)
  2 failing

  1) Hapi Instrumentation - Core Tests
       Instrumenting Hapi Routes
         should update rpcMetadata.route information:
     AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
+ actual - expected

+ undefined
- '/users/{userId}'
      at /Users/arimus/workspace/opentelemetry-js-contrib/plugins/node/opentelemetry-instrumentation-hapi/test/hapi.test.ts:407:18
      at processTicksAndRejections (internal/process/task_queues.js:95:5)
      at Context.<anonymous> (test/hapi.test.ts:394:7)

  2) Hapi Instrumentation - Core Tests
       Instrumenting Hapi Routes
         when handler is in route.options level
           should create a child span for single routes:

      AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:

1 !== 2

      + expected - actual

      -1
      +2

      at /Users/arimus/workspace/opentelemetry-js-contrib/plugins/node/opentelemetry-instrumentation-hapi/test/hapi.test.ts:136:20
      at processTicksAndRejections (internal/process/task_queues.js:95:5)
      at Context.<anonymous> (test/hapi.test.ts:126:9)

I found a fix that allows the test to pass (instrumentation.ts, line:393), although I'm not positive what the implications are on a broader level.

        const rpcMetadata = getRPCMetadata(api.context.active());
        if (rpcMetadata?.type === RPCType.HTTP) {
          // @ts-ignore
          rpcMetadata?.route = route.path; // <<<<<< ADDED - set the route path onto the rpcMetadata object

          const rootSpanMetadata = getRootSpanMetadata(route);
          rpcMetadata.span.updateName(rootSpanMetadata.name);
          rpcMetadata.span.setAttributes(rootSpanMetadata.attributes);
        }

And I haven't yet determined why the span completion count is only 1 instead of 2 in this other test. Happy to help test if @toddtarsi wants to update this pull request and get the tests passing.

Some guidance from the author(s) would be good on what is necessary to get this merged outside of getting tests passing (e.g. versioning, etc.) Worst case, I guess a new NPM module can be created to support Hapi v21 in the meantime, but keeping things here would be ideal.

@sguimont
Copy link

Hi, @arimus. We try to correct and run a PATCHED version of the HAPI plugin to runs correctly with HAPI 21. In your last comment, you provided a fix but we don't know how you have implemented the getRootSpanMetadata(route). Could you provide the code of that function please? It will help us a lot.

@mjsalinger
Copy link

@here Is there anything that can be done to move this issue along? Anything I could do to help?

@nlochschmidt
Copy link
Contributor

@toddtarsi It looks to me as if the major hurdles came from upgrading type dependencies to hapi 21. What do you think about staying on @types/hapi__hapi for a little longer, but moving it to devDependencies as to not cause issues for folks?

This looks like it would work: nlochschmidt@a299190. I'd be happy to provide an alternative PR for hapi v21 support based on this.

@nlochschmidt
Copy link
Contributor

@toddtarsi I had a closer look at your PR today and I think it's possible to restore support for versions 17 to 20. My solution requires a few more any, but with tav in place now, I think that might be worth it.

main...nlochschmidt:opentelemetry-js-contrib:update-hapi-to-v21

I added joi as a dev dependency as mentioned by @IAmVisco. I think the alternative is to use skipLibCheck: true in the hapi local tsconfig.json. I see some other modules doing the same, but I am not sure what's preferred around here.

If you want, you can pull my changes into this PR, otherwise I will create a new one.

@nlochschmidt
Copy link
Contributor

This PR can be closed.

#1985 has been merged, which includes these changes.

@blumamir
Copy link
Member

blumamir commented May 2, 2024

This PR can be closed.

#1985 has been merged, which includes these changes.

Thanks for updating here 🙏

@blumamir blumamir closed this May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.