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

Expose 'trace' in RESTDataSource as a protected method #2182

Conversation

eduardoramirez
Copy link

@eduardoramirez eduardoramirez commented Jan 15, 2019

Expose RESTDataSource.trace as a protected method so implementers can override the default behavior. This is useful for instrumenting a data-source with tracing logic.

TODO:

  • Update CHANGELOG.md with your change (include reference to issue & this PR)
  • Make sure all of the significant new logic is covered by tests
  • Rebase your changes on master so that they can be merged easily
  • Make sure all tests and linter rules pass

@slagiewka
Copy link

@martijnwalraven hey, does the team have any thoughts on that?

@Guillaume-Mayer
Copy link

I was about to submit something similar:

  private async trace<TResult>(
    label: string,
    fn: () => Promise<TResult>,
  ): Promise<TResult> {
    if (this.shouldTraceLog()) {
      // We're not using console.time because that isn't supported on Cloudflare
      const startTime = Date.now();
      try {
        return await fn();
      } finally {
        const duration = Date.now() - startTime;
        this.traceLog(label, duration);
      }
    } else {
      return fn();
    }
  }

  protected shouldTraceLog(): boolean {
    return process && process.env && process.env.NODE_ENV === 'development';
  }

  protected async traceLog(label: string, duration: number): Promise<void> {
    console.log(`${label} (${duration}ms)`);
  }

I'd like to be able to activate the trace independently of NODE_ENV.
Ideally I would like to include the cache status (HIT/MISS) in the trace, not sure how.

@eduardoramirez eduardoramirez deleted the eduardoramirez/allow-trace-to-override branch November 1, 2019 18:51
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants