module OpenTelemetry

Overview


## Global Trace Provider
----------------------------------------------------------------

OpenTelemetry.configure do |config|
  config.service_name = "my_app_or_library"
  config.service_version = "1.1.1"
  config.exporter = OpenTelemetry::Exporter.new(variant: :stdout)
end

trace = OpenTelemetry.trace_provider("my_app_or_library", "1.1.1").trace
trace = OpenTelemetry.trace_provider do |provider|
  provider.service_name = "my_app_or_library"
  provider.service_version = "1.1.1"
end.trace

## Trace Providers as Objects With Unique Configuration
----------------------------------------------------------------

provider_a = OpenTelemetry::TraceProvider.new("my_app_or_library", "1.1.1")
provider_a.exporter = OpenTelemetry::Exporter.new(variant: :stdout)

provider_b = OpenTelementry::TraceProvider.new do |config|
  config.service_name = "my_app_or_library"
  config.service_version = "1.1.1"
  config.exporter = OpenTelemetry::Exporter.new(variant: :stdout)
end

## Getting a Trace From a Provider Object
----------------------------------------------------------------

trace = provider_a.trace # Inherit all configuration from the Provider Object

trace = provider_a.trace("microservice foo", "1.2.3") # Override the configuration

trace = provider_a.trace do |provider|
  provider.service_name = "microservice foo"
  provider.service_version = "1.2.3"
end.trace

## Creating Spans Using a Trace
----------------------------------------------------------------

trace.in_span("request") do |span|
  span.set_attribute("verb", "GET")
  span.set_attribute("url", "http://example.com/foo")
  span.add_event("dispatching to handler")
  trace.in_span("handler") do |child_span|
    child_span.add_event("handling request")
    trace.in_span("db") do |child_span|
      child_span.add_event("querying database")
    end
  end
end

Defined in:

lib/opentelemetry-api/src/anyattribute.cr
lib/opentelemetry-api/src/anyvalue.cr
lib/opentelemetry-api/src/api/abstract_context.cr
lib/opentelemetry-api/src/api/abstract_event.cr
lib/opentelemetry-api/src/api/abstract_id_generator.cr
lib/opentelemetry-api/src/api/abstract_resource.cr
lib/opentelemetry-api/src/api/abstract_span.cr
lib/opentelemetry-api/src/api/abstract_span_context.cr
lib/opentelemetry-api/src/api/abstract_status.cr
lib/opentelemetry-api/src/api/id_generator/abstract_base.cr
lib/opentelemetry-api/src/api/sendable.cr
lib/opentelemetry-api/src/api/span/abstract_kind.cr
lib/opentelemetry-api/src/api/span_context/abstract_config.cr
lib/opentelemetry-api/src/api/trace_flags.cr
lib/opentelemetry-api/src/attribute.cr
aliases.cr
clock.cr
context.cr
context/key.cr
event.cr
exporter.cr
exporters/abstract.cr
exporters/base.cr
exporters/buffered_base.cr
exporters/buffered_exporter.cr
exporters/http.cr
exporters/io.cr
exporters/null.cr
exporters/stdout.cr
exporters/unbuffered_exporter.cr
id_generator.cr
id_generator/random.cr
id_generator/unique.cr
instrument.cr:1
instrument.cr:53
instrument/counter.cr
instrumentation.cr
log.cr
log_collection.cr
log_provider.cr
message.cr
meter.cr
meter/exceptions.cr
meter_provider.cr
name.cr
opentelemetry-sdk.cr
propagation/text_map_getter.cr
propagation/text_map_setter.cr
propagation/trace_context.cr
propagation/trace_context/trace_parent.cr
proto/common.pb.cr
proto/logs.pb.cr
proto/logs_service.pb.cr
proto/metrics.pb.cr
proto/metrics_config_service.pb.cr
proto/metrics_service.pb.cr
proto/resource.pb.cr
proto/trace.pb.cr
proto/trace_config.pb.cr
proto/trace_service.pb.cr
provider.cr
provider/configuration.cr
provider/configuration/factory.cr
resource.cr
sampler.cr
sampler/sampling_result.cr
samplers/always_off.cr
samplers/always_on.cr
samplers/always_record.cr
samplers/parent_based.cr
samplers/trace_id_ratio_based.cr
sendable.cr
span.cr
span/kind.cr
span_context.cr
span_context/config.cr
status.cr
trace.cr
trace/exceptions.cr
trace_flags.cr
trace_provider.cr
version.cr

Constant Summary

