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

Fix SourceMapper typing #101

Merged
merged 3 commits into from
Dec 16, 2024
Merged

Fix SourceMapper typing #101

merged 3 commits into from
Dec 16, 2024

Conversation

bryanhuhta
Copy link
Contributor

@bryanhuhta bryanhuhta commented Sep 11, 2024

When using the SourceMapper in a TypeScript project, the following error occurs:

Type 'import("/Users/bryan/grafana/pyroscope-nodejs/dist/cjs/sourcemapper").SourceMapper' is not assignable to type 'import("/Users/bryan/grafana/pyroscope-nodejs/node_modules/@datadog/pprof/out/src/sourcemapper/sourcemapper").SourceMapper'.
  Types have separate declarations of a private property 'getMappingInfo'.ts(2322)

The critical piece being:

Types have separate declarations of a private property 'getMappingInfo'.ts(2322)

This comes from this method:

private getMappingInfo(inputPath: string): MapInfoCompiled | null {
if (this.infoMap.has(path.normalize(inputPath))) {
return this.infoMap.get(inputPath) as MapInfoCompiled;
}
return null;
}

The cause is that we can't use the @pyroscope/nodejs SourceMapper type in place of the @ddog/pprof SourceMapper type because private methods aren't considered when matching type shapes in TypeScript. See microsoft/TypeScript#7755 (comment) for an example and explanation.

As a result, we should not expose the @ddog/pprof SourceMapper type in the PyroscopeConfig type. Rather, we should expose our own implementation of SourceMapper then do a conversion to the DataDog type internally.

The critical change is this method:

https://github.com/grafana/pyroscope-nodejs/pull/101/files#diff-068acd199ee4e6261a4645ae640daf8a4f48c526e60caf6bf55a3ae770faadd9R126-R134

Only convert to DDog `SourceMapper` type internally
@bryanhuhta bryanhuhta self-assigned this Sep 11, 2024
@bryanhuhta bryanhuhta requested review from a team as code owners September 11, 2024 23:46
Copy link
Collaborator

@simonswine simonswine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@simonswine simonswine merged commit 0a0b6cd into main Dec 16, 2024
6 checks passed
@simonswine simonswine deleted the fix-sourcemapper branch December 16, 2024 14:24
@simonswine simonswine mentioned this pull request Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants