Skip to content
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

feat: Create additional log record interfaces for SDK #3

Closed
wants to merge 6 commits into from

Conversation

kaylareopelle
Copy link
Owner

@kaylareopelle kaylareopelle commented Aug 21, 2023

Implements the ReadableLogRecord and ReadWriteLogRecord as described in the Logs SDK specs and the Logs Data Model.

It also adds a SeverityNumber class to the API. I noticed many other implementations of the logs signal have this and there is reference to this class in the documentation for the additional log record interfaces. The numbers correspond to the references in the Logs Data Model. I'm happy to break this out into a separate PR there's a preference to keep all work on the SDK and API separate.

@kaylareopelle kaylareopelle changed the title Logs SDK - Additional Log Record Interfaces feat: Create additional log record interfaces for SDK Aug 21, 2023
severity_number: nil,
body: nil,
attributes: nil,
logger: nil
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm tempted to follow JS here and pass in the logger to get those attributes, but I'm open to other ideas.

module OpenTelemetry
module SDK
module Logs
# A {LogRecord} interface that can write to the full {LogRecord} and
Copy link
Owner Author

@kaylareopelle kaylareopelle Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix these LogRecord references to link to the API. This may need to wait until the API is published on rubygems/rdoc

Comment on lines +64 to +65
@resource = logger&.resource
@instrumentation_scope = logger&.instrumentation_scope
Copy link
Owner Author

@kaylareopelle kaylareopelle Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the Logs Data Model, every attribute on a log record is optional, with the exception of observed_timestamp. This makes a logger not required, since resource and instrumentation_scope do not need to be present.

Though one could argue instrumentation_scope is required since the "optional" references in the data model field description are for the name and version attributes on the instrumentation scope.

If we come to the conclusion that instrumentation_scope is required, we should probably make logger required and remove the safe navigation operators.

Comment on lines +25 to +26
# @param [optional Float, Time] timestamp Time when the event occurred.
# @param [optional Float, Time] observed_timestamp Time when the event
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Float - The Process.clock_gettime return value's class
Time - The documented param class for timestamp on a Span is the Time class

Is there a preference for the type of object passed here? My guess would be Float/Process.clock_gettime as it seems that many gems replaced their calls to Time.now with Process.clock_gettime in 2021's 1.0 release.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Remember -- Any changes to ReadWriteLogRecord should be made to ReadableLogRecord too!

logger: nil
)
@timestamp = timestamp
@observed_timestamp = observed_timestamp || timestamp || Process.clock_gettime(Process::CLOCK_REALTIME)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one feels a bit tricky...

Observed Timestamp. If unspecified the implementation SHOULD set it equal to the current time.
source

Logs Data Model observed timestamp description for comparison

This leads me to think the order of assignment would be as described above. I could also see a scenario where observed_timestamp is not available as an argument on initialize and can only be created from timestamp or Process.clock_gettime. Thoughts?

)
@timestamp = timestamp
@observed_timestamp = observed_timestamp || timestamp || Process.clock_gettime(Process::CLOCK_REALTIME)
@span_context = span_context
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Logs Data Model liststrace_id, span_id, and trace_flags as separate attributes. These attributes are all present in an OpenTelemetry::SDK::Trace::SpanContext object.

The Logs SDK spec says:

The trace context fields MUST be populated from the resolved Context (either the explicitly passed Context or the current Context) when emitted."

Each language treats this a little differently:

What makes the most sense for Ruby? I'm leaning toward SpanContext and adding the current span context as the default. Is there a way to get the current span context? I've found a way to get the current Context via Context.current, but Context doesn't seem quite right since it doesn't necessarily have trace_id, span_id, and trace_flags as far as I can tell.

@kaylareopelle kaylareopelle marked this pull request as ready for review August 22, 2023 23:29
@kaylareopelle kaylareopelle marked this pull request as draft August 22, 2023 23:32
@kaylareopelle
Copy link
Owner Author

Next steps:

  • Remove Readable log record
  • Add note about following span and freezing the log record on the processor before sending it to the exporter
  • Rename ReadWrite to Log record and move the ReadWrite stuff over to Log Record

@kaylareopelle kaylareopelle changed the base branch from logger-provider-sdk to sdk-logger-provider August 25, 2023 22:54
@kaylareopelle kaylareopelle changed the base branch from sdk-logger-provider to logger-provider-sdk August 25, 2023 22:55
@kaylareopelle
Copy link
Owner Author

Ultimately went in a different direction for this work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant