Skip to content

Fix symbol extraction for instrumented methods - #6339

Merged
p-datadog merged 15 commits into
masterfrom
tyler.finethy/symdb-instrumented-methods
Oct 1, 2026
Merged

p-datadog merged 15 commits into
masterfrom
tyler.finethy/symdb-instrumented-methods

Conversation

@tylfin

@tylfin tylfin commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Preserve original method symbols and source metadata when DI probes prepend wrappers, in both full and incremental symbol extraction.

Motivation:

An existing method logpoint can make its target disappear from code search and source lookup: reflection resolves the prepended DI wrapper, which is then excluded as gem code.
Resolve the method declared by the inspected class or module instead of extracting the wrapper.

Change log entry

Yes. Fix methods disappearing from code search and source lookup when method logpoints are already installed.

Additional Notes:

How to test the change?

Unit tests added

Resolve original method declarations behind prepended wrappers so existing method probes do not hide application symbols or source metadata. Preserve inherited visibility overrides and gem filtering, and cover full and incremental extraction with active probes.
@tylfin tylfin added the AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos label Sep 18, 2026
@dd-octo-sts dd-octo-sts Bot added the debugger Live Debugger (+Dynamic Instrumentation, +Symbol Database) label Sep 18, 2026
@tylfin
tylfin requested a review from p-datadog September 18, 2026 17:03
@datadog-prod-us1-5

datadog-prod-us1-5 Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Tests

✅ All CI checks and tests passed.

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
• Patch Coverage: 16.28%
• Overall Coverage: 90.51% (+0.13%)

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

@tylfin
tylfin marked this pull request as ready for review September 18, 2026 18:17
@tylfin
tylfin requested review from a team as code owners September 18, 2026 18:17
p-ddsign and others added 2 commits September 23, 2026 16:29
Add a YARD docstring to declared_instance_method matching the surrounding
private methods, and rename the parameter from name to method_name for
consistency with the rest of the extractor. Drop the inline comment that
described prepend semantics by contrast.
@p-datadog

Copy link
Copy Markdown
Member

@codex review

@p-datadog
p-datadog requested a lite review from Copilot September 23, 2026 21:32
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-28T14:31:19.782992Z 6ecb24b Manual request
🔒 Security Review ✅ Completed 2026-09-28T14:31:20.467869Z 6ecb24b Manual request
ℹ️ 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

All reviewed changes are covered by regression tests with no unresolved blocking issues.

Review effort: Lite
Findings: None

What changed in this PR

Fixes symbol extraction for methods wrapped by Dynamic Instrumentation probes, preserving original method metadata and source information.

Changes:

  • Resolves original methods through prepend chains.
  • Applies the fix to full and incremental extraction.
  • Adds regression tests, RBS typing, and a changelog entry.
File Description
unreleased/​20260918164420.json Documents the fix.
spec/​datadog/​symbol_database/​extractor_spec.rb Adds probe and visibility regression coverage.
sig/​datadog/​symbol_database/​extractor.rbs Declares the new helper signature.
lib/​datadog/​symbol_database/​extractor.rb Resolves original method metadata.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 98ca024434

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@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: 98ca024434

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/datadog/symbol_database/extractor.rb
Comment thread sig/datadog/symbol_database/extractor.rbs
Replace the tautological visibility-override test, which passed against a
no-op declared_instance_method, with a prepend-skip assertion on the resolved
owner. Add a fallback-branch test for the super_method-nil path. Assert the
DI wrapper is actually installed in the active-probes before block so a silent
hook no-op cannot leave the tests green. Use let(:filename) instead of the
@filename instance variable in the active-probes context.
extract resolves every method through declared_instance_method three times
(find_source_file, calculate_class_line_range, extract_method_scopes), each
walk re-walking the super_method chain. Memoize per (mod, method_name) for the
duration of a single extract call so each method is resolved once. extract_all
stays uncached: its two passes must re-resolve to detect methods that moved
files between passes. Document that the singleton-method path in
find_source_file is not memoized because method-logpoint probes prepend
instance methods only.
@pr-commenter

pr-commenter Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-09-28 21:16:47

Comparing candidate commit a3d8a2a in PR branch tyler.finethy/symdb-instrumented-methods with baseline commit c47e5e8 in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 52 metrics, 0 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Strech
Strech previously approved these changes Sep 24, 2026
@Strech
Strech dismissed their stale review September 24, 2026 07:44

Accidental

extract computed find_source_file up to three times per call (once in
user_code_module?, once in extract, once in the scope builder) and
extract_targetable_lines twice per public/protected method (once in
calculate_class_line_range, once in extract_method_scope). The
@method_resolution_cache memoized only the cheap declared_instance_method
reflection, leaving the expensive iseq compilation duplicated.

extract now resolves source_file once and threads it into the scope
builders. extract_class_scope builds one record per method holding the
resolved location, targetable lines, visibility, arity, and parameters;
calculate_class_line_range reduces over the public/protected records and
build_method_scopes maps over the user-code records, so each method is
resolved and iseq-compiled once. declared_instance_method is now a pure
helper with no instance state.
@dd-octo-sts

dd-octo-sts Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Typing analysis

Note: Ignored files are excluded from the next sections.

steep:ignore comments

This PR clears 10 steep:ignore comments.

steep:ignore comments (+0-10) ✅ Cleared:
lib/datadog/opentelemetry/signal_configuration.rb:15
lib/datadog/opentelemetry/signal_configuration.rb:25
lib/datadog/opentelemetry/signal_configuration.rb:26
lib/datadog/opentelemetry/signal_configuration.rb:27
lib/datadog/opentelemetry/signal_configuration.rb:29
lib/datadog/opentelemetry/signal_configuration.rb:31
lib/datadog/opentelemetry/signal_configuration.rb:44
lib/datadog/opentelemetry/signal_configuration.rb:46
lib/datadog/symbol_database/extractor.rb:995
lib/datadog/symbol_database/extractor.rb:996

