Repository navigation
feat: bundle libdd_trace_c.so into the plugin .rock - #110
adeshkumar1 wants to merge 8 commits into
Conversation
Ships the native dd-trace-cpp library (both linux/amd64 and linux/arm64) inside a single LuaRocks .rock package so `luarocks install kong-plugin-ddtrace` is self-sufficient. - build/Dockerfile compiles dd-trace-cpp on Ubuntu 22.04 (matching Kong Gateway's runtime) using cmake from the Kitware APT repo. - .dd-trace-cpp-version pins the upstream ref; bump when upgrading. - tracer.lua picks the arch-specific .so via ffi.arch + package.cpath. - rockspec install.lib declares both arch-suffixed libraries. - .github/workflows/build-rock.yml (reusable) builds both arches on native runners, packs the .rock, installs it in a Kong container to smoke-test plugin load. dev.yml/main.yml/release.yml invoke it with publish-mode none/tip/release respectively. - Version bumped to 0.3.0 — first release requiring the native library. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…workflow validation
- Delete stale 0.2.2-1.rockspec from a past release. - Tighten artifact upload glob to only grab generated rockspecs (kong-plugin-ddtrace-*.rockspec), not the unversioned template. - Use handler.lua VERSION + .pr.<sha> for PR builds so rock filenames read like 0.3.0.pr.1234abc instead of the opaque 0.0.0.pr.
|
@codex review |
There was a problem hiding this comment.
Pull request overview
This PR makes kong-plugin-ddtrace installation self-sufficient by bundling the native libdd_trace_c.so (amd64 + arm64) into a single LuaRocks .rock, and updates CI to build/package/test/publish that artifact.
Changes:
- Add a Docker-based build pipeline to compile
dd-trace-cpp’s C binding and pin the upstream ref via.dd-trace-cpp-version. - Package both
x86_64andaarch64.sofiles into the rock (rockspec install rules + runtime loader selection intracer.lua). - Replace existing packaging/release workflows with a reusable
build-rock.ymlworkflow (build libs, pack rock, smoke-test in Kong Gateway, optionally publish).
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
kong/plugins/ddtrace/tracer.lua |
Switch native library loading to an arch-suffixed LuaRocks-installed .so, with fallback to system library. |
kong/plugins/ddtrace/handler.lua |
Bump plugin version to 0.3.0. |
kong-plugin-ddtrace.rockspec |
Install both arch-specific native libraries into $LUA_CDIR via build.install.lib. |
kong-plugin-ddtrace-0.2.2-1.rockspec |
Remove the old versioned rockspec from the repo. |
build/Dockerfile |
Add a build image to compile libdd_trace_c.so from pinned dd-trace-cpp. |
.github/workflows/build-rock.yml |
New reusable workflow to build libs, pack a combined rock, test in Kong, and publish tip/release. |
.github/workflows/dev.yml |
Invoke reusable rock build workflow for PRs (no publish). |
.github/workflows/main.yml |
Invoke reusable workflow for tip builds on main. |
.github/workflows/release.yml |
Invoke reusable workflow for tagged releases. |
.dd-trace-cpp-version |
New upstream ref pin for dd-trace-cpp. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| permissions: | ||
| contents: write | ||
|
|
There was a problem hiding this comment.
Workflow-wide permissions: contents: write grants write access to GITHUB_TOKEN for all jobs (including lint/test). To follow least-privilege, scope contents: write to only the job(s) that actually create/update releases/tags (e.g. the build-rock reusable-workflow invocation / publish jobs).
| permissions: | ||
| contents: write | ||
|
|
There was a problem hiding this comment.
Workflow-wide permissions: contents: write gives write access to GITHUB_TOKEN for the entire workflow. Consider scoping contents: write down to only the job(s) that publish releases, and keep other jobs at the default read-only permissions to reduce blast radius.
| local lib_name = (ffi.arch == "x64") and "libdd_trace_c-x86_64" or "libdd_trace_c-aarch64" | ||
| local lib_path = package.searchpath(lib_name, package.cpath) |
There was a problem hiding this comment.
lib_name defaults to the aarch64 library for any non-x64 architecture. On other LuaJIT arch values (e.g. x86, ppc64le, etc.) this will search for the wrong module name and can lead to confusing load behavior. Consider mapping explicitly (e.g. handle x64 and arm64 only) and falling back to the system dd_trace_c (or raising a clear "unsupported architecture" error) for anything else.
| local lib_name = (ffi.arch == "x64") and "libdd_trace_c-x86_64" or "libdd_trace_c-aarch64" | |
| local lib_path = package.searchpath(lib_name, package.cpath) | |
| local lib_name | |
| if ffi.arch == "x64" then | |
| lib_name = "libdd_trace_c-x86_64" | |
| elseif ffi.arch == "arm64" then | |
| lib_name = "libdd_trace_c-aarch64" | |
| end | |
| local lib_path = lib_name and package.searchpath(lib_name, package.cpath) |
| echo "" | ||
| echo "## Install" | ||
| echo "1. Download the rock." | ||
| echo "2. Install it using luarock: \`luarock install <ROCK>.src.rock\`" |
There was a problem hiding this comment.
The generated release notes instruct users to run luarock install <ROCK>.src.rock, but the tool is luarocks (with an “s”) and this workflow produces a binary .rock (renamed to .all.rock), not a .src.rock. Update the instructions to match the actual artifact name/command so installs don’t fail.
| echo "2. Install it using luarock: \`luarock install <ROCK>.src.rock\`" | |
| echo "2. Install it using luarocks: \`luarocks install <ROCK>.all.rock\`" |
| @@ -0,0 +1 @@ | |||
| 5dfaf40 | |||
There was a problem hiding this comment.
This file pins dd-trace-cpp using a 7-character short SHA. Short SHAs can become ambiguous over time as the upstream repo grows, which would break reproducibility. Prefer pinning the full 40-character commit SHA (or an annotated tag) to keep builds deterministic.
| 5dfaf40 | |
| <replace-with-the-full-40-character-commit-sha-for-5dfaf40> |
There was a problem hiding this comment.
💡 Codex Review
kong-plugin-ddtrace/.github/workflows/dev.yml
Lines 5 to 6 in 86b0af3
For pull_request, GitHub evaluates branches against the PR base branch and requires at least one positive pattern when ! exclusions are used. This new workflow only lists !main, so the PR workflow is not a valid include/exclude filter and, in the normal case of PRs targeting main, the lint/test/package validation will not run.
ℹ️ 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".
- Pin dd-trace-cpp by full 40-char SHA (not 7-char) for reproducibility. - Scope 'contents: write' to just the build-rock job in main/release, instead of granting it workflow-wide. - Make tracer.lua's arch detection explicit (x64 / arm64) so other LuaJIT archs fall through to the system fallback instead of silently trying aarch64. - Fix tip release notes: luarock → luarocks, .src.rock → .all.rock.
branches with only negations (!main) isn't a valid filter — GitHub requires at least one positive include. The old filter was a no-op; PRs weren't triggering dev.yml automatically. Switch to branches-ignore which does what we actually mean: run on any PR not targeting main. Also drop the stray tags: filter — pull_request events don't have tag context, so it was always ignored.
|
@codex review |
Summary
Ships the native
libdd_trace_c.so(bothlinux/amd64andlinux/arm64) inside a single LuaRocks.rocksoluarocks install kong-plugin-ddtraceis self-sufficient. Matches the packaging design reviewed with Damien.What changed
build/Dockerfile— compilesdd-trace-cppon Ubuntu 22.04 (matching Kong Gateway's runtime base) with cmake from the Kitware APT repo. Outputs/libdd_trace_c.sovia ascratchexport stage, pulled out withdocker buildx --output type=local..dd-trace-cpp-version— pins the upstream ref (5dfaf40, the commit that merged PR #309 — explicit span timestamps). Bump this file to upgrade.kong/plugins/ddtrace/tracer.lua— arch-aware loader: detectsffi.arch, callspackage.searchpath("libdd_trace_c-<arch>", package.cpath), falls back to systemffi.load("dd_trace_c").kong-plugin-ddtrace.rockspec— addsbuild.install.libwith both arch-suffixed entries so LuaRocks installs both into\$LUA_CDIR..github/workflows/build-rock.yml— reusable workflow:ubuntu-latest(amd64) andubuntu-24.04-arm(arm64). Each runs the Dockerfile, extracts the.so, uploads an artifact.packjob combines artifacts, runsgen-rockspec.py+luarocks make+luarocks packto produce the binary rock.test-packageinstalls the rock intokong/kong-gateway:3.5.0.0-ubuntu(withlibcurl4as runtime dep) and runskong start.publish-modeinput (none|tip|release).dev.yml/main.yml/release.yml— invoke the reusable workflow. PRs validate up throughtest-packagebut don't publish. Main pushes update thetippre-release. Tags publish to LuaRocks.kong/plugins/ddtrace/handler.lua—VERSIONbumped to0.3.0. Requiring a native library is a breaking install-story change.Deferred / out of scope
.sois built and shipped buttest-packageonly runs on amd64 (no arm64 Kong Gateway image). Defer until we see an arm64-specific issue.🤖 Generated with Claude Code