-
Notifications
You must be signed in to change notification settings - Fork 371
fix: normalize INPUT_JOB_NAME hyphen variant so OTLP spans include the actual job name #24823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -152,6 +152,32 @@ describe("action_setup_otlp run()", () => { | |
| fetchSpy.mockRestore(); | ||
| }); | ||
|
|
||
| it("uses job name from INPUT_JOB-NAME (hyphen form) in setup span when INPUT_JOB_NAME is not set", async () => { | ||
| const tmpOut = path.join(path.dirname(__dirname), `action_setup_otlp_test_job_name_hyphen_${Date.now()}.txt`); | ||
| try { | ||
| process.env.OTEL_EXPORTER_OTLP_ENDPOINT = "http://localhost:14317"; | ||
| process.env["INPUT_JOB-NAME"] = "agent"; | ||
| delete process.env.INPUT_JOB_NAME; | ||
| process.env.GITHUB_OUTPUT = tmpOut; | ||
| process.env.GITHUB_ENV = tmpOut; | ||
|
|
||
| let capturedBody; | ||
| const fetchSpy = vi.spyOn(global, "fetch").mockImplementation((_url, opts) => { | ||
| capturedBody = opts?.body; | ||
| return Promise.resolve(new Response(null, { status: 200 })); | ||
| }); | ||
|
|
||
| await runSetup(); | ||
|
|
||
| const payload = JSON.parse(capturedBody); | ||
| const spanName = payload?.resourceSpans?.[0]?.scopeSpans?.[0]?.spans?.[0]?.name; | ||
| expect(spanName).toBe("gh-aw.agent.setup"); | ||
| fetchSpy.mockRestore(); | ||
| } finally { | ||
|
Comment on lines
+155
to
+176
|
||
| fs.rmSync(tmpOut, { force: true }); | ||
| } | ||
| }); | ||
|
|
||
| it("includes github.repository, github.run_id resource attributes in setup span", async () => { | ||
| const tmpOut = path.join(path.dirname(__dirname), `action_setup_otlp_test_resource_attrs_${Date.now()}.txt`); | ||
| try { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -57,6 +57,18 @@ async function run() { | |||||||||||||||||||||||||||||||||
| console.log("[otlp] INPUT_TRACE_ID not set, a new trace ID will be generated"); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Normalize job-name input: handle both INPUT_JOB_NAME (underscore, standard) | ||||||||||||||||||||||||||||||||||
| // and INPUT_JOB-NAME (hyphen, used by some runner versions). Mirror the same | ||||||||||||||||||||||||||||||||||
| // two-key lookup that INPUT_TRACE_ID uses above so script-mode invocations | ||||||||||||||||||||||||||||||||||
| // (setup.sh → node action_setup_otlp.cjs) always resolve the job name even | ||||||||||||||||||||||||||||||||||
| // when the runner preserves the original hyphen in the env var name. | ||||||||||||||||||||||||||||||||||
| const inputJobName = (process.env.INPUT_JOB_NAME || process.env["INPUT_JOB-NAME"] || "").trim(); | ||||||||||||||||||||||||||||||||||
| if (inputJobName) { | ||||||||||||||||||||||||||||||||||
| // Normalise to the canonical underscore form so sendJobSetupSpan (which | ||||||||||||||||||||||||||||||||||
| // reads process.env.INPUT_JOB_NAME) always finds the value. | ||||||||||||||||||||||||||||||||||
| process.env.INPUT_JOB_NAME = inputJobName; | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+65
to
+69
|
||||||||||||||||||||||||||||||||||
| const inputJobName = (process.env.INPUT_JOB_NAME || process.env["INPUT_JOB-NAME"] || "").trim(); | |
| if (inputJobName) { | |
| // Normalise to the canonical underscore form so sendJobSetupSpan (which | |
| // reads process.env.INPUT_JOB_NAME) always finds the value. | |
| process.env.INPUT_JOB_NAME = inputJobName; | |
| const inputJobNameUnderscore = (process.env.INPUT_JOB_NAME || "").trim(); | |
| const inputJobNameHyphen = (process.env["INPUT_JOB-NAME"] || "").trim(); | |
| const inputJobName = inputJobNameUnderscore || inputJobNameHyphen; | |
| if (inputJobName) { | |
| // Normalise to the canonical underscore form so sendJobSetupSpan (which | |
| // reads process.env.INPUT_JOB_NAME) always finds the value. | |
| process.env.INPUT_JOB_NAME = inputJobName; | |
| } else if (process.env.INPUT_JOB_NAME && !inputJobNameUnderscore) { | |
| // Clear whitespace-only underscore-form input so downstream consumers do | |
| // not treat it as a real job name. | |
| delete process.env.INPUT_JOB_NAME; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lookup
(process.env.INPUT_JOB_NAME || process.env["INPUT_JOB-NAME"])occurs before trimming, so a whitespace-onlyINPUT_JOB_NAMEwill prevent the hyphen-form value from being used and will fall back to the default span name after.trim(). To make the fallback robust, trim both candidates first and pick the first non-empty trimmed value.