Skip to content

Commit c1dc0b8

Browse files
committed
enable debug logs
1 parent 6d0cce1 commit c1dc0b8

File tree

6 files changed

+168
-86
lines changed

6 files changed

+168
-86
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,4 @@ jobs:
5959
secrets.SELF_CHECK_OTEL_AUTHORIZATION_TOKEN}}"}'
6060
env:
6161
OTEL_EXPORTER_OTLP_PROTOCOL: 'http/protobuf'
62-
ACTIONS_STEP_DEBUG: 'false'
63-
64-
- name: Verify Test Results
65-
id: verify
66-
run: echo "Action completed successfully"
62+
ACTIONS_STEP_DEBUG: 'true'

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index.js

Lines changed: 102 additions & 68 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rollup.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const config = {
1212
format: 'es',
1313
sourcemap: true
1414
},
15+
// external: [/^@opentelemetry\//],
1516
plugins: [typescript(), nodeResolve({ preferBuiltins: true }), commonjs()]
1617
}
1718

src/main.ts

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as core from '@actions/core'
2+
23
import * as github from '@actions/github'
34
import { ingestDir } from './junit-parser.js'
45
import { generateMetrics, type TMetricsConfig } from './metrics-generator.js'
56
import { MetricsSubmitter } from './metrics-submitter.js'
67
import {
7-
ConsoleMetricExporter,
88
MeterProvider,
99
PeriodicExportingMetricReader
1010
} from '@opentelemetry/sdk-metrics'
@@ -21,9 +21,62 @@ import {
2121

2222
const DEFAULT_EXPORT_INTERVAL_MS = 1000
2323
const DEFAULT_TIMEOUT_MS = 30000
24+
import {
25+
DiagConsoleLogger,
26+
DiagLogFunction,
27+
DiagLogLevel,
28+
DiagLogger,
29+
diag
30+
} from '@opentelemetry/api'
31+
32+
class CapturingDiagLogger implements DiagLogger {
33+
private baseLogger: DiagConsoleLogger
34+
private capturedOutput: string = ''
35+
36+
constructor() {
37+
this.baseLogger = new DiagConsoleLogger()
38+
}
39+
40+
private capture(level: string, message: string, ...args: unknown[]) {
41+
const fullMessage = `[${level}] ${message} ${args.join(' ')}\n`
42+
this.capturedOutput += fullMessage
43+
}
44+
45+
error: DiagLogFunction = (message: string, ...args: unknown[]) => {
46+
this.capture('ERROR', message, ...args)
47+
this.baseLogger.error(message, ...args)
48+
}
49+
50+
warn: DiagLogFunction = (message: string, ...args: unknown[]) => {
51+
this.capture('WARN', message, ...args)
52+
this.baseLogger.warn(message, ...args)
53+
}
54+
55+
info: DiagLogFunction = (message: string, ...args: unknown[]) => {
56+
this.capture('INFO', message, ...args)
57+
this.baseLogger.info(message, ...args)
58+
}
59+
60+
debug: DiagLogFunction = (message: string, ...args: unknown[]) => {
61+
this.capture('DEBUG', message, ...args)
62+
this.baseLogger.debug(message, ...args)
63+
}
64+
65+
verbose: DiagLogFunction = (message: string, ...args: unknown[]) => {
66+
this.capture('VERBOSE', message, ...args)
67+
this.baseLogger.verbose(message, ...args)
68+
}
69+
70+
getCapturedOutput(): string {
71+
return this.capturedOutput
72+
}
73+
}
2474

2575
export async function run(): Promise<void> {
2676
try {
77+
const logger = new CapturingDiagLogger()
78+
diag.setLogger(logger, DiagLogLevel.ERROR)
79+
2780
const junitXmlFolder = core.getInput('junit-xml-folder', { required: true })
2881
const serviceName = core.getInput('service-name', { required: true })
2982
const serviceNamespace = core.getInput('service-namespace', {
@@ -78,15 +131,6 @@ export async function run(): Promise<void> {
78131
})
79132
]
80133

81-
if (process.env.ACTIONS_STEP_DEBUG === 'true') {
82-
readers.push(
83-
new PeriodicExportingMetricReader({
84-
exporter: new ConsoleMetricExporter(),
85-
exportIntervalMillis: DEFAULT_EXPORT_INTERVAL_MS
86-
})
87-
)
88-
}
89-
90134
const meterProvider = new MeterProvider({
91135
resource,
92136
readers
@@ -122,7 +166,14 @@ export async function run(): Promise<void> {
122166

123167
await meterProvider.forceFlush()
124168

125-
core.info(`✅ CI visibility metrics submitted successfully`)
169+
const diagOutput = logger.getCapturedOutput()
170+
171+
if (diagOutput.includes('metrics export failed')) {
172+
core.error(`❌ CI visibility metrics submission failed: ${diagOutput}`)
173+
core.setFailed(`Action failed: ${diagOutput}`)
174+
} else {
175+
core.info(`✅ CI visibility metrics submitted successfully`)
176+
}
126177
} catch (error) {
127178
const errorMessage = error instanceof Error ? error.message : String(error)
128179
core.error(`❌ CI visibility metrics submission failed: ${errorMessage}`)

0 commit comments

Comments
 (0)