Skip to content

hapi instrumentation: this not bound for plugin register method #2624

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

Closed
seemk opened this issue Jan 7, 2025 · 1 comment · Fixed by signalfx/splunk-otel-js#1004
Closed
Labels
bug Something isn't working pkg:instrumentation-hapi priority:p1 Bugs which cause problems in end-user applications such as crashes, data inconsistencies

Comments

@seemk
Copy link
Contributor

seemk commented Jan 7, 2025

What version of OpenTelemetry are you using?

@opentelemetry/instrumentation-hapi 0.45.0

What did you do?

import * as hapi from '@hapi/hapi';

const plugin1 = {
  name: 'plugin1',
  value: 42,
  register: async function (server: hapi.Server, options: any) {
    server.route({
      method: 'GET',
      path: '/1',
      handler: (request, h) => {
        return `hello, world, ${this.value} ${options.name}`;
      },
    });
  },
};

// OR

class MyPlugin implements hapi.PluginBase<any, any> {
  public name: string = 'MyPlugin';
  constructor(public value: number) {}

  public register(server: hapi.Server): void | Promise<void> {
      server.route({
        method: 'GET',
        path: '/2',
        handler: async (req, h) => {
          return `${this.value}`; // this is undefined
        }
      });
    }
}

await server.register([plugin1, new MyPlugin(42)]);

What did you expect to see?

Application not returning HTTP 500.

What did you see instead?

Application returning HTTP 500 due to undefined this.

@seemk seemk added the bug Something isn't working label Jan 7, 2025
@pichlermarc pichlermarc added priority:p1 Bugs which cause problems in end-user applications such as crashes, data inconsistencies pkg:instrumentation-hapi labels Jan 7, 2025
@pichlermarc
Copy link
Member

Fixed by #2625

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pkg:instrumentation-hapi priority:p1 Bugs which cause problems in end-user applications such as crashes, data inconsistencies
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants