# dd-opentelemetry-exporter-ruby *Note*: This Repository has been deprecated and is no longer actively maintained. Please refer to [OTLP Ingest in Datadog Agent](https://docs.datadoghq.com/tracing/setup_overview/open_standards/#otlp-ingest-in-datadog-agent) for support options for using OpenTelemetry and Datadog. # OpenTelemetry Datadog Span Exporter **[DEPRECATED]** The `opentelemetry-exporters-datadog` gem provides a Datadog exporter for OpenTelemetry for Ruby. Using `opentelemetry-exporters-datadog`, an application can configure OpenTelemetry to export collected tracing data to [Datadog][datadog-home]. ## What is OpenTelemetry? [OpenTelemetry][opentelemetry-home] 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. OpenTelemetry provides a single set of APIs, libraries, agents, and collector services to capture distributed traces and metrics from your application. ## How does this gem fit in? The `opentelemetry-exporters-datadog` gem is a plugin that provides Datadog Tracing export. To export to Datadog, an application can include this gem along with `opentelemetry-sdk`, and configure the `SDK` to use the provided Datadog exporter as a span processor. Generally, *libraries* that produce telemetry data should avoid depending directly on specific exporters, deferring that choice to the application developer. ## Setup - If you use [bundler][bundler-home], include the following in your `Gemfile`: ``` gem 'opentelemetry-exporters-datadog' gem 'opentelemetry-api', '~> 0.5' gem 'opentelemetry-sdk', '~> 0.5' ``` - Or install the gem directly using: ``` gem install opentelemetry-api gem install opentelemetry-sdk gem install opentelemetry-exporters-datadog ``` - Then, configure the SDK to use the Datadog exporter as a span processor, and use the OpenTelemetry interfaces to produces traces and other information. Following is a basic example. ```ruby require 'opentelemetry/sdk' require 'opentelemetry-exporters-datadog' # Configure the sdk with custom export OpenTelemetry::SDK.configure do |c| c.add_span_processor( OpenTelemetry::Exporters::Datadog::DatadogSpanProcessor.new( OpenTelemetry::Exporters::Datadog::Exporter.new( service_name: 'my_service', agent_url: 'http://localhost:8126' ) ) ) end # For propagation of datadog specific distibuted tracing headers, # set http propagation to the Composite Propagator OpenTelemetry::Exporters::Datadog::Propagator.auto_configure # For manual configuration of propagation of datadog specific distibuted tracing headers, # add the Datadog Propagator to the list of extractors and injectors, like below # extractors = [ # OpenTelemetry::Trace::Propagation::TraceContext.rack_extractor, # OpenTelemetry::CorrelationContext::Propagation.rack_extractor, # OpenTelemetry::Exporters::Datadog::Propagator.new # ] # injectors = [ # OpenTelemetry::Trace::Propagation::TraceContext.text_injector, # OpenTelemetry::CorrelationContext::Propagation.text_injector, # OpenTelemetry::Exporters::Datadog::Propagator.new # ] # OpenTelemetry.propagation.http = OpenTelemetry::Context::Propagation::CompositePropagator.new(injectors, extractors) # To start a trace you need to get a Tracer from the TracerProvider tracer = OpenTelemetry.tracer_provider.tracer('my_app_or_gem', '0.1.0') # create a span tracer.in_span('foo') do |span| # set an attribute span.set_attribute('platform', 'osx') # add an event span.add_event(name: 'event in bar') # create bar as child of foo tracer.in_span('bar') do |child_span| # inspect the span pp child_span end end ``` For additional examples, see the [examples on github][examples-github]. ## Probability Based Sampling Setup - By default, the OpenTelemetry tracer will sample and record all spans. This default is the suggest sampling approach to take when exporting to Datadog. However, if you wish to use Probability Based sampling, we recommend that, in order for the Datadog trace-agent to collect trace related metrics effectively, to use the `DatadogProbabilitySampler`. You can enabled Datadog Probability based sampling with the code snippet below. ```ruby #sampling rate must be a value between 0.0 and 1.0 sampling_rate = 0.75 OpenTelemetry.tracer_provider.active_trace_config = OpenTelemetry::SDK::Tracer::Config::Tracer::TraceConfig.new( sampler: OpenTelemetry::SDK::Trace::Export::DatadogProbabilitySampler.default_with_probability(sampling_rate) ) ``` ## Configuration Options #### Configuration Options - Datadog Agent URL By default the OpenTelemetry Datadog Exporter transmits traces to localhost:8126. You can configure the application to send traces to a diffent URL using the following environmennt variables: - `DD_TRACE_AGENT_URL`: The `: