Skip to content

Add opt-in OTLP metrics emission for per-job run observability - #78433

Merged
pelikhan merged 19 commits into
mainfrom
copilot/feat-add-otlp-metrics-emission
Nov 17, 2026
Merged

pelikhan merged 19 commits into
mainfrom
copilot/feat-add-otlp-metrics-emission

Conversation

@pelikhan

@pelikhan pelikhan commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Adds OTLP metrics alongside the existing traces/logs pipeline for job duration, failures, token usage, tool calls, and safe-output volume. Metrics are enabled by default when OTLP is configured, with an explicit opt-out.

Fixes #78427

Configuration and export

  • The compiler injects GH_AW_OTEL_METRICS: ${{ vars.GH_AW_OTEL_METRICS || 'true' }} unless workflow env overrides it. Set GH_AW_OTEL_METRICS: "false" to disable metrics. gh aw env get/update exposes default_otel_metrics for repository, organization, and enterprise defaults; deleting the variable restores default-on behavior. The runtime emits metrics only when the effective value is the literal true.
  • Exports to /v1/metrics on all configured OTLP endpoints, reusing endpoint-specific headers, retries, and partial-success handling for rejected data points.
  • Supports OTLP/HTTP JSON (default) and binary http/protobuf. OTEL_EXPORTER_OTLP_METRICS_PROTOCOL takes precedence over OTEL_EXPORTER_OTLP_PROTOCOL. Unsupported protocols and encoding errors produce diagnostics rather than silently falling back to JSON.
  • Uses a dependency-free protobuf encoder for gauges, monotonic sums, explicit-bucket histograms, and trace-linked exemplars. No runtime dependency on @opentelemetry/otlp-transformer or other OpenTelemetry packages; SDK protocol types are used only for byte-for-byte conformance tests.
  • Sanitized payloads are mirrored as raw OTLP JSON to /tmp/gh-aw/otel-metrics.jsonl before export, regardless of wire encoding. The unified artifact includes the agent job's mirror only when metrics are enabled. Agent-job built-ins are emitted before artifact upload; other jobs' post-job metrics are exported remotely and are not included in that artifact.
  • Metric build, mirror, and export failures are non-fatal and produce diagnostics.

Built-in metrics

Metric Type / unit Purpose
gh_aw.job.duration Histogram / s Wall-clock job duration
gh_aw.job.errors Counter / {job} Failed, timed-out, and cancelled jobs
gen_ai.client.token.usage Counter / {token} Input, output, cache-read, and cache-write usage, by gen_ai.token.type
gh_aw.agent.turns Histogram / {turn} Agent turns
gh_aw.tool_calls Counter / {call} Tool calls by success/error status
gh_aw.workflow.output.items Counter / {item} Safe-output items by type
gh_aw.ai.credits.limit_exceeded Counter / {event} Known AI-credit limit failures
gh_aw.ai.credits.rate_limit_errors Counter / {event} Known AI-credit rate-limit failures
gh_aw.otlp.export.failures Counter / {failure} Observed OTLP export failures

Counters and histograms use delta temporality. Compatibility aliases (gh_aw.run.*, gh_aw.tokens.*, and gh_aw.safe_outputs) remain available; query canonical metrics or aliases, not both. The run aliases still describe job-level observations.

Custom instrumentation and safeguards

Exports logMetric(name, value, { type, unit, description, attributes, buckets }) from otlp.cjs and index.cjs. Supports gauges (default), delta counters, and explicit-bucket histograms, with per-series aggregation and a one-second flush timer.

Custom metrics allow at most eight attributes and 100 unique series per process, with 128-character attribute keys/string values. High-cardinality keys identifying individual runs, jobs, traces, commits, users, issues, pull requests, conversations, or URLs are rejected. Metric resources retain only bounded repository, workflow, engine, event, and job identity; trace IDs appear in exemplars rather than metric dimensions. Shared secret redactors sanitize metric identity and string values before mirroring/export, and custom calls containing recognized credentials or configured secrets are rejected with a warning.

Compiler, documentation, and validation

  • Adds metrics export, response handling, pre-upload conclusion emission, and conditional artifact/recovery collection; updates environment management, documentation, and the OpenTelemetry specification.
  • Regenerates workflow lock files and WASM golden fixtures for the compiler changes. Merges the latest main and preserves its Dependabot workflow tool contract.
  • Local validation: 1,098 JavaScript tests and 18 Dependabot workflow-contract tests passed, along with impacted Go tests, type checking, JavaScript lint, instruction-prefix checks, and workflow drift checks (368 workflows compiled successfully).
  • The full pre-PR gate still reports pre-existing custom Go lint findings in code untouched by the merge conflict resolution; it is not fully green.

