Proposal: More flexible Logger.emit#155
Conversation
| pub const EmitOptions = struct { | ||
| /// Human-readable severity label (e.g. "WARN", "CRITICAL"). | ||
| /// Optional: backends can derive a standard label from `severity_number`. | ||
| /// Useful when bridging from a logging system that has its own level names. | ||
| severity_text: ?[]const u8 = null, | ||
|
|
||
| /// Key-value pairs attached to this log record. | ||
| attributes: ?[]const Attribute = null, | ||
|
|
||
| /// Span context to correlate this log record with an active trace. | ||
| /// Pass `span.span_context` to enable log-trace correlation in the backend. | ||
| span_context: ?trace.SpanContext = null, | ||
| }; |
There was a problem hiding this comment.
Can you please add all optional parameters dicated by the API spec of emit?
https://opentelemetry.io/docs/specs/otel/logs/api/#emit-a-logrecord
I like the dedicated struct for options, it's also wide-spread practice in Zig codebases, so we can have all fields in the struct.
There was a problem hiding this comment.
I suggest to add for now Timestamp and Observed Timestamp which are actually optional and already supported by ReadWriteLogRecord. If I recall correctly we support implicit Context and we can later on support an explicit definition.
|
By reading this PR I realized our existing implementation of |
|
Thanks @agagniere for the proposal. Actually the SDK is under heavy development and I don't see any issue to have breaking changes (@inge4pres do you agree?). I have a couple of points:
Yeah. I think because we were really focused on having a complete "flow". My real concern is the missing (optional) event name. |
inge4pres
left a comment
There was a problem hiding this comment.
LGTM, nice improvement of the API, thanks 🙏🏼
non blocking questions down here
|
I'll add another commit to pass a Not-yet written follow-up PRs:
|
Thanks, I completely slipped in this during the review, indeed we should use Context there. |
inge4pres
left a comment
There was a problem hiding this comment.
Wonderful 👏🏼 merging this one now
| timestamp: ?u64 = null, | ||
| trace_id: ?[16]u8 = null, | ||
| span_id: ?[8]u8 = null, | ||
| trace_flags: ?u8 = null, |
Superseeds #154
#154 is non-breaking but adds a new method for emitting logs, that is the same as emit but with an additional argument.
This PR proposes a more future-proof solution, with an Option struct argument with default value, allowing optional arguments for
emit.This will allow, for instance, adding source location, without adding yet another method, and without breaking existing calls.
The proposed new signature is:
mandatory severity level: Pass an explicitoptional severity0for no levelnullfor an unspecified level.info,.err, etc.{ .severity = 8 }