Skip to content
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

Proposing few more attributes #138

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
31 changes: 29 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ async function traceWorkflowRunJobs({ provider, workflowRunJobs, }) {
trace: api_1.trace,
tracer,
job,
workflowRun: workflowRunJobs.workflowRun,
workflowArtifacts: workflowRunJobs.workflowRunArtifacts,
});
}
Expand All @@ -436,7 +437,7 @@ async function traceWorkflowRunJobs({ provider, workflowRunJobs, }) {
return rootSpan.spanContext();
}
exports.traceWorkflowRunJobs = traceWorkflowRunJobs;
async function traceWorkflowRunJob({ parentContext, trace, parentSpan, tracer, job, workflowArtifacts, }) {
async function traceWorkflowRunJob({ parentContext, trace, parentSpan, tracer, job, workflowRun, workflowArtifacts, }) {
var _a;
core.debug(`Trace Job ${job.id}`);
if (!job.completed_at) {
Expand All @@ -447,6 +448,17 @@ async function traceWorkflowRunJob({ parentContext, trace, parentSpan, tracer, j
const ctx = trace.setSpan(parentContext, parentSpan);
const startTime = new Date(job.started_at);
const completedTime = new Date(job.completed_at);
/* eslint-disable */
// Tried bumping the version to 19 of @octokit/rest but created_at is not available on it :/
// It surely exists though https://docs.github.com/en/rest/actions/workflow-jobs?apiVersion=2022-11-28
// @ts-ignore
const job_created_at = job.created_at || undefined;
/* eslint-enable */
// jobs can be queued waiting for a runner to be available
const createdTime = job_created_at ? new Date(job_created_at) : undefined;
const queued_ms = createdTime
? startTime.getTime() - createdTime.getTime()
: undefined;
const span = tracer.startSpan(job.name, {
attributes: {
"github.job.id": job.id,
Expand All @@ -460,6 +472,14 @@ async function traceWorkflowRunJob({ parentContext, trace, parentSpan, tracer, j
"github.job.labels": job.labels.join(", ") || undefined,
"github.job.started_at": job.started_at || undefined,
"github.job.completed_at": job.completed_at || undefined,
"github.job.created_at": job_created_at,
"github.job.queued_ms": queued_ms,
"github.workflow_id": workflowRun.workflow_id,
"github.run_id": workflowRun.id,
"github.run_number": workflowRun.run_number,
"github.workflow": workflowRun.name || undefined,
"github.head_sha": workflowRun.head_sha,
"github.head_branch": workflowRun.head_branch || undefined,
"github.conclusion": job.conclusion || undefined,
error: job.conclusion === "failure",
},
Expand All @@ -486,6 +506,7 @@ async function traceWorkflowRunJob({ parentContext, trace, parentSpan, tracer, j
tracer,
workflowArtifacts,
step,
workflowRun,
});
}
}
Expand Down Expand Up @@ -529,7 +550,7 @@ exports.traceWorkflowRunStep = void 0;
const core = __importStar(__nccwpck_require__(42186));
const api_1 = __nccwpck_require__(65163);
const trace_otlp_file_1 = __nccwpck_require__(40535);
async function traceWorkflowRunStep({ job, parentContext, parentSpan, trace, tracer, workflowArtifacts, step, }) {
async function traceWorkflowRunStep({ job, parentContext, parentSpan, trace, tracer, workflowArtifacts, step, workflowRun, }) {
if (!step || !step.completed_at || !step.started_at) {
const stepName = (step === null || step === void 0 ? void 0 : step.name) || "UNDEFINED";
console.warn(`Step ${stepName} is not completed yet.`);
Expand All @@ -550,6 +571,12 @@ async function traceWorkflowRunStep({ job, parentContext, parentSpan, trace, tra
"github.job.step.started_at": step.started_at || undefined,
"github.job.step.completed_at": step.completed_at || undefined,
"github.job.step.id": step.id,
"github.workflow_id": workflowRun.workflow_id,
"github.run_id": workflowRun.id,
"github.run_number": workflowRun.run_number,
"github.workflow": workflowRun.name || undefined,
"github.head_sha": workflowRun.head_sha,
"github.head_branch": workflowRun.head_branch || undefined,
error: step.conclusion === "failure",
},
startTime,
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ describe("listWorkflowRunArtifacts", () => {
statusText: "OK",
config: {},
});
/* eslint-disable */
// @ts-ignore
Copy link
Author

Choose a reason for hiding this comment

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

Got a type issue that blocks commits without this

const lookup = await listWorkflowRunArtifacts(mockContext, mockOctokit, 1);
/* eslint-enable */
const response = lookup("lint-and-test", "run tests");
if (!response) {
fail("Lookup Failed: Did not parse zip file correctly");
Expand Down
27 changes: 27 additions & 0 deletions src/tracing/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
WorkflowRunJob,
WorkflowRunJobStep,
WorkflowArtifactLookup,
WorkflowRun,
} from "../github";

import { traceWorkflowRunStep } from "./step";
Expand Down Expand Up @@ -148,6 +149,7 @@ export async function traceWorkflowRunJobs({
trace,
tracer,
job,
workflowRun: workflowRunJobs.workflowRun,
workflowArtifacts: workflowRunJobs.workflowRunArtifacts,
});
}
Expand All @@ -163,6 +165,7 @@ type TraceWorkflowRunJobParams = {
trace: TraceAPI;
tracer: Tracer;
job: WorkflowRunJob;
workflowRun: WorkflowRun;
workflowArtifacts: WorkflowArtifactLookup;
};

Expand All @@ -172,6 +175,7 @@ async function traceWorkflowRunJob({
parentSpan,
tracer,
job,
workflowRun,
workflowArtifacts,
}: TraceWorkflowRunJobParams) {
core.debug(`Trace Job ${job.id}`);
Expand All @@ -183,6 +187,20 @@ async function traceWorkflowRunJob({
const ctx = trace.setSpan(parentContext, parentSpan);
const startTime = new Date(job.started_at);
const completedTime = new Date(job.completed_at);

/* eslint-disable */
// Tried bumping the version to 19 of @octokit/rest but created_at is not available on it :/
// It surely exists though https://docs.github.com/en/rest/actions/workflow-jobs?apiVersion=2022-11-28
// @ts-ignore
const job_created_at: string | undefined = job.created_at || undefined;
/* eslint-enable */

// jobs can be queued waiting for a runner to be available
const createdTime = job_created_at ? new Date(job_created_at) : undefined;
const queued_ms = createdTime
? startTime.getTime() - createdTime.getTime()
: undefined;

const span = tracer.startSpan(
job.name,
{
Expand All @@ -198,6 +216,14 @@ async function traceWorkflowRunJob({
"github.job.labels": job.labels.join(", ") || undefined,
"github.job.started_at": job.started_at || undefined,
"github.job.completed_at": job.completed_at || undefined,
"github.job.created_at": job_created_at,
"github.job.queued_ms": queued_ms,
"github.workflow_id": workflowRun.workflow_id,
"github.run_id": workflowRun.id,
"github.run_number": workflowRun.run_number,
"github.workflow": workflowRun.name || undefined,
"github.head_sha": workflowRun.head_sha,
"github.head_branch": workflowRun.head_branch || undefined,
"github.conclusion": job.conclusion || undefined,
error: job.conclusion === "failure",
},
Expand Down Expand Up @@ -227,6 +253,7 @@ async function traceWorkflowRunJob({
tracer,
workflowArtifacts,
step,
workflowRun,
});
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/tracing/step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
WorkflowRunJobStep,
WorkflowRunJob,
WorkflowArtifactLookup,
WorkflowRun,
} from "../github";
import { traceOTLPFile } from "./trace-otlp-file";

Expand All @@ -16,6 +17,7 @@ export type TraceWorkflowRunStepParams = {
tracer: Tracer;
workflowArtifacts: WorkflowArtifactLookup;
step?: WorkflowRunJobStep;
workflowRun: WorkflowRun;
};
export async function traceWorkflowRunStep({
job,
Expand All @@ -25,6 +27,7 @@ export async function traceWorkflowRunStep({
tracer,
workflowArtifacts,
step,
workflowRun,
}: TraceWorkflowRunStepParams) {
if (!step || !step.completed_at || !step.started_at) {
const stepName = step?.name || "UNDEFINED";
Expand All @@ -48,6 +51,12 @@ export async function traceWorkflowRunStep({
"github.job.step.started_at": step.started_at || undefined,
"github.job.step.completed_at": step.completed_at || undefined,
"github.job.step.id": step.id,
"github.workflow_id": workflowRun.workflow_id,
"github.run_id": workflowRun.id,
"github.run_number": workflowRun.run_number,
"github.workflow": workflowRun.name || undefined,
"github.head_sha": workflowRun.head_sha,
"github.head_branch": workflowRun.head_branch || undefined,
error: step.conclusion === "failure",
},
startTime,
Expand Down