Skip to content

feat: add a pprof profile builder and a tee visitor - #441

Draft
szegedi wants to merge 2 commits into
szegedi/otel-serializerfrom
szegedi/otel-builder-extensions
Draft

szegedi wants to merge 2 commits into
szegedi/otel-serializerfrom
szegedi/otel-builder-extensions

Conversation

@szegedi

@szegedi szegedi commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?:

Adds two visitor utilities on top of #437:

  • PprofProfileBuilder: the pprof counterpart of OtelProfilesBuilder. visitor() collects one normalized profile, build() returns it as a pprof Profile. serializeTimeProfile() and serializeHeapProfile() now use it; their output is unchanged.
  • teeVisitor(...visitors): delivers one visit to several visitors, translating frame and stack IDs for each.

Both are exported from the package.

Motivation:

Needed for the upcoming OTel support in dd-trace-js:

  • The events profiler builds its pprof by hand with pprof-format. With PprofProfileBuilder it can emit through a visitor, and the same code produces pprof or, through OtelProfilesBuilder, OTel.
  • teeVisitor lets one collection produce both formats, so pprof and OTel output can be compared while OTel support is rolled out.

Additional Notes:

  • pprof samples have no timestamps, so PprofProfileBuilder doesn't encode sample timestamps. A visitor that needs them carries them as labels, as dd-trace-js already does with end_timestamp_ns.
  • The missing-source-map comment now comes from the visitor's end() call, which reports the same result the normalizer returns.
  • Stacked on feat: add an OpenTelemetry profiles serializer #437; only the last two commits are new here.

How to test the change?:

ts/test/test-profile-serializer.ts checks that PprofProfileBuilder produces byte-identical output to serializeTimeProfile(), and handles a visitor that emits samples itself (no frames, labels, the missing-source-map comment). ts/test/test-otel-serializer.ts checks that a tee'd visit produces the same pprof and OTel bytes as separate visits. npm test.

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Overall package size

Self size: 3 MB
Deduped: 4.12 MB
No deduping: 4.12 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | pprof-format | 2.4.0 | 912.36 kB | 912.36 kB | | source-map | 0.8.0 | 185.66 kB | 185.66 kB | | node-gyp-build | 4.8.4 | 13.86 kB | 13.86 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@szegedi
szegedi force-pushed the szegedi/otel-builder-extensions branch from b00c035 to 6f9e989 Compare November 12, 2026 12:13
@szegedi
szegedi force-pushed the szegedi/otel-serializer branch from 1cca0e8 to 6d9b255 Compare November 12, 2026 12:13
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Pipelines

❌ Errors

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 7 Pipeline jobs failed

Build | asan (26) — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

Build | build / alpine-test-26 — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

Build | build / centos-test-26 — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

View all 7 failed jobs.

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: a6a083c | Docs | View more details | Give us feedback!

PprofProfileBuilder is the pprof counterpart of OtelProfilesBuilder: its
visitor() collects one normalized profile, and build() returns it as a
pprof Profile. A profiler that emits samples itself, such as a timeline
of events, can then produce pprof through the same visitor it uses for
OTel, instead of building pprof objects by hand.

serializeTimeProfile() and serializeHeapProfile() now use it, and their
output is unchanged. The builder and its options are exported from the
package. The missing source map comment comes from the visitor's end()
call, which reports the same result the normalizer returns. pprof
samples have no timestamps, so sample timestamps aren't encoded; a
profiler that needs them carries them as labels.
teeVisitor() passes a single visit on to several visitors, so that one
collection can produce a profile in more than one format, e.g. pprof and
OTel while the two are compared. Each visitor returns its own frame and
stack IDs, so the tee hands out IDs of its own and translates them for
each visitor. It is exported from the package.
@szegedi
szegedi force-pushed the szegedi/otel-serializer branch from 6d9b255 to a136cc8 Compare November 12, 2026 12:40
@szegedi
szegedi force-pushed the szegedi/otel-builder-extensions branch from 6f9e989 to a6a083c Compare November 12, 2026 12:40

This branch has not been deployed

No deployments
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.

1 participant