pelikhan and others added 2 commits November 16, 2026 19:00
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Copilot stopped work on behalf of pelikhan due to an error November 16, 2026 19:39
@pelikhan

Copy link
Copy Markdown
Collaborator Author

@copilot keep working

@sudivate

Copy link
Copy Markdown

Thanks for this. The plumbing looks solid: the fail-closed endpoint filtering is kept, per-endpoint headers are used, there's no endpoint override, the metric resource drops per-run IDs, and the JSONL mirror is in the unified artifact. I reviewed it against specs/otel-observability-spec.md from the perspective of an Azure Monitor collector consumer. Some suggestions before it leaves WIP:

Dimensions

  1. No repository dimension. The metric resource is built by hand (service.name, service.version, github.event_name, github.job, plus gh-aw.workflow.name for logMetric) and, unlike buildGitHubActionsResourceAttributes for spans, never reads OTEL_RESOURCE_ATTRIBUTES. That correctly drops gh-aw.run.id, but it also drops gh-aw.repository. OTEL_SERVICE_NAME doesn't help, because the compiler sets it to gh-aw.<workflow-id>. Anyone sending several repos to one collector gets same-named workflows merged together. Could the metric resource take a bounded allowlist from OTEL_RESOURCE_ATTRIBUTES (at least gh-aw.repository and gh-aw.engine.id) and never the run ID? That fits §8.3: there's one value per repo.
  2. Duration has no engine or model dimension. Only the token counters carry gen_ai.request.model/gh-aw.engine.id, so duration can't be compared by model.
  3. Undocumented dimensions. §11.5 mentions gh-aw.tool.status and gh-aw.safe_output.type, but not the other data-point attributes the code emits: gh-aw.job.name, gh-aw.workflow.name, cicd.pipeline.task.run.result (all metrics), and gen_ai.request.model/gh-aw.engine.id (token counters). Listing them per metric would let backends plan for cardinality.

Spec alignment

  1. Metric names. §11.2/§11.3 already define cicd.pipeline.run.duration/cicd.pipeline.run.errors, gen_ai.client.token.usage (with gen_ai.token.type) and gh_aw.workflow.output.items. §11.5 introduces gh_aw.run.*, gh_aw.tokens.* and gh_aw.safe_outputs without relating them to those. Could it use the existing names, or state that the new names are aliases, to avoid a later migration (§2.3)? Also, gh_aw.run.duration is measured per job, so the name is misleading.
  2. Temporality. §12.6 says logMetric counters are delta sums, but the code uses delta (aggregationTemporality: 1) for the built-in histograms and counters too, and §11.5 doesn't say so. Stating it there would tell collector users to add deltatocumulative for cumulative backends such as Prometheus.
  3. Export failures. §6.4(5) requires gh_aw.otlp.export.failures once metrics are enabled. It isn't emitted.
  4. Exemplars. §11.4 says to attach trace and span context as exemplars. Without them there's no way back from a metric to a run, which matters because run IDs are correctly excluded.
  5. Run ID opt-in. §8.1 says gh-aw.run.id "MUST be opt-in for metrics", but no opt-in mechanism is defined. Either define one or reword that line.
  6. Test mapping. §17 needs updating for the new exporter path and tests.

Data collected but not emitted

  1. Cache tokens. The conclusion span records gen_ai.usage.cache_read.input_tokens and cache_creation.input_tokens, but the metrics drop them. Cache tokens are billed differently, so cost tracking needs them.
  2. Turns. gh-aw.turns is available. Please emit gh_aw.agent.turns (§11.3).
  3. AI-credit limits. gh-aw.max_ai_credits_exceeded and ai_credits_rate_limit_error would make useful bounded counters.
  4. Cancelled runs. sendJobConclusionSpan sets span status ERROR for cancelled (isAgentNonOK), but gh_aw.run.errors counts only failure/timed_out (and the JSDoc on sendJobConclusionSpan still says only those two set ERROR). Please make the two consistent, or document why they differ.

Configuration

  1. Opt-in. The compiler doesn't inject ${{ vars.GH_AW_OTEL_METRICS }} the way it does for OTEL_EXPORTER_OTLP_PROTOCOL, so each workflow needs a hand-edited env: block. Injecting it, or using the reserved §5.6 observability.otlp.signals, would make it a repo- or org-level switch.
  2. logMetric limits. Attribute types are validated, but there's no cap on keys or series, so callers can still add per-run values. A small key limit plus a documented "no per-run identifiers" rule would keep §11.1 and §11.4 enforceable.

