-
Notifications
You must be signed in to change notification settings - Fork 276
feat(observability): structured JSON logs and event fields #66
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package observability | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "log" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe this is time to pick a logging pkg, e.g. https://betterstack.com/community/guides/logging/best-golang-logging-libraries/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer zap, but I'll create an issue to see what others think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this one #76 |
||
| "time" | ||
| ) | ||
|
|
||
| // LogEvent emits a structured JSON log line with a standard envelope | ||
| // Fields provided by callers take precedence and will not be overwritten. | ||
| func LogEvent(event string, fields map[string]interface{}) { | ||
| if fields == nil { | ||
| fields = map[string]interface{}{} | ||
| } | ||
| if _, ok := fields["event"]; !ok { | ||
| fields["event"] = event | ||
| } | ||
| if _, ok := fields["ts"]; !ok { | ||
| fields["ts"] = time.Now().UTC().Format(time.RFC3339Nano) | ||
| } | ||
| b, err := json.Marshal(fields) | ||
| if err != nil { | ||
| // Fallback to regular log on marshal error | ||
| log.Printf("event=%s marshal_error=%v fields_len=%d", event, err, len(fields)) | ||
| return | ||
| } | ||
| log.Println(string(b)) | ||
| } | ||
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.
should USD be a specific naming suffix for this metric?
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.
if we want to support more units a dimension in metric should be easier to extend.
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.
Your suggestion is good.
Maybe I can change the metric name to
llm_model_cost_totaland add acurrencylabel. e.g.llm_model_cost_total{currency="USD"}But a trade-off needs to be made here.
Pros:
Cons:
WDYT? @Xunzhuo @rootfs
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.
For the cons, maybe we should have clear docs around metrics, it is a bit bad to add more metrics when units increase linearly
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.
adding a currency label is a good idea!
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
I created an issue for tracking.
#75