Skip to content

Commit

Permalink
Add step.status; remove unused step.id (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
corentinmusard authored Dec 30, 2024
1 parent 8a3c672 commit 512d40d
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 234 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.12.0] - 2024-12-30

### Added

- Add step.status field

### Changed

- Remove trace.ts dependency on github.ts
Expand Down Expand Up @@ -54,7 +60,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support for `https` endpoints (proto over http).
- Update to node 20.x

[unreleased]: https://github.com/corentinmusard/otel-cicd-action/compare/v1.11.0...HEAD
[unreleased]: https://github.com/corentinmusard/otel-cicd-action/compare/v1.12.0...HEAD
[1.12.0]: https://github.com/corentinmusard/otel-cicd-action/compare/v1.11.0...v1.12.0
[1.11.0]: https://github.com/corentinmusard/otel-cicd-action/compare/v1.10.0...v1.11.0
[1.10.0]: https://github.com/corentinmusard/otel-cicd-action/compare/v1.9.1...v1.10.0
[1.9.1]: https://github.com/corentinmusard/otel-cicd-action/compare/v1.9.0...v1.9.1
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ We provide sample code for popular platforms. If you feel one is missing, please
| Jaeger | WIP |
| Grafana | WIP |

### On workflow_run event (recommended)
### On workflow_run event

```yaml
on:
Expand Down Expand Up @@ -81,7 +81,9 @@ jobs:
| ------- | ----------------------------------------- |
| traceId | The OpenTelemetry Trace ID for this Trace |

## Honeycomb Example Trace
[Sample OpenTelemetry Output](./src/__assets__/output.txt) (id, traceId and parentId have been redacted).

#### Honeycomb Example Trace

![HoneyComb Example](./docs/honeycomb-example.png)

Expand Down
52 changes: 22 additions & 30 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68186,9 +68186,8 @@ async function traceOTLPFile(path) {

const tracer$1 = trace.getTracer("otel-cicd-action");
async function traceWorkflowRunStep({ parentSpan, parentContext, jobName, step, workflowArtifacts, }) {
if (!step || !step.completed_at || !step.started_at) {
const stepName = step?.name || "UNDEFINED";
coreExports.warning(`Step ${stepName} is not completed yet.`);
if (!step.completed_at || !step.started_at) {
coreExports.warning(`Step ${step.name} is not completed yet.`);
return;
}
if (step.conclusion === "cancelled" || step.conclusion === "skipped") {
Expand All @@ -68201,43 +68200,36 @@ async function traceWorkflowRunStep({ parentSpan, parentContext, jobName, step,
const completedTime = new Date(step.completed_at);
const span = tracer$1.startSpan(step.name, {
attributes: {
"github.job.step.status": step.status,
"github.job.step.conclusion": step.conclusion ?? undefined,
"github.job.step.name": step.name,
"github.job.step.number": step.number,
"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.job.step.started_at": step.started_at ?? undefined,
"github.job.step.completed_at": step.completed_at ?? undefined,
error: step.conclusion === "failure",
},
startTime,
}, ctx);
const spanId = span.spanContext().spanId;
try {
const code = step.conclusion === "failure" ? SpanStatusCode.ERROR : SpanStatusCode.OK;
span.setStatus({ code });
coreExports.debug(`Step Span<${spanId}>: Started<${step.started_at}>`);
if (step.conclusion) {
span.setAttribute("github.job.step.conclusion", step.conclusion);
}
await traceArtifact({
jobName,
stepName: step.name,
workflowArtifacts,
});
}
finally {
coreExports.debug(`Step Span<${spanId}>: Ended<${step.completed_at}>`);
// Some skipped and post jobs return completed_at dates that are older than started_at
span.end(new Date(Math.max(startTime.getTime(), completedTime.getTime())));
}
const code = step.conclusion === "failure" ? SpanStatusCode.ERROR : SpanStatusCode.OK;
span.setStatus({ code });
await traceArtifact(jobName, step.name, workflowArtifacts);
// Some skipped and post jobs return completed_at dates that are older than started_at
span.end(new Date(Math.max(startTime.getTime(), completedTime.getTime())));
}
async function traceArtifact({ jobName, stepName, workflowArtifacts }) {
async function traceArtifact(jobName, stepName, workflowArtifacts) {
const artifact = workflowArtifacts(jobName, stepName);
if (artifact) {
coreExports.debug(`Found Artifact ${artifact?.path}`);
if (!artifact) {
coreExports.debug(`No artifact to trace for Job<${jobName}> Step<${stepName}>`);
return;
}
coreExports.debug(`Found artifact ${artifact?.path}`);
try {
await traceOTLPFile(artifact.path);
}
else {
coreExports.debug(`No Artifact to trace for Job<${jobName}> Step<${stepName}>`);
catch (error) {
if (error instanceof Error) {
coreExports.warning(`Failed to trace artifact ${artifact.path}: ${error.message}`);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ const config: JestConfigWithTsJest = {
collectCoverageFrom: ["src/**/*.ts", "!src/config.ts", "!src/index.ts", "!src/replay.ts", "!src/__fixtures__/**"],
coverageThreshold: {
global: {
statements: 80,
statements: 70,
branches: 50,
functions: 70,
lines: 80,
lines: 70,
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": true,
"name": "otel-cicd-action",
"type": "module",
"version": "1.9.0",
"version": "1.12.0",
"description": "Github Action that export CI/CD workflows to any endpoint compatible with OpenTelemetry",
"scripts": {
"prepare": "husky",
Expand Down
Loading

0 comments on commit 512d40d

Please sign in to comment.