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

Node SDK: allow to construct ExtendedIncomingMessage and ExtendedResponse in order to send logs from everywhere in project #915

Open
Kenya-West opened this issue Sep 14, 2023 · 0 comments
Labels
node Issues related to our Node SDK

Comments

@Kenya-West
Copy link

I noticed that Node SDK support only the requests made from frontend to a backend's controller.

But if you send HTTP requests from your backend to another place in the Internet, it becomes impossible to send ReadMe logs.

For example, I am using Nest with underlying Fastify backend and try to intercept backend's requests via this code:

export class InterceptorsModule {
  constructor(
    private readonly httpService: HttpService,
    private readonly configService: ConfigService,
  ) {
    // here we intercept every response backend receives from some external API
    this.httpService.axiosRef.interceptors.response.use((response) => {
      let interceptedResponse = OrdAuthResponseInterceptor(
        response,
        this.configService,
      );
      return interceptedResponse;
    });
  }
}

and OrdAuthResponseInterceptor() is just a function:

export function OrdAuthResponseInterceptor(
  response: AxiosResponse<unknown, unknown>,
  configService: ConfigService,
) {
  log(
    configService.get('TELEMETRY_TOKEN'),
    response.config as unknown as ExtendedIncomingMessage, // `response.config` contains request
    response as any, // contains response
    {
      apiKey: 'someAPI',
      label: 'someLabel',
    },
    {
      development: configService.get('NODE_ENV') === 'development',
    },
  );
  return response;
}

And it expectedly fails with error like:

err TypeError: res.once is not a function
    at log (somePath\node_modules\readmeio\src\lib\log.ts:177:7)
    at TelemetryResponseInterceptor (somePath\src\interceptors\telemetry\telemetry.interceptor.ts:23:6)
    at somePath\src\interceptors\interceptors.module.ts:40:57
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
TypeError: res.setHeader is not a function
    at setDocumentationHeader (somePath\node_modules\readmeio\src\lib\log.ts:78:7)
    at somePath\node_modules\readmeio\src\lib\log.ts:116:7   
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

That's because I have provided wrong object, masked as ExtendedIncomingMessage and ExtendedResponse - but I don't have other choice. Your readme.log() method expects ExtendedIncomingMessage and ExtendedResponse for request and response accordingly.

I guess I cannot construct ExtendedIncomingMessage and ExtendedResponse because they are too complicated.

Can you please allow us to send simple props like body, status, statusText and payload when sending logs?

@gratcliff gratcliff added the node Issues related to our Node SDK label Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
node Issues related to our Node SDK
Projects
None yet
Development

No branches or pull requests

2 participants