Module: OpenTelemetry

Extended by:
OpenTelemetry
Included in:
OpenTelemetry
Defined in:
lib/opentelemetry/error.rb,
lib/opentelemetry/trace.rb,
lib/opentelemetry/baggage.rb,
lib/opentelemetry/context.rb,
lib/opentelemetry/version.rb,
lib/opentelemetry/internal.rb,
lib/opentelemetry/trace/link.rb,
lib/opentelemetry/trace/span.rb,
lib/opentelemetry/context/key.rb,
lib/opentelemetry/trace/status.rb,
lib/opentelemetry/trace/tracer.rb,
lib/opentelemetry/baggage/entry.rb,
lib/opentelemetry/baggage/builder.rb,
lib/opentelemetry/trace/span_kind.rb,
lib/opentelemetry/trace/tracestate.rb,
lib/opentelemetry/trace/propagation.rb,
lib/opentelemetry/trace/trace_flags.rb,
lib/opentelemetry/trace/span_context.rb,
lib/opentelemetry/baggage/propagation.rb,
lib/opentelemetry/context/propagation.rb,
lib/opentelemetry/internal/proxy_tracer.rb,
lib/opentelemetry/trace/tracer_provider.rb,
lib/opentelemetry/internal/proxy_tracer_provider.rb,
lib/opentelemetry/trace/propagation/trace_context.rb,
lib/opentelemetry/baggage/propagation/context_keys.rb,
lib/opentelemetry/context/propagation/rack_env_getter.rb,
lib/opentelemetry/context/propagation/text_map_getter.rb,
lib/opentelemetry/context/propagation/text_map_setter.rb,
lib/opentelemetry/baggage/propagation/text_map_propagator.rb,
lib/opentelemetry/context/propagation/text_map_propagator.rb,
lib/opentelemetry/context/propagation/noop_text_map_propagator.rb,
lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb,
lib/opentelemetry/context/propagation/composite_text_map_propagator.rb,
lib/opentelemetry/trace/propagation/trace_context/text_map_propagator.rb,
lib/opentelemetry.rb

Overview

OpenTelemetry is an open source observability framework, providing a general-purpose API, SDK, and related tools required for the instrumentation of cloud-native software, frameworks, and libraries.

The OpenTelemetry module provides global accessors for telemetry objects.

Defined Under Namespace

Modules: Baggage, Internal, Trace Classes: Context, Error

Constant Summary collapse

VERSION =

Current OpenTelemetry version

'1.4.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#error_handlerCallable

Returns configured error handler or a default that logs the exception and message at ERROR level.

Returns:

  • (Callable)

    configured error handler or a default that logs the exception and message at ERROR level.



36
37
38
# File 'lib/opentelemetry.rb', line 36

def error_handler
  @error_handler ||= ->(exception: nil, message: nil) { logger.error("OpenTelemetry error: #{[message, exception&.message, exception&.backtrace&.first].compact.join(' - ')}") }
end

#loggerObject, Logger

Returns configured Logger or a default STDOUT Logger.

Returns:

  • (Object, Logger)

    configured Logger or a default STDOUT Logger.



30
31
32
# File 'lib/opentelemetry.rb', line 30

def logger
  @logger ||= Logger.new($stdout, level: ENV['OTEL_LOG_LEVEL'] || Logger::INFO)
end

#propagationContext::Propagation::Propagator

Returns a propagator instance.

Returns:

  • (Context::Propagation::Propagator)

    a propagator instance



69
70
71
# File 'lib/opentelemetry.rb', line 69

def propagation
  @propagation ||= Context::Propagation::NoopTextMapPropagator.new
end

Instance Method Details

#handle_error(exception: nil, message: nil) ⇒ Object

Handles an error by calling the configured error_handler.

Parameters:

  • exception (optional Exception) (defaults to: nil)

    The exception to be handled

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

    An error message.



44
45
46
# File 'lib/opentelemetry.rb', line 44

def handle_error(exception: nil, message: nil)
  error_handler.call(exception: exception, message: message)
end

#tracer_providerObject, Trace::TracerProvider

Returns registered tracer provider or a default no-op implementation of the tracer provider.

Returns:

  • (Object, Trace::TracerProvider)

    registered tracer provider or a default no-op implementation of the tracer provider.



64
65
66
# File 'lib/opentelemetry.rb', line 64

def tracer_provider
  @mutex.synchronize { @tracer_provider }
end

#tracer_provider=(provider) ⇒ Object

Register the global tracer provider.

Parameters:

  • provider (TracerProvider)

    A tracer provider to register as the global instance.



52
53
54
55
56
57
58
59
60
# File 'lib/opentelemetry.rb', line 52

def tracer_provider=(provider)
  @mutex.synchronize do
    if @tracer_provider.instance_of? Internal::ProxyTracerProvider
      logger.debug("Upgrading default proxy tracer provider to #{provider.class}")
      @tracer_provider.delegate = provider
    end
    @tracer_provider = provider
  end
end