Skip to content

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

Open
@Kenya-West

Description

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    nodeIssues related to our Node SDK

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions