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: Update Logger#on_emit to create LogRecords #1611

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

kaylareopelle
Copy link
Contributor

This PR creates a LogRecord class that is read/writeable to start with, and becomes read-only when it transitions to LogRecordData.

Additionally, it provides the SDK implementation of the Logs Bridge API Logger#on_emit method to emit LogRecords to the processing pipeline.

Relates to the following specs:

Resolves: #1484

Copy link
Contributor

github-actions bot commented May 5, 2024

👋 This pull request has been marked as stale because it has been open with no activity. You can: comment on the issue or remove the stale label to hold stale off for a while, add the keep label to hold stale off permanently, or do nothing. If you do nothing this pull request will be closed eventually by the stale bot

@github-actions github-actions bot added the stale label May 5, 2024
Previously, trace_id, span_id, and trace_flags were assigned based on
the OpenTelemetry::Trace.current_span's SpanContext. The specification
requires a context be accepted as an argument on emit.

If no context is provided, OpenTelemetry::Context.current will be used.

If there isn't a current span on OpenTelemetry::Context.current
trace_id, span_id, and trace_flags will be nil unless they are passed
as arguments.

Also, remaining #emit methods are renamed to #on_emit.
#
# @api public
def emit(
def on_emit(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we renamed the method in #1517, I forgot to go back and change the references in the API.

This code was leftover and should have been removed.
Now, the specfic `trace_id`, `span_id`, and `trace_flags`
attributes are used instead.
@span_id = span_id
@trace_flags = trace_flags
@resource = logger&.resource
@instrumentation_scope = logger&.instrumentation_scope
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible for a log record to get created from an api logger? Otherwise I would expect instrumentation scope to always be present (do we need the safe operator here?).

@trace_id = trace_id
@span_id = span_id
@trace_flags = trace_flags
@resource = logger&.resource
Copy link
Contributor

Choose a reason for hiding this comment

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

I know there's a method added to the sdk logger here to support this but it still reads like logger.logger_provider.resource to me.

I wonder if there's any merit in following the same pattern we did with the tracer https://github.com/open-telemetry/opentelemetry-ruby/blob/main/sdk/lib/opentelemetry/sdk/trace/tracer.rb#L35

:resource, # optional OpenTelemetry::SDK::Resources::Resource
:instrumentation_scope, # OpenTelemetry::SDK::InstrumentationScope
:total_recorded_attributes) do # Integer
def unix_nano_timestamp
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: is that possible to do alias_method :unix_nano_observed_timestamp, :unix_nano_timestamp?

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.

Logs SDK - LogRecord
3 participants