@@ -33914,8 +33914,8 @@ var esm$4 = /*#__PURE__*/Object.freeze({
33914
33914
trace: trace
33915
33915
});
33916
33916
33917
- const tracer$2 = trace.getTracer("otel-cicd-action");
33918
33917
async function traceStep(step) {
33918
+ const tracer = trace.getTracer("otel-cicd-action");
33919
33919
if (!step.completed_at || !step.started_at) {
33920
33920
coreExports.info(`Step ${step.name} is not completed yet.`);
33921
33921
return;
@@ -33927,7 +33927,7 @@ async function traceStep(step) {
33927
33927
const startTime = new Date(step.started_at);
33928
33928
const completedTime = new Date(step.completed_at);
33929
33929
const attributes = stepToAttributes(step);
33930
- await tracer$2 .startActiveSpan(step.name, { attributes, startTime }, async (span) => {
33930
+ await tracer.startActiveSpan(step.name, { attributes, startTime }, async (span) => {
33931
33931
const code = step.conclusion === "failure" ? SpanStatusCode.ERROR : SpanStatusCode.OK;
33932
33932
span.setStatus({ code });
33933
33933
// Some skipped and post jobs return completed_at dates that are older than started_at
@@ -33946,8 +33946,8 @@ function stepToAttributes(step) {
33946
33946
};
33947
33947
}
33948
33948
33949
- const tracer$1 = trace.getTracer("otel-cicd-action");
33950
33949
async function traceJob(job, annotations) {
33950
+ const tracer = trace.getTracer("otel-cicd-action");
33951
33951
if (!job.completed_at) {
33952
33952
coreExports.info(`Job ${job.id} is not completed yet`);
33953
33953
return;
@@ -33958,7 +33958,7 @@ async function traceJob(job, annotations) {
33958
33958
...jobToAttributes(job),
33959
33959
...annotationsToAttributes(annotations),
33960
33960
};
33961
- await tracer$1 .startActiveSpan(job.name, { attributes, startTime }, async (span) => {
33961
+ await tracer.startActiveSpan(job.name, { attributes, startTime }, async (span) => {
33962
33962
const code = job.conclusion === "failure" ? SpanStatusCode.ERROR : SpanStatusCode.OK;
33963
33963
span.setStatus({ code });
33964
33964
for (const step of job.steps ?? []) {
@@ -34024,8 +34024,8 @@ function annotationsToAttributes(annotations) {
34024
34024
return attributes;
34025
34025
}
34026
34026
34027
- const tracer = trace.getTracer("otel-cicd-action");
34028
34027
async function traceWorkflowRun(workflowRun, jobs, jobAnnotations, prLabels) {
34028
+ const tracer = trace.getTracer("otel-cicd-action");
34029
34029
const startTime = new Date(workflowRun.run_started_at ?? workflowRun.created_at);
34030
34030
const attributes = workflowRunToAttributes(workflowRun, prLabels);
34031
34031
return await tracer.startActiveSpan(workflowRun.name ?? workflowRun.display_title, { attributes, root: true, startTime }, async (rootSpan) => {
@@ -86103,6 +86103,42 @@ class DeterministicIdGenerator {
86103
86103
}
86104
86104
}
86105
86105
86106
+ async function fetchGithub(token, runId) {
86107
+ const octokit = githubExports.getOctokit(token);
86108
+ coreExports.info(`Get workflow run for ${runId}`);
86109
+ const workflowRun = await getWorkflowRun(githubExports.context, octokit, runId);
86110
+ coreExports.info("Get jobs");
86111
+ const jobs = await listJobsForWorkflowRun(githubExports.context, octokit, runId);
86112
+ coreExports.info("Get job annotations");
86113
+ const jobsId = (jobs ?? []).map((job) => job.id);
86114
+ let jobAnnotations = {};
86115
+ try {
86116
+ jobAnnotations = await getJobsAnnotations(githubExports.context, octokit, jobsId);
86117
+ }
86118
+ catch (error) {
86119
+ if (error instanceof RequestError) {
86120
+ coreExports.info(`Failed to get job annotations: ${error.message}}`);
86121
+ }
86122
+ else {
86123
+ throw error;
86124
+ }
86125
+ }
86126
+ coreExports.info("Get PRs labels");
86127
+ const prNumbers = (workflowRun.pull_requests ?? []).map((pr) => pr.number);
86128
+ let prLabels = {};
86129
+ try {
86130
+ prLabels = await getPRsLabels(githubExports.context, octokit, prNumbers);
86131
+ }
86132
+ catch (error) {
86133
+ if (error instanceof RequestError) {
86134
+ coreExports.info(`Failed to get PRs labels: ${error.message}}`);
86135
+ }
86136
+ else {
86137
+ throw error;
86138
+ }
86139
+ }
86140
+ return { workflowRun, jobs, jobAnnotations, prLabels };
86141
+ }
86106
86142
async function run() {
86107
86143
try {
86108
86144
const otlpEndpoint = coreExports.getInput("otlpEndpoint");
@@ -86111,31 +86147,8 @@ async function run() {
86111
86147
const runId = Number.parseInt(coreExports.getInput("runId") || `${githubExports.context.runId}`);
86112
86148
const extraAttributes = stringToRecord(coreExports.getInput("extraAttributes"));
86113
86149
const ghToken = coreExports.getInput("githubToken") || process.env["GITHUB_TOKEN"] || "";
86114
- const octokit = githubExports.getOctokit(ghToken);
86115
- coreExports.info(`Get workflow run for ${runId}`);
86116
- const workflowRun = await getWorkflowRun(githubExports.context, octokit, runId);
86117
- coreExports.info("Get jobs");
86118
- const jobs = await listJobsForWorkflowRun(githubExports.context, octokit, runId);
86119
- coreExports.info("Get job annotations");
86120
- const jobsId = (jobs ?? []).map((job) => job.id);
86121
- let jobAnnotations = {};
86122
- try {
86123
- jobAnnotations = await getJobsAnnotations(githubExports.context, octokit, jobsId);
86124
- }
86125
- catch (error) {
86126
- const message = error instanceof Error ? error.message : JSON.stringify(error);
86127
- coreExports.info(`Failed to get job annotations: ${message}}`);
86128
- }
86129
- coreExports.info("Get PRs labels");
86130
- const prNumbers = (workflowRun.pull_requests ?? []).map((pr) => pr.number);
86131
- let prLabels = {};
86132
- try {
86133
- prLabels = await getPRsLabels(githubExports.context, octokit, prNumbers);
86134
- }
86135
- catch (error) {
86136
- const message = error instanceof Error ? error.message : JSON.stringify(error);
86137
- coreExports.info(`Failed to get PRs labels: ${message}}`);
86138
- }
86150
+ coreExports.info("Use Github API to fetch workflow data");
86151
+ const { workflowRun, jobs, jobAnnotations, prLabels } = await fetchGithub(ghToken, runId);
86139
86152
coreExports.info(`Create tracer provider for ${otlpEndpoint}`);
86140
86153
const attributes = {
86141
86154
[ATTR_SERVICE_NAME]: otelServiceName || workflowRun.name || `${workflowRun.workflow_id}`,
0 commit comments