INSTANCE_ID = CSUUID.unique.to_s
NAME = "OpenTelemetry Crystal"
VERSION = SDK::VERSION

Class Method Summary

Macro Summary

Class Method Detail

def self.clock : Clock #

.clock class property allows alternative implementations for testing or simulations


[View source]
def self.clock=(clock : Clock) #

.clock class property allows alternative implementations for testing or simulations


[View source]
def self.config : TraceProvider::Configuration #

The .config class property provides direct access to the global default TracerProvider configuration.


[View source]
def self.config=(config : TraceProvider::Configuration) #

The .config class property provides direct access to the global default TracerProvider configuration.


[View source]
def self.configure(&block : TraceProvider::Configuration::Factory -> ) #

Use this method to configure the global trace provider. The provided block will receive a OpenTelemetry::Provider::Configuration::Factory instance, which will be used to generate a OpenTelemetry::Provider::Configuration struct instance.


[View source]
def self.configure #

Calling .configure with no block results in a global TracerProvider being configured with the default configuration. This is useful in cases where it is known that environment variable configuration is going to be used exclusively.

# Depend on SDK environment variables ([https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md))
# for all configuration.
OpenTelememtry.configure

[View source]
def self.current_span #

Returns the current active Span in the current fiber, or nil if there is no currently active Span.


[View source]
def self.handle_error(error) #

[View source]
def self.instrumentation_library #

[View source]
def self.instrumentation_scope #

[View source]
def self.provider : TraceProvider #

.provider class property provides direct access to the global default Tracerprovider instance.


[View source]
def self.provider=(provider : TraceProvider) #

.provider class property provides direct access to the global default Tracerprovider instance.


[View source]
def self.trace #

Returns the currently active Tracer in the current fiber. If there is no currently active Tracer, then a new Tracer will be created and returned. Once a new Tracer has been created, it will remain active until at least one Span has been opened in it, and then subsequently closed.


[View source]
def self.trace(&) #

Invokes the provided block with either the currently active Tracer, if one exists, or a new Tracer, if there isn't one currently active. The block version of opening a new Tracer ensures that only the code that executes between when the block starts executing, and when it finishes executing, will be included in the finished trace.


[View source]
def self.trace_provider(service_name : String | Nil = nil, service_version : String | Nil = nil, exporter = nil) #

Configure and return a new TracerProvider instance, using the method arguments. The configured TracerProvider will have the configuration from the global instance merged with it, which means that given no additional configuration, the newly provided TracerProvider will have the same configuration as the global TracerProvider


[View source]
def self.trace_provider(&block : TraceProvider::Configuration::Factory -> ) #

Configure and return a new TracerProvider instance, using the provided block. The configured TracerProvider will have the configuration from the global instance merged with it, which means that given no additional configuration, the newly provided TracerProvider will have the same configuration as the global TracerProvider


[View source]
def self.tracer #

Alias. The spec uses TracerProviders, which manage Tracers, but which have internal methods and entities like trace_id and TraceState and TraceFlags. Then this library was initially written, I opted for uniformly consistent naming, but that violates the spec. Future versions will move towards deprecating the uniform naming, in places where that naming violates the spec. This is here to start preparing for that transition.


[View source]
def self.tracer(&) #

Alias. The spec uses TracerProviders, which manage Tracers, but which have internal methods and entities like trace_id and TraceState and TraceFlags. Then this library was initially written, I opted for uniformly consistent naming, but that violates the spec. Future versions will move towards deprecating the uniform naming, in places where that naming violates the spec. This is here to start preparing for that transition.


[View source]
def self.tracer_provider(service_name : String | Nil = nil, service_version : String | Nil = nil, exporter = nil) #

Alias. The spec uses TracerProviders, which manage Tracers, but which have internal methods and entities like trace_id and TraceState and TraceFlags. Then this library was initially written, I opted for uniformly consistent naming, but that violates the spec. Future versions will move towards deprecating the uniform naming, in places where that naming violates the spec. This is here to start preparing for that transition.


[View source]
def self.tracer_provider(&block : TraceProvider::Configuration::Factory -> ) #

Alias. The spec uses TracerProviders, which manage Tracers, but which have internal methods and entities like trace_id and TraceState and TraceFlags. Then this library was initially written, I opted for uniformly consistent naming, but that violates the spec. Future versions will move towards deprecating the uniform naming, in places where that naming violates the spec. This is here to start preparing for that transition.


[View source]
def self.with_clock(clock : Clock, &) #

[View source]

Macro Detail

macro close_span #

[View source]
macro in_span(span_name, &block) #

[View source]