runner: add DBConnFunc hook for custom DB connections - #7
Merged
Merged
Conversation
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
approved these changes
Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add an optional
DBConnFunccallback toStageRunnerConfigandArchiveRunnerConfigthat 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.DBinstances are created.Changes
db_helper.go: DefineDBConnFunctypestage_runner.go: AddDBConnFuncto config/struct, use it insetupDBAndCheckIfRunSucceeded()for both primary and replica DB connectionsarchive_runner.go: Same pattern for archive runnerdb_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 propagationTesting
All new unit tests pass without requiring a live MySQL instance. Full package builds cleanly.