Skip to content
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ jobs:
- name: Test command, progress and parser compatibility
run: >-
python -m pytest -q
src/regshape/tests/test_request_report_cli.py
src/regshape/tests/test_request_report.py
src/regshape/tests/test_telemetry_log_file.py
src/regshape/tests/test_version.py
Expand Down
95 changes: 91 additions & 4 deletions docs/library/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,96 @@ The Click-only `telemetry_options` decorator lives in `regshape.cli.telemetry`,
not in the library. It maps the existing six
[telemetry options](../../specs/telemetry-enhancements.md#8-updated-cli-flags)
and root `--log-file` value into a library session. Option names, defaults,
output formats and exit codes are unchanged. The adapter uses
output formats and existing operation exit codes are unchanged. The adapter uses
`restore_config=False` so existing outer result/warning scopes retain access
to the command configuration after the owned log closes.

## Request-report foundation
### Automatic command-line request reports

Supported leaves automatically print a plain-text **Pull request report** or
**Push request report** on stderr: `artifact pull`, `config get`, `layer get`,
`blob get`, `manifest get`, `manifest put`, `layout push`, `docker push`,
`blob upload`, and `blob mount`. This is an intentional change from quiet
diagnostics by default, including noninteractive invocations.

- `--telemetry-verbosity 0` (or `-tv 0`) suppresses collection and output without
acquiring report storage.
- `--telemetry-format json` emits one consolidated, schema-versioned
`request_report` event per library invocation instead of text. It does not
change command-result JSON or raw payloads on stdout.
- `--no-progress`, result `--json`, and nonterminal stderr suppress animation,
**not** reporting. Local-only `layout push --dry-run` reports zero actual
requests without constructing a registry client. Layout push reports include
the library-sanitized supplied source path, matching the library entry point.
- Root `--log-file PATH` appends the report in the selected format. Existing
telemetry closes its log before result/warning delivery; the report adapter
then opens the same path in append mode for report delivery and closes only
that owned handle. A failed telemetry log is not reopened.
Manifest and blob transfers reject logs that alias download outputs or upload
source files (including hard links and symlinks) before opening either file.
Layout pushes (including dry runs) require logs outside the source directory;
existing outside log files must have exactly one hard link. Ambiguous
multiply-linked logs fail closed rather than scanning the entire source graph.
Archive sources use the same file-alias guard as other uploads.
- `--time-methods`, `--time-scenarios`, `--debug-calls`, and `--metrics` remain
independently opt-in. All six common telemetry controls are also available
on `docker push`.

Storage is acquired lazily at the first explicit library operation scope, so
preflight-only failures retain their command errors without allocating a
collector. The SDK's `request_report_factory` supports the same caller-owned
lazy acquisition; an explicit `request_report_collector` takes precedence.
First acquisition is serialized per configuration, including copied worker
contexts; factory callbacks must not recursively establish reporting scopes.
Secure report storage currently requires native Linux/macOS filesystem
primitives. Other platforms fail explicitly instead of producing an unverified
report; use `-tv 0` for commands otherwise supported there. This does not bypass
separate native-filesystem requirements of artifact and layout operations.

The SDK records session flush/owned-log close failures in
`TelemetryConfig.cleanup_failed`, including secondary failures suppressed by a
primary operation error. A successful session entry resets that status. The
command adapter uses it to avoid reopening failed logs. Collection errors first
discovered during export also make an otherwise successful command exit nonzero;
spool-read failures do not mark healthy diagnostic sinks as failed.
Nested warning/report coordinators share failed-destination state, including
distinct standard-output/error descriptors that alias the same pipe. The report
coordinator also tracks result writes/flushes for commands without a warning
coordinator. Aliased proxies share failure state immediately, so even scenario
telemetry emitted before the outer command exits cannot retry a failed destination.
Progress cleanup likewise cannot repaint a final failed row on a known failed
terminal; its original exception and resource cleanup are preserved without
further destination writes or flushes.

Reports follow settled library operations, progress and telemetry finalization,
then command results/errors and deferred download warnings. Authentication,
ordered assets, descriptor occurrences, repeated attempts and redirect hops come
from the library model. Full method names and known digests are retained; terminal
controls are escaped. Durations use seconds with microsecond precision;
unavailable facts say `Unknown`, not zero. Remote activity and whole-operation
elapsed time have different boundaries; cumulative chain times are not sums
of overlapping intervals.

A sole collection, export or report-cleanup failure exits nonzero, even after a
successful operation. Published downloads and acknowledged pushes are **not
rolled back**: check the operation result and verify uncertain publication before
retrying. A primary operation error or cancellation retains precedence.
An otherwise successful command whose final stdout flush fails also exits
nonzero, with a result-output diagnostic rather than a report-export diagnostic;
available reports still reach healthy stderr and enabled logs.
Failed stdout buffers are guarded against a second flush during process shutdown.
Result tracking preserves Click's encoding adaptation and binary output, including
Unicode results on ASCII process streams; adapted buffer failures share the same
no-retry state. Borrowed text streams and binary buffers are never closed.
Broken report destinations are not retried. Reports contain sanitized diagnostic
metadata, not payloads, headers or raw exception messages; log retention remains
the caller's responsibility.

This command integration does not close the parent capability's remaining
[integrated validation and default-on readiness gates](../../specs/request-reporting.md#10-performance-and-scale)
or imply release availability.

## Library request reports

`TelemetryConfig.request_report_collector` defaults to `None`. The opt-in
`RequestReportCollector` owns sanitized metadata storage, not clients or output
Expand All @@ -93,8 +178,10 @@ ordinary, legacy and pooled adapter dispatches, including token GET/POST calls,
authentication probes, retries and every automatic redirect hop. With the collector
configured, `pull_artifact`, `download_config`, `download_layer`, `get_blob`,
`get_blobs`, `get_manifest` and `download_manifest` establish operation scopes
automatically. Command-line activation and push attribution remain separate
delivery items in [the approved design](../../specs/request-reporting.md).
automatically. Push entry points also establish scopes: `push_manifest`,
`push_layout`, `execute_layout_push`, `push_image`, blob upload facades and blob
mount facades. Direct Python reporting remains opt-in and never prints by itself.
See [the approved design](../../specs/request-reporting.md).

```python
import sys
Expand Down
2 changes: 2 additions & 0 deletions src/regshape/cli/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from regshape.cli.options import artifact_option
from regshape.cli.progress import ProgressDisplay
from regshape.cli.telemetry import telemetry_options
from regshape.cli.request_report import request_reporting
from regshape.libs.artifacts import (
ArtifactFormat,
ArtifactLimits,
Expand Down Expand Up @@ -176,6 +177,7 @@ def artifact() -> None:


@artifact.command("pull")
@request_reporting
@_after_telemetry
@telemetry_options
@artifact_option(help_text="Complete artifact source (registry/repo:tag or registry/repo@sha256:...).")
Expand Down
8 changes: 7 additions & 1 deletion src/regshape/cli/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
import click
import requests

from regshape.cli.downloads import DownloadWarnings, download_options, download_policy
from regshape.cli.downloads import DownloadWarnings, download_options, download_policy, separate_file_log
from regshape.cli.formatting import emit_error, emit_json, reference_error_context
from regshape.cli.progress import ProgressDisplay
from regshape.cli.telemetry import telemetry_options
from regshape.cli.request_report import request_reporting
from regshape.libs.blobs import (
delete_blob,
get_blob,
Expand Down Expand Up @@ -116,6 +117,8 @@ def wrapper(*args: Any, **kwargs: Any) -> None:


@blob.command("get")
@request_reporting
@separate_file_log("output")
@_after_blob_telemetry
@telemetry_options
@click.option("--no-progress", is_flag=True, default=False, help="Disable interactive transfer progress.")
Expand Down Expand Up @@ -277,6 +280,8 @@ def blob_delete(ctx, repo, digest):


@blob.command("upload")
@request_reporting
@separate_file_log("source_file", source=True)
@telemetry_options
@click.option("--no-progress", is_flag=True, default=False, help="Disable interactive transfer progress.")
@click.option(
Expand Down Expand Up @@ -370,6 +375,7 @@ def blob_upload(ctx, repo, source_file, digest, media_type, chunked, chunk_size,


@blob.command("mount")
@request_reporting
@telemetry_options
@click.option(
"--repo",
Expand Down
2 changes: 2 additions & 0 deletions src/regshape/cli/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from regshape.cli.options import artifact_option
from regshape.cli.progress import ProgressDisplay
from regshape.cli.telemetry import telemetry_options
from regshape.cli.request_report import request_reporting
from regshape.libs.artifacts import ArtifactLimits
from regshape.libs.blobs import DownloadOptions, DownloadStatus
from regshape.libs.components import (
Expand Down Expand Up @@ -236,6 +237,7 @@ def _operation(
def _get_command(component: Component) -> click.Command:
"""Declare identical resource policy/lifetimes; only layer has a required zero-based index."""
@click.command("get", help=_HELP)
@request_reporting
@partial(_after_telemetry, component=component)
@telemetry_options
@artifact_option(
Expand Down
6 changes: 6 additions & 0 deletions src/regshape/cli/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

from regshape.cli.formatting import emit_error, emit_json, format_size, short_digest
from regshape.cli.progress import ProgressDisplay
from regshape.cli.request_report import request_reporting
from regshape.cli.telemetry import telemetry_options
from regshape.libs.docker import export_image, list_images, push_image
from regshape.libs.errors import (
ArtifactError,
Expand Down Expand Up @@ -153,6 +155,8 @@ def export_cmd(ctx, image, output, platform, as_json):


@docker.command("push")
@request_reporting
@telemetry_options
@click.option("--no-progress", is_flag=True, default=False, help="Disable interactive transfer progress.")
@click.option(
"--image", "-i",
Expand Down Expand Up @@ -200,6 +204,8 @@ def push_cmd(ctx, image, dest, platform, force, chunked, chunk_size, as_json, no
changing export, upload protocols or the result schema. Invalid destinations
and strict local snapshot/native-platform failures produce an error, not success.
Summary counts come directly from the same PushResult fields as layout push.
Common telemetry controls select the automatic stderr request report without
adding fields to result JSON or enabling debug/timing/metrics diagnostics.
"""
insecure = ctx.obj.get("insecure", False) if ctx.obj else False

Expand Down
Loading
Loading