Skip to content

feat(sr): generate the Session Replay models from rum-events-format - #1310

Open
JuanNaranjoDD wants to merge 38 commits into
developfrom
juan.naranjo/sr-schemas-updates
Open

JuanNaranjoDD wants to merge 38 commits into
developfrom
juan.naranjo/sr-schemas-updates

Conversation

@JuanNaranjoDD

@JuanNaranjoDD JuanNaranjoDD commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What and why?

The Session Replay data models of datadog_session_replay are written by hand (lib/src/sr_data_models.dart), while dd-sdk-ios and dd-sdk-android generate theirs from rum-events-format. The Flutter models have drifted from the schema. Embedded content wireframes, shape gradients, the composition tree, and the view end and visual viewport records are missing, and every schema change has to be ported by hand.

This PR adds tools/sr_models_generator, a Dart command-line tool that generates the models from rum-events-format, and commits its output: packages/datadog_session_replay/lib/src/generated/sr_data_models.dart (73 types). This repository only keeps a reference to rum-events-format: the commit pinned in sr_models_generator.yaml. The schemas are fetched at that commit when generating, into .dart_tool/, and are never committed. A CI step fails when the committed models do not match the pinned schemas.

No SDK behavior changes. The generated models are not used yet. The recorders and the processor still use the hand-written models, and switching them over is a follow-up (see below).

How?

sr_models_generator.yaml ─► fetch the pinned commit ─► SchemaLoader ─► ModelResolver ─► DartPrinter ─► dart format ─► write / --check

  • SchemaLoader reads each schema file once. It resolves the $ref forms rum-events-format uses: relative files, fragments in another file, and fragments in the same file. It follows chains of references and reports cycles with the full chain. A reference that leaves the schemas root is an error.

  • ModelResolver turns schemas into a description of the types: classes, enums and sealed unions. It merges allOf, turns enum into enums and const properties into fixed values, and turns oneOf into sealed unions. Each union picks the property that tells its variants apart, or fails when there is none. Validation-only keywords are ignored. Any other keyword outside the subset rum-events-format uses stops generation with an error naming the file and JSON pointer, so no type is generated without part of its schema. Two schemas that would give the same type name fail too.

  • Naming. Each type is named SR + its schema title (MobileSegment → SRSegment). Untitled schemas are named after their owner and property (SRMetaRecord + data → SRMetaRecordData). type_renames keeps the names of the hand-written Flutter models (SRContentClip, SRAlignment, SRIncrementalAdd, …). A rename that matches no type is an error, so stale renames don't silently stop applying.

  • DartPrinter writes:

    • enhanced enums;
    • @immutable final classes with fromJson/toJson, where null fields are left out of the JSON and ==/hashCode compare lists item by item;
    • sealed unions with the getters their variants share;
    • doc comments taken from the schema descriptions.

    fromJson reports the type and field of any value with the wrong type. The output is run through dart format with the settings of its destination package.

  • Local schemas. schemas/ holds schemas for data that is not in rum-events-format. enriched-record-schema.json describes the records as the plugin hands them to its iOS and Android code (the keys EnrichedRecordJSON.swift and EnrichedRecord.kt read), and generates SREnrichedRecord. These schemas appear to rum-events-format as flutter/, so they refer to its schemas with relative $refs.

  • Command line. melos run generate:sr_models generates the models. melos run generate:sr_models:check checks them, which is what CI runs. melos run generate:sr_models:update moves the pin to the latest master. --ref <branch, tag or SHA> pins another commit, and only after its models are generated. .gitattributes marks the generated file linguist-generated, so GitHub collapses it in diffs.

Review checklist

  • This pull request has appropriate unit and / or integration tests
  • This pull request references a Github or JIRA issue — PANA-10317

@JuanNaranjoDD
JuanNaranjoDD requested review from a team as code owners November 17, 2026 14:35
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T13:36:49.958557Z edf6b07 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b263114edb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread tools/sr_models_generator/README.md Resolved

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: FAIL

The pin updater rejects quoted commit SHAs that the configuration loader accepts, preventing updates to valid YAML configurations. A localized regex change can preserve quotes and trailing comments.

Open Bits AI session

🤖 Bits Code Review · Commit b263114

joepeeples
joepeeples previously approved these changes Nov 17, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2e262df11e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: FAIL

The tool fetches pinned schemas and resolves type descriptions; Dart emission remains pending. Quoted-SHA pin updates are fixed. Cyclic allOf wrappers can hang resolution. Recursive unions can fail depending on property order. Unsupported keywords on intermediate reference nodes can be silently ignored.

Open Bits AI session

🤖 Bits Code Review · Commit 2e262df

