-
Notifications
You must be signed in to change notification settings - Fork 0
Wide event logging #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7c7b314
log2 first iteration
mishankov 823440a
Update log.go
mishankov 312f040
Implement log2 tail sampling
mishankov 645fbfb
move package-docs skill
mishankov 6fd763c
init log2 docs
mishankov 1d9f14b
expose docs on dev command
mishankov 7edc522
cleaning up
mishankov 61e01ea
next try init
mishankov c7aae03
Update logger even more
mishankov aae72ee
Delete log2.mdx
mishankov 0192a5f
demo
mishankov 8bb2962
Update astro.config.mjs
mishankov 2337771
better case from log attrs
mishankov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,4 +24,4 @@ tasks: | |
| docs: | ||
| dir: docs | ||
| cmds: | ||
| - npm run dev | ||
| - bun run dev | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "log/slog" | ||
| "os" | ||
| "time" | ||
|
|
||
| "github.com/platforma-dev/platforma/log3" | ||
| ) | ||
|
|
||
| func main() { | ||
| logger := log3.NewWideEventLogger( | ||
| os.Stdout, | ||
| log3.NewDefaultSampler(3*time.Second, 200, 0.1), | ||
| "json", | ||
| nil, | ||
| ) | ||
|
|
||
| ev := log3.NewEvent("test_event") | ||
|
|
||
| ev.AddStep(slog.LevelInfo, "some step") | ||
| ev.AddError(errors.New("some error")) | ||
| ev.AddAttrs(map[string]any{ | ||
| "attr1": 1, | ||
| "attr2": true, | ||
| }) | ||
|
|
||
| logger.WriteEvent(context.Background(), ev) | ||
| } |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Package log2 provides wide-event logging with tail sampling. | ||
| package log2 | ||
|
|
||
| import ( | ||
| "io" | ||
| "log/slog" | ||
| "os" | ||
| "time" | ||
| ) | ||
|
|
||
| const ( | ||
| defaultFormat = "json" | ||
| defaultKeepStatus = 500 | ||
| defaultMaxSteps = 100 | ||
| defaultRandomKeepRate = 0.05 | ||
| defaultSlowThreshold = 2 * time.Second | ||
| ) | ||
|
|
||
| // Config configures logger behavior. | ||
| type Config struct { | ||
| Writer io.Writer | ||
| Format string | ||
| Level slog.Level | ||
| ContextKeys map[string]any | ||
| Sampler TailSampler | ||
| MaxSteps int | ||
| } | ||
|
|
||
| // DefaultConfig returns default logger configuration. | ||
| func DefaultConfig() Config { | ||
| return Config{ | ||
| Writer: os.Stdout, | ||
| Format: defaultFormat, | ||
| Level: slog.LevelInfo, | ||
| Sampler: NewDefaultTailSampler(DefaultTailSamplerConfig{ | ||
| SlowThreshold: defaultSlowThreshold, | ||
| RandomKeepRate: defaultRandomKeepRate, | ||
| KeepStatusAtLeast: defaultKeepStatus, | ||
| }), | ||
| MaxSteps: defaultMaxSteps, | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package log2 | ||
|
|
||
| import "context" | ||
|
|
||
| type contextKey string | ||
|
|
||
| // LogEventContextKey is used to store Event in context. | ||
| const LogEventContextKey contextKey = "platformaLogEvent" | ||
|
|
||
| // EventFromContext gets an event from context. | ||
| func EventFromContext(ctx context.Context) (*Event, bool) { | ||
| if ctx == nil { | ||
| return nil, false | ||
| } | ||
|
|
||
| ev, ok := ctx.Value(LogEventContextKey).(*Event) | ||
| if !ok || ev == nil { | ||
| return nil, false | ||
| } | ||
|
|
||
| return ev, true | ||
| } | ||
|
|
||
| // WithEvent stores an event in context. | ||
| func WithEvent(ctx context.Context, ev *Event) context.Context { | ||
| if ctx == nil { | ||
| ctx = context.Background() | ||
| } | ||
|
|
||
| return context.WithValue(ctx, LogEventContextKey, ev) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: platforma-dev/platforma
Length of output: 919
🏁 Script executed:
Repository: platforma-dev/platforma
Length of output: 267
🏁 Script executed:
Repository: platforma-dev/platforma
Length of output: 1371
🏁 Script executed:
Repository: platforma-dev/platforma
Length of output: 1888
Update documentation to reflect bun as the required package manager for docs, or add a fallback.
The docs task now requires
bun run dev, butdocs/README.mdstill instructs contributors to usenpm installandnpm run dev. This mismatch will break the workflow for contributors without bun. Sincedocs/bun.lockconfirms bun is the intended package manager, updatedocs/README.mdto document bun as a requirement, or add a fallback command in the Taskfile to maintain npm compatibility.🔧 Fallback option for Taskfile
docs: dir: docs cmds: - - bun run dev + - | + if command -v bun >/dev/null 2>&1; then + bun run dev + else + npm run dev + fi📝 Committable suggestion
🤖 Prompt for AI Agents