Skip to content

feat(metrics): add opt-in BEAM runtime metrics collector - #1188

Open
solnic wants to merge 1 commit into
masterfrom
feat/runtime-metrics-collector
Open

solnic wants to merge 1 commit into
masterfrom
feat/runtime-metrics-collector

Conversation

@solnic

@solnic solnic commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Adds automatic BEAM runtime metrics. It must be enabled in your config:

config :sentry,
  metrics: [
    runtime: [
      # Enable auto-metrics - this is `false` by default
      enabled: true
    ],
    # Attach `elixir_version` and `otp_version` to the default attributes if you want.
    #
    # This is `false` by default.
    version_attributes: true
  ]

Once enabled, memory usage is reported as gauges, in bytes:

  • elixir.runtime.mem.total
  • elixir.runtime.mem.processes
  • elixir.runtime.mem.processes_used
  • elixir.runtime.mem.system
  • elixir.runtime.mem.atom
  • elixir.runtime.mem.atom_used
  • elixir.runtime.mem.binary
  • elixir.runtime.mem.code
  • elixir.runtime.mem.ets

Collection frequency

The SDK handles telemetry_poller's events to get the data, the interval can be adjusted using the following config:

config :telemetry_poller, default: [period: 30_000]

image

@solnic
solnic force-pushed the feat/runtime-metrics-collector branch 6 times, most recently from 0a75de8 to 76f4c08 Compare September 11, 2026 09:52
@solnic
solnic removed this pull request from stack #1192 September 11, 2026 09:57
@solnic
solnic changed the base branch from master to fix/telemetry-processor-deadlines September 11, 2026 09:57
@solnic
solnic added this pull request to stack #1206 September 11, 2026 09:58
@solnic
solnic force-pushed the feat/runtime-metrics-collector branch from 76f4c08 to ba29223 Compare September 11, 2026 12:18
@solnic
solnic force-pushed the feat/runtime-metrics-collector branch from ba29223 to 9b9e2f1 Compare September 11, 2026 12:35
@solnic
solnic removed this pull request from stack #1206 September 14, 2026 08:49
Base automatically changed from fix/telemetry-processor-deadlines to master September 14, 2026 12:09
@solnic
solnic added this pull request to stack #1210 September 15, 2026 08:50
@solnic
solnic force-pushed the feat/runtime-metrics-collector branch 3 times, most recently from 8e3778f to 36c1b3e Compare September 15, 2026 14:28
@solnic
solnic marked this pull request as ready for review September 16, 2026 08:19

@cursor cursor 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.

Stale Bugbot comment from a previous run.

Comment thread lib/sentry/metrics/runtime.ex Outdated

@whatyouhide whatyouhide left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Have we considered doing this via the extremely well-established https://github.com/beam-telemetry/telemetry_poller under the hood?

@solnic

solnic commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator Author

Have we considered doing this via the extremely well-established https://github.com/beam-telemetry/telemetry_poller under the hood?

@whatyouhide yeah we could but custom plumbing would still be needed. Do you think it'd still be better? I'm all for having less code over here of course.

@whatyouhide

Copy link
Copy Markdown
Collaborator

@solnic yes I think it's worth it. telemetry_poller actually emits VM-metric events already so Sentry could also just register a telemetry handler for those to clean up things a bit more.

@solnic
solnic force-pushed the feat/runtime-metrics-collector branch from 36c1b3e to 0ee95b0 Compare September 16, 2026 13:27
@solnic
solnic removed this pull request from stack #1210 September 16, 2026 13:27
@solnic
solnic added this pull request to stack #1211 September 16, 2026 13:28
Comment thread lib/sentry/application.ex Outdated

@cursor cursor 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.

Stale Bugbot comment from a previous run.

Comment thread lib/sentry/application.ex Outdated
@solnic
solnic removed this pull request from stack #1211 September 16, 2026 13:33
@solnic
solnic added this pull request to stack #1214 September 16, 2026 13:34
@solnic
solnic marked this pull request as draft September 16, 2026 13:36
@solnic
solnic force-pushed the feat/runtime-metrics-collector branch 7 times, most recently from 29d2d1f to 8b3520f Compare September 17, 2026 13:11
@solnic
solnic marked this pull request as ready for review September 17, 2026 13:15
@solnic
solnic requested a review from whatyouhide September 17, 2026 13:22
@solnic
solnic force-pushed the feat/runtime-metrics-collector branch from 8b3520f to b6553a4 Compare September 18, 2026 07:16

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b6553a4. Configure here.

_ = :telemetry.attach_many(@handler_id, @events, &__MODULE__.handle_event/4, config(opts))

:ok
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Startup crash without telemetry present

Medium Severity

Enabling metrics.runtime calls :telemetry.attach_many/4 during application start with no check that :telemetry (or telemetry_poller) is loaded. Both are optional dependencies, so a boot with runtime: [enabled: true] and no telemetry raises UndefinedFunctionError and takes down the :sentry app. Tracing already warns and disables itself when its optional stack is missing; this path does not. If telemetry is present but telemetry_poller is not, the handler still attaches and the feature silently never reports.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b6553a4. Configure here.

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