@datadog-official

datadog-official Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Pipelines

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

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

The tool fetches pinned schemas and resolves type descriptions; Dart emission remains pending. Quoted-SHA pin updates remain fixed. Wrapper cycles now fail explicitly, recursive unions wait for complete variants, and intermediate reference nodes receive keyword validation. No review findings remain open.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit f53bc3e

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d9028202b8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: FAIL

The tool fetches pinned schemas, resolves model types, and emits Dart with round-trip validation support. Earlier pin-update and resolver defects remain fixed. Three printer issues remain: fields named other break equality, fields named identical cause compilation failures, and special characters in discriminator keys can produce invalid Dart.

Open Bits AI session

🤖 Bits Code Review · Commit d902820

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 86f4570598

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: FAIL

The tool now fetches schemas, resolves model types, and generates Dart through a check/update CLI. Earlier pin-update, resolver, and printer findings are fixed. One issue remains: valid renames used only by later schema roots abort generation before those roots are visited.

Open Bits AI session

🤖 Bits Code Review · Commit 86f4570

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

The PR adds schema fetching, type resolution, Dart generation, a check/update CLI, and committed Session Replay models with CI freshness checking. Rename validation now waits for all roots, fixing the last open finding. Earlier pin-update, resolver, and printer issues remain resolved. No findings remain open.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 831b43a

@JuanNaranjoDD JuanNaranjoDD changed the title Session Replay models generator, part 1: read and fetch the schemas feat(sr): generate the Session Replay models from rum-events-format Nov 24, 2026
@JuanNaranjoDD
JuanNaranjoDD changed the base branch from juan.naranjo/sr-schemas to develop November 24, 2026 10:09
@JuanNaranjoDD
JuanNaranjoDD dismissed joepeeples’s stale review November 24, 2026 10:09

The base branch was changed.

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

The static review found no reportable defects. Flutter CI passed the generation consistency check, while replay recording continues to use the handwritten models pending a separate migration.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 831b43a

Start tools/sr_models_generator, a Dart tool that will generate the Session Replay data models from the rum-events-format JSON schemas, as dd-sdk-ios and dd-sdk-android already do, instead of writing them by hand.

This commit adds the package, its lint rules, a command-line entry point that supports --help, and a README describing the design.
Add SchemaNode, a schema object together with its location (file and JSON pointer), and SchemaLoader, which reads schema files once and resolves the  forms rum-events-format uses: relative file paths, fragments in another file and fragments in the same file. deref() follows chains of references and fails on cycles.
Add sr_models_generator.yaml, the only reference kept to rum-events-format: the repository, the pinned commit, the root schema and the output file. The commit must be a full SHA so the same pin always generates the same models.
checkoutCommit checks out the pinned commit of rum-events-format in a cache directory, reusing it without network access when it is already cached. fetchLatest downloads the commit a branch or tag points to, which is how the pin is moved. Both download only that one commit.

The cache lives inside the dd-sdk-flutter repository (.dart_tool/), so git only runs there once the directory has its own .git; otherwise checkout --force would act on the outer repository.
Add the model the resolver will produce from the schemas and the printer will turn into Dart: classes with their fields, unions of classes told apart by a discriminator, and string enums.

Add the naming helpers that turn schema keys and enum values into valid Dart names.
ModelResolver walks the schemas from a root and builds the types to generate: objects become classes, with the properties and required keys of their allOf parts merged in order; arrays become lists of their items; integer, number, string and boolean become primitives. Each schema location yields a single type, so a schema referenced several times, or using itself, is resolved once.

Types are named 'SR' + their title without 'Mobile', and inline object after their owner and property. enum, const and oneOf are rejected until they are supported.
String enums become enum definitions, with values mapped to Dart case names. A property with a const value becomes a field with that fixed value; it must be a required string or integer, as are all the const properties in rum-events-format.
A oneOf of titled object schemas becomes a union of their classes. The variants are told apart by the only const property they all have with a
different value in each, and the union exposes the fields every variant shares.

With this, the whole mobile Session Replay schema resolves.
Two schemas producing the same type name now fail, naming both schema locations. type_renames, read from the configuration with the other naming settings, renames a type by its generated name or a single schema by its location; a rename that matches nothing fails, so it cannot go stale. SRWireframeClip is renamed SRContentClip, as in dd-sdk-ios.