One open question (I haven't verified this): built-in metrics are only emitted from sendJobConclusionSpan. If a job can end without that post step running (runner loss, hard cancel), those jobs won't show up in gh_aw.run.errors. Is that acceptable, or should errors also be derived somewhere that always runs?

Happy to test the next revision against an Azure Monitor collector.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

@copilot keep working

Gated otel-metrics.jsonl on the explicit metrics opt-in while preserving the trace/error artifact paths. Added enabled, disabled, and unconfigured coverage. Commit: d448033.

@pelikhan

Copy link
Copy Markdown
Collaborator Author

@copilot apply comments from #78433 (comment)

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@pelikhan pelikhan changed the title [WIP] Add built-in OTLP metrics emission for per-job run observability Add opt-in OTLP metrics emission for per-job run observability Nov 16, 2026
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

@copilot apply comments from #78433 (comment)

Applied the linked review follow-ups in 627016b. The metrics flag remains explicit in workflow env for now; compiler injection from an Actions variable is deferred to preserve the compile-time artifact inclusion guard.

Thanks for this. The plumbing looks solid: the fail-closed endpoint filtering is kept, per-endpoint headers are used, there's no endpoint override, the metric resource drops per-run IDs, and the JSONL...

Implemented the metric resource allowlist, job/model dimensions, documented dimensions and delta temporality, compatibility aliases, export-failure counters, exemplars, cache tokens, turns, credit counters, cancellation handling, and custom metric bounds in 627016b. I documented runner-loss/hard-cancel as best-effort. I did not add an Actions-variable metrics switch: artifact inclusion remains compile-time gated on explicit GH_AW_OTEL_METRICS=true to preserve the artifact safety fix.

@pelikhan
pelikhan marked this pull request as ready for review November 16, 2026 21:53
Copilot AI adaptive review requested due to automatic review settings November 16, 2026 21:53
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Specification Reviewer completed successfully!

Caution

agentic threat detected
Threat detection flagged this output in warn mode. Manual review is REQUIRED before any follow-up automation.

Details

Potential security threats were detected in the agent output. Detected threat types: prompt injection.

Review the workflow run logs for details.

Generated by PR Specification Reviewer for #78433 · copilot · gpt56 · ~5 AIC · ⌖ ~2 AIC · ⊞ 1.6K · ◷

@github-actions

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer is reviewing this pull request using Matt Pocock's engineering skills...

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

PR Code Quality Reviewer

Outcome: reported_action

The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt56 · ~7 AIC · ⌖ ~1 AIC · ⊞ 1.5K · ◷

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

🧪 Test quality analysis by Test Quality Sentinel · copilot · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ⊞ 7.2K · ◷

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Generated by Ponytail Reviewer for #78433 · codex · routed: gpt61 medium · ~8 AIC · ⌖ ~1 AIC · ⊞ 185 · ◷

@pelikhan

Copy link
Copy Markdown
Collaborator Author

@copilot enabled by default with env var to turn off . Env var must support gh aw env command

gh-aw-bot and others added 3 commits November 17, 2026 01:46
…-metrics-emission

# Conflicts:
#	.github/workflows/dependabot-burner.lock.yml
#	scripts/dependabot-burner-selection.test.cjs

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:...

Merged latest main in 4a95ed6. Updated the transport tests for the boolean false result in 9131971 and made the metrics mirror fixture filesystem-independent in 64a0c72. The impacted setup JS suite passes (777/777), and build/recompile succeeded. CodeQL timed out; I did not retry it.

*/
async function sendOTLPSpan(endpoint, payload, { maxRetries = 2, baseDelayMs = 100, skipJSONL = false, headersOverride = undefined, signal = "traces" } = {}) {
const sanitizedPayload = sanitizeOTLPPayload(payload);
async function sendOTLPSpan(endpoint, payload, { maxRetries = 2, baseDelayMs = 100, skipJSONL = false, headersOverride = undefined, signal = "traces", sanitize = sanitizeOTLPPayload } = {}) {
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Preserve the updated Dependabot tool contract, align its regression assertion, and regenerate workflow locks with the merged compiler.

Validation: workflow contract tests, impacted Go and JavaScript tests, JavaScript lint, and workflow drift checks passed. The full pre-PR gate reports existing custom Go linter findings in unchanged code.

Co-authored-by: Copilot App <[email protected]>
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.

Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering.

Structured data
{
  "completed_task": 0,
  "head": "b39d6b8cb690d2e168ba26b0b555dee851643b9b",
  "kind": "requested",
  "schema_version": "1",
  "state": "71ba46bddd02408ae80cade3667ecc69ffca99c6ca9f2c797c294fec4fba488f",
  "work": [],
  "workflow": "pr-sous-chef"
}

Generated by 👨🍳 PR Sous Chef · pi · routed: haiku55 xhigh · ~2 AIC · ⌖ ~2 AIC · ⊞ 7K · ◷
Comment /souschef to run again

@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v1.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add built-in OTLP metrics emission for per-job run observability

6 participants