Report a startup event to trace, off the main thread and with an opt-out - #218
Merged
Conversation
…n opt-out The trace client (trace-client-java 0.1.0, MIT) is vendored as one file under preponderous.viron.trace, unmodified apart from the package line, together with its test. A UsageReporter component sends a single "startup" event once the context is ready (ApplicationReadyEvent), tagged with the project version (filled in from the Maven version at build time, the jar's Implementation-Version as a fallback) and service=true, and closes the client on context shutdown. Nothing is sent per request, and nothing about users, hosts, addresses or data. The client returns immediately, never throws, and queues at most 256 reports, so an unreachable trace server is a dropped report rather than a slow start-up. Reporting is configured through usage-reporting.* properties with environment overrides; USAGE_REPORTING_ENABLED=false turns it off. A blank key or a malformed endpoint yields a disabled client rather than a failed start-up. Tests keep reporting off (src/test/resources/application.properties) so no context start-up contacts the real service; one Spring test points it at a loopback stub and checks the event that arrives. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WYoD9SsaRz8PjakTSHhmn6
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
Usage reporting via the trace service is added to Viron. On start-up, once the Spring context is ready (
ApplicationReadyEvent), onestartupevent is sent; the client is closed when the context shuts down. The change is entirely additive: no existing class, property or behaviour is altered.TraceClient.java(trace-client-java 0.1.0, MIT) is vendored as a single file underpreponderous.viron.trace, unmodified apart from the package line, together with its test. No dependency is added.UsageReporter(@Component) builds the client fromusage-reporting.*properties, sends the event, and closes the client in@PreDestroy.usage-reporting.version=@project.version@, resource-filtered by the Spring Boot parent), with the jar'sImplementation-Versionas the fallback.Guarantees
The client returns immediately (the HTTP call runs on a single daemon thread), never throws (a server that is down, slow or rejecting the key is a dropped report logged at debug level), and is bounded (at most 256 reports are queued; beyond that new ones are dropped). A blank key or a malformed endpoint yields a disabled client rather than a failed start-up, so the report can never be the reason the service does not come up or a request waits.
What is sent, and what is not
Sent, once per start-up:
application: "viron",name: "startup", tagsversion(the project version) andservice: "true"(so hosted services can be hidden from the fleet view on the operator page). Nothing is sent per request, and no usernames, hostnames, IPs, paths, or any data the service holds are ever included.Opt-out
Configured in
application.propertieswith environment overrides, following the file's existing${VAR:default}convention:usage-reporting.enabledUSAGE_REPORTING_ENABLEDtrueusage-reporting.endpointUSAGE_REPORTING_ENDPOINThttps://trace.danielstephenson.devusage-reporting.keyUSAGE_REPORTING_KEYUSAGE_REPORTING_ENABLED=falseturns it off. The README,sample.envandcompose.ymlare updated to say so. No first-run notice is needed since the service is operator-hosted; an INFO line at start-up states whether reporting is on and how to turn it off.Test plan
./mvnw test -Bon JDK 21 (the CI toolchain): 454 → 472 tests, 0 failures (18 added: 10 vendored client tests, 7UsageReporterTestunit tests, 1UsageReporterStartupEventTest).src/test/resources/application.propertiessetsusage-reporting.enabled=false, so no context start-up in the suite contacts the real service; the one Spring test that turns it on points the endpoint at a loopback JDKHttpServervia@DynamicPropertySourceand asserts on the event that arrives.unzip -l:BOOT-INF/classes/preponderous/viron/trace/TraceClient.classandUsageReporter.classare present, and the packagedapplication.propertiescarriesusage-reporting.version=0.7.0-SNAPSHOT-8-8-2026.java -jar target/viron-0.7.0-SNAPSHOT-8-8-2026.jar --server.port=0withUSAGE_REPORTING_ENDPOINT=http://127.0.0.1:47311) against a 10-line Pythonhttp.serverhandler. Exactly one request arrived,POST /api/metrics,Authorization: Bearer <the bundled key>, body:{"application":"viron","name":"startup","tags":{"service":"true","version":"0.7.0-SNAPSHOT-8-8-2026"}}USAGE_REPORTING_ENABLED=falseloggedUsage reporting is off.and the stub received nothing.🤖 Generated with Claude Code
https://claude.ai/code/session_01WYoD9SsaRz8PjakTSHhmn6
drafted by Claude on behalf of Daniel Stephenson