Keywords outside the supported set now fail instead of being ignored.
Resolve the mobile Session Replay schemas at the pinned commit and check every generated class, enum and union, and how each union tells its
variants apart.
Classes, unions, enums and their fields get a documentation comment from their schema description, wrapped to 80 columns, with the characters dartdoc would read as references or HTML escaped.
SchemaLoader mounts other directories as folders of the schemas root, so schemas kept in this repository can refer to the rum-events-format ones with plain relative . The configuration lists several root_schemas and mounts local_schemas as flutter/. Paths that leave the schemas now fail.
Add enriched-record-schema.json, the records with their RUM application, session and view IDs as the plugin hands them to its iOS and Android code, so that SREnrichedRecord is generated with the Session Replay models instead of being written by hand.
dart run sr_models_generator checks out the pinned rum-events-format commit, generates the models of every root schema, formats them as the destination package would, and writes them with a header naming the schemas commit. Configuration, schema and download problems end the run with a message and write nothing.
dart run sr_models_generator --check generates the models as a normal run would and fails, naming the first changed line, when the generated
file differs or is missing. It writes nothing, so CI can run it.
dart run sr_models_generator --ref <branch, tag or SHA> pins the commit the ref points to and generates its models. The pin only moves once the models of the new schemas are generated, so a ref whose schemas cannot be generated leaves the configuration and the models as they were.
Decode and encode back every mobile sample of rum-events-format at the pinned commit with the generated models. Each sample lists the keys it has that no mobile schema declares, which the models drop; any other difference, or a sample added upstream, fails the test.
Add melos scripts to generate the Session Replay models, to check they are up to date, and to pin the latest rum-events-format master, and document how to use the generator and how to move the pin.
checkoutCommit and fetchLatest report downloads through a progress callback instead of writing to stderr, and the command line prints them with its other messages. Tools that show stderr as errors, like melos, no longer flag a successful run.
@JuanNaranjoDD
JuanNaranjoDD force-pushed the juan.naranjo/sr-schemas-updates branch from 831b43a to abd6b1d Compare November 24, 2026 10:42

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

Static review identified no reportable correctness defects. The generator’s execution and generated-model round trips remain unverified because Dart and Flutter are unavailable.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit abd6b1d

@maciejburda
maciejburda requested a review from cdn34dd November 24, 2026 10:51

@fuzzybinary fuzzybinary left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is a lot more code than it needs to be, and we can utilize some packages to help with some of it, specifically I think we can use:

  • json_serializable in several places both in the tool for the YAML parsing along side checked_yaml, and to simplify the code we're generating for the SR models, even though that will then require a secondary dart build call.
  • code_builder to have a more battle tested code generator, which should also support formatting for you
  • yaml_edit which will avoid a complicated Regex and simplify the yaml editing code.

I also don't think we need unit tests that perform a git download, which not only can cause problems in CI but seriously lengthens the unit tests. The tests that check to see if the code generates properly given certain models, and a single validation step in CI that regenerates the file and checks to see if the directory is dirty should be sufficient.

Lastly, I'm not super comfortable putting things in .dart_tool. Although other code generators do that, those tend to be maintained by the Dart team. I'd rather we put something into a .tmp directory or similar... same as other tools meant for CI.

Comment thread .gitattributes Resolved
- Parse the command line in bin/ and pass a GeneratorOptions record to
  runGenerator; rename cli.dart to runner.dart.
- Fail when not run from tools/sr_models_generator.
- Keep the rum-events-format checkout in a git-ignored .tmp/ instead of
  .dart_tool/.
- Edit the pinned commit with yaml_edit instead of a regex.
- Strip only title prefixes listed in strip_from_titles.
- Compute UnionDefinition.sharedFields once, and document why definitions
  are mutable and that their names are Dart identifiers.
- Drop the exact class, enum and union lists from the rum-events-format
  tests; CI checks the generated file.
- Move the models guide to the datadog_session_replay CONTRIBUTING.

@fuzzybinary fuzzybinary left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Excellent changes, I think this is a lot cleaner now. There are a few minor changes that I think are worth tackling before merging this in.

///
/// [output] and [localSchemas] are resolved against the directory of
/// [file].
factory GeneratorConfig.parse(String source, {required String file}) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This rebuilds the config field by field; if this grows much, consider splitting the YAML shape from the loaded config.

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: FAIL

The PR adds schema-generated replay models, JSON serialization, CI freshness checks, and generated official samples, addressing manual sample drift. One issue remains open: removing fixture lookup’s fallback breaks tests under this head’s Flutter CI runner because the prerequisite Dart-runner split is absent; execution remains unverified without Dart or Flutter.

Open Bits AI session

🤖 Bits Code Review · Commit aa85520

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

The PR generates Session Replay models and official samples from pinned schemas, with JSON serialization and CI freshness checks. The earlier fixture-lookup failure is resolved because CI now runs the generator package with dart test; no findings remain open, although execution remains unverified without Dart and Flutter.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit edf6b07

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants