Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions actions/setup/js/send_otlp_span.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,9 @@ async function sendJobSetupSpan(options = {}) {
if (engineId) {
attributes.push(buildAttr("gh-aw.engine.id", engineId));
}
if (eventName) {
attributes.push(buildAttr("gh-aw.event_name", eventName));
}

const resourceAttributes = [buildAttr("github.repository", repository), buildAttr("github.run_id", runId)];
if (repository && runId) {
Expand Down Expand Up @@ -707,6 +710,7 @@ async function sendJobConclusionSpan(spanName, options = {}) {
if (jobName) attributes.push(buildAttr("gh-aw.job.name", jobName));
if (engineId) attributes.push(buildAttr("gh-aw.engine.id", engineId));
if (model) attributes.push(buildAttr("gh-aw.model", model));
if (eventName) attributes.push(buildAttr("gh-aw.event_name", eventName));
attributes.push(buildAttr("gh-aw.staged", staged));
if (!isNaN(effectiveTokens) && effectiveTokens > 0) {
attributes.push(buildAttr("gh-aw.effective_tokens", effectiveTokens));
Expand Down
56 changes: 56 additions & 0 deletions actions/setup/js/send_otlp_span.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,34 @@ describe("sendJobSetupSpan", () => {
expect(resourceKeys).not.toContain("github.event_name");
});

it("includes gh-aw.event_name as span attribute when GITHUB_EVENT_NAME is set", async () => {
const mockFetch = vi.fn().mockResolvedValue({ ok: true, status: 200, statusText: "OK" });
vi.stubGlobal("fetch", mockFetch);

process.env.OTEL_EXPORTER_OTLP_ENDPOINT = "https://traces.example.com";
process.env.GITHUB_EVENT_NAME = "workflow_dispatch";

await sendJobSetupSpan();

const body = JSON.parse(mockFetch.mock.calls[0][1].body);
const span = body.resourceSpans[0].scopeSpans[0].spans[0];
expect(span.attributes).toContainEqual({ key: "gh-aw.event_name", value: { stringValue: "workflow_dispatch" } });
});

it("omits gh-aw.event_name span attribute when GITHUB_EVENT_NAME is not set", async () => {
const mockFetch = vi.fn().mockResolvedValue({ ok: true, status: 200, statusText: "OK" });
vi.stubGlobal("fetch", mockFetch);

process.env.OTEL_EXPORTER_OTLP_ENDPOINT = "https://traces.example.com";

await sendJobSetupSpan();

const body = JSON.parse(mockFetch.mock.calls[0][1].body);
const span = body.resourceSpans[0].scopeSpans[0].spans[0];
const keys = span.attributes.map(a => a.key);
expect(keys).not.toContain("gh-aw.event_name");
});

it("includes github.ref as resource attribute when GITHUB_REF is set", async () => {
const mockFetch = vi.fn().mockResolvedValue({ ok: true, status: 200, statusText: "OK" });
vi.stubGlobal("fetch", mockFetch);
Expand Down Expand Up @@ -1578,6 +1606,34 @@ describe("sendJobConclusionSpan", () => {
expect(resourceKeys).not.toContain("github.event_name");
});

it("includes gh-aw.event_name as span attribute when GITHUB_EVENT_NAME is set", async () => {
const mockFetch = vi.fn().mockResolvedValue({ ok: true, status: 200, statusText: "OK" });
vi.stubGlobal("fetch", mockFetch);

process.env.OTEL_EXPORTER_OTLP_ENDPOINT = "https://traces.example.com";
process.env.GITHUB_EVENT_NAME = "pull_request";

await sendJobConclusionSpan("gh-aw.job.conclusion");

const body = JSON.parse(mockFetch.mock.calls[0][1].body);
const span = body.resourceSpans[0].scopeSpans[0].spans[0];
expect(span.attributes).toContainEqual({ key: "gh-aw.event_name", value: { stringValue: "pull_request" } });
});

it("omits gh-aw.event_name span attribute when GITHUB_EVENT_NAME is not set", async () => {
const mockFetch = vi.fn().mockResolvedValue({ ok: true, status: 200, statusText: "OK" });
vi.stubGlobal("fetch", mockFetch);

process.env.OTEL_EXPORTER_OTLP_ENDPOINT = "https://traces.example.com";

await sendJobConclusionSpan("gh-aw.job.conclusion");

const body = JSON.parse(mockFetch.mock.calls[0][1].body);
const span = body.resourceSpans[0].scopeSpans[0].spans[0];
const keys = span.attributes.map(a => a.key);
expect(keys).not.toContain("gh-aw.event_name");
});

it("includes github.ref as resource attribute when GITHUB_REF is set", async () => {
const mockFetch = vi.fn().mockResolvedValue({ ok: true, status: 200, statusText: "OK" });
vi.stubGlobal("fetch", mockFetch);
Expand Down
Loading