Skip to content

Add profile processing option to Express middleware for improved function naming #88

@harshrai654

Description

@harshrai654

Hi,
Currently, the ContinuousProfiler includes profile processing functionality. We propose extending this capability to the Express middleware by introducing a configuration option that utilizes the processProfile utility function.

Key points:

  1. New Configuration Option:

    • Introduce a config option in the Express middleware to enable profile processing.
    • This would leverage the existing processProfile utility function.
  2. Documentation Update:

    • The current documentation for pull mode with Express middleware is incomplete.
    • The NodeJS SDK documentation only mentions pull mode with Grafana Alloy or Grafana Agent.
    • We should add detailed instructions for using pull mode with Express middleware.
  3. Improved Function Naming:

    • This feature would be particularly beneficial for scenarios involving anonymous functions.
    • Instead of generic "anonymous function" labels in the profile output, users would see filenames, enhancing debuggability.
    • This improvement is inspired by the discussion in issue Restore fileName to anonymous function names #84.
  4. Real-world Use Case:

    • Our team encountered this need and believes it could be generally useful.

    • As a temporary solution, we patched the middleware to call the processProfile utility function:

      async function collectProfile(profiler) {
          const profile = profiler.profile().profile;
          const processedProfile = processProfile(profile)
          profiler.stop();
          return encode(processedProfile);
      }
    • This workaround functions correctly with pull mode.

By implementing this feature, we can enhance the profiling capabilities of the Express middleware, providing more detailed and useful information to users, especially in scenarios involving anonymous functions.

I am more than happy to implement this feature and contribute to the project if needed. Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions