strc: add ability to override time in Span.Event and Span.End#51
Merged
lzap merged 4 commits intoosbuild:mainfrom Oct 1, 2025
Merged
strc: add ability to override time in Span.Event and Span.End#51lzap merged 4 commits intoosbuild:mainfrom
lzap merged 4 commits intoosbuild:mainfrom
Conversation
Linter was not configured previously, this commit adds .golangci.yml file and fixes all the issues reported by it.
The retry test was flaky due to improper synchronization. The return statement was missing and it could not be done in sync.Once effectively. Replaced with atomic counter which is more straightforward.
Previously, the send frequency was hardcoded, which made tests slower. Now, it can be set via a parameter, allowing tests to run faster.
Span start, event and end time is automatically taken via `time.Now()`
call but there are some use cases when this needs to be overridden to a
specific time. Use special attributes to do that:
span := strc.Start(ctx, "span name", "started", time.Now())
span.Event("an event", "at", time.Now())
span.End("finished", time.Now())
Also adds TraceID() method to Span to return the trace ID. This will be
usefil in images/ library to collect logs from JSONSeq osbuild monitor and
keep them in a LRU cache.
schuellerf
approved these changes
Sep 29, 2025
Contributor
schuellerf
left a comment
There was a problem hiding this comment.
Thanks!
If there are more "custom attributes", it would be cool to collect them in consts and/or a list in the documentation, like an index, to find faster what's possible.
For now, it's great that there is documentation 🥳
croissanne
reviewed
Oct 1, 2025
Member
croissanne
left a comment
There was a problem hiding this comment.
LGTM, but I think an example of the use case can't hurt. Either in the README or the commit message.
Collaborator
Author
|
Thank you very much! |
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.
strc: add ability to override time in Span.Event and Span.End
Span start, event and end time is automatically taken via
time.Now()call but there are some use cases when this needs to be overridden to a
specific time. Use special attributes to do that:
Also adds TraceID() method to Span to return the trace ID. This will be
usefil in images/ library to collect logs from JSONSeq osbuild monitor and
keep them in a LRU cache.
This small feature is needed for composer worker reading events from JSON Monitor coming out of
osbuildso events can be emitted via thestrcAPI with correct timing information. @croissanne @schuellerf thanks for review!While working on it linter complained a lot so I added configuration, fixed many linter issues mostly related to closing and then this revealed one flaky test which I also fixed.