Skip to content

runner: add DBConnFunc hook for custom DB connections - #7

Merged
morgo merged 1 commit into
block:mainfrom
Areson:ioberst/add-dbconnfunc-hook
Apr 23, 2026
Merged

morgo merged 1 commit into
block:mainfrom
Areson:ioberst/add-dbconnfunc-hook

Conversation

@Areson

@Areson Areson commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Add an optional DBConnFunc callback to StageRunnerConfig and ArchiveRunnerConfig that lets callers inject a custom *sql.DB (e.g. with Datadog APM tracing) without adding tracing dependencies to the OSS library.

When nil (the default), the existing dbconn.New() path is used, preserving full backward compatibility.

Motivation

Services that embed polt may need to instrument MySQL connections with tracing. Without a hook, the only option is to fork or modify the OSS library to add tracing imports — which would pull tracing dependencies into the OSS project.

This hook keeps the tracing concern in the caller while giving it full control over how *sql.DB instances are created.

Changes

  • db_helper.go: Define DBConnFunc type
  • stage_runner.go: Add DBConnFunc to config/struct, use it in setupDBAndCheckIfRunSucceeded() for both primary and replica DB connections
  • archive_runner.go: Same pattern for archive runner
  • db_helper_test.go (new): 10 unit tests covering type assignability, nil-by-default backward compat, storage on both runners, correct DSN/config passthrough, and error propagation

Testing

All new unit tests pass without requiring a live MySQL instance. Full package builds cleanly.

Add an optional DBConnFunc callback to StageRunnerConfig and
ArchiveRunnerConfig that lets callers inject a custom *sql.DB
(e.g. with Datadog APM tracing) without adding tracing dependencies
to the OSS library.

When nil (the default), the existing dbconn.New() path is used,
preserving full backward compatibility.

Amp-Thread-ID: https://ampcode.com/threads/T-019dbbef-f6eb-74cb-9af8-686adc8b2a1f
Co-authored-by: Amp <amp@ampcode.com>
@morgo
morgo merged commit 5f45ab7 into block:main Apr 23, 2026
11 checks passed
@Areson
Areson deleted the ioberst/add-dbconnfunc-hook branch April 23, 2026 22:16
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