Repository navigation
feat(telemetry): send upload telemetry as OTLP metrics to public-api (TRUNK-23773) - #1328
Merged
trunk-io[bot] merged 3 commits intoNov 16, 2026
Merged
Conversation
…te (TRUNK-23773) The upload metrics went to trunk1's telemetry service (telemetry.<host>/v1/flakytests-cli/upload-metrics) as protobuf with the raw key on x-api-token, which only a legacy key could authenticate. They now go to sawmill-api's CLI telemetry route, /v2/cloud/telemetry/v1/logs on the API host, as one OTLP JSON log record, with the run's API key on Authorization: the gateway exchanges a v2 or a legacy key for a JWT, and the route stamps the org from it. The record carries what UploadMetrics did, under the names the route keeps for trunk-analytics-cli (trunk-io/trunk-cloud#5923): whether the upload failed and its failure category, the CLI and upload durations, the quarantine query result and resolution mode, and the repository's host, owner and name. The send keeps its 1 s timeout and stays best-effort; a run with no API key (a fork pull request, whose GitHub Actions login the gateway refuses on this path) sends nothing. The mock server serves the new path and reads the OTLP record back into UploadMetrics, so the existing telemetry tests check what is sent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
😎 Merged successfully - details. |
This was referenced Nov 13, 2026
acatxnamedvirtue
requested review from
TylerJang27,
dfrankland and
max-trunk
November 13, 2026 18:21
…773) The CLI telemetry route moved from trunk-cloud's sawmill-api into trunk2's public-api (trunk-io/trunk2#8502). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the single OTLP log record with one OTLP/HTTP JSON ExportMetricsServiceRequest to public-api's /v2/telemetry/v1/metrics: an upload count and the upload and run duration histograms, delta temporality, with trunk1's telemetry-service labels, duration buckets and boundedLabel rule. The mock server decodes the metrics back so the telemetry tests assert status, failure reason, quarantine result, repo labels and each duration's bucket. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TylerJang27
approved these changes
Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TRUNK-23773: analytics-cli's upload telemetry moves off trunk1 to trunk2's public-api, so it no longer needs the legacy org key. It's sent as OTLP metrics (decided 2026-11-16). public-api validates each data point and records its own counter and histograms, as trunk1's telemetry service did (trunk-io/trunk2#8568).
ApiClient::telemetry_upload_metricsPOSTed the protobufUploadMetricstotelemetry.<host>/v1/flakytests-cli/upload-metricson trunk1, with the raw key onx-api-token. That works only for a legacy key. trunk1 turned each event into itsupload_metricscounter and itsupload_durationandcli_run_durationhistograms.ExportMetricsServiceRequestto<api host>/v2/telemetry/v1/metrics(trunk-io/trunk2#8568), with the run's API key onAuthorization.api/src/otlp.rsbuilds three delta metrics, each with one data point per run:trunk.analytics_cli.uploads{upload}upload.status(success/failed),upload.failure_reason,quarantine.query_result,trunk.vcs.repository.owner/.nametrunk.analytics_cli.upload.durations(upload start → finished)upload.statustrunk.analytics_cli.run.durations(CLI start → upload finished)upload.status[0.05 … 600]. A histogram is skipped when a timestamp is missing or runs backwards.boundedLabel. Each value is cut to 32 characters (owner 39, name 100). It becomesinvalidif it has characters outside[A-Za-z0-9._+/-], andunknownwhen missing; a successful upload sendsfailure_reason = unknown.quarantine.resolution_modeand the repository host are dropped.other:status:successorfailed.quarantine_query_result: the six values above.failure_reason: this CLI'serror_reasonvalues (unknown,connection, the fourunknown_<endpoint>values). An HTTP status such as400_bad_requestis recorded ashttp_400.client_version: a semver of at most 32 characters.failure_reasonlist in trunk2 has to change witherror_reasonhere.The resource has
service.name,service.version,deployment.environment.name(productiononhttps://api.trunk.io, elsestaging),os.typeandhost.arch. The route rejects any other metric, type, unit, temporality or bucket bounds, so a change here needs a matching public-api change in trunk2.CONTRIBUTING.mdsays so.Deploy order
This merges to
main, which only ships as 1.x. trunk-io/trunk2#8568 (the metrics route, and the gateway lane covering it) must be in production before 1.0.0 is promoted. Otherwise every upload's telemetry is refused and lost silently.The route was first built in sawmill-api (trunk-io/trunk-cloud#5923, closed). It moved to trunk2 on 2026-11-13, as the logs route (#8502), and on 2026-11-16 the metrics route took over analytics-cli's telemetry.
#1313, #1314 and #1329 are restacked on this PR.
Test plan
/v2/telemetry/v1/metricsand decodes the request strictly. It rejects any deviation in service, metric names, units, delta temporality, the monotonic flag, counts, or a bucket array without exactly one1.cargo test -p apiand-p test_report --test telemetrypass.-p trunk-analytics-cli --test upload --test test: everything passes except the 3 Swift xunit tests, which fail the same way on unmodifiedmainon this machine.trunk fmtandtrunk checkreport no new issues.🤖 Generated with Claude Code