Untyped methods

This PR introduces 1 partially typed method, and clears 1 partially typed method. It increases the percentage of typed methods from 71.2% to 71.83% (+0.63%).

Partially typed methods (+1-1) ❌ Introduced:
sig/datadog/core/remote/component.rbs:37
└── def self.build: (
          untyped settings,
          Datadog::Core::Configuration::AgentSettings agent_settings,
          logger: Core::Logger,
          telemetry: Datadog::Core::Telemetry::Component,
          ?open_feature_component_provider: (^() -> Datadog::OpenFeature::Component?)?
        ) -> Datadog::Core::Remote::Component?
✅ Cleared:
sig/datadog/core/remote/component.rbs:37
└── def self.build: (
          untyped settings,
          Datadog::Core::Configuration::AgentSettings agent_settings,
          logger: Core::Logger,
          telemetry: Datadog::Core::Telemetry::Component
        ) -> Datadog::Core::Remote::Component?

If you believe a method or an attribute is rightfully untyped or partially typed, you can add # untyped:accept on the line before the definition to remove it from the stats.

build_method_records returned an Array<Hash> with nine fixed keys consumed
via record[:key] lookups, leaving the contract untyped in RBS and a typo'd
key silently yielding nil. Introduce Datadog::SymbolDatabase::MethodRecord,
a keyword_init Struct, so the record shape is a named type with typed
accessors and a self-documenting constructor.
@p-datadog

Copy link
Copy Markdown
Member

@codex review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Address the Ruby compatibility issue and the RBS style nit.

Review effort: Lite
Findings: 1 High severity

Open (1)

Comment thread lib/datadog/symbol_database/extractor.rb Outdated

@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: 6770656749

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/datadog/symbol_database/extractor.rb Outdated
Comment thread sig/datadog/symbol_database/method_record.rbs Outdated
@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 6770656749

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

calculate_class_line_range skipped private methods, so a class whose
earliest or latest method was private got an underreported start_line or
end_line. The extract_all path (convert_node_to_scope) already spanned all
visibilities; this makes the extract path match. Adds a test with private
methods bounding the class to pin the span.
build_method_records produced an Array<MethodRecord> so calculate_class_line_range
and build_method_scopes could reuse one resolution per method. The record only
existed to feed a class line range that spanned gem-defined methods too, which
contradicted the extract_all path (convert_node_to_scope derives the range from
user-code method scopes) and could put a gem file's line numbers on a user-file
CLASS scope.

Drop MethodRecord and build the METHOD scopes once in extract_class_scope via
build_class_method_scopes (reusing build_instance_method_scope, one iseq compile
per method). Derive the class line range from those scopes with line_range_from_scopes,
shared with convert_node_to_scope so the two paths cannot diverge again.
@p-datadog

Copy link
Copy Markdown
Member

@codex review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

A critical Steep type-checking issue remains in the extractor.

Review effort: Lite
Findings: 1 High severity

Open (1)
Resolved since last review (1)

Comment thread lib/datadog/symbol_database/extractor.rb

@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: 6ecb24beff

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/datadog/symbol_database/extractor.rb
@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 6ecb24beff

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

p-ddsign and others added 5 commits September 28, 2026 16:45
Address review comment: a method removed or redefined between collecting
method_names and resolving them makes declared_instance_method raise
NameError. With only the method-level rescue, that discarded every scope for
the class instead of just the affected method — regressing the per-method
isolation the earlier extract_method_scope rescue provided.

Add a per-method rescue inside the filter_map block, matching the shape used
by collect_method_names_by_file and build_file_scope, so a single method's
failure drops only that method. The outer method-level rescue is retained as
the class-level backstop.

- Fixed in lib/datadog/symbol_database/extractor.rb build_class_method_scopes
- Added regression coverage in spec/datadog/symbol_database/extractor_spec.rb
  asserting surviving methods still produce scopes when one raises NameError

Verified: rspec (targeted + full extractor_spec, 156 examples 0 failures),
steep check (no type errors), standardrb and rubocop clean.

Co-Authored-By: Claude <noreply@anthropic.com>
find_source_file resolves the source location of each instance and singleton
method inside its two loops. This PR routed those loops through
declared_instance_method, which raises NameError when a method is removed or
redefined between name collection and lookup. Without a per-method rescue, one
such failure aborted the whole lookup — including the const_source_location
fallbacks — and returned nil, the same regression fixed in
build_class_method_scopes.

Add a per-method rescue to both loops so a single method's failure is skipped
and later user-code paths are still found. The method-level rescue is retained
as the backstop.

- Fixed in lib/datadog/symbol_database/extractor.rb find_source_file
  (instance-method loop and singleton-method loop)
- Added regression coverage in spec/datadog/symbol_database/extractor_spec.rb
  for both loops: a later user-code path is still found when an earlier method
  raises NameError

Verified: rspec (targeted + full extractor_spec, 156 examples 0 failures),
steep check (no type errors), standardrb and rubocop clean.

Co-Authored-By: Claude <noreply@anthropic.com>
@p-datadog
p-datadog merged commit 96ddffc into master Oct 1, 2026
609 checks passed
@p-datadog
p-datadog deleted the tyler.finethy/symdb-instrumented-methods branch October 1, 2026 16:42
@dd-octo-sts dd-octo-sts Bot added this to the 2.44.0 milestone Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos debugger Live Debugger (+Dynamic Instrumentation, +Symbol Database)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants