Skip to content

feat: bundle libdd_trace_c.so into the plugin .rock - #110

Draft
adeshkumar1 wants to merge 8 commits into
cpp-ffi-rewritefrom
adeshkumar1/packaging
Draft

adeshkumar1 wants to merge 8 commits into
cpp-ffi-rewritefrom
adeshkumar1/packaging

Conversation

@adeshkumar1

@adeshkumar1 adeshkumar1 commented Apr 23, 2026 •

Copy link
Copy Markdown

Summary

Ships the native libdd_trace_c.so (both linux/amd64 and linux/arm64) inside a single LuaRocks .rock so luarocks install kong-plugin-ddtrace is self-sufficient. Matches the packaging design reviewed with Damien.

What changed

  • build/Dockerfile — compiles dd-trace-cpp on Ubuntu 22.04 (matching Kong Gateway's runtime base) with cmake from the Kitware APT repo. Outputs /libdd_trace_c.so via a scratch export stage, pulled out with docker 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: detects ffi.arch, calls package.searchpath("libdd_trace_c-<arch>", package.cpath), falls back to system ffi.load("dd_trace_c").
  • kong-plugin-ddtrace.rockspec — adds build.install.lib with both arch-suffixed entries so LuaRocks installs both into \$LUA_CDIR.
  • .github/workflows/build-rock.yml — reusable workflow:
    • Matrix over ubuntu-latest (amd64) and ubuntu-24.04-arm (arm64). Each runs the Dockerfile, extracts the .so, uploads an artifact.
    • pack job combines artifacts, runs gen-rockspec.py + luarocks make + luarocks pack to produce the binary rock.
    • test-package installs the rock into kong/kong-gateway:3.5.0.0-ubuntu (with libcurl4 as runtime dep) and runs kong start.
    • Publish job is gated on the publish-mode input (none | tip | release).
  • dev.yml / main.yml / release.yml — invoke the reusable workflow. PRs validate up through test-package but don't publish. Main pushes update the tip pre-release. Tags publish to LuaRocks.
  • kong/plugins/ddtrace/handler.lua — VERSION bumped to 0.3.0. Requiring a native library is a breaking install-story change.

Deferred / out of scope

  • arm64 test coverage in CI — the arm64 .so is built and shipped but test-package only runs on amd64 (no arm64 Kong Gateway image). Defer until we see an arm64-specific issue.
  • Upstream version pinning — using a SHA is intentional; no dd-trace-cpp release tag yet contains PR #309. Switch to a semver tag once upstream cuts one.

🤖 Generated with Claude Code

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>
@adeshkumar1
adeshkumar1 marked this pull request as draft April 23, 2026 19:28
- 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.
@adeshkumar1
adeshkumar1 requested a review from Copilot April 23, 2026 21:05
@adeshkumar1

Copy link
Copy Markdown
Author

@codex review

Copilot AI 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.

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_64 and aarch64 .so files into the rock (rockspec install rules + runtime loader selection in tracer.lua).
  • Replace existing packaging/release workflows with a reusable build-rock.yml workflow (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.

Comment thread .github/workflows/main.yml Outdated
Comment on lines +8 to +10
permissions:
contents: write

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
Comment thread .github/workflows/release.yml Outdated
Comment on lines +8 to +10
permissions:
contents: write

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment thread kong/plugins/ddtrace/tracer.lua Outdated
Comment on lines +76 to +77
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)

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.
Comment thread .github/workflows/build-rock.yml Outdated
echo ""
echo "## Install"
echo "1. Download the rock."
echo "2. Install it using luarock: \`luarock install <ROCK>.src.rock\`"

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
echo "2. Install it using luarock: \`luarock install <ROCK>.src.rock\`"
echo "2. Install it using luarocks: \`luarocks install <ROCK>.all.rock\`"

Copilot uses AI. Check for mistakes.
Comment thread .dd-trace-cpp-version Outdated
@@ -0,0 +1 @@
5dfaf40

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
5dfaf40
<replace-with-the-full-40-character-commit-sha-for-5dfaf40>

Copilot uses AI. Check for mistakes.

@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

branches:
- '!main'

P1 Badge Fix the PR trigger filters

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

Copy link
Copy Markdown
Author

@codex review

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