Class: OpenTelemetry::SDK::Logs::Logger

Inherits:
Logs::Logger
  • Object
show all
Defined in:
lib/opentelemetry/sdk/logs/logger.rb

Overview

The SDK implementation of OpenTelemetry::Logs::Logger

Instance Method Summary collapse

Constructor Details

#initialize(name, version, logger_provider) ⇒ OpenTelemetry::SDK::Logs::Logger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new OpenTelemetry::SDK::Logs::Logger instance. This should not be called directly. New loggers should be created using OpenTelemetry::SDK::Logs::LoggerProvider#logger.

Parameters:



24
25
26
27
# File 'lib/opentelemetry/sdk/logs/logger.rb', line 24

def initialize(name, version, logger_provider)
  @instrumentation_scope = InstrumentationScope.new(name, version)
  @logger_provider = logger_provider
end

Instance Method Details

#on_emit(timestamp: nil, observed_timestamp: Time.now, severity_text: nil, severity_number: nil, body: nil, attributes: nil, trace_id: nil, span_id: nil, trace_flags: nil, context: OpenTelemetry::Context.current) ⇒ Object

Emit a OpenTelemetry::SDK::Logs::LogRecord to the processing pipeline.

Parameters:

  • timestamp (optional Time) (defaults to: nil)

    Time when the event occurred.

  • observed_timestamp (optional Time) (defaults to: Time.now)

    Time when the event was observed by the collection system.

  • span_context (optional OpenTelemetry::Trace::SpanContext)

    The OpenTelemetry::Trace::SpanContext to associate with the OpenTelemetry::SDK::Logs::LogRecord.

  • severity_text (optional String) (defaults to: nil)

    Original string representation of the severity as it is known at the source. Also known as log level.

  • severity_number (optional Integer) (defaults to: nil)

    Numerical value of the severity. Smaller numerical values correspond to less severe events (such as debug events), larger numerical values correspond to more severe events (such as errors and critical events).

  • body (optional String, Numeric, Boolean, Array<String, Numeric, Boolean>, Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}) (defaults to: nil)

    A value containing the body of the log record.

  • attributes (optional Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}) (defaults to: nil)

    Additional information about the event.

  • trace_id (optional String (16-byte binary)) (defaults to: nil)

    Request trace id as defined in W3C Trace Context. Can be set for logs that are part of request processing and have an assigned trace id.

  • span_id (optional String (8-byte binary)) (defaults to: nil)

    Span id. Can be set for logs that are part of a particular processing span. If span_id is present trace_id should also be present.

  • trace_flags (optional Integer (8-bit byte of bit flags)) (defaults to: nil)

    Trace flag as defined in W3C Trace Context specification. At the time of writing the specification defines one flag - the SAMPLED flag.

  • context (optional OpenTelemetry::Context) (defaults to: OpenTelemetry::Context.current)

    The OpenTelemetry::Context to associate with the OpenTelemetry::SDK::Logs::LogRecord.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/opentelemetry/sdk/logs/logger.rb', line 64

def on_emit(timestamp: nil,
            observed_timestamp: Time.now,
            severity_text: nil,
            severity_number: nil,
            body: nil,
            attributes: nil,
            trace_id: nil,
            span_id: nil,
            trace_flags: nil,
            context: OpenTelemetry::Context.current)
  current_span = OpenTelemetry::Trace.current_span(context)
  span_context = current_span.context unless current_span == OpenTelemetry::Trace::Span::INVALID

  @logger_provider.on_emit(timestamp: timestamp,
                           observed_timestamp: observed_timestamp,
                           severity_text: severity_text,
                           severity_number: severity_number,
                           body: body,
                           attributes: attributes,
                           trace_id: trace_id || span_context&.trace_id,
                           span_id: span_id || span_context&.span_id,
                           trace_flags: trace_flags || span_context&.trace_flags,
                           instrumentation_scope: @instrumentation_scope,
                           context: context)
end