From dd02868b54cdcedb3e3826b266b3aed3c9757be7 Mon Sep 17 00:00:00 2001 From: nvh0412 Date: Fri, 15 Nov 2024 16:14:06 +1100 Subject: [PATCH 1/8] Add Karafka integration --- appraisal/ruby-2.7.rb | 1 + appraisal/ruby-3.0.rb | 1 + appraisal/ruby-3.1.rb | 1 + appraisal/ruby-3.2.rb | 1 + appraisal/ruby-3.3.rb | 1 + appraisal/ruby-3.4.rb | 1 + docs/GettingStarted.md | 406 +++++++++--------- lib/datadog/tracing/contrib.rb | 1 + lib/datadog/tracing/contrib/karafka.rb | 37 ++ .../contrib/karafka/configuration/settings.rb | 27 ++ .../karafka/distributed/propagation.rb | 47 ++ lib/datadog/tracing/contrib/karafka/event.rb | 28 ++ lib/datadog/tracing/contrib/karafka/events.rb | 28 ++ .../contrib/karafka/events/error/occur.rb | 28 ++ .../contrib/karafka/events/worker/process.rb | 77 ++++ lib/datadog/tracing/contrib/karafka/ext.rb | 25 ++ .../tracing/contrib/karafka/integration.rb | 42 ++ .../tracing/contrib/karafka/patcher.rb | 59 +++ .../tracing/contrib/karafka/patcher_spec.rb | 90 ++++ 19 files changed, 709 insertions(+), 192 deletions(-) create mode 100644 lib/datadog/tracing/contrib/karafka.rb create mode 100644 lib/datadog/tracing/contrib/karafka/configuration/settings.rb create mode 100644 lib/datadog/tracing/contrib/karafka/distributed/propagation.rb create mode 100644 lib/datadog/tracing/contrib/karafka/event.rb create mode 100644 lib/datadog/tracing/contrib/karafka/events.rb create mode 100644 lib/datadog/tracing/contrib/karafka/events/error/occur.rb create mode 100644 lib/datadog/tracing/contrib/karafka/events/worker/process.rb create mode 100644 lib/datadog/tracing/contrib/karafka/ext.rb create mode 100644 lib/datadog/tracing/contrib/karafka/integration.rb create mode 100644 lib/datadog/tracing/contrib/karafka/patcher.rb create mode 100644 spec/datadog/tracing/contrib/karafka/patcher_spec.rb diff --git a/appraisal/ruby-2.7.rb b/appraisal/ruby-2.7.rb index 60d2ec62d9d..2fd78ac0be7 100644 --- a/appraisal/ruby-2.7.rb +++ b/appraisal/ruby-2.7.rb @@ -193,6 +193,7 @@ gem 'concurrent-ruby' gem 'dalli', '>= 3.0.0' gem 'grpc' + gem 'karafka' gem 'mongo', '>= 2.8.0', '< 2.15.0' # TODO: FIX TEST BREAKAGES ON >= 2.15 https://github.com/DataDog/dd-trace-rb/issues/1596 gem 'rack-test' # Dev dependencies for testing rack-based code gem 'rake', '>= 12.3' diff --git a/appraisal/ruby-3.0.rb b/appraisal/ruby-3.0.rb index f4b00ee4ec0..a0e7779301b 100644 --- a/appraisal/ruby-3.0.rb +++ b/appraisal/ruby-3.0.rb @@ -115,6 +115,7 @@ gem 'concurrent-ruby' gem 'dalli', '>= 3.0.0' gem 'grpc', '>= 1.38.0', platform: :ruby # Minimum version with Ruby 3.0 support + gem 'karafka' gem 'mongo', '>= 2.8.0', '< 2.15.0' # TODO: FIX TEST BREAKAGES ON >= 2.15 https://github.com/DataDog/dd-trace-rb/issues/1596 gem 'rack-test' # Dev dependencies for testing rack-based code gem 'rake', '>= 12.3' diff --git a/appraisal/ruby-3.1.rb b/appraisal/ruby-3.1.rb index f4b00ee4ec0..a0e7779301b 100644 --- a/appraisal/ruby-3.1.rb +++ b/appraisal/ruby-3.1.rb @@ -115,6 +115,7 @@ gem 'concurrent-ruby' gem 'dalli', '>= 3.0.0' gem 'grpc', '>= 1.38.0', platform: :ruby # Minimum version with Ruby 3.0 support + gem 'karafka' gem 'mongo', '>= 2.8.0', '< 2.15.0' # TODO: FIX TEST BREAKAGES ON >= 2.15 https://github.com/DataDog/dd-trace-rb/issues/1596 gem 'rack-test' # Dev dependencies for testing rack-based code gem 'rake', '>= 12.3' diff --git a/appraisal/ruby-3.2.rb b/appraisal/ruby-3.2.rb index f4b00ee4ec0..a0e7779301b 100644 --- a/appraisal/ruby-3.2.rb +++ b/appraisal/ruby-3.2.rb @@ -115,6 +115,7 @@ gem 'concurrent-ruby' gem 'dalli', '>= 3.0.0' gem 'grpc', '>= 1.38.0', platform: :ruby # Minimum version with Ruby 3.0 support + gem 'karafka' gem 'mongo', '>= 2.8.0', '< 2.15.0' # TODO: FIX TEST BREAKAGES ON >= 2.15 https://github.com/DataDog/dd-trace-rb/issues/1596 gem 'rack-test' # Dev dependencies for testing rack-based code gem 'rake', '>= 12.3' diff --git a/appraisal/ruby-3.3.rb b/appraisal/ruby-3.3.rb index 77faa8ba5c7..1a8d96f6671 100644 --- a/appraisal/ruby-3.3.rb +++ b/appraisal/ruby-3.3.rb @@ -115,6 +115,7 @@ gem 'concurrent-ruby' gem 'dalli', '>= 3.0.0' gem 'grpc', '>= 1.38.0', platform: :ruby # Minimum version with Ruby 3.0 support + gem 'karafka' gem 'mongo', '>= 2.8.0', '< 2.15.0' # TODO: FIX TEST BREAKAGES ON >= 2.15 https://github.com/DataDog/dd-trace-rb/issues/1596 gem 'rack-test' # Dev dependencies for testing rack-based code gem 'rake', '>= 12.3' diff --git a/appraisal/ruby-3.4.rb b/appraisal/ruby-3.4.rb index 6cb1bf51ce2..10544b03cba 100644 --- a/appraisal/ruby-3.4.rb +++ b/appraisal/ruby-3.4.rb @@ -122,6 +122,7 @@ gem 'concurrent-ruby' gem 'dalli', '>= 3.0.0' gem 'grpc', '>= 1.38.0', platform: :ruby # Minimum version with Ruby 3.0 support + gem 'karafka' gem 'mongo', '>= 2.8.0', '< 2.15.0' # TODO: FIX TEST BREAKAGES ON >= 2.15 https://github.com/DataDog/dd-trace-rb/issues/1596 gem 'rack-test' # Dev dependencies for testing rack-based code gem 'rake', '>= 12.3' diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 8a1196fa138..eaff2b38aca 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -317,7 +317,7 @@ end | Key | Env Var | Type | Description | Default | | --------- | ------------------------------- | ------ | -------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_ACTION_CABLE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_ACTION_CABLE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | ### Action Mailer @@ -335,10 +335,10 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| ------------ | - | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_ACTION_MAILER_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `email_data` | | `Bool` | Whether or not to append additional email payload metadata to `action_mailer.deliver` spans. Fields include `['subject', 'to', 'from', 'bcc', 'cc', 'date', 'perform_deliveries']`. | `false` | +| Key | Env Var | Type | Description | Default | +| ------------ | -------------------------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | +| `enabled` | `DD_TRACE_ACTION_MAILER_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `email_data` | | `Bool` | Whether or not to append additional email payload metadata to `action_mailer.deliver` spans. Fields include `['subject', 'to', 'from', 'bcc', 'cc', 'date', 'perform_deliveries']`. | `false` | ### Action Pack @@ -355,9 +355,9 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| --------- | ------------------------------- | ------ | -------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_ACTION_PACK_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| Key | Env Var | Type | Description | Default | +| --------- | ------------------------------ | ------ | -------------------------------------------- | ------- | +| `enabled` | `DD_TRACE_ACTION_PACK_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | ### Action View @@ -374,10 +374,10 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| -------------------- | - | ------- | ---------------------------------------------------------------------------------------------------------------------------------- | ---------- | -| `enabled` | `DD_TRACE_ACTION_VIEW_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `template_base_path` | | `String` | Used when the template name is parsed. If you don't store your templates in the `views/` folder, you may need to change this value | `'views/'` | +| Key | Env Var | Type | Description | Default | +| -------------------- | ------------------------------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------- | ---------- | +| `enabled` | `DD_TRACE_ACTION_VIEW_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `template_base_path` | | `String` | Used when the template name is parsed. If you don't store your templates in the `views/` folder, you may need to change this value | `'views/'` | ### Active Job @@ -396,9 +396,9 @@ ExampleJob.perform_later `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| --------- | ------------------------------- | ------ | -------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_ACTIVE_JOB_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| Key | Env Var | Type | Description | Default | +| --------- | ----------------------------- | ------ | -------------------------------------------- | ------- | +| `enabled` | `DD_TRACE_ACTIVE_JOB_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | ### Active Model Serializers @@ -418,9 +418,9 @@ ActiveModelSerializers::SerializableResource.new(test_obj).serializable_hash `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| --------- | ------------------------------- | ------ | -------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_ACTIVE_MODEL_SERIALIZERS_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| Key | Env Var | Type | Description | Default | +| --------- | ------------------------------------------- | ------ | -------------------------------------------- | ------- | +| `enabled` | `DD_TRACE_ACTIVE_MODEL_SERIALIZERS_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | ### Active Record @@ -445,10 +445,10 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| -------------- | - | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | -| `enabled` | `DD_TRACE_ACTIVE_RECORD_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `service_name` | | `String` | Override the service name for the SQL query instrumentation. ActiveRecord instantiation instrumentation always uses the application's configured service name. | Name of database adapter (e.g. `'mysql2'`) | +| Key | Env Var | Type | Description | Default | +| -------------- | -------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | +| `enabled` | `DD_TRACE_ACTIVE_RECORD_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `service_name` | | `String` | Override the service name for the SQL query instrumentation. ActiveRecord instantiation instrumentation always uses the application's configured service name. | Name of database adapter (e.g. `'mysql2'`) | **Configuring trace settings per database** @@ -534,10 +534,10 @@ cache.read('city') `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| --------------- | - | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- | -| `enabled` | `DD_TRACE_ACTIVE_SUPPORT_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `cache_service` | | `String` | Name of application running the `active_support` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `active_support-cache` | +| Key | Env Var | Type | Description | Default | +| --------------- | --------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- | +| `enabled` | `DD_TRACE_ACTIVE_SUPPORT_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `cache_service` | | `String` | Name of application running the `active_support` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `active_support-cache` | ### AWS @@ -559,7 +559,7 @@ Aws::S3::Client.new.list_buckets | Key | Env Var | Type | Description | Default | | -------------- | --------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_AWS_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_AWS_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_AWS_SERVICE_NAME` | `String` | Name of application running the `aws` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `aws` | | `peer_service` | `DD_TRACE_AWS_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | @@ -597,9 +597,9 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| --------- | ------------------------------- | ------ | -------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_CONCURRENT_RUBY_ENABLED` | `Bool` | Whether the integration propagates contexts. | `true` | +| Key | Env Var | Type | Description | Default | +| --------- | ---------------------------------- | ------ | -------------------------------------------- | ------- | +| `enabled` | `DD_TRACE_CONCURRENT_RUBY_ENABLED` | `Bool` | Whether the integration propagates contexts. | `true` | ### Dalli @@ -623,7 +623,7 @@ client.set('abc', 123) | Key | Env Var | Type | Description | Default | | ----------------- | ------------------------------------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | -| `enabled` | `DD_TRACE_DALLI_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_DALLI_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `command_enabled` | `DD_TRACE_MEMCACHED_COMMAND_ENABLED` | `Bool` | Collect commands as the `memcached.command` tag. Command `keys` can potentially contain sensitive information. | `false` | | `service_name` | `DD_TRACE_DALLI_SERVICE_NAME` | `String` | Name of application running the `dalli` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `memcached` | | `peer_service` | `DD_TRACE_DALLI_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | @@ -644,10 +644,10 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| ---------- | - | ----- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | -| `enabled` | `DD_TRACE_DELAYED_JOB_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | +| Key | Env Var | Type | Description | Default | +| ---------- | ------------------------------ | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | +| `enabled` | `DD_TRACE_DELAYED_JOB_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | ### Elasticsearch @@ -673,7 +673,7 @@ Datadog.configure_onto(client.transport, **options) | Key | Env Var | Type | Description | Default | | -------------- | ------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------- | -| `enabled` | `DD_TRACE_ELASTICSEARCH_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_ELASTICSEARCH_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_ELASTICSEARCH_SERVICE_NAME` | `String` | Name of application running the `elasticsearch` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `elasticsearch` | | `peer_service` | `DD_TRACE_ELASTICSEARCH_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `quantize` | | `Hash` | Hash containing options for quantization. May include `:show` with an Array of keys to not quantize (or `:all` to skip quantization), or `:exclude` with Array of keys to exclude entirely. | `{}` | @@ -700,7 +700,7 @@ end | Key | Env Var | Type | Description | Default | | --------------------- | ----------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_ETHON_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_ETHON_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_ETHON_SERVICE_NAME` | `String` | Name of application running the `ethon` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `ethon` | | `peer_service` | `DD_TRACE_ETHON_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) | `true` | @@ -733,12 +733,12 @@ connection.get | Key | Env Var | Type | Description | Default | | --------------------- | ----------------------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | -| `enabled` | `DD_TRACE_EXCON_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_EXCON_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_EXCON_SERVICE_NAME` | `String` | Name of application running the `excon` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `excon` | | `peer_service` | `DD_TRACE_EXCON_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) | `true` | | `split_by_domain` | | `Bool` | Uses the request domain as the service name when set to `true`. | `false` | -| `on_error` | | `Proc` | Custom error handler invoked when a request raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | +| `on_error` | | `Proc` | Custom error handler invoked when a request raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | | `error_status_codes` | `DD_TRACE_EXCON_ERROR_STATUS_CODES` | `Array`\|`Range` | Defines HTTP status codes that are traced as errors. Value can be a range (`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `400...600` | **Configuring connections to use different settings** @@ -798,12 +798,12 @@ connection.get('/foo') | Key | Env Var | Type | Description | Default | | --------------------- | ------------------------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | -| `enabled` | `DD_TRACE_FARADAY_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_FARADAY_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_FARADAY_SERVICE_NAME` | `String` | Name of application running the `faraday` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `faraday` | | `peer_service` | `DD_TRACE_FARADAY_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) | `true` | | `split_by_domain` | | `Bool` | Uses the request domain as the service name when set to `true`. | `false` | -| `on_error` | | `Proc` | Custom error handler invoked when a request raises an error. Provided `span` and `error` as arguments. Sets an error on the span by default. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | +| `on_error` | | `Proc` | Custom error handler invoked when a request raises an error. Provided `span` and `error` as arguments. Sets an error on the span by default. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | | `error_status_codes` | `DD_TRACE_FARADAY_ERROR_STATUS_CODES` | `Array`\|`Range` | Defines HTTP status codes that are traced as errors. Value can be a range (`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `400...600` | ### Grape @@ -834,7 +834,7 @@ end | Key | Env Var | Type | Description | Default | | -------------------- | ----------------------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | -| `enabled` | `DD_TRACE_GRAPE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_GRAPE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `error_status_codes` | `DD_TRACE_GRAPE_ERROR_STATUS_CODES` | `Array`\|`Range` | Defines HTTP status codes that are traced as errors. Value can be a range (`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `500...600` | ### GraphQL @@ -861,15 +861,15 @@ YourSchema.execute(query, variables: {}, context: {}, operation_name: nil) The `instrument :graphql` method accepts the following parameters. Additional options can be substituted in for `options`: -| Key | Env Var | Type | Description | Default | -| ------------------------ | -------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------- | -| `enabled` | `DD_TRACE_GRAPHQL_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `schemas` | | `Array` | Array of `GraphQL::Schema` objects (that support class-based schema only) to trace. If you do not provide any, then tracing will applied to all the schemas. | `[]` | -| `with_unified_tracer` | | `Bool` | (Recommended) Enable to instrument with `UnifiedTrace` tracer for `graphql` >= v2.2, **enabling support for API Catalog**. `with_deprecated_tracer` has priority over this. Default is `false`, using `GraphQL::Tracing::DataDogTrace` instead | `false` | -| `with_deprecated_tracer` | | `Bool` | Enable to instrument with deprecated `GraphQL::Tracing::DataDogTracing`. This has priority over `with_unified_tracer`. Default is `false`, using `GraphQL::Tracing::DataDogTrace` instead | `false` | -| `service_name` | | `String` | Service name used for graphql instrumentation | `'ruby-graphql'` | +| Key | Env Var | Type | Description | Default | +| ------------------------ | -------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------- | +| `enabled` | `DD_TRACE_GRAPHQL_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `schemas` | | `Array` | Array of `GraphQL::Schema` objects (that support class-based schema only) to trace. If you do not provide any, then tracing will applied to all the schemas. | `[]` | +| `with_unified_tracer` | | `Bool` | (Recommended) Enable to instrument with `UnifiedTrace` tracer for `graphql` >= v2.2, **enabling support for API Catalog**. `with_deprecated_tracer` has priority over this. Default is `false`, using `GraphQL::Tracing::DataDogTrace` instead | `false` | +| `with_deprecated_tracer` | | `Bool` | Enable to instrument with deprecated `GraphQL::Tracing::DataDogTracing`. This has priority over `with_unified_tracer`. Default is `false`, using `GraphQL::Tracing::DataDogTrace` instead | `false` | +| `service_name` | | `String` | Service name used for graphql instrumentation | `'ruby-graphql'` | -Once an instrumentation strategy is selected (`with_unified_tracer: true`, `with_deprecated_tracer: true`, or *no option set* which defaults to `GraphQL::Tracing::DataDogTrace`), it is not possible to change the instrumentation strategy in the same Ruby process. +Once an instrumentation strategy is selected (`with_unified_tracer: true`, `with_deprecated_tracer: true`, or _no option set_ which defaults to `GraphQL::Tracing::DataDogTrace`), it is not possible to change the instrumentation strategy in the same Ruby process. This is especially important for [auto instrumented applications](#rails-or-hanami-applications) because an automatic initial instrumentation is always applied at startup, thus such applications will always instrument GraphQL with the default strategy (`GraphQL::Tracing::DataDogTrace`). **Manually configuring GraphQL schemas** @@ -952,7 +952,7 @@ client.my_endpoint(DemoMessage.new(contents: 'hello!')) | Key | Env Var | Type | Description | Default | | --------------------- | ---------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ | -| `enabled` | `DD_TRACE_GRPC_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_GRPC_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_GRPC_SERVICE_NAME` | `String` | Name of application running the `grpc` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `grpc` | | `peer_service` | `DD_TRACE_GRPC_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) | `true` | @@ -995,10 +995,10 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| -------------- | - | ------- | ------------------------------------------ | ------- | -| `enabled` | `DD_TRACE_HANAMI_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `service_name` | | `String` | Service name for `hanami` instrumentation. | `nil` | +| Key | Env Var | Type | Description | Default | +| -------------- | ------------------------- | -------- | -------------------------------------------- | ------- | +| `enabled` | `DD_TRACE_HANAMI_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `service_name` | | `String` | Service name for `hanami` instrumentation. | `nil` | ### http.rb @@ -1021,7 +1021,7 @@ end | Key | Env Var | Type | Description | Default | | --------------------- | ------------------------------------ | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | -| `enabled` | `DD_TRACE_HTTPRB_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_HTTPRB_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_HTTPRB_SERVICE_NAME` | `String` | Name of application running the `httprb` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `httprb` | | `peer_service` | `DD_TRACE_HTTPRB_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) | `true` | @@ -1049,7 +1049,7 @@ end | Key | Env Var | Type | Description | Default | | --------------------- | ---------------------------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | -| `enabled` | `DD_TRACE_HTTPCLIENT_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_HTTPCLIENT_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_HTTPCLIENT_SERVICE_NAME` | `String` | Name of application running the `httpclient` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `httpclient` | | `peer_service` | `DD_TRACE_HTTPCLIENT_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) | `true` | @@ -1093,9 +1093,31 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| --------- | ------------------------------- | ------ | -------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_KAFKA_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| Key | Env Var | Type | Description | Default | +| --------- | ------------------------ | ------ | -------------------------------------------- | ------- | +| `enabled` | `DD_TRACE_KAFKA_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | + +### Karafka + +The karafka integration provides tracing of the `karafka` gem: + +You can enable it through `Datadog.configure`: + +```ruby +require 'karafka' +require 'datadog' + +Datadog.configure do |c| + c.tracing.instrument :karafka, **options +end +``` + +`options` are the following keyword arguments: + +| Key | Env Var | Type | Description | Default | +| --------------------- | ------------------------ | ------ | --------------------------------------------------- | ------- | +| `enabled` | `DD_TRACE_KAFKA_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) | `false` | ### MongoDB @@ -1122,7 +1144,7 @@ Datadog.configure_onto(client, **options) | Key | Env Var | Type | Description | Default | | -------------- | ----------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ | -| `enabled` | `DD_TRACE_MONGO_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_MONGO_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_MONGO_SERVICE_NAME` | `String` | Name of application running the `mongo` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `mongodb` | | `peer_service` | `DD_TRACE_MONGO_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `quantize` | | `Hash` | Hash containing options for quantization. May include `:show` with an Array of keys to not quantize (or `:all` to skip quantization), or `:exclude` with Array of keys to exclude entirely. | `{ show: [:collection, :database, :operation] }` | @@ -1178,11 +1200,11 @@ client.query("SELECT * FROM users WHERE group='x'") | Key | Env Var | Type | Description | Default | | --------------------- | ------------------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------- | -| `enabled` | `DD_TRACE_MYSQL2_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_MYSQL2_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_MYSQL2_SERVICE_NAME` | `String` | Name of application running the `mysql2` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `mysql2` | | `peer_service` | `DD_TRACE_MYSQL2_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `comment_propagation` | `DD_DBM_PROPAGATION_MODE` | `String` | SQL comment propagation mode for database monitoring.
(example: `disabled` \| `service`\| `full`).

**Important**: _Note that enabling SQL comment propagation results in potentially confidential data (service names) being stored in the databases which can then be accessed by other third parties that have been granted access to the database._ | `'disabled'` | -| `append_comment` | | `Bool` | Appends the SQL comment propagation to the query string. Prepends the comment if `false`. For long query strings, the appended propagation comment might be truncated, causing loss of correlation between the query and trace. | `false` | +| `append_comment` | | `Bool` | Appends the SQL comment propagation to the query string. Prepends the comment if `false`. For long query strings, the appended propagation comment might be truncated, causing loss of correlation between the query and trace. | `false` | | `on_error` | | `Proc` | Custom error handler invoked when MySQL raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring errors that are handled at the application level. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | ### Net/HTTP @@ -1215,7 +1237,7 @@ content = Net::HTTP.get(URI('http://127.0.0.1/index.html')) | Key | Env Var | Type | Description | Default | | --------------------- | ---------------------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | -| `enabled` | `DD_TRACE_HTTP_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_HTTP_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_NET_HTTP_SERVICE_NAME` | `String` | Name of application running the `net/http` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `net/http` | | `peer_service` | `DD_TRACE_NET_HTTP_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) | `true` | @@ -1254,7 +1276,7 @@ client.cluster.health | Key | Env Var | Type | Description | Default | | -------------- | ---------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | -| `enabled` | `DD_TRACE_OPENSEARCH_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_OPENSEARCH_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_OPENSEARCH_SERVICE_NAME` | `String` | Name of application running the `opensearch` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `opensearch` | | `peer_service` | `DD_TRACE_OPENSEARCH_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `quantize` | | `Hash` | Hash containing options for quantization. May include `:show` with an Array of keys to not quantize (or `:all` to skip quantization), or `:exclude` with Array of keys to exclude entirely. | `{}` | @@ -1278,14 +1300,14 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| --------------------- | -------------------------- | ------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | -| `enabled` | `DD_TRACE_PG_ENABLED` | `true` | Whether the integration should create spans. | `true` | -| `service_name` | `DD_TRACE_PG_SERVICE_NAME` | `String` | Name of application running the `pg` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `pg` | -| `peer_service` | `DD_TRACE_PG_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | -| `comment_propagation` | `DD_DBM_PROPAGATION_MODE` | `String` | SQL comment propagation mode for database monitoring.
(example: `disabled` \| `service`\| `full`).

**Important**: _Note that enabling sql comment propagation results in potentially confidential data (service names) being stored in the databases which can then be accessed by other 3rd parties that have been granted access to the database._ | `'disabled'` | -| `append_comment` | | `Bool` | Appends the SQL comment propagation to the query string. Prepends the comment if `false`. For long query strings, the appended propagation comment might be truncated, causing loss of correlation between the query and trace. | `false` | -| `on_error` | | `Proc` | Custom error handler invoked when PG raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring errors from Postgres that are handled at the application level. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | +| Key | Env Var | Type | Description | Default | +| --------------------- | -------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | +| `enabled` | `DD_TRACE_PG_ENABLED` | `true` | Whether the integration should create spans. | `true` | +| `service_name` | `DD_TRACE_PG_SERVICE_NAME` | `String` | Name of application running the `pg` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `pg` | +| `peer_service` | `DD_TRACE_PG_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | +| `comment_propagation` | `DD_DBM_PROPAGATION_MODE` | `String` | SQL comment propagation mode for database monitoring.
(example: `disabled` \| `service`\| `full`).

**Important**: _Note that enabling sql comment propagation results in potentially confidential data (service names) being stored in the databases which can then be accessed by other 3rd parties that have been granted access to the database._ | `'disabled'` | +| `append_comment` | | `Bool` | Appends the SQL comment propagation to the query string. Prepends the comment if `false`. For long query strings, the appended propagation comment might be truncated, causing loss of correlation between the query and trace. | `false` | +| `on_error` | | `Proc` | Custom error handler invoked when PG raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring errors from Postgres that are handled at the application level. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | ### Presto @@ -1316,7 +1338,7 @@ client.run("select * from system.nodes") | Key | Env Var | Type | Description | Default | | -------------- | ------------------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | -| `enabled` | `DD_TRACE_PRESTO_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_PRESTO_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_PRESTO_SERVICE_NAME` | `String` | Name of application running the `presto` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `presto` | | `peer_service` | `DD_TRACE_PRESTO_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | @@ -1338,7 +1360,7 @@ end | Key | Env Var | Type | Description | Default | | ---------- | ------------------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ | -| `enabled` | `DD_TRACE_QUE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_QUE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `tag_args` | `DD_TRACE_QUE_TAG_ARGS_ENABLED` | `Bool` | Enable tagging of a job's args field. `true` for on, `false` for off. | `false` | | `tag_data` | `DD_TRACE_QUE_TAG_DATA_ENABLED` | `Bool` | Enable tagging of a job's data field. `true` for on, `false` for off. | `false` | | `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error \| span.set_error(error) unless span.nil? }` | @@ -1361,7 +1383,7 @@ end | Key | Env Var | Type | Description | Default | | -------------- | ------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | -| `enabled` | `DD_TRACE_RACECAR_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_RACECAR_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_RACECAR_SERVICE_NAME` | `String` | Name of application running the `racecar` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `racecar` | ### Rack @@ -1389,24 +1411,24 @@ run app `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| -------------------------------- | - | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------ | -| `enabled` | `DD_TRACE_RACK_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `application` | | [`Rack Application`](https://github.com/rack/rack/blob/800e53fbe15b3424b7a8946b067bf6f2e648d5a8/SPEC.rdoc#label-Rack+applications) | Your Rack application. Required for `middleware_names`. | `nil` | -| `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) so that this service trace is connected with a trace of another service if tracing headers are received | `true` | -| `headers` | | `Hash` | Hash of HTTP request or response headers to add as tags to the `rack.request`. Accepts `request` and `response` keys with Array values e.g. `['Last-Modified']`. Adds `http.request.headers.*` and `http.response.headers.*` tags respectively. This option overrides the global `DD_TRACE_HEADER_TAGS`, see [Applying header tags to root spans][header tags] for more information. | `{ response: ['Content-Type', 'X-Request-ID'] }` | -| `middleware_names` | | `Bool` | Enable this if you want to use the last executed middleware class as the resource name for the `rack` span. If enabled alongside the `rails` instrumention, `rails` takes precedence by setting the `rack` resource name to the active `rails` controller when applicable. Requires `application` option to use. | `false` | -| `quantize` | | `Hash` | Hash containing options for quantization. May include `:query` or `:fragment`. | `{}` | -| `quantize.base` | | | Defines behavior for URL base (scheme, host, port). May be `:show` to keep URL base in `http.url` tag and not set `http.base_url` tag, or `nil` to remove URL base from `http.url` tag by default, leaving a path and setting `http.base_url`. Option must be nested inside the `quantize` option. | `nil` | -| `quantize.query` | | | Hash containing options for query portion of URL quantization. May include `:show` or `:exclude`. See options below. Option must be nested inside the `quantize` option. | `{}` | -| `quantize.query.show` | | | Defines which values should always be shown. May be an Array of strings, `:all` to show all values, or `nil` to show no values. Option must be nested inside the `query` option. | `nil` | -| `quantize.query.exclude` | | | Defines which values should be removed entirely. May be an Array of strings, `:all` to remove the query string entirely, or `nil` to exclude nothing. Option must be nested inside the `query` option. | `nil` | -| `quantize.query.obfuscate` | | | Defines query string redaction behaviour. May be a hash of options, `:internal` to use the default internal obfuscation settings, or `nil` to disable obfuscation. Note that obfuscation is a string-wise operation, not a key-value operation. When enabled, `query.show` defaults to `:all` if otherwise unset. Option must be nested inside the `query` option. | `nil` | -| `quantize.query.obfuscate.with` | | | Defines the string to replace obfuscated matches with. May be a String. Option must be nested inside the `query.obfuscate` option. | `''` | -| `quantize.query.obfuscate.regex` | | | Defines the regex with which the query string will be redacted. May be a Regexp, or `:internal` to use the default internal Regexp, which redacts well-known sensitive data. Each match is redacted entirely by replacing it with `query.obfuscate.with`. Option must be nested inside the `query.obfuscate` option. | `:internal` | -| `quantize.fragment` | | | Defines behavior for URL fragments. May be `:show` to show URL fragments, or `nil` to remove fragments. Option must be nested inside the `quantize` option. | `nil` | -| `request_queuing` | | `Bool` | Track HTTP request time spent in the queue of the frontend server. See [HTTP request queuing](#http-request-queuing) for setup details. | `false` | -| `web_service_name` | | `String` | Service name for frontend server request queuing spans. (e.g. `'nginx'`) | `'web-server'` | +| Key | Env Var | Type | Description | Default | +| -------------------------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------ | +| `enabled` | `DD_TRACE_RACK_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `application` | | [`Rack Application`](https://github.com/rack/rack/blob/800e53fbe15b3424b7a8946b067bf6f2e648d5a8/SPEC.rdoc#label-Rack+applications) | Your Rack application. Required for `middleware_names`. | `nil` | +| `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) so that this service trace is connected with a trace of another service if tracing headers are received | `true` | +| `headers` | | `Hash` | Hash of HTTP request or response headers to add as tags to the `rack.request`. Accepts `request` and `response` keys with Array values e.g. `['Last-Modified']`. Adds `http.request.headers.*` and `http.response.headers.*` tags respectively. This option overrides the global `DD_TRACE_HEADER_TAGS`, see [Applying header tags to root spans][header tags] for more information. | `{ response: ['Content-Type', 'X-Request-ID'] }` | +| `middleware_names` | | `Bool` | Enable this if you want to use the last executed middleware class as the resource name for the `rack` span. If enabled alongside the `rails` instrumention, `rails` takes precedence by setting the `rack` resource name to the active `rails` controller when applicable. Requires `application` option to use. | `false` | +| `quantize` | | `Hash` | Hash containing options for quantization. May include `:query` or `:fragment`. | `{}` | +| `quantize.base` | | | Defines behavior for URL base (scheme, host, port). May be `:show` to keep URL base in `http.url` tag and not set `http.base_url` tag, or `nil` to remove URL base from `http.url` tag by default, leaving a path and setting `http.base_url`. Option must be nested inside the `quantize` option. | `nil` | +| `quantize.query` | | | Hash containing options for query portion of URL quantization. May include `:show` or `:exclude`. See options below. Option must be nested inside the `quantize` option. | `{}` | +| `quantize.query.show` | | | Defines which values should always be shown. May be an Array of strings, `:all` to show all values, or `nil` to show no values. Option must be nested inside the `query` option. | `nil` | +| `quantize.query.exclude` | | | Defines which values should be removed entirely. May be an Array of strings, `:all` to remove the query string entirely, or `nil` to exclude nothing. Option must be nested inside the `query` option. | `nil` | +| `quantize.query.obfuscate` | | | Defines query string redaction behaviour. May be a hash of options, `:internal` to use the default internal obfuscation settings, or `nil` to disable obfuscation. Note that obfuscation is a string-wise operation, not a key-value operation. When enabled, `query.show` defaults to `:all` if otherwise unset. Option must be nested inside the `query` option. | `nil` | +| `quantize.query.obfuscate.with` | | | Defines the string to replace obfuscated matches with. May be a String. Option must be nested inside the `query.obfuscate` option. | `''` | +| `quantize.query.obfuscate.regex` | | | Defines the regex with which the query string will be redacted. May be a Regexp, or `:internal` to use the default internal Regexp, which redacts well-known sensitive data. Each match is redacted entirely by replacing it with `query.obfuscate.with`. Option must be nested inside the `query.obfuscate` option. | `:internal` | +| `quantize.fragment` | | | Defines behavior for URL fragments. May be `:show` to show URL fragments, or `nil` to remove fragments. Option must be nested inside the `quantize` option. | `nil` | +| `request_queuing` | | `Bool` | Track HTTP request time spent in the queue of the frontend server. See [HTTP request queuing](#http-request-queuing) for setup details. | `false` | +| `web_service_name` | | `String` | Service name for frontend server request queuing spans. (e.g. `'nginx'`) | `'web-server'` | Deprecation notice: @@ -1482,15 +1504,15 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| --------------------- | - | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- | -| `enabled` | `DD_TRACE_RAILS_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) so that this service trace is connected with a trace of another service if tracing headers are received | `true` | -| `request_queuing` | | `Bool` | Track HTTP request time spent in the queue of the frontend server. See [HTTP request queuing](#http-request-queuing) for setup details. | `false` | -| `middleware` | | `Bool` | Add the trace middleware to the Rails application. Set to `false` if you don't want the middleware to load. | `true` | -| `middleware_names` | | `Bool` | Enables any short-circuited middleware requests to display the middleware name as a resource for the trace. | `false` | -| `service_name` | | `String` | Service name used when tracing application requests (on the `rack` level) | `''` (inferred from your Rails application namespace) | -| `template_base_path` | | `String` | Used when the template name is parsed. If you don't store your templates in the `views/` folder, you may need to change this value | `'views/'` | +| Key | Env Var | Type | Description | Default | +| --------------------- | ------------------------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- | +| `enabled` | `DD_TRACE_RAILS_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) so that this service trace is connected with a trace of another service if tracing headers are received | `true` | +| `request_queuing` | | `Bool` | Track HTTP request time spent in the queue of the frontend server. See [HTTP request queuing](#http-request-queuing) for setup details. | `false` | +| `middleware` | | `Bool` | Add the trace middleware to the Rails application. Set to `false` if you don't want the middleware to load. | `true` | +| `middleware_names` | | `Bool` | Enables any short-circuited middleware requests to display the middleware name as a resource for the trace. | `false` | +| `service_name` | | `String` | Service name used when tracing application requests (on the `rack` level) | `''` (inferred from your Rails application namespace) | +| `template_base_path` | | `String` | Used when the template name is parsed. If you don't store your templates in the `views/` folder, you may need to change this value | `'views/'` | **Supported versions** @@ -1530,13 +1552,13 @@ Rake::Task['my_task'].invoke `options` are the following keyword arguments: -| Key | Env Var| Type | Description | Default | -| -------------- | - | ------- | -------------------------------------------------------------------------------------------------------- | -------- | -| `enabled` | | `Bool` | Defines whether Rake tasks should be traced. Useful for temporarily disabling tracing. `true` or `false` | `true` | -| `quantize` | | `Hash` | Hash containing options for quantization of task arguments. See below for more details and examples. | `{}` | -| `service_name` | | `String` | Service name used for `rake` instrumentation | `'rake'` | -| `tasks` | | `Array` | Names of the Rake tasks to instrument | `[]` | -| `enabled` | `DD_TRACE_RAKE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| Key | Env Var | Type | Description | Default | +| -------------- | ----------------------- | -------- | -------------------------------------------------------------------------------------------------------- | -------- | +| `enabled` | | `Bool` | Defines whether Rake tasks should be traced. Useful for temporarily disabling tracing. `true` or `false` | `true` | +| `quantize` | | `Hash` | Hash containing options for quantization of task arguments. See below for more details and examples. | `{}` | +| `service_name` | | `String` | Service name used for `rake` instrumentation | `'rake'` | +| `tasks` | | `Array` | Names of the Rake tasks to instrument | `[]` | +| `enabled` | `DD_TRACE_RAKE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | **Configuring task quantization behavior** @@ -1593,7 +1615,7 @@ redis.set 'foo', 'bar' | Key | Env Var | Type | Description | Default | | -------------- | ----------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_REDIS_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_REDIS_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_REDIS_SERVICE_NAME` | `String` | Name of application running the `redis` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `redis` | | `peer_service` | `DD_TRACE_REDIS_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `command_args` | `DD_REDIS_COMMAND_ARGS` | `Bool` | Show the command arguments (for example, `key` in `GET key`) as resource name and tag. If `false`, only the command name is shown (for example, `GET`). | false | @@ -1707,10 +1729,10 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| ---------- | - | ----- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | -| `enabled` | `DD_TRACE_RESQUE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | +| Key | Env Var | Type | Description | Default | +| ---------- | ------------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | +| `enabled` | `DD_TRACE_RESQUE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | ### Rest Client @@ -1729,7 +1751,7 @@ end | Key | Env Var | Type | Description | Default | | --------------------- | ----------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | -| `enabled` | `DD_TRACE_REST_CLIENT_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_REST_CLIENT_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_REST_CLIENT_SERVICE_NAME` | `String` | Name of application running the `rest_client` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `rest_client` | | `peer_service` | `DD_TRACE_REST_CLIENT_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) | `true` | @@ -1764,10 +1786,10 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| -------------- | - | ------- | ---------------------------------------- | ------- | -| `enabled` | `DD_TRACE_RODA_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `service_name` | | `String` | Service name for `roda` instrumentation. | `nil` | +| Key | Env Var | Type | Description | Default | +| -------------- | ----------------------- | -------- | -------------------------------------------- | ------- | +| `enabled` | `DD_TRACE_RODA_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `service_name` | | `String` | Service name for `roda` instrumentation. | `nil` | ### Sequel @@ -1797,10 +1819,10 @@ articles.all `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| -------------- | - | ------- | ----------------------------------------- | ------------------------------------------ | -| `enabled` | `DD_TRACE_SEQUEL_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `service_name` | | `String` | Service name for `sequel` instrumentation | Name of database adapter (e.g. `'mysql2'`) | +| Key | Env Var | Type | Description | Default | +| -------------- | ------------------------- | -------- | -------------------------------------------- | ------------------------------------------ | +| `enabled` | `DD_TRACE_SEQUEL_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `service_name` | | `String` | Service name for `sequel` instrumentation | Name of database adapter (e.g. `'mysql2'`) | **Configuring databases to use different settings** @@ -1831,11 +1853,11 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| ---------- | - | ----- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | -| `enabled` | `DD_TRACE_SHORYUKEN_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `tag_body` | | `Bool` | Tag spans with the SQS message body `true` or `false` | `false` | -| `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | +| Key | Env Var | Type | Description | Default | +| ---------- | ---------------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | +| `enabled` | `DD_TRACE_SHORYUKEN_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `tag_body` | | `Bool` | Tag spans with the SQS message body `true` or `false` | `false` | +| `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | ### Sidekiq @@ -1853,12 +1875,12 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| --------------------- | - | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | -| `enabled` | `DD_TRACE_SIDEKIQ_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `distributed_tracing` | | `Bool` | Enabling [distributed tracing](#distributed-tracing) creates a parent-child relationship between the `sidekiq.push` span and the `sidekiq.job` span.

**Important**: _Enabling distributed_tracing for asynchronous processing can result in drastic changes in your trace graph. Such cases include long running jobs, retried jobs, and jobs scheduled in the far future. Make sure to inspect your traces after enabling this feature._ | `false` | -| `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | -| `quantize` | | `Hash` | Hash containing options for quantization of job arguments. | `{}` | +| Key | Env Var | Type | Description | Default | +| --------------------- | -------------------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | +| `enabled` | `DD_TRACE_SIDEKIQ_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `distributed_tracing` | | `Bool` | Enabling [distributed tracing](#distributed-tracing) creates a parent-child relationship between the `sidekiq.push` span and the `sidekiq.job` span.

**Important**: _Enabling distributed_tracing for asynchronous processing can result in drastic changes in your trace graph. Such cases include long running jobs, retried jobs, and jobs scheduled in the far future. Make sure to inspect your traces after enabling this feature._ | `false` | +| `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | +| `quantize` | | `Hash` | Hash containing options for quantization of job arguments. | `{}` | ### Sinatra @@ -1910,12 +1932,12 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| ----------------------- | - | ----- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ | -| `enabled` | `DD_TRACE_SINATRA_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) so that this service trace is connected with a trace of another service if tracing headers are received | `true` | -| `headers` | | `Hash` | Hash of HTTP request or response headers to add as tags to the `sinatra.request`. Accepts `request` and `response` keys with Array values e.g. `['Last-Modified']`. Adds `http.request.headers.*` and `http.response.headers.*` tags respectively. This option overrides the global `DD_TRACE_HEADER_TAGS`, see [Applying header tags to root spans][header tags] for more information. | `{ response: ['Content-Type', 'X-Request-ID'] }` | -| `resource_script_names` | | `Bool` | Prepend resource names with script name | `false` | +| Key | Env Var | Type | Description | Default | +| ----------------------- | -------------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ | +| `enabled` | `DD_TRACE_SINATRA_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) so that this service trace is connected with a trace of another service if tracing headers are received | `true` | +| `headers` | | `Hash` | Hash of HTTP request or response headers to add as tags to the `sinatra.request`. Accepts `request` and `response` keys with Array values e.g. `['Last-Modified']`. Adds `http.request.headers.*` and `http.response.headers.*` tags respectively. This option overrides the global `DD_TRACE_HEADER_TAGS`, see [Applying header tags to root spans][header tags] for more information. | `{ response: ['Content-Type', 'X-Request-ID'] }` | +| `resource_script_names` | | `Bool` | Prepend resource names with script name | `false` | ### Sneakers @@ -1933,11 +1955,11 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| ---------- | - | ----- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | -| `enabled` | `DD_TRACE_SNEAKERS_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `tag_body` | | `Bool` | Enable tagging of job message. `true` for on, `false` for off. | `false` | -| `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | +| Key | Env Var | Type | Description | Default | +| ---------- | --------------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | +| `enabled` | `DD_TRACE_SNEAKERS_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `tag_body` | | `Bool` | Enable tagging of job message. `true` for on, `false` for off. | `false` | +| `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | ### Stripe @@ -1955,9 +1977,9 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| --------- | ------------------------------- | ------ | -------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_STRIPE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| Key | Env Var | Type | Description | Default | +| --------- | ------------------------- | ------ | -------------------------------------------- | ------- | +| `enabled` | `DD_TRACE_STRIPE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | ### Sucker Punch @@ -1978,7 +2000,7 @@ LogJob.perform_async('login') | Key | Env Var | Type | Description | Default | | --------- | ------------------------------- | ------ | -------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_SUCKER_PUNCH_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_SUCKER_PUNCH_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | ### Trilogy @@ -1998,14 +2020,14 @@ client.query("SELECT * FROM users WHERE group='x'") `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| -------------- | ------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | -| `enabled` | `DD_TRACE_TRILOGY_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `service_name` | `DD_TRACE_TRILOGY_SERVICE_NAME` | `String` | Name of application running the `trilogy` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `trilogy` | -| `peer_service` | `DD_TRACE_TRILOGY_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | -| `comment_propagation` | `DD_DBM_PROPAGATION_MODE` | `String` | SQL comment propagation mode for database monitoring.
(example: `disabled` \| `service`\| `full`).

**Important**: _Note that enabling SQL comment propagation results in potentially confidential data (service names) being stored in the databases which can then be accessed by other third parties that have been granted access to the database._ | `'disabled'` | -| `append_comment` | | `Bool` | Appends the SQL comment propagation to the query string. Prepends the comment if `false`. For long query strings, the appended propagation comment might be truncated, causing loss of correlation between the query and trace. | `false` | -| `on_error` | | `Proc` | Custom error handler invoked when MySQL raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring errors that are handled at the application level. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | +| Key | Env Var | Type | Description | Default | +| --------------------- | ------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------- | +| `enabled` | `DD_TRACE_TRILOGY_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `service_name` | `DD_TRACE_TRILOGY_SERVICE_NAME` | `String` | Name of application running the `trilogy` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `trilogy` | +| `peer_service` | `DD_TRACE_TRILOGY_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | +| `comment_propagation` | `DD_DBM_PROPAGATION_MODE` | `String` | SQL comment propagation mode for database monitoring.
(example: `disabled` \| `service`\| `full`).

**Important**: _Note that enabling SQL comment propagation results in potentially confidential data (service names) being stored in the databases which can then be accessed by other third parties that have been granted access to the database._ | `'disabled'` | +| `append_comment` | | `Bool` | Appends the SQL comment propagation to the query string. Prepends the comment if `false`. For long query strings, the appended propagation comment might be truncated, causing loss of correlation between the query and trace. | `false` | +| `on_error` | | `Proc` | Custom error handler invoked when MySQL raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring errors that are handled at the application level. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | ## Additional configuration @@ -2032,42 +2054,42 @@ For example, if `tracing.sampling.default_rate` is configured by [Remote Configu **Available configuration options:** -| Setting | Env Var | Type | Default | Description | -| ------------------------------------------------------ | ------------------------------------------------------- | ------------------------------------- | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| **Global** | | | | | -| `agent.host` | `DD_AGENT_HOST` | `String` | `127.0.0.1` | Hostname of Agent to where trace data will be sent. | -| `agent.port` | `DD_TRACE_AGENT_PORT` | `Integer` | `8126` | Port of Agent host to where trace data will be sent. If the [Agent configuration](#configuring-trace-data-ingestion) sets `receiver_port` or `DD_APM_RECEIVER_PORT` to something other than the default `8126`, then `DD_TRACE_AGENT_PORT` or `DD_TRACE_AGENT_URL` must match it. | -| | `DD_TRACE_AGENT_URL` | | `nil` | Sets the URL endpoint where traces are sent. Has priority over `agent.host` and `agent.port`. If the [Agent configuration](#configuring-trace-data-ingestion) sets `receiver_port` or `DD_APM_RECEIVER_PORT` to something other than the default `8126`, then `DD_TRACE_AGENT_PORT` or `DD_TRACE_AGENT_URL` must match it. | -| `diagnostics.debug` | `DD_TRACE_DEBUG` | `Bool` | `false` | Enables or disables debug mode. Prints verbose logs. **NOT recommended for production or other sensitive environments.** See [Debugging and diagnostics](#debugging-and-diagnostics) for more details. | -| `diagnostics.startup_logs.enabled` | `DD_TRACE_STARTUP_LOGS` | `Bool` | `nil` | Prints startup configuration and diagnostics to log. For assessing state of tracing at application startup. See [Debugging and diagnostics](#debugging-and-diagnostics) for more details. | -| `env` | `DD_ENV` | `String` | `nil` | Your application environment. (e.g. `production`, `staging`, etc.) This value is set as a tag on all traces. | -| `service` | `DD_SERVICE` | `String` | _Ruby filename_ | Your application's default service name. (e.g. `billing-api`) This value is set as a tag on all traces. | -| `tags` | `DD_TAGS` | `Hash` | `nil` | Custom tags in value pairs separated by `,` (e.g. `layer:api,team:intake`) These tags are set on all traces. See [Environment and tags](#environment-and-tags) for more details. | -| `time_now_provider` | | `Proc` | `->{ Time.now }` | Changes how time is retrieved. See [Setting the time provider](#setting-the-time-provider) for more details. | -| `version` | `DD_VERSION` | `String` | `nil` | Your application version (e.g. `2.5`, `202003181415`, `1.3-alpha`, etc.) This value is set as a tag on all traces. | -| `telemetry.enabled` | `DD_INSTRUMENTATION_TELEMETRY_ENABLED` | `Bool` | `true` | Allows you to enable sending telemetry data to Datadog. Can be disabled, as documented [here](https://docs.datadoghq.com/tracing/configure_data_security/#telemetry-collection). | -| **Tracing** | | | | | -| `tracing.contrib.peer_service_mapping` | `DD_TRACE_PEER_SERVICE_MAPPING` | `Hash` | `nil` | Defines remapping of `peer.service` tag across all instrumentation. Provide a list of `old_value1:new_value1, old_value2:new_value2, ...` | -| `tracing.contrib.global_default_service_name.enabled` | `DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED` | `Bool` | `false` | Changes the default value for `service_name` to the application service name across all instrumentation | +| Setting | Env Var | Type | Default | Description | +| ------------------------------------------------------ | ------------------------------------------------------- | ------------------------------------- | ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| **Global** | | | | | +| `agent.host` | `DD_AGENT_HOST` | `String` | `127.0.0.1` | Hostname of Agent to where trace data will be sent. | +| `agent.port` | `DD_TRACE_AGENT_PORT` | `Integer` | `8126` | Port of Agent host to where trace data will be sent. If the [Agent configuration](#configuring-trace-data-ingestion) sets `receiver_port` or `DD_APM_RECEIVER_PORT` to something other than the default `8126`, then `DD_TRACE_AGENT_PORT` or `DD_TRACE_AGENT_URL` must match it. | +| | `DD_TRACE_AGENT_URL` | | `nil` | Sets the URL endpoint where traces are sent. Has priority over `agent.host` and `agent.port`. If the [Agent configuration](#configuring-trace-data-ingestion) sets `receiver_port` or `DD_APM_RECEIVER_PORT` to something other than the default `8126`, then `DD_TRACE_AGENT_PORT` or `DD_TRACE_AGENT_URL` must match it. | +| `diagnostics.debug` | `DD_TRACE_DEBUG` | `Bool` | `false` | Enables or disables debug mode. Prints verbose logs. **NOT recommended for production or other sensitive environments.** See [Debugging and diagnostics](#debugging-and-diagnostics) for more details. | +| `diagnostics.startup_logs.enabled` | `DD_TRACE_STARTUP_LOGS` | `Bool` | `nil` | Prints startup configuration and diagnostics to log. For assessing state of tracing at application startup. See [Debugging and diagnostics](#debugging-and-diagnostics) for more details. | +| `env` | `DD_ENV` | `String` | `nil` | Your application environment. (e.g. `production`, `staging`, etc.) This value is set as a tag on all traces. | +| `service` | `DD_SERVICE` | `String` | _Ruby filename_ | Your application's default service name. (e.g. `billing-api`) This value is set as a tag on all traces. | +| `tags` | `DD_TAGS` | `Hash` | `nil` | Custom tags in value pairs separated by `,` (e.g. `layer:api,team:intake`) These tags are set on all traces. See [Environment and tags](#environment-and-tags) for more details. | +| `time_now_provider` | | `Proc` | `->{ Time.now }` | Changes how time is retrieved. See [Setting the time provider](#setting-the-time-provider) for more details. | +| `version` | `DD_VERSION` | `String` | `nil` | Your application version (e.g. `2.5`, `202003181415`, `1.3-alpha`, etc.) This value is set as a tag on all traces. | +| `telemetry.enabled` | `DD_INSTRUMENTATION_TELEMETRY_ENABLED` | `Bool` | `true` | Allows you to enable sending telemetry data to Datadog. Can be disabled, as documented [here](https://docs.datadoghq.com/tracing/configure_data_security/#telemetry-collection). | +| **Tracing** | | | | | +| `tracing.contrib.peer_service_mapping` | `DD_TRACE_PEER_SERVICE_MAPPING` | `Hash` | `nil` | Defines remapping of `peer.service` tag across all instrumentation. Provide a list of `old_value1:new_value1, old_value2:new_value2, ...` | +| `tracing.contrib.global_default_service_name.enabled` | `DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED` | `Bool` | `false` | Changes the default value for `service_name` to the application service name across all instrumentation | | `tracing.propagation_extract_first` | `DD_TRACE_PROPAGATION_EXTRACT_FIRST` | `Bool` | `false` | Stop searching after detecting the first valid propagation format. See [Distributed Tracing](#distributed-tracing) for more details. | -| `tracing.propagation_style_extract` | `DD_TRACE_PROPAGATION_STYLE_EXTRACT` | `Array` | `['Datadog','tracecontext']` | Distributed tracing propagation formats to extract. Overrides `DD_TRACE_PROPAGATION_STYLE`. See [Distributed Tracing](#distributed-tracing) for more details. | -| `tracing.propagation_style_inject` | `DD_TRACE_PROPAGATION_STYLE_INJECT` | `Array` | `['Datadog','tracecontext']` | Distributed tracing propagation formats to inject. Overrides `DD_TRACE_PROPAGATION_STYLE`. See [Distributed Tracing](#distributed-tracing) for more details. | -| `tracing.propagation_style` | `DD_TRACE_PROPAGATION_STYLE` | `Array` | `nil` | Distributed tracing propagation formats to extract and inject. See [Distributed Tracing](#distributed-tracing) for more details. | -| `tracing.enabled` | `DD_TRACE_ENABLED` | `Bool` | `true` | Enables or disables tracing. If set to `false` instrumentation will still run, but no traces are sent to the trace agent. | -| `tracing.header_tags` | `DD_TRACE_HEADER_TAGS` | `Array` | `nil` | Record HTTP headers as span tags. See [Applying header tags to root spans][header tags] for more information. | -| `tracing.instrument(, )` | | | | Activates instrumentation for a specific library. See [Integration instrumentation](#integration-instrumentation) for more details. | -| `tracing.log_injection` | `DD_LOGS_INJECTION` | `Bool` | `true` | Injects [Trace Correlation](#trace-correlation) information into Rails logs if present. Supports the default logger (`ActiveSupport::TaggedLogging`), `lograge`, and `semantic_logger`. | -| `tracing.partial_flush.enabled` | | `Bool` | `false` | Enables or disables partial flushing. Partial flushing submits completed portions of a trace to the agent. Used when tracing instruments long running tasks (e.g. jobs) with many spans. | -| `tracing.partial_flush.min_spans_threshold` | | `Integer` | `500` | The number of spans that must be completed in a trace before partial flushing submits those completed spans. | -| `tracing.sampler` | | `Datadog::Tracing::Sampling::Sampler` | `nil` | Advanced usage only. Sets a custom `Datadog::Tracing::Sampling::Sampler` instance. If provided, the tracer will use this sampler to determine sampling behavior. See [Custom sampling](#custom-sampling) for details. | -| `tracing.sampling.default_rate` | `DD_TRACE_SAMPLE_RATE` | `Float` | `nil` | Sets the trace sampling rate between `0.0` (0%) and `1.0` (100%). | -| `tracing.sampling.rate_limit` | `DD_TRACE_RATE_LIMIT` | `Integer` | `100` (per second) | Sets a maximum number of traces per second to sample. Set a rate limit to avoid the ingestion volume overages in the case of traffic spikes. | +| `tracing.propagation_style_extract` | `DD_TRACE_PROPAGATION_STYLE_EXTRACT` | `Array` | `['Datadog','tracecontext']` | Distributed tracing propagation formats to extract. Overrides `DD_TRACE_PROPAGATION_STYLE`. See [Distributed Tracing](#distributed-tracing) for more details. | +| `tracing.propagation_style_inject` | `DD_TRACE_PROPAGATION_STYLE_INJECT` | `Array` | `['Datadog','tracecontext']` | Distributed tracing propagation formats to inject. Overrides `DD_TRACE_PROPAGATION_STYLE`. See [Distributed Tracing](#distributed-tracing) for more details. | +| `tracing.propagation_style` | `DD_TRACE_PROPAGATION_STYLE` | `Array` | `nil` | Distributed tracing propagation formats to extract and inject. See [Distributed Tracing](#distributed-tracing) for more details. | +| `tracing.enabled` | `DD_TRACE_ENABLED` | `Bool` | `true` | Enables or disables tracing. If set to `false` instrumentation will still run, but no traces are sent to the trace agent. | +| `tracing.header_tags` | `DD_TRACE_HEADER_TAGS` | `Array` | `nil` | Record HTTP headers as span tags. See [Applying header tags to root spans][header tags] for more information. | +| `tracing.instrument(, )` | | | | Activates instrumentation for a specific library. See [Integration instrumentation](#integration-instrumentation) for more details. | +| `tracing.log_injection` | `DD_LOGS_INJECTION` | `Bool` | `true` | Injects [Trace Correlation](#trace-correlation) information into Rails logs if present. Supports the default logger (`ActiveSupport::TaggedLogging`), `lograge`, and `semantic_logger`. | +| `tracing.partial_flush.enabled` | | `Bool` | `false` | Enables or disables partial flushing. Partial flushing submits completed portions of a trace to the agent. Used when tracing instruments long running tasks (e.g. jobs) with many spans. | +| `tracing.partial_flush.min_spans_threshold` | | `Integer` | `500` | The number of spans that must be completed in a trace before partial flushing submits those completed spans. | +| `tracing.sampler` | | `Datadog::Tracing::Sampling::Sampler` | `nil` | Advanced usage only. Sets a custom `Datadog::Tracing::Sampling::Sampler` instance. If provided, the tracer will use this sampler to determine sampling behavior. See [Custom sampling](#custom-sampling) for details. | +| `tracing.sampling.default_rate` | `DD_TRACE_SAMPLE_RATE` | `Float` | `nil` | Sets the trace sampling rate between `0.0` (0%) and `1.0` (100%). | +| `tracing.sampling.rate_limit` | `DD_TRACE_RATE_LIMIT` | `Integer` | `100` (per second) | Sets a maximum number of traces per second to sample. Set a rate limit to avoid the ingestion volume overages in the case of traffic spikes. | | `tracing.sampling.rules` | `DD_TRACE_SAMPLING_RULES` | `String` | `nil` | Sets trace-level sampling rules, matching against the local root span. The format is a `String` with JSON, containing an Array of Objects. Each Object must have a float attribute `sample_rate` (between 0.0 and 1.0, inclusive), and optionally `name`, `service`, `resource`, and `tags` string attributes. `name`, `service`, `resource`, and `tags` control to which traces this sampling rule applies; if they are all absent, then this rule applies to all traces. Rules are evaluated in order of declaration in the array; only the first to match is applied. If none apply, then `tracing.sampling.default_rate` is applied. | -| `tracing.sampling.span_rules` | `DD_SPAN_SAMPLING_RULES`,`ENV_SPAN_SAMPLING_RULES_FILE` | `String` | `nil` | Sets [Single Span Sampling](#single-span-sampling) rules. These rules allow you to keep spans even when their respective traces are dropped. | -| `tracing.trace_id_128_bit_generation_enabled` | `DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED` | `Bool` | `true` | `true` to generate 128 bits trace ID and `false` to generate 64 bits trace ID | -| `tracing.report_hostname` | `DD_TRACE_REPORT_HOSTNAME` | `Bool` | `false` | Adds hostname tag to traces. | -| `tracing.test_mode.enabled` | `DD_TRACE_TEST_MODE_ENABLED` | `Bool` | `false` | Enables or disables test mode, for use of tracing in test suites. | -| `tracing.test_mode.trace_flush` | | `Datadog::Tracing::TraceFlush` | `nil` | Object that determines trace flushing behavior. | +| `tracing.sampling.span_rules` | `DD_SPAN_SAMPLING_RULES`,`ENV_SPAN_SAMPLING_RULES_FILE` | `String` | `nil` | Sets [Single Span Sampling](#single-span-sampling) rules. These rules allow you to keep spans even when their respective traces are dropped. | +| `tracing.trace_id_128_bit_generation_enabled` | `DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED` | `Bool` | `true` | `true` to generate 128 bits trace ID and `false` to generate 64 bits trace ID | +| `tracing.report_hostname` | `DD_TRACE_REPORT_HOSTNAME` | `Bool` | `false` | Adds hostname tag to traces. | +| `tracing.test_mode.enabled` | `DD_TRACE_TEST_MODE_ENABLED` | `Bool` | `false` | Enables or disables test mode, for use of tracing in test suites. | +| `tracing.test_mode.trace_flush` | | `Datadog::Tracing::TraceFlush` | `nil` | Object that determines trace flushing behavior. | #### Custom logging diff --git a/lib/datadog/tracing/contrib.rb b/lib/datadog/tracing/contrib.rb index 13a15640333..4e51e6a5b78 100644 --- a/lib/datadog/tracing/contrib.rb +++ b/lib/datadog/tracing/contrib.rb @@ -55,6 +55,7 @@ module Contrib require_relative 'contrib/httprb/integration' require_relative 'contrib/integration' require_relative 'contrib/kafka/integration' +require_relative 'contrib/karafka' require_relative 'contrib/lograge/integration' require_relative 'contrib/mongodb/integration' require_relative 'contrib/mysql2/integration' diff --git a/lib/datadog/tracing/contrib/karafka.rb b/lib/datadog/tracing/contrib/karafka.rb new file mode 100644 index 00000000000..cc456287e18 --- /dev/null +++ b/lib/datadog/tracing/contrib/karafka.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require_relative 'component' +require_relative 'karafka/integration' +require_relative 'karafka/distributed/propagation' + +module Datadog + module Tracing + module Contrib + # `Karafka` integration public API + module Karafka + def self.inject(digest, data) + raise 'Please invoke Datadog.configure at least once before calling this method' unless @propagation + + @propagation.inject!(digest, data) + end + + def self.extract(data) + raise 'Please invoke Datadog.configure at least once before calling this method' unless @propagation + + @propagation.extract(data) + end + + Contrib::Component.register('karafka') do |config| + tracing = config.tracing + tracing.propagation_style + + @propagation = Sidekiq::Distributed::Propagation.new( + propagation_style_inject: tracing.propagation_style_inject, + propagation_style_extract: tracing.propagation_style_extract, + propagation_extract_first: tracing.propagation_extract_first + ) + end + end + end + end +end diff --git a/lib/datadog/tracing/contrib/karafka/configuration/settings.rb b/lib/datadog/tracing/contrib/karafka/configuration/settings.rb new file mode 100644 index 00000000000..9eae5c6909d --- /dev/null +++ b/lib/datadog/tracing/contrib/karafka/configuration/settings.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require_relative '../../configuration/settings' +require_relative '../ext' + +module Datadog + module Tracing + module Contrib + module Karafka + module Configuration + # @public_api + class Settings < Contrib::Configuration::Settings + option :enabled do |o| + o.type :bool + o.env Ext::ENV_ENABLED + o.default true + end + + option :service_name + + option :distributed_tracing, default: false, type: :bool + end + end + end + end + end +end diff --git a/lib/datadog/tracing/contrib/karafka/distributed/propagation.rb b/lib/datadog/tracing/contrib/karafka/distributed/propagation.rb new file mode 100644 index 00000000000..5aa8fe8e363 --- /dev/null +++ b/lib/datadog/tracing/contrib/karafka/distributed/propagation.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +require_relative '../../../distributed/fetcher' +require_relative '../../../distributed/propagation' +require_relative '../../../distributed/b3_multi' +require_relative '../../../distributed/b3_single' +require_relative '../../../distributed/datadog' +require_relative '../../../distributed/none' +require_relative '../../../distributed/trace_context' +require_relative '../../../configuration/ext' + +module Datadog + module Tracing + module Contrib + module Karafka + module Distributed + # Extracts and injects propagation through Kafka message headers. + class Propagation < Tracing::Distributed::Propagation + def initialize( + propagation_style_inject:, + propagation_style_extract:, + propagation_extract_first: + ) + super( + propagation_styles: { + Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_MULTI_HEADER => + Tracing::Distributed::B3Multi.new(fetcher: Tracing::Distributed::Fetcher), + Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_SINGLE_HEADER => + Tracing::Distributed::B3Single.new(fetcher: Tracing::Distributed::Fetcher), + Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_DATADOG => + Tracing::Distributed::Datadog.new(fetcher: Tracing::Distributed::Fetcher), + Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_TRACE_CONTEXT => + Tracing::Distributed::TraceContext.new(fetcher: Tracing::Distributed::Fetcher), + Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_NONE => Tracing::Distributed::None.new + }, + propagation_style_inject: propagation_style_inject, + propagation_style_extract: propagation_style_extract, + propagation_extract_first: propagation_extract_first + ) + end + end + end + end + end + end +end + diff --git a/lib/datadog/tracing/contrib/karafka/event.rb b/lib/datadog/tracing/contrib/karafka/event.rb new file mode 100644 index 00000000000..b535c4b854e --- /dev/null +++ b/lib/datadog/tracing/contrib/karafka/event.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require_relative '../analytics' +require_relative 'ext' + +module Datadog + module Tracing + module Contrib + module Karafka + module Event + def self.included(base) + base.extend(ClassMethods) + end + + module ClassMethods + def span_options + { service: configuration[:service_name] } + end + + def configuration + Datadog.configuration.tracing[:karafka] + end + end + end + end + end + end +end diff --git a/lib/datadog/tracing/contrib/karafka/events.rb b/lib/datadog/tracing/contrib/karafka/events.rb new file mode 100644 index 00000000000..9ea56969ac0 --- /dev/null +++ b/lib/datadog/tracing/contrib/karafka/events.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require_relative 'events/worker/process' + +module Datadog + module Tracing + module Contrib + module Karafka + # Defines collection of instrumented Kafka events + module Events + ALL = [ + Events::Worker::Process, + ] + + module_function + + def all + self::ALL + end + + def subscribe! + all.each(&:subscribe!) + end + end + end + end + end +end diff --git a/lib/datadog/tracing/contrib/karafka/events/error/occur.rb b/lib/datadog/tracing/contrib/karafka/events/error/occur.rb new file mode 100644 index 00000000000..c97caaa1e1b --- /dev/null +++ b/lib/datadog/tracing/contrib/karafka/events/error/occur.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require_relative '../../ext' +require_relative '../../event' + +require 'byebug' + +module Datadog + module Tracing + module Contrib + module Karafka + module Events + module Error + module Occur + include Karafka::Event + + def self.subscribe! + ::Karafka.monitor.subscribe 'error.consume' do |event| + end + end + end + end + end + end + end + end +end + diff --git a/lib/datadog/tracing/contrib/karafka/events/worker/process.rb b/lib/datadog/tracing/contrib/karafka/events/worker/process.rb new file mode 100644 index 00000000000..95fa3077c4e --- /dev/null +++ b/lib/datadog/tracing/contrib/karafka/events/worker/process.rb @@ -0,0 +1,77 @@ +# frozen_string_literal: true + +require_relative '../../ext' +require_relative '../../event' + +module Datadog + module Tracing + module Contrib + module Karafka + module Events + module Worker + module Process + include Karafka::Event + + def self.subscribe! + ::Karafka.monitor.subscribe 'worker.process' do |event| + # Start a trace + span = Tracing.trace(Ext::SPAN_WORKER_PROCESS, **span_options) + + job = event[:job] + job_type = fetch_job_type(job.class) + consumer = job.executor.topic.consumer + topic = job.executor.topic.name + + action = case job_type + when 'Periodic' + 'tick' + when 'PeriodicNonBlocking' + 'tick' + when 'Shutdown' + 'shutdown' + when 'Revoked' + 'revoked' + when 'RevokedNonBlocking' + 'revoked' + when 'Idle' + 'idle' + when 'Eofed' + 'eofed' + when 'EofedNonBlocking' + 'eofed' + else + 'consume' + end + + span.resource = "#{consumer}##{action}" + span.set_tag(Ext::TAG_TOPIC, topic) if topic + + if action == 'consume' + span.set_tag(Ext::TAG_MESSAGE_COUNT, job.messages.count) + span.set_tag(Ext::TAG_PARTITION, job.executor.partition) + span.set_tag(Ext::TAG_OFFSET, job.messages.first.metadata.offset) + end + + span + end + + ::Karafka.monitor.subscribe 'worker.completed' do |event| + Tracing.active_span&.finish + end + end + + def self.span_options + super.merge({ tags: { Tracing::Metadata::Ext::TAG_OPERATION => Ext::TAG_OPERATION_PROCESS_BATCH } }) + end + + def self.fetch_job_type(job_class) + @job_types_cache ||= {} + @job_types_cache[job_class] ||= job_class.to_s.split('::').last + end + end + end + end + end + end + end +end diff --git a/lib/datadog/tracing/contrib/karafka/ext.rb b/lib/datadog/tracing/contrib/karafka/ext.rb new file mode 100644 index 00000000000..d3be29040e9 --- /dev/null +++ b/lib/datadog/tracing/contrib/karafka/ext.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module Datadog + module Tracing + module Contrib + module Karafka + module Ext + ENV_ENABLED = 'DD_TRACE_KARAFKA_ENABLED' + + SPAN_MESSAGE_CONSUME = 'karafka.consume' + SPAN_WORKER_PROCESS = 'worker.process' + + TAG_TOPIC = 'kafka.topic' + TAG_PARTITION = 'kafka.partition' + TAG_OFFSET = 'kafka.offset' + TAG_OFFSET_LAG = 'kafka.offset_lag' + TAG_MESSAGE_COUNT = 'kafka.message_count' + TAG_MESSAGE_KEY = 'kafka.message_key' + + TAG_OPERATION_PROCESS_BATCH = 'consumer.process_batch' + end + end + end + end +end diff --git a/lib/datadog/tracing/contrib/karafka/integration.rb b/lib/datadog/tracing/contrib/karafka/integration.rb new file mode 100644 index 00000000000..b28cacbd47b --- /dev/null +++ b/lib/datadog/tracing/contrib/karafka/integration.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require_relative '../integration' +require_relative 'patcher' + +module Datadog + module Tracing + module Contrib + module Karafka + # Description of Kafka integration + class Integration + include Contrib::Integration + + MINIMUM_VERSION = Gem::Version.new('2.1.0') + + # @public_api Changing the integration name or integration options can cause breaking changes + register_as :karafka, auto_patch: false + + def self.version + Gem.loaded_specs['karafka'] && Gem.loaded_specs['karafka'].version + end + + def self.loaded? + !defined?(::Karafka).nil? + end + + def self.compatible? + super && version >= MINIMUM_VERSION + end + + def new_configuration + Configuration::Settings.new + end + + def patcher + Patcher + end + end + end + end + end +end diff --git a/lib/datadog/tracing/contrib/karafka/patcher.rb b/lib/datadog/tracing/contrib/karafka/patcher.rb new file mode 100644 index 00000000000..ebd76411812 --- /dev/null +++ b/lib/datadog/tracing/contrib/karafka/patcher.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +require_relative '../patcher' +require_relative 'events' +require_relative 'ext' +require_relative 'distributed/propagation' + +module Datadog + module Tracing + module Contrib + module Karafka + module MessagesPatch + def configuration + Datadog.configuration.tracing[:sidekiq] + end + + def propagation + @propagation ||= Contrib::Sidekiq::Distributed::Propagation.new + end + + def each(&block) + @messages_array.each do |message| + if configuration[:distributed_tracing] + trace_digest = Karafka.extract(message.metadata.headers) + Datadog::Tracing.continue_trace!(trace_digest) if trace_digest + end + + Tracing.trace(Ext::SPAN_MESSAGE_CONSUME) do |span| + span.set_tag(Ext::TAG_OFFSET, message.metadata.offset) + span.set_tag(Ext::TAG_TOPIC, message.topic) + + span.resource = message.topic + + yield message + end + end + end + end + + # Patcher enables patching of 'karafka' module. + module Patcher + include Contrib::Patcher + + module_function + + def target_version + Integration.version + end + + def patch + Events.subscribe! + + ::Karafka::Messages::Messages.prepend(MessagesPatch) + end + end + end + end + end +end diff --git a/spec/datadog/tracing/contrib/karafka/patcher_spec.rb b/spec/datadog/tracing/contrib/karafka/patcher_spec.rb new file mode 100644 index 00000000000..aa709558dec --- /dev/null +++ b/spec/datadog/tracing/contrib/karafka/patcher_spec.rb @@ -0,0 +1,90 @@ +require 'datadog/tracing/contrib/support/spec_helper' +require 'datadog/tracing/contrib/analytics_examples' + +require 'karafka' +require 'datadog' + +RSpec.describe 'Karafka patcher' do + let(:configuration_options) { {} } + let(:client_id) { SecureRandom.uuid } + let(:span) do + spans.find { |s| s.name == span_name } + end + + before do + Datadog.configure do |c| + c.tracing.instrument :karafka, configuration_options + end + end + + around do |example| + # Reset before and after each example; don't allow global state to linger. + Datadog.registry[:karafka].reset_configuration! + example.run + Datadog.registry[:karafka].reset_configuration! + end + + describe 'Karafka::message#consume' do + let(:span_name) { Datadog::Tracing::Contrib::Karafka::Ext::SPAN_MESSAGE_CONSUME } + + it 'is expected to send a span' do + deserializer = ->(_) { 1 } + metadata = ::Karafka::Messages::Metadata.new.tap do |metadata| + metadata['deserializer'] = deserializer + metadata['offset'] = 412 + end + raw_payload = rand.to_s + + message = Karafka::Messages::Message.new(raw_payload, metadata) + allow(message).to receive(:timestamp).and_return(Time.now) + allow(message).to receive(:topic).and_return('topic_a') + + topic = Karafka::Routing::Topic.new('topic_a', double(id: 0)) + + messages = Karafka::Messages::Builders::Messages.call([message], topic, 0, Time.now) + + messages.each do |msg| + expect(msg).to be_a(Karafka::Messages::Message) + end + + expect(spans).to have(1).items + expect(span).to_not be nil + expect(span.get_tag('kafka.offset')).to eq 412 + expect(span.get_tag('kafka.topic')).to eq 'topic_a' + expect(span).to_not have_error + expect(span.resource).to eq 'topic_a' + end + end + + describe 'worker.process' do + let(:span_name) { Datadog::Tracing::Contrib::Karafka::Ext::SPAN_WORKER_PROCESS } + + it 'is expected to send a span' do + deserializer = ->(_) { 1 } + metadata = ::Karafka::Messages::Metadata.new.tap do |metadata| + metadata['deserializer'] = deserializer + metadata['offset'] = 412 + end + raw_payload = rand.to_s + + message = Karafka::Messages::Message.new(raw_payload, metadata) + job = double(executor: double(topic: double(name: 'topic_a', consumer: 'ABC'), partition: 0), messages: [message]) + + Karafka.monitor.instrument('worker.process', { job: job }) do + puts "ac" + end + + Karafka.monitor.instrument('worker.completed', { job: job }) do + puts "ac" + end + + expect(spans).to have(1).items + expect(span).to_not be nil + expect(span.get_tag('kafka.offset')).to eq 412 + expect(span.get_tag('kafka.topic')).to eq 'topic_a' + expect(span.get_tag('kafka.partition')).to eq 0 + expect(span.get_tag('kafka.message_count')).to eq 1 + expect(span.resource).to eq 'ABC#consume' + end + end +end From 10645a73ad7ed9a1a6e4267b154b451031547e34 Mon Sep 17 00:00:00 2001 From: nvh0412 Date: Fri, 22 Nov 2024 16:47:00 +1100 Subject: [PATCH 2/8] chore: Add karafka mapping --- spec/datadog/tracing/contrib_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/datadog/tracing/contrib_spec.rb b/spec/datadog/tracing/contrib_spec.rb index ec3f8f37ca3..f50cdfb2739 100644 --- a/spec/datadog/tracing/contrib_spec.rb +++ b/spec/datadog/tracing/contrib_spec.rb @@ -52,7 +52,8 @@ 'sneakers' => 'Sneakers', 'stripe' => 'Stripe', 'sucker_punch' => 'SuckerPunch', - 'trilogy' => 'Trilogy' + 'trilogy' => 'Trilogy', + 'karafka' => 'Karafka' } Dir.chdir("#{root}/lib/datadog/tracing/contrib") do |pwd| From ecb1897e4d1daf0ee4a2766afa5f0ff50054fc06 Mon Sep 17 00:00:00 2001 From: nvh0412 Date: Sat, 23 Nov 2024 10:06:54 +1100 Subject: [PATCH 3/8] chore: remove redudnant changes --- docs/GettingStarted.md | 406 +++++++++--------- .../contrib/karafka/events/error/occur.rb | 28 -- 2 files changed, 192 insertions(+), 242 deletions(-) delete mode 100644 lib/datadog/tracing/contrib/karafka/events/error/occur.rb diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index eaff2b38aca..8a1196fa138 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -317,7 +317,7 @@ end | Key | Env Var | Type | Description | Default | | --------- | ------------------------------- | ------ | -------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_ACTION_CABLE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_ACTION_CABLE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | ### Action Mailer @@ -335,10 +335,10 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| ------------ | -------------------------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_ACTION_MAILER_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `email_data` | | `Bool` | Whether or not to append additional email payload metadata to `action_mailer.deliver` spans. Fields include `['subject', 'to', 'from', 'bcc', 'cc', 'date', 'perform_deliveries']`. | `false` | +| Key | Env Var | Type | Description | Default | +| ------------ | - | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | +| `enabled` | `DD_TRACE_ACTION_MAILER_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `email_data` | | `Bool` | Whether or not to append additional email payload metadata to `action_mailer.deliver` spans. Fields include `['subject', 'to', 'from', 'bcc', 'cc', 'date', 'perform_deliveries']`. | `false` | ### Action Pack @@ -355,9 +355,9 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| --------- | ------------------------------ | ------ | -------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_ACTION_PACK_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| Key | Env Var | Type | Description | Default | +| --------- | ------------------------------- | ------ | -------------------------------------------- | ------- | +| `enabled` | `DD_TRACE_ACTION_PACK_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | ### Action View @@ -374,10 +374,10 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| -------------------- | ------------------------------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------- | ---------- | -| `enabled` | `DD_TRACE_ACTION_VIEW_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `template_base_path` | | `String` | Used when the template name is parsed. If you don't store your templates in the `views/` folder, you may need to change this value | `'views/'` | +| Key | Env Var | Type | Description | Default | +| -------------------- | - | ------- | ---------------------------------------------------------------------------------------------------------------------------------- | ---------- | +| `enabled` | `DD_TRACE_ACTION_VIEW_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `template_base_path` | | `String` | Used when the template name is parsed. If you don't store your templates in the `views/` folder, you may need to change this value | `'views/'` | ### Active Job @@ -396,9 +396,9 @@ ExampleJob.perform_later `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| --------- | ----------------------------- | ------ | -------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_ACTIVE_JOB_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| Key | Env Var | Type | Description | Default | +| --------- | ------------------------------- | ------ | -------------------------------------------- | ------- | +| `enabled` | `DD_TRACE_ACTIVE_JOB_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | ### Active Model Serializers @@ -418,9 +418,9 @@ ActiveModelSerializers::SerializableResource.new(test_obj).serializable_hash `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| --------- | ------------------------------------------- | ------ | -------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_ACTIVE_MODEL_SERIALIZERS_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| Key | Env Var | Type | Description | Default | +| --------- | ------------------------------- | ------ | -------------------------------------------- | ------- | +| `enabled` | `DD_TRACE_ACTIVE_MODEL_SERIALIZERS_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | ### Active Record @@ -445,10 +445,10 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| -------------- | -------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | -| `enabled` | `DD_TRACE_ACTIVE_RECORD_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `service_name` | | `String` | Override the service name for the SQL query instrumentation. ActiveRecord instantiation instrumentation always uses the application's configured service name. | Name of database adapter (e.g. `'mysql2'`) | +| Key | Env Var | Type | Description | Default | +| -------------- | - | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | +| `enabled` | `DD_TRACE_ACTIVE_RECORD_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `service_name` | | `String` | Override the service name for the SQL query instrumentation. ActiveRecord instantiation instrumentation always uses the application's configured service name. | Name of database adapter (e.g. `'mysql2'`) | **Configuring trace settings per database** @@ -534,10 +534,10 @@ cache.read('city') `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| --------------- | --------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- | -| `enabled` | `DD_TRACE_ACTIVE_SUPPORT_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `cache_service` | | `String` | Name of application running the `active_support` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `active_support-cache` | +| Key | Env Var | Type | Description | Default | +| --------------- | - | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- | +| `enabled` | `DD_TRACE_ACTIVE_SUPPORT_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `cache_service` | | `String` | Name of application running the `active_support` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `active_support-cache` | ### AWS @@ -559,7 +559,7 @@ Aws::S3::Client.new.list_buckets | Key | Env Var | Type | Description | Default | | -------------- | --------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_AWS_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_AWS_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_AWS_SERVICE_NAME` | `String` | Name of application running the `aws` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `aws` | | `peer_service` | `DD_TRACE_AWS_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | @@ -597,9 +597,9 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| --------- | ---------------------------------- | ------ | -------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_CONCURRENT_RUBY_ENABLED` | `Bool` | Whether the integration propagates contexts. | `true` | +| Key | Env Var | Type | Description | Default | +| --------- | ------------------------------- | ------ | -------------------------------------------- | ------- | +| `enabled` | `DD_TRACE_CONCURRENT_RUBY_ENABLED` | `Bool` | Whether the integration propagates contexts. | `true` | ### Dalli @@ -623,7 +623,7 @@ client.set('abc', 123) | Key | Env Var | Type | Description | Default | | ----------------- | ------------------------------------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | -| `enabled` | `DD_TRACE_DALLI_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_DALLI_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `command_enabled` | `DD_TRACE_MEMCACHED_COMMAND_ENABLED` | `Bool` | Collect commands as the `memcached.command` tag. Command `keys` can potentially contain sensitive information. | `false` | | `service_name` | `DD_TRACE_DALLI_SERVICE_NAME` | `String` | Name of application running the `dalli` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `memcached` | | `peer_service` | `DD_TRACE_DALLI_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | @@ -644,10 +644,10 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| ---------- | ------------------------------ | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | -| `enabled` | `DD_TRACE_DELAYED_JOB_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | +| Key | Env Var | Type | Description | Default | +| ---------- | - | ----- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | +| `enabled` | `DD_TRACE_DELAYED_JOB_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | ### Elasticsearch @@ -673,7 +673,7 @@ Datadog.configure_onto(client.transport, **options) | Key | Env Var | Type | Description | Default | | -------------- | ------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------- | -| `enabled` | `DD_TRACE_ELASTICSEARCH_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_ELASTICSEARCH_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_ELASTICSEARCH_SERVICE_NAME` | `String` | Name of application running the `elasticsearch` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `elasticsearch` | | `peer_service` | `DD_TRACE_ELASTICSEARCH_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `quantize` | | `Hash` | Hash containing options for quantization. May include `:show` with an Array of keys to not quantize (or `:all` to skip quantization), or `:exclude` with Array of keys to exclude entirely. | `{}` | @@ -700,7 +700,7 @@ end | Key | Env Var | Type | Description | Default | | --------------------- | ----------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_ETHON_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_ETHON_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_ETHON_SERVICE_NAME` | `String` | Name of application running the `ethon` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `ethon` | | `peer_service` | `DD_TRACE_ETHON_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) | `true` | @@ -733,12 +733,12 @@ connection.get | Key | Env Var | Type | Description | Default | | --------------------- | ----------------------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | -| `enabled` | `DD_TRACE_EXCON_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_EXCON_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_EXCON_SERVICE_NAME` | `String` | Name of application running the `excon` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `excon` | | `peer_service` | `DD_TRACE_EXCON_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) | `true` | | `split_by_domain` | | `Bool` | Uses the request domain as the service name when set to `true`. | `false` | -| `on_error` | | `Proc` | Custom error handler invoked when a request raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | +| `on_error` | | `Proc` | Custom error handler invoked when a request raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | | `error_status_codes` | `DD_TRACE_EXCON_ERROR_STATUS_CODES` | `Array`\|`Range` | Defines HTTP status codes that are traced as errors. Value can be a range (`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `400...600` | **Configuring connections to use different settings** @@ -798,12 +798,12 @@ connection.get('/foo') | Key | Env Var | Type | Description | Default | | --------------------- | ------------------------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | -| `enabled` | `DD_TRACE_FARADAY_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_FARADAY_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_FARADAY_SERVICE_NAME` | `String` | Name of application running the `faraday` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `faraday` | | `peer_service` | `DD_TRACE_FARADAY_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) | `true` | | `split_by_domain` | | `Bool` | Uses the request domain as the service name when set to `true`. | `false` | -| `on_error` | | `Proc` | Custom error handler invoked when a request raises an error. Provided `span` and `error` as arguments. Sets an error on the span by default. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | +| `on_error` | | `Proc` | Custom error handler invoked when a request raises an error. Provided `span` and `error` as arguments. Sets an error on the span by default. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | | `error_status_codes` | `DD_TRACE_FARADAY_ERROR_STATUS_CODES` | `Array`\|`Range` | Defines HTTP status codes that are traced as errors. Value can be a range (`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `400...600` | ### Grape @@ -834,7 +834,7 @@ end | Key | Env Var | Type | Description | Default | | -------------------- | ----------------------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | -| `enabled` | `DD_TRACE_GRAPE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_GRAPE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `error_status_codes` | `DD_TRACE_GRAPE_ERROR_STATUS_CODES` | `Array`\|`Range` | Defines HTTP status codes that are traced as errors. Value can be a range (`400...600`), or an array of ranges/integers `[403, 500...600]`. If configured with environment variable, use dash for range (`'400-599'`) and comma for adding element into an array (`'403,500-599'`) | `500...600` | ### GraphQL @@ -861,15 +861,15 @@ YourSchema.execute(query, variables: {}, context: {}, operation_name: nil) The `instrument :graphql` method accepts the following parameters. Additional options can be substituted in for `options`: -| Key | Env Var | Type | Description | Default | -| ------------------------ | -------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------- | -| `enabled` | `DD_TRACE_GRAPHQL_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `schemas` | | `Array` | Array of `GraphQL::Schema` objects (that support class-based schema only) to trace. If you do not provide any, then tracing will applied to all the schemas. | `[]` | -| `with_unified_tracer` | | `Bool` | (Recommended) Enable to instrument with `UnifiedTrace` tracer for `graphql` >= v2.2, **enabling support for API Catalog**. `with_deprecated_tracer` has priority over this. Default is `false`, using `GraphQL::Tracing::DataDogTrace` instead | `false` | -| `with_deprecated_tracer` | | `Bool` | Enable to instrument with deprecated `GraphQL::Tracing::DataDogTracing`. This has priority over `with_unified_tracer`. Default is `false`, using `GraphQL::Tracing::DataDogTrace` instead | `false` | -| `service_name` | | `String` | Service name used for graphql instrumentation | `'ruby-graphql'` | +| Key | Env Var | Type | Description | Default | +| ------------------------ | -------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------- | +| `enabled` | `DD_TRACE_GRAPHQL_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `schemas` | | `Array` | Array of `GraphQL::Schema` objects (that support class-based schema only) to trace. If you do not provide any, then tracing will applied to all the schemas. | `[]` | +| `with_unified_tracer` | | `Bool` | (Recommended) Enable to instrument with `UnifiedTrace` tracer for `graphql` >= v2.2, **enabling support for API Catalog**. `with_deprecated_tracer` has priority over this. Default is `false`, using `GraphQL::Tracing::DataDogTrace` instead | `false` | +| `with_deprecated_tracer` | | `Bool` | Enable to instrument with deprecated `GraphQL::Tracing::DataDogTracing`. This has priority over `with_unified_tracer`. Default is `false`, using `GraphQL::Tracing::DataDogTrace` instead | `false` | +| `service_name` | | `String` | Service name used for graphql instrumentation | `'ruby-graphql'` | -Once an instrumentation strategy is selected (`with_unified_tracer: true`, `with_deprecated_tracer: true`, or _no option set_ which defaults to `GraphQL::Tracing::DataDogTrace`), it is not possible to change the instrumentation strategy in the same Ruby process. +Once an instrumentation strategy is selected (`with_unified_tracer: true`, `with_deprecated_tracer: true`, or *no option set* which defaults to `GraphQL::Tracing::DataDogTrace`), it is not possible to change the instrumentation strategy in the same Ruby process. This is especially important for [auto instrumented applications](#rails-or-hanami-applications) because an automatic initial instrumentation is always applied at startup, thus such applications will always instrument GraphQL with the default strategy (`GraphQL::Tracing::DataDogTrace`). **Manually configuring GraphQL schemas** @@ -952,7 +952,7 @@ client.my_endpoint(DemoMessage.new(contents: 'hello!')) | Key | Env Var | Type | Description | Default | | --------------------- | ---------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ | -| `enabled` | `DD_TRACE_GRPC_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_GRPC_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_GRPC_SERVICE_NAME` | `String` | Name of application running the `grpc` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `grpc` | | `peer_service` | `DD_TRACE_GRPC_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) | `true` | @@ -995,10 +995,10 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| -------------- | ------------------------- | -------- | -------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_HANAMI_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `service_name` | | `String` | Service name for `hanami` instrumentation. | `nil` | +| Key | Env Var | Type | Description | Default | +| -------------- | - | ------- | ------------------------------------------ | ------- | +| `enabled` | `DD_TRACE_HANAMI_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `service_name` | | `String` | Service name for `hanami` instrumentation. | `nil` | ### http.rb @@ -1021,7 +1021,7 @@ end | Key | Env Var | Type | Description | Default | | --------------------- | ------------------------------------ | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | -| `enabled` | `DD_TRACE_HTTPRB_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_HTTPRB_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_HTTPRB_SERVICE_NAME` | `String` | Name of application running the `httprb` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `httprb` | | `peer_service` | `DD_TRACE_HTTPRB_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) | `true` | @@ -1049,7 +1049,7 @@ end | Key | Env Var | Type | Description | Default | | --------------------- | ---------------------------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | -| `enabled` | `DD_TRACE_HTTPCLIENT_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_HTTPCLIENT_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_HTTPCLIENT_SERVICE_NAME` | `String` | Name of application running the `httpclient` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `httpclient` | | `peer_service` | `DD_TRACE_HTTPCLIENT_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) | `true` | @@ -1093,31 +1093,9 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| --------- | ------------------------ | ------ | -------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_KAFKA_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | - -### Karafka - -The karafka integration provides tracing of the `karafka` gem: - -You can enable it through `Datadog.configure`: - -```ruby -require 'karafka' -require 'datadog' - -Datadog.configure do |c| - c.tracing.instrument :karafka, **options -end -``` - -`options` are the following keyword arguments: - -| Key | Env Var | Type | Description | Default | -| --------------------- | ------------------------ | ------ | --------------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_KAFKA_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) | `false` | +| Key | Env Var | Type | Description | Default | +| --------- | ------------------------------- | ------ | -------------------------------------------- | ------- | +| `enabled` | `DD_TRACE_KAFKA_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | ### MongoDB @@ -1144,7 +1122,7 @@ Datadog.configure_onto(client, **options) | Key | Env Var | Type | Description | Default | | -------------- | ----------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ | -| `enabled` | `DD_TRACE_MONGO_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_MONGO_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_MONGO_SERVICE_NAME` | `String` | Name of application running the `mongo` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `mongodb` | | `peer_service` | `DD_TRACE_MONGO_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `quantize` | | `Hash` | Hash containing options for quantization. May include `:show` with an Array of keys to not quantize (or `:all` to skip quantization), or `:exclude` with Array of keys to exclude entirely. | `{ show: [:collection, :database, :operation] }` | @@ -1200,11 +1178,11 @@ client.query("SELECT * FROM users WHERE group='x'") | Key | Env Var | Type | Description | Default | | --------------------- | ------------------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------- | -| `enabled` | `DD_TRACE_MYSQL2_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_MYSQL2_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_MYSQL2_SERVICE_NAME` | `String` | Name of application running the `mysql2` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `mysql2` | | `peer_service` | `DD_TRACE_MYSQL2_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `comment_propagation` | `DD_DBM_PROPAGATION_MODE` | `String` | SQL comment propagation mode for database monitoring.
(example: `disabled` \| `service`\| `full`).

**Important**: _Note that enabling SQL comment propagation results in potentially confidential data (service names) being stored in the databases which can then be accessed by other third parties that have been granted access to the database._ | `'disabled'` | -| `append_comment` | | `Bool` | Appends the SQL comment propagation to the query string. Prepends the comment if `false`. For long query strings, the appended propagation comment might be truncated, causing loss of correlation between the query and trace. | `false` | +| `append_comment` | | `Bool` | Appends the SQL comment propagation to the query string. Prepends the comment if `false`. For long query strings, the appended propagation comment might be truncated, causing loss of correlation between the query and trace. | `false` | | `on_error` | | `Proc` | Custom error handler invoked when MySQL raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring errors that are handled at the application level. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | ### Net/HTTP @@ -1237,7 +1215,7 @@ content = Net::HTTP.get(URI('http://127.0.0.1/index.html')) | Key | Env Var | Type | Description | Default | | --------------------- | ---------------------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | -| `enabled` | `DD_TRACE_HTTP_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_HTTP_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_NET_HTTP_SERVICE_NAME` | `String` | Name of application running the `net/http` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `net/http` | | `peer_service` | `DD_TRACE_NET_HTTP_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) | `true` | @@ -1276,7 +1254,7 @@ client.cluster.health | Key | Env Var | Type | Description | Default | | -------------- | ---------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | -| `enabled` | `DD_TRACE_OPENSEARCH_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_OPENSEARCH_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_OPENSEARCH_SERVICE_NAME` | `String` | Name of application running the `opensearch` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `opensearch` | | `peer_service` | `DD_TRACE_OPENSEARCH_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `quantize` | | `Hash` | Hash containing options for quantization. May include `:show` with an Array of keys to not quantize (or `:all` to skip quantization), or `:exclude` with Array of keys to exclude entirely. | `{}` | @@ -1300,14 +1278,14 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| --------------------- | -------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | -| `enabled` | `DD_TRACE_PG_ENABLED` | `true` | Whether the integration should create spans. | `true` | -| `service_name` | `DD_TRACE_PG_SERVICE_NAME` | `String` | Name of application running the `pg` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `pg` | -| `peer_service` | `DD_TRACE_PG_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | -| `comment_propagation` | `DD_DBM_PROPAGATION_MODE` | `String` | SQL comment propagation mode for database monitoring.
(example: `disabled` \| `service`\| `full`).

**Important**: _Note that enabling sql comment propagation results in potentially confidential data (service names) being stored in the databases which can then be accessed by other 3rd parties that have been granted access to the database._ | `'disabled'` | -| `append_comment` | | `Bool` | Appends the SQL comment propagation to the query string. Prepends the comment if `false`. For long query strings, the appended propagation comment might be truncated, causing loss of correlation between the query and trace. | `false` | -| `on_error` | | `Proc` | Custom error handler invoked when PG raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring errors from Postgres that are handled at the application level. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | +| Key | Env Var | Type | Description | Default | +| --------------------- | -------------------------- | ------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | +| `enabled` | `DD_TRACE_PG_ENABLED` | `true` | Whether the integration should create spans. | `true` | +| `service_name` | `DD_TRACE_PG_SERVICE_NAME` | `String` | Name of application running the `pg` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `pg` | +| `peer_service` | `DD_TRACE_PG_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | +| `comment_propagation` | `DD_DBM_PROPAGATION_MODE` | `String` | SQL comment propagation mode for database monitoring.
(example: `disabled` \| `service`\| `full`).

**Important**: _Note that enabling sql comment propagation results in potentially confidential data (service names) being stored in the databases which can then be accessed by other 3rd parties that have been granted access to the database._ | `'disabled'` | +| `append_comment` | | `Bool` | Appends the SQL comment propagation to the query string. Prepends the comment if `false`. For long query strings, the appended propagation comment might be truncated, causing loss of correlation between the query and trace. | `false` | +| `on_error` | | `Proc` | Custom error handler invoked when PG raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring errors from Postgres that are handled at the application level. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | ### Presto @@ -1338,7 +1316,7 @@ client.run("select * from system.nodes") | Key | Env Var | Type | Description | Default | | -------------- | ------------------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | -| `enabled` | `DD_TRACE_PRESTO_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_PRESTO_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_PRESTO_SERVICE_NAME` | `String` | Name of application running the `presto` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `presto` | | `peer_service` | `DD_TRACE_PRESTO_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | @@ -1360,7 +1338,7 @@ end | Key | Env Var | Type | Description | Default | | ---------- | ------------------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ | -| `enabled` | `DD_TRACE_QUE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_QUE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `tag_args` | `DD_TRACE_QUE_TAG_ARGS_ENABLED` | `Bool` | Enable tagging of a job's args field. `true` for on, `false` for off. | `false` | | `tag_data` | `DD_TRACE_QUE_TAG_DATA_ENABLED` | `Bool` | Enable tagging of a job's data field. `true` for on, `false` for off. | `false` | | `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error \| span.set_error(error) unless span.nil? }` | @@ -1383,7 +1361,7 @@ end | Key | Env Var | Type | Description | Default | | -------------- | ------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | -| `enabled` | `DD_TRACE_RACECAR_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_RACECAR_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_RACECAR_SERVICE_NAME` | `String` | Name of application running the `racecar` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `racecar` | ### Rack @@ -1411,24 +1389,24 @@ run app `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| -------------------------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------ | -| `enabled` | `DD_TRACE_RACK_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `application` | | [`Rack Application`](https://github.com/rack/rack/blob/800e53fbe15b3424b7a8946b067bf6f2e648d5a8/SPEC.rdoc#label-Rack+applications) | Your Rack application. Required for `middleware_names`. | `nil` | -| `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) so that this service trace is connected with a trace of another service if tracing headers are received | `true` | -| `headers` | | `Hash` | Hash of HTTP request or response headers to add as tags to the `rack.request`. Accepts `request` and `response` keys with Array values e.g. `['Last-Modified']`. Adds `http.request.headers.*` and `http.response.headers.*` tags respectively. This option overrides the global `DD_TRACE_HEADER_TAGS`, see [Applying header tags to root spans][header tags] for more information. | `{ response: ['Content-Type', 'X-Request-ID'] }` | -| `middleware_names` | | `Bool` | Enable this if you want to use the last executed middleware class as the resource name for the `rack` span. If enabled alongside the `rails` instrumention, `rails` takes precedence by setting the `rack` resource name to the active `rails` controller when applicable. Requires `application` option to use. | `false` | -| `quantize` | | `Hash` | Hash containing options for quantization. May include `:query` or `:fragment`. | `{}` | -| `quantize.base` | | | Defines behavior for URL base (scheme, host, port). May be `:show` to keep URL base in `http.url` tag and not set `http.base_url` tag, or `nil` to remove URL base from `http.url` tag by default, leaving a path and setting `http.base_url`. Option must be nested inside the `quantize` option. | `nil` | -| `quantize.query` | | | Hash containing options for query portion of URL quantization. May include `:show` or `:exclude`. See options below. Option must be nested inside the `quantize` option. | `{}` | -| `quantize.query.show` | | | Defines which values should always be shown. May be an Array of strings, `:all` to show all values, or `nil` to show no values. Option must be nested inside the `query` option. | `nil` | -| `quantize.query.exclude` | | | Defines which values should be removed entirely. May be an Array of strings, `:all` to remove the query string entirely, or `nil` to exclude nothing. Option must be nested inside the `query` option. | `nil` | -| `quantize.query.obfuscate` | | | Defines query string redaction behaviour. May be a hash of options, `:internal` to use the default internal obfuscation settings, or `nil` to disable obfuscation. Note that obfuscation is a string-wise operation, not a key-value operation. When enabled, `query.show` defaults to `:all` if otherwise unset. Option must be nested inside the `query` option. | `nil` | -| `quantize.query.obfuscate.with` | | | Defines the string to replace obfuscated matches with. May be a String. Option must be nested inside the `query.obfuscate` option. | `''` | -| `quantize.query.obfuscate.regex` | | | Defines the regex with which the query string will be redacted. May be a Regexp, or `:internal` to use the default internal Regexp, which redacts well-known sensitive data. Each match is redacted entirely by replacing it with `query.obfuscate.with`. Option must be nested inside the `query.obfuscate` option. | `:internal` | -| `quantize.fragment` | | | Defines behavior for URL fragments. May be `:show` to show URL fragments, or `nil` to remove fragments. Option must be nested inside the `quantize` option. | `nil` | -| `request_queuing` | | `Bool` | Track HTTP request time spent in the queue of the frontend server. See [HTTP request queuing](#http-request-queuing) for setup details. | `false` | -| `web_service_name` | | `String` | Service name for frontend server request queuing spans. (e.g. `'nginx'`) | `'web-server'` | +| Key | Env Var | Type | Description | Default | +| -------------------------------- | - | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------ | +| `enabled` | `DD_TRACE_RACK_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `application` | | [`Rack Application`](https://github.com/rack/rack/blob/800e53fbe15b3424b7a8946b067bf6f2e648d5a8/SPEC.rdoc#label-Rack+applications) | Your Rack application. Required for `middleware_names`. | `nil` | +| `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) so that this service trace is connected with a trace of another service if tracing headers are received | `true` | +| `headers` | | `Hash` | Hash of HTTP request or response headers to add as tags to the `rack.request`. Accepts `request` and `response` keys with Array values e.g. `['Last-Modified']`. Adds `http.request.headers.*` and `http.response.headers.*` tags respectively. This option overrides the global `DD_TRACE_HEADER_TAGS`, see [Applying header tags to root spans][header tags] for more information. | `{ response: ['Content-Type', 'X-Request-ID'] }` | +| `middleware_names` | | `Bool` | Enable this if you want to use the last executed middleware class as the resource name for the `rack` span. If enabled alongside the `rails` instrumention, `rails` takes precedence by setting the `rack` resource name to the active `rails` controller when applicable. Requires `application` option to use. | `false` | +| `quantize` | | `Hash` | Hash containing options for quantization. May include `:query` or `:fragment`. | `{}` | +| `quantize.base` | | | Defines behavior for URL base (scheme, host, port). May be `:show` to keep URL base in `http.url` tag and not set `http.base_url` tag, or `nil` to remove URL base from `http.url` tag by default, leaving a path and setting `http.base_url`. Option must be nested inside the `quantize` option. | `nil` | +| `quantize.query` | | | Hash containing options for query portion of URL quantization. May include `:show` or `:exclude`. See options below. Option must be nested inside the `quantize` option. | `{}` | +| `quantize.query.show` | | | Defines which values should always be shown. May be an Array of strings, `:all` to show all values, or `nil` to show no values. Option must be nested inside the `query` option. | `nil` | +| `quantize.query.exclude` | | | Defines which values should be removed entirely. May be an Array of strings, `:all` to remove the query string entirely, or `nil` to exclude nothing. Option must be nested inside the `query` option. | `nil` | +| `quantize.query.obfuscate` | | | Defines query string redaction behaviour. May be a hash of options, `:internal` to use the default internal obfuscation settings, or `nil` to disable obfuscation. Note that obfuscation is a string-wise operation, not a key-value operation. When enabled, `query.show` defaults to `:all` if otherwise unset. Option must be nested inside the `query` option. | `nil` | +| `quantize.query.obfuscate.with` | | | Defines the string to replace obfuscated matches with. May be a String. Option must be nested inside the `query.obfuscate` option. | `''` | +| `quantize.query.obfuscate.regex` | | | Defines the regex with which the query string will be redacted. May be a Regexp, or `:internal` to use the default internal Regexp, which redacts well-known sensitive data. Each match is redacted entirely by replacing it with `query.obfuscate.with`. Option must be nested inside the `query.obfuscate` option. | `:internal` | +| `quantize.fragment` | | | Defines behavior for URL fragments. May be `:show` to show URL fragments, or `nil` to remove fragments. Option must be nested inside the `quantize` option. | `nil` | +| `request_queuing` | | `Bool` | Track HTTP request time spent in the queue of the frontend server. See [HTTP request queuing](#http-request-queuing) for setup details. | `false` | +| `web_service_name` | | `String` | Service name for frontend server request queuing spans. (e.g. `'nginx'`) | `'web-server'` | Deprecation notice: @@ -1504,15 +1482,15 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| --------------------- | ------------------------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- | -| `enabled` | `DD_TRACE_RAILS_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) so that this service trace is connected with a trace of another service if tracing headers are received | `true` | -| `request_queuing` | | `Bool` | Track HTTP request time spent in the queue of the frontend server. See [HTTP request queuing](#http-request-queuing) for setup details. | `false` | -| `middleware` | | `Bool` | Add the trace middleware to the Rails application. Set to `false` if you don't want the middleware to load. | `true` | -| `middleware_names` | | `Bool` | Enables any short-circuited middleware requests to display the middleware name as a resource for the trace. | `false` | -| `service_name` | | `String` | Service name used when tracing application requests (on the `rack` level) | `''` (inferred from your Rails application namespace) | -| `template_base_path` | | `String` | Used when the template name is parsed. If you don't store your templates in the `views/` folder, you may need to change this value | `'views/'` | +| Key | Env Var | Type | Description | Default | +| --------------------- | - | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- | +| `enabled` | `DD_TRACE_RAILS_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) so that this service trace is connected with a trace of another service if tracing headers are received | `true` | +| `request_queuing` | | `Bool` | Track HTTP request time spent in the queue of the frontend server. See [HTTP request queuing](#http-request-queuing) for setup details. | `false` | +| `middleware` | | `Bool` | Add the trace middleware to the Rails application. Set to `false` if you don't want the middleware to load. | `true` | +| `middleware_names` | | `Bool` | Enables any short-circuited middleware requests to display the middleware name as a resource for the trace. | `false` | +| `service_name` | | `String` | Service name used when tracing application requests (on the `rack` level) | `''` (inferred from your Rails application namespace) | +| `template_base_path` | | `String` | Used when the template name is parsed. If you don't store your templates in the `views/` folder, you may need to change this value | `'views/'` | **Supported versions** @@ -1552,13 +1530,13 @@ Rake::Task['my_task'].invoke `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| -------------- | ----------------------- | -------- | -------------------------------------------------------------------------------------------------------- | -------- | -| `enabled` | | `Bool` | Defines whether Rake tasks should be traced. Useful for temporarily disabling tracing. `true` or `false` | `true` | -| `quantize` | | `Hash` | Hash containing options for quantization of task arguments. See below for more details and examples. | `{}` | -| `service_name` | | `String` | Service name used for `rake` instrumentation | `'rake'` | -| `tasks` | | `Array` | Names of the Rake tasks to instrument | `[]` | -| `enabled` | `DD_TRACE_RAKE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| Key | Env Var| Type | Description | Default | +| -------------- | - | ------- | -------------------------------------------------------------------------------------------------------- | -------- | +| `enabled` | | `Bool` | Defines whether Rake tasks should be traced. Useful for temporarily disabling tracing. `true` or `false` | `true` | +| `quantize` | | `Hash` | Hash containing options for quantization of task arguments. See below for more details and examples. | `{}` | +| `service_name` | | `String` | Service name used for `rake` instrumentation | `'rake'` | +| `tasks` | | `Array` | Names of the Rake tasks to instrument | `[]` | +| `enabled` | `DD_TRACE_RAKE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | **Configuring task quantization behavior** @@ -1615,7 +1593,7 @@ redis.set 'foo', 'bar' | Key | Env Var | Type | Description | Default | | -------------- | ----------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_REDIS_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_REDIS_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_REDIS_SERVICE_NAME` | `String` | Name of application running the `redis` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `redis` | | `peer_service` | `DD_TRACE_REDIS_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `command_args` | `DD_REDIS_COMMAND_ARGS` | `Bool` | Show the command arguments (for example, `key` in `GET key`) as resource name and tag. If `false`, only the command name is shown (for example, `GET`). | false | @@ -1729,10 +1707,10 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| ---------- | ------------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | -| `enabled` | `DD_TRACE_RESQUE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | +| Key | Env Var | Type | Description | Default | +| ---------- | - | ----- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | +| `enabled` | `DD_TRACE_RESQUE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | ### Rest Client @@ -1751,7 +1729,7 @@ end | Key | Env Var | Type | Description | Default | | --------------------- | ----------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | -| `enabled` | `DD_TRACE_REST_CLIENT_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_REST_CLIENT_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | | `service_name` | `DD_TRACE_REST_CLIENT_SERVICE_NAME` | `String` | Name of application running the `rest_client` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `rest_client` | | `peer_service` | `DD_TRACE_REST_CLIENT_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | | `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) | `true` | @@ -1786,10 +1764,10 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| -------------- | ----------------------- | -------- | -------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_RODA_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `service_name` | | `String` | Service name for `roda` instrumentation. | `nil` | +| Key | Env Var | Type | Description | Default | +| -------------- | - | ------- | ---------------------------------------- | ------- | +| `enabled` | `DD_TRACE_RODA_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `service_name` | | `String` | Service name for `roda` instrumentation. | `nil` | ### Sequel @@ -1819,10 +1797,10 @@ articles.all `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| -------------- | ------------------------- | -------- | -------------------------------------------- | ------------------------------------------ | -| `enabled` | `DD_TRACE_SEQUEL_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `service_name` | | `String` | Service name for `sequel` instrumentation | Name of database adapter (e.g. `'mysql2'`) | +| Key | Env Var | Type | Description | Default | +| -------------- | - | ------- | ----------------------------------------- | ------------------------------------------ | +| `enabled` | `DD_TRACE_SEQUEL_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `service_name` | | `String` | Service name for `sequel` instrumentation | Name of database adapter (e.g. `'mysql2'`) | **Configuring databases to use different settings** @@ -1853,11 +1831,11 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| ---------- | ---------------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | -| `enabled` | `DD_TRACE_SHORYUKEN_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `tag_body` | | `Bool` | Tag spans with the SQS message body `true` or `false` | `false` | -| `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | +| Key | Env Var | Type | Description | Default | +| ---------- | - | ----- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | +| `enabled` | `DD_TRACE_SHORYUKEN_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `tag_body` | | `Bool` | Tag spans with the SQS message body `true` or `false` | `false` | +| `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | ### Sidekiq @@ -1875,12 +1853,12 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| --------------------- | -------------------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | -| `enabled` | `DD_TRACE_SIDEKIQ_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `distributed_tracing` | | `Bool` | Enabling [distributed tracing](#distributed-tracing) creates a parent-child relationship between the `sidekiq.push` span and the `sidekiq.job` span.

**Important**: _Enabling distributed_tracing for asynchronous processing can result in drastic changes in your trace graph. Such cases include long running jobs, retried jobs, and jobs scheduled in the far future. Make sure to inspect your traces after enabling this feature._ | `false` | -| `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | -| `quantize` | | `Hash` | Hash containing options for quantization of job arguments. | `{}` | +| Key | Env Var | Type | Description | Default | +| --------------------- | - | ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | +| `enabled` | `DD_TRACE_SIDEKIQ_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `distributed_tracing` | | `Bool` | Enabling [distributed tracing](#distributed-tracing) creates a parent-child relationship between the `sidekiq.push` span and the `sidekiq.job` span.

**Important**: _Enabling distributed_tracing for asynchronous processing can result in drastic changes in your trace graph. Such cases include long running jobs, retried jobs, and jobs scheduled in the far future. Make sure to inspect your traces after enabling this feature._ | `false` | +| `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | +| `quantize` | | `Hash` | Hash containing options for quantization of job arguments. | `{}` | ### Sinatra @@ -1932,12 +1910,12 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| ----------------------- | -------------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ | -| `enabled` | `DD_TRACE_SINATRA_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) so that this service trace is connected with a trace of another service if tracing headers are received | `true` | -| `headers` | | `Hash` | Hash of HTTP request or response headers to add as tags to the `sinatra.request`. Accepts `request` and `response` keys with Array values e.g. `['Last-Modified']`. Adds `http.request.headers.*` and `http.response.headers.*` tags respectively. This option overrides the global `DD_TRACE_HEADER_TAGS`, see [Applying header tags to root spans][header tags] for more information. | `{ response: ['Content-Type', 'X-Request-ID'] }` | -| `resource_script_names` | | `Bool` | Prepend resource names with script name | `false` | +| Key | Env Var | Type | Description | Default | +| ----------------------- | - | ----- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ | +| `enabled` | `DD_TRACE_SINATRA_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) so that this service trace is connected with a trace of another service if tracing headers are received | `true` | +| `headers` | | `Hash` | Hash of HTTP request or response headers to add as tags to the `sinatra.request`. Accepts `request` and `response` keys with Array values e.g. `['Last-Modified']`. Adds `http.request.headers.*` and `http.response.headers.*` tags respectively. This option overrides the global `DD_TRACE_HEADER_TAGS`, see [Applying header tags to root spans][header tags] for more information. | `{ response: ['Content-Type', 'X-Request-ID'] }` | +| `resource_script_names` | | `Bool` | Prepend resource names with script name | `false` | ### Sneakers @@ -1955,11 +1933,11 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| ---------- | --------------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | -| `enabled` | `DD_TRACE_SNEAKERS_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `tag_body` | | `Bool` | Enable tagging of job message. `true` for on, `false` for off. | `false` | -| `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | +| Key | Env Var | Type | Description | Default | +| ---------- | - | ----- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | +| `enabled` | `DD_TRACE_SNEAKERS_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `tag_body` | | `Bool` | Enable tagging of job message. `true` for on, `false` for off. | `false` | +| `on_error` | | `Proc` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | ### Stripe @@ -1977,9 +1955,9 @@ end `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| --------- | ------------------------- | ------ | -------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_STRIPE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| Key | Env Var | Type | Description | Default | +| --------- | ------------------------------- | ------ | -------------------------------------------- | ------- | +| `enabled` | `DD_TRACE_STRIPE_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | ### Sucker Punch @@ -2000,7 +1978,7 @@ LogJob.perform_async('login') | Key | Env Var | Type | Description | Default | | --------- | ------------------------------- | ------ | -------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_SUCKER_PUNCH_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `enabled` | `DD_TRACE_SUCKER_PUNCH_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | ### Trilogy @@ -2020,14 +1998,14 @@ client.query("SELECT * FROM users WHERE group='x'") `options` are the following keyword arguments: -| Key | Env Var | Type | Description | Default | -| --------------------- | ------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------- | -| `enabled` | `DD_TRACE_TRILOGY_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `service_name` | `DD_TRACE_TRILOGY_SERVICE_NAME` | `String` | Name of application running the `trilogy` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `trilogy` | -| `peer_service` | `DD_TRACE_TRILOGY_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | -| `comment_propagation` | `DD_DBM_PROPAGATION_MODE` | `String` | SQL comment propagation mode for database monitoring.
(example: `disabled` \| `service`\| `full`).

**Important**: _Note that enabling SQL comment propagation results in potentially confidential data (service names) being stored in the databases which can then be accessed by other third parties that have been granted access to the database._ | `'disabled'` | -| `append_comment` | | `Bool` | Appends the SQL comment propagation to the query string. Prepends the comment if `false`. For long query strings, the appended propagation comment might be truncated, causing loss of correlation between the query and trace. | `false` | -| `on_error` | | `Proc` | Custom error handler invoked when MySQL raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring errors that are handled at the application level. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | +| Key | Env Var | Type | Description | Default | +| -------------- | ------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | +| `enabled` | `DD_TRACE_TRILOGY_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `service_name` | `DD_TRACE_TRILOGY_SERVICE_NAME` | `String` | Name of application running the `trilogy` instrumentation. May be overridden by `global_default_service_name`. [See _Additional Configuration_ for more details](#additional-configuration) | `trilogy` | +| `peer_service` | `DD_TRACE_TRILOGY_PEER_SERVICE` | `String` | Name of external service the application connects to | `nil` | +| `comment_propagation` | `DD_DBM_PROPAGATION_MODE` | `String` | SQL comment propagation mode for database monitoring.
(example: `disabled` \| `service`\| `full`).

**Important**: _Note that enabling SQL comment propagation results in potentially confidential data (service names) being stored in the databases which can then be accessed by other third parties that have been granted access to the database._ | `'disabled'` | +| `append_comment` | | `Bool` | Appends the SQL comment propagation to the query string. Prepends the comment if `false`. For long query strings, the appended propagation comment might be truncated, causing loss of correlation between the query and trace. | `false` | +| `on_error` | | `Proc` | Custom error handler invoked when MySQL raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring errors that are handled at the application level. | `proc { \|span, error\| span.set_error(error) unless span.nil? }` | ## Additional configuration @@ -2054,42 +2032,42 @@ For example, if `tracing.sampling.default_rate` is configured by [Remote Configu **Available configuration options:** -| Setting | Env Var | Type | Default | Description | -| ------------------------------------------------------ | ------------------------------------------------------- | ------------------------------------- | ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| **Global** | | | | | -| `agent.host` | `DD_AGENT_HOST` | `String` | `127.0.0.1` | Hostname of Agent to where trace data will be sent. | -| `agent.port` | `DD_TRACE_AGENT_PORT` | `Integer` | `8126` | Port of Agent host to where trace data will be sent. If the [Agent configuration](#configuring-trace-data-ingestion) sets `receiver_port` or `DD_APM_RECEIVER_PORT` to something other than the default `8126`, then `DD_TRACE_AGENT_PORT` or `DD_TRACE_AGENT_URL` must match it. | -| | `DD_TRACE_AGENT_URL` | | `nil` | Sets the URL endpoint where traces are sent. Has priority over `agent.host` and `agent.port`. If the [Agent configuration](#configuring-trace-data-ingestion) sets `receiver_port` or `DD_APM_RECEIVER_PORT` to something other than the default `8126`, then `DD_TRACE_AGENT_PORT` or `DD_TRACE_AGENT_URL` must match it. | -| `diagnostics.debug` | `DD_TRACE_DEBUG` | `Bool` | `false` | Enables or disables debug mode. Prints verbose logs. **NOT recommended for production or other sensitive environments.** See [Debugging and diagnostics](#debugging-and-diagnostics) for more details. | -| `diagnostics.startup_logs.enabled` | `DD_TRACE_STARTUP_LOGS` | `Bool` | `nil` | Prints startup configuration and diagnostics to log. For assessing state of tracing at application startup. See [Debugging and diagnostics](#debugging-and-diagnostics) for more details. | -| `env` | `DD_ENV` | `String` | `nil` | Your application environment. (e.g. `production`, `staging`, etc.) This value is set as a tag on all traces. | -| `service` | `DD_SERVICE` | `String` | _Ruby filename_ | Your application's default service name. (e.g. `billing-api`) This value is set as a tag on all traces. | -| `tags` | `DD_TAGS` | `Hash` | `nil` | Custom tags in value pairs separated by `,` (e.g. `layer:api,team:intake`) These tags are set on all traces. See [Environment and tags](#environment-and-tags) for more details. | -| `time_now_provider` | | `Proc` | `->{ Time.now }` | Changes how time is retrieved. See [Setting the time provider](#setting-the-time-provider) for more details. | -| `version` | `DD_VERSION` | `String` | `nil` | Your application version (e.g. `2.5`, `202003181415`, `1.3-alpha`, etc.) This value is set as a tag on all traces. | -| `telemetry.enabled` | `DD_INSTRUMENTATION_TELEMETRY_ENABLED` | `Bool` | `true` | Allows you to enable sending telemetry data to Datadog. Can be disabled, as documented [here](https://docs.datadoghq.com/tracing/configure_data_security/#telemetry-collection). | -| **Tracing** | | | | | -| `tracing.contrib.peer_service_mapping` | `DD_TRACE_PEER_SERVICE_MAPPING` | `Hash` | `nil` | Defines remapping of `peer.service` tag across all instrumentation. Provide a list of `old_value1:new_value1, old_value2:new_value2, ...` | -| `tracing.contrib.global_default_service_name.enabled` | `DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED` | `Bool` | `false` | Changes the default value for `service_name` to the application service name across all instrumentation | +| Setting | Env Var | Type | Default | Description | +| ------------------------------------------------------ | ------------------------------------------------------- | ------------------------------------- | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| **Global** | | | | | +| `agent.host` | `DD_AGENT_HOST` | `String` | `127.0.0.1` | Hostname of Agent to where trace data will be sent. | +| `agent.port` | `DD_TRACE_AGENT_PORT` | `Integer` | `8126` | Port of Agent host to where trace data will be sent. If the [Agent configuration](#configuring-trace-data-ingestion) sets `receiver_port` or `DD_APM_RECEIVER_PORT` to something other than the default `8126`, then `DD_TRACE_AGENT_PORT` or `DD_TRACE_AGENT_URL` must match it. | +| | `DD_TRACE_AGENT_URL` | | `nil` | Sets the URL endpoint where traces are sent. Has priority over `agent.host` and `agent.port`. If the [Agent configuration](#configuring-trace-data-ingestion) sets `receiver_port` or `DD_APM_RECEIVER_PORT` to something other than the default `8126`, then `DD_TRACE_AGENT_PORT` or `DD_TRACE_AGENT_URL` must match it. | +| `diagnostics.debug` | `DD_TRACE_DEBUG` | `Bool` | `false` | Enables or disables debug mode. Prints verbose logs. **NOT recommended for production or other sensitive environments.** See [Debugging and diagnostics](#debugging-and-diagnostics) for more details. | +| `diagnostics.startup_logs.enabled` | `DD_TRACE_STARTUP_LOGS` | `Bool` | `nil` | Prints startup configuration and diagnostics to log. For assessing state of tracing at application startup. See [Debugging and diagnostics](#debugging-and-diagnostics) for more details. | +| `env` | `DD_ENV` | `String` | `nil` | Your application environment. (e.g. `production`, `staging`, etc.) This value is set as a tag on all traces. | +| `service` | `DD_SERVICE` | `String` | _Ruby filename_ | Your application's default service name. (e.g. `billing-api`) This value is set as a tag on all traces. | +| `tags` | `DD_TAGS` | `Hash` | `nil` | Custom tags in value pairs separated by `,` (e.g. `layer:api,team:intake`) These tags are set on all traces. See [Environment and tags](#environment-and-tags) for more details. | +| `time_now_provider` | | `Proc` | `->{ Time.now }` | Changes how time is retrieved. See [Setting the time provider](#setting-the-time-provider) for more details. | +| `version` | `DD_VERSION` | `String` | `nil` | Your application version (e.g. `2.5`, `202003181415`, `1.3-alpha`, etc.) This value is set as a tag on all traces. | +| `telemetry.enabled` | `DD_INSTRUMENTATION_TELEMETRY_ENABLED` | `Bool` | `true` | Allows you to enable sending telemetry data to Datadog. Can be disabled, as documented [here](https://docs.datadoghq.com/tracing/configure_data_security/#telemetry-collection). | +| **Tracing** | | | | | +| `tracing.contrib.peer_service_mapping` | `DD_TRACE_PEER_SERVICE_MAPPING` | `Hash` | `nil` | Defines remapping of `peer.service` tag across all instrumentation. Provide a list of `old_value1:new_value1, old_value2:new_value2, ...` | +| `tracing.contrib.global_default_service_name.enabled` | `DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED` | `Bool` | `false` | Changes the default value for `service_name` to the application service name across all instrumentation | | `tracing.propagation_extract_first` | `DD_TRACE_PROPAGATION_EXTRACT_FIRST` | `Bool` | `false` | Stop searching after detecting the first valid propagation format. See [Distributed Tracing](#distributed-tracing) for more details. | -| `tracing.propagation_style_extract` | `DD_TRACE_PROPAGATION_STYLE_EXTRACT` | `Array` | `['Datadog','tracecontext']` | Distributed tracing propagation formats to extract. Overrides `DD_TRACE_PROPAGATION_STYLE`. See [Distributed Tracing](#distributed-tracing) for more details. | -| `tracing.propagation_style_inject` | `DD_TRACE_PROPAGATION_STYLE_INJECT` | `Array` | `['Datadog','tracecontext']` | Distributed tracing propagation formats to inject. Overrides `DD_TRACE_PROPAGATION_STYLE`. See [Distributed Tracing](#distributed-tracing) for more details. | -| `tracing.propagation_style` | `DD_TRACE_PROPAGATION_STYLE` | `Array` | `nil` | Distributed tracing propagation formats to extract and inject. See [Distributed Tracing](#distributed-tracing) for more details. | -| `tracing.enabled` | `DD_TRACE_ENABLED` | `Bool` | `true` | Enables or disables tracing. If set to `false` instrumentation will still run, but no traces are sent to the trace agent. | -| `tracing.header_tags` | `DD_TRACE_HEADER_TAGS` | `Array` | `nil` | Record HTTP headers as span tags. See [Applying header tags to root spans][header tags] for more information. | -| `tracing.instrument(, )` | | | | Activates instrumentation for a specific library. See [Integration instrumentation](#integration-instrumentation) for more details. | -| `tracing.log_injection` | `DD_LOGS_INJECTION` | `Bool` | `true` | Injects [Trace Correlation](#trace-correlation) information into Rails logs if present. Supports the default logger (`ActiveSupport::TaggedLogging`), `lograge`, and `semantic_logger`. | -| `tracing.partial_flush.enabled` | | `Bool` | `false` | Enables or disables partial flushing. Partial flushing submits completed portions of a trace to the agent. Used when tracing instruments long running tasks (e.g. jobs) with many spans. | -| `tracing.partial_flush.min_spans_threshold` | | `Integer` | `500` | The number of spans that must be completed in a trace before partial flushing submits those completed spans. | -| `tracing.sampler` | | `Datadog::Tracing::Sampling::Sampler` | `nil` | Advanced usage only. Sets a custom `Datadog::Tracing::Sampling::Sampler` instance. If provided, the tracer will use this sampler to determine sampling behavior. See [Custom sampling](#custom-sampling) for details. | -| `tracing.sampling.default_rate` | `DD_TRACE_SAMPLE_RATE` | `Float` | `nil` | Sets the trace sampling rate between `0.0` (0%) and `1.0` (100%). | -| `tracing.sampling.rate_limit` | `DD_TRACE_RATE_LIMIT` | `Integer` | `100` (per second) | Sets a maximum number of traces per second to sample. Set a rate limit to avoid the ingestion volume overages in the case of traffic spikes. | +| `tracing.propagation_style_extract` | `DD_TRACE_PROPAGATION_STYLE_EXTRACT` | `Array` | `['Datadog','tracecontext']` | Distributed tracing propagation formats to extract. Overrides `DD_TRACE_PROPAGATION_STYLE`. See [Distributed Tracing](#distributed-tracing) for more details. | +| `tracing.propagation_style_inject` | `DD_TRACE_PROPAGATION_STYLE_INJECT` | `Array` | `['Datadog','tracecontext']` | Distributed tracing propagation formats to inject. Overrides `DD_TRACE_PROPAGATION_STYLE`. See [Distributed Tracing](#distributed-tracing) for more details. | +| `tracing.propagation_style` | `DD_TRACE_PROPAGATION_STYLE` | `Array` | `nil` | Distributed tracing propagation formats to extract and inject. See [Distributed Tracing](#distributed-tracing) for more details. | +| `tracing.enabled` | `DD_TRACE_ENABLED` | `Bool` | `true` | Enables or disables tracing. If set to `false` instrumentation will still run, but no traces are sent to the trace agent. | +| `tracing.header_tags` | `DD_TRACE_HEADER_TAGS` | `Array` | `nil` | Record HTTP headers as span tags. See [Applying header tags to root spans][header tags] for more information. | +| `tracing.instrument(, )` | | | | Activates instrumentation for a specific library. See [Integration instrumentation](#integration-instrumentation) for more details. | +| `tracing.log_injection` | `DD_LOGS_INJECTION` | `Bool` | `true` | Injects [Trace Correlation](#trace-correlation) information into Rails logs if present. Supports the default logger (`ActiveSupport::TaggedLogging`), `lograge`, and `semantic_logger`. | +| `tracing.partial_flush.enabled` | | `Bool` | `false` | Enables or disables partial flushing. Partial flushing submits completed portions of a trace to the agent. Used when tracing instruments long running tasks (e.g. jobs) with many spans. | +| `tracing.partial_flush.min_spans_threshold` | | `Integer` | `500` | The number of spans that must be completed in a trace before partial flushing submits those completed spans. | +| `tracing.sampler` | | `Datadog::Tracing::Sampling::Sampler` | `nil` | Advanced usage only. Sets a custom `Datadog::Tracing::Sampling::Sampler` instance. If provided, the tracer will use this sampler to determine sampling behavior. See [Custom sampling](#custom-sampling) for details. | +| `tracing.sampling.default_rate` | `DD_TRACE_SAMPLE_RATE` | `Float` | `nil` | Sets the trace sampling rate between `0.0` (0%) and `1.0` (100%). | +| `tracing.sampling.rate_limit` | `DD_TRACE_RATE_LIMIT` | `Integer` | `100` (per second) | Sets a maximum number of traces per second to sample. Set a rate limit to avoid the ingestion volume overages in the case of traffic spikes. | | `tracing.sampling.rules` | `DD_TRACE_SAMPLING_RULES` | `String` | `nil` | Sets trace-level sampling rules, matching against the local root span. The format is a `String` with JSON, containing an Array of Objects. Each Object must have a float attribute `sample_rate` (between 0.0 and 1.0, inclusive), and optionally `name`, `service`, `resource`, and `tags` string attributes. `name`, `service`, `resource`, and `tags` control to which traces this sampling rule applies; if they are all absent, then this rule applies to all traces. Rules are evaluated in order of declaration in the array; only the first to match is applied. If none apply, then `tracing.sampling.default_rate` is applied. | -| `tracing.sampling.span_rules` | `DD_SPAN_SAMPLING_RULES`,`ENV_SPAN_SAMPLING_RULES_FILE` | `String` | `nil` | Sets [Single Span Sampling](#single-span-sampling) rules. These rules allow you to keep spans even when their respective traces are dropped. | -| `tracing.trace_id_128_bit_generation_enabled` | `DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED` | `Bool` | `true` | `true` to generate 128 bits trace ID and `false` to generate 64 bits trace ID | -| `tracing.report_hostname` | `DD_TRACE_REPORT_HOSTNAME` | `Bool` | `false` | Adds hostname tag to traces. | -| `tracing.test_mode.enabled` | `DD_TRACE_TEST_MODE_ENABLED` | `Bool` | `false` | Enables or disables test mode, for use of tracing in test suites. | -| `tracing.test_mode.trace_flush` | | `Datadog::Tracing::TraceFlush` | `nil` | Object that determines trace flushing behavior. | +| `tracing.sampling.span_rules` | `DD_SPAN_SAMPLING_RULES`,`ENV_SPAN_SAMPLING_RULES_FILE` | `String` | `nil` | Sets [Single Span Sampling](#single-span-sampling) rules. These rules allow you to keep spans even when their respective traces are dropped. | +| `tracing.trace_id_128_bit_generation_enabled` | `DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED` | `Bool` | `true` | `true` to generate 128 bits trace ID and `false` to generate 64 bits trace ID | +| `tracing.report_hostname` | `DD_TRACE_REPORT_HOSTNAME` | `Bool` | `false` | Adds hostname tag to traces. | +| `tracing.test_mode.enabled` | `DD_TRACE_TEST_MODE_ENABLED` | `Bool` | `false` | Enables or disables test mode, for use of tracing in test suites. | +| `tracing.test_mode.trace_flush` | | `Datadog::Tracing::TraceFlush` | `nil` | Object that determines trace flushing behavior. | #### Custom logging diff --git a/lib/datadog/tracing/contrib/karafka/events/error/occur.rb b/lib/datadog/tracing/contrib/karafka/events/error/occur.rb deleted file mode 100644 index c97caaa1e1b..00000000000 --- a/lib/datadog/tracing/contrib/karafka/events/error/occur.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../ext' -require_relative '../../event' - -require 'byebug' - -module Datadog - module Tracing - module Contrib - module Karafka - module Events - module Error - module Occur - include Karafka::Event - - def self.subscribe! - ::Karafka.monitor.subscribe 'error.consume' do |event| - end - end - end - end - end - end - end - end -end - From f9b6e3633d41bfab9934ec819bfa7427f1791180 Mon Sep 17 00:00:00 2001 From: nvh0412 Date: Sat, 23 Nov 2024 10:11:12 +1100 Subject: [PATCH 4/8] chore: Add karafka getting started properly --- docs/GettingStarted.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 8a1196fa138..8ae0e466dc3 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -1097,6 +1097,27 @@ end | --------- | ------------------------------- | ------ | -------------------------------------------- | ------- | | `enabled` | `DD_TRACE_KAFKA_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +### Karafka + +The karafka integration provides tracing of the `karafka` gem: +You can enable it through `Datadog.configure`: + +```ruby +require 'karafka' +require 'datadog' + +Datadog.configure do |c| + c.tracing.instrument :karafka, **options +end + +``` +`options` are the following keyword arguments: + +| Key | Env Var | Type | Description | Default | +| --------------------- | ------------------------ | ------ | --------------------------------------------------- | ------- | +| `enabled` | `DD_TRACE_KARAFKA_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | +| `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) | `false` | + ### MongoDB The integration traces any `Command` that is sent from the [MongoDB Ruby Driver](https://github.com/mongodb/mongo-ruby-driver) to a MongoDB cluster. By extension, Object Document Mappers (ODM) such as Mongoid are automatically instrumented if they use the official Ruby driver. To activate the integration, simply: From 41cb65fc0bd37a837e1669ac698b07795e0984ea Mon Sep 17 00:00:00 2001 From: nvh0412 Date: Tue, 26 Nov 2024 23:31:19 +1100 Subject: [PATCH 5/8] chore: Address feedbacks Use Tracing.trace wrapper to add consumer trace Use Instrumentation::Monitor to instrument and have a proper trace wrapper --- docs/GettingStarted.md | 4 +- lib/datadog/tracing/contrib/karafka/event.rb | 28 ------- lib/datadog/tracing/contrib/karafka/events.rb | 28 ------- .../contrib/karafka/events/worker/process.rb | 77 ------------------- lib/datadog/tracing/contrib/karafka/ext.rb | 1 + .../tracing/contrib/karafka/integration.rb | 4 +- .../tracing/contrib/karafka/monitor.rb | 68 ++++++++++++++++ .../tracing/contrib/karafka/patcher.rb | 6 +- .../tracing/contrib/karafka/patcher_spec.rb | 14 +--- 9 files changed, 80 insertions(+), 150 deletions(-) delete mode 100644 lib/datadog/tracing/contrib/karafka/event.rb delete mode 100644 lib/datadog/tracing/contrib/karafka/events.rb delete mode 100644 lib/datadog/tracing/contrib/karafka/events/worker/process.rb create mode 100644 lib/datadog/tracing/contrib/karafka/monitor.rb diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 8ae0e466dc3..12490a25137 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -1115,8 +1115,8 @@ end | Key | Env Var | Type | Description | Default | | --------------------- | ------------------------ | ------ | --------------------------------------------------- | ------- | -| `enabled` | `DD_TRACE_KARAFKA_ENABLED` | `Bool` | Whether the integration should create spans. | `true` | -| `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing) | `false` | +| `enabled` | `DD_TRACE_KARAFKA_ENABLED` | `Bool` | Specifies whether the integration should create spans. | `true` | +| `distributed_tracing` | | `Bool` | Enables [distributed tracing](#distributed-tracing). | `false` | ### MongoDB diff --git a/lib/datadog/tracing/contrib/karafka/event.rb b/lib/datadog/tracing/contrib/karafka/event.rb deleted file mode 100644 index b535c4b854e..00000000000 --- a/lib/datadog/tracing/contrib/karafka/event.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -require_relative '../analytics' -require_relative 'ext' - -module Datadog - module Tracing - module Contrib - module Karafka - module Event - def self.included(base) - base.extend(ClassMethods) - end - - module ClassMethods - def span_options - { service: configuration[:service_name] } - end - - def configuration - Datadog.configuration.tracing[:karafka] - end - end - end - end - end - end -end diff --git a/lib/datadog/tracing/contrib/karafka/events.rb b/lib/datadog/tracing/contrib/karafka/events.rb deleted file mode 100644 index 9ea56969ac0..00000000000 --- a/lib/datadog/tracing/contrib/karafka/events.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -require_relative 'events/worker/process' - -module Datadog - module Tracing - module Contrib - module Karafka - # Defines collection of instrumented Kafka events - module Events - ALL = [ - Events::Worker::Process, - ] - - module_function - - def all - self::ALL - end - - def subscribe! - all.each(&:subscribe!) - end - end - end - end - end -end diff --git a/lib/datadog/tracing/contrib/karafka/events/worker/process.rb b/lib/datadog/tracing/contrib/karafka/events/worker/process.rb deleted file mode 100644 index 95fa3077c4e..00000000000 --- a/lib/datadog/tracing/contrib/karafka/events/worker/process.rb +++ /dev/null @@ -1,77 +0,0 @@ -# frozen_string_literal: true - -require_relative '../../ext' -require_relative '../../event' - -module Datadog - module Tracing - module Contrib - module Karafka - module Events - module Worker - module Process - include Karafka::Event - - def self.subscribe! - ::Karafka.monitor.subscribe 'worker.process' do |event| - # Start a trace - span = Tracing.trace(Ext::SPAN_WORKER_PROCESS, **span_options) - - job = event[:job] - job_type = fetch_job_type(job.class) - consumer = job.executor.topic.consumer - topic = job.executor.topic.name - - action = case job_type - when 'Periodic' - 'tick' - when 'PeriodicNonBlocking' - 'tick' - when 'Shutdown' - 'shutdown' - when 'Revoked' - 'revoked' - when 'RevokedNonBlocking' - 'revoked' - when 'Idle' - 'idle' - when 'Eofed' - 'eofed' - when 'EofedNonBlocking' - 'eofed' - else - 'consume' - end - - span.resource = "#{consumer}##{action}" - span.set_tag(Ext::TAG_TOPIC, topic) if topic - - if action == 'consume' - span.set_tag(Ext::TAG_MESSAGE_COUNT, job.messages.count) - span.set_tag(Ext::TAG_PARTITION, job.executor.partition) - span.set_tag(Ext::TAG_OFFSET, job.messages.first.metadata.offset) - end - - span - end - - ::Karafka.monitor.subscribe 'worker.completed' do |event| - Tracing.active_span&.finish - end - end - - def self.span_options - super.merge({ tags: { Tracing::Metadata::Ext::TAG_OPERATION => Ext::TAG_OPERATION_PROCESS_BATCH } }) - end - - def self.fetch_job_type(job_class) - @job_types_cache ||= {} - @job_types_cache[job_class] ||= job_class.to_s.split('::').last - end - end - end - end - end - end - end -end diff --git a/lib/datadog/tracing/contrib/karafka/ext.rb b/lib/datadog/tracing/contrib/karafka/ext.rb index d3be29040e9..17c7ff1f6d1 100644 --- a/lib/datadog/tracing/contrib/karafka/ext.rb +++ b/lib/datadog/tracing/contrib/karafka/ext.rb @@ -10,6 +10,7 @@ module Ext SPAN_MESSAGE_CONSUME = 'karafka.consume' SPAN_WORKER_PROCESS = 'worker.process' + TAG_CONSUMER = 'kafka.consumer' TAG_TOPIC = 'kafka.topic' TAG_PARTITION = 'kafka.partition' TAG_OFFSET = 'kafka.offset' diff --git a/lib/datadog/tracing/contrib/karafka/integration.rb b/lib/datadog/tracing/contrib/karafka/integration.rb index b28cacbd47b..4a89d643287 100644 --- a/lib/datadog/tracing/contrib/karafka/integration.rb +++ b/lib/datadog/tracing/contrib/karafka/integration.rb @@ -11,7 +11,9 @@ module Karafka class Integration include Contrib::Integration - MINIMUM_VERSION = Gem::Version.new('2.1.0') + # Minimum version of the Karafka library that we support + # https://karafka.io/docs/Versions-Lifecycle-and-EOL/#versioning-strategy + MINIMUM_VERSION = Gem::Version.new('2.2.0') # @public_api Changing the integration name or integration options can cause breaking changes register_as :karafka, auto_patch: false diff --git a/lib/datadog/tracing/contrib/karafka/monitor.rb b/lib/datadog/tracing/contrib/karafka/monitor.rb new file mode 100644 index 00000000000..bcc22f75924 --- /dev/null +++ b/lib/datadog/tracing/contrib/karafka/monitor.rb @@ -0,0 +1,68 @@ +# frozen_string_literal: true + +require_relative 'ext' + +module Datadog + module Tracing + module Contrib + module Karafka + # Custom monitor for Karafka + class Monitor < ::Karafka::Instrumentation::Monitor + TRACEABLE_EVENTS = %w[ + worker.processed + ].freeze + + def instrument(event_id, payload = EMPTY_HASH, &block) + return super unless TRACEABLE_EVENTS.include?(event_id) + + Datadog::Tracing.trace(Ext::SPAN_WORKER_PROCESS) do |span| + job = payload[:job] + job_type = fetch_job_type(job.class) + consumer = job.executor.topic.consumer + + action = case job_type + when 'Periodic' + 'tick' + when 'PeriodicNonBlocking' + 'tick' + when 'Shutdown' + 'shutdown' + when 'Revoked' + 'revoked' + when 'RevokedNonBlocking' + 'revoked' + when 'Idle' + 'idle' + when 'Eofed' + 'eofed' + when 'EofedNonBlocking' + 'eofed' + else + 'consume' + end + + span.resource = "#{consumer}##{action}" + + if action == 'consume' + span.set_tag(Ext::TAG_MESSAGE_COUNT, job.messages.count) + span.set_tag(Ext::TAG_PARTITION, job.executor.partition) + span.set_tag(Ext::TAG_OFFSET, job.messages.first.metadata.offset) + span.set_tag(Ext::TAG_TOPIC, job.executor.topic.name) + span.set_tag(Ext::TAG_CONSUMER, consumer) + end + + super + end + end + + private + + def fetch_job_type(job_class) + @job_types_cache ||= {} + @job_types_cache[job_class] ||= job_class.to_s.split('::').last + end + end + end + end + end +end diff --git a/lib/datadog/tracing/contrib/karafka/patcher.rb b/lib/datadog/tracing/contrib/karafka/patcher.rb index ebd76411812..2469cfb85f2 100644 --- a/lib/datadog/tracing/contrib/karafka/patcher.rb +++ b/lib/datadog/tracing/contrib/karafka/patcher.rb @@ -1,14 +1,15 @@ # frozen_string_literal: true require_relative '../patcher' -require_relative 'events' require_relative 'ext' require_relative 'distributed/propagation' +require_relative 'monitor' module Datadog module Tracing module Contrib module Karafka + # Patch to add tracing to Karafka::Messages::Messages module MessagesPatch def configuration Datadog.configuration.tracing[:sidekiq] @@ -48,8 +49,7 @@ def target_version end def patch - Events.subscribe! - + ::Karafka::App.config.monitor = Monitor.new ::Karafka::Messages::Messages.prepend(MessagesPatch) end end diff --git a/spec/datadog/tracing/contrib/karafka/patcher_spec.rb b/spec/datadog/tracing/contrib/karafka/patcher_spec.rb index aa709558dec..83b3125285b 100644 --- a/spec/datadog/tracing/contrib/karafka/patcher_spec.rb +++ b/spec/datadog/tracing/contrib/karafka/patcher_spec.rb @@ -28,9 +28,7 @@ let(:span_name) { Datadog::Tracing::Contrib::Karafka::Ext::SPAN_MESSAGE_CONSUME } it 'is expected to send a span' do - deserializer = ->(_) { 1 } metadata = ::Karafka::Messages::Metadata.new.tap do |metadata| - metadata['deserializer'] = deserializer metadata['offset'] = 412 end raw_payload = rand.to_s @@ -56,13 +54,11 @@ end end - describe 'worker.process' do + describe 'worker.processed' do let(:span_name) { Datadog::Tracing::Contrib::Karafka::Ext::SPAN_WORKER_PROCESS } it 'is expected to send a span' do - deserializer = ->(_) { 1 } metadata = ::Karafka::Messages::Metadata.new.tap do |metadata| - metadata['deserializer'] = deserializer metadata['offset'] = 412 end raw_payload = rand.to_s @@ -70,12 +66,8 @@ message = Karafka::Messages::Message.new(raw_payload, metadata) job = double(executor: double(topic: double(name: 'topic_a', consumer: 'ABC'), partition: 0), messages: [message]) - Karafka.monitor.instrument('worker.process', { job: job }) do - puts "ac" - end - - Karafka.monitor.instrument('worker.completed', { job: job }) do - puts "ac" + Karafka.monitor.instrument('worker.processed', { job: job }) do + # Noop end expect(spans).to have(1).items From 9dd469cdbb64f559a0a6bc8c865984c6bd364368 Mon Sep 17 00:00:00 2001 From: nvh0412 Date: Tue, 26 Nov 2024 23:53:18 +1100 Subject: [PATCH 6/8] chore: correct monitor require position --- lib/datadog/tracing/contrib/karafka/patcher.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/datadog/tracing/contrib/karafka/patcher.rb b/lib/datadog/tracing/contrib/karafka/patcher.rb index 2469cfb85f2..09fef798086 100644 --- a/lib/datadog/tracing/contrib/karafka/patcher.rb +++ b/lib/datadog/tracing/contrib/karafka/patcher.rb @@ -3,7 +3,6 @@ require_relative '../patcher' require_relative 'ext' require_relative 'distributed/propagation' -require_relative 'monitor' module Datadog module Tracing @@ -49,6 +48,8 @@ def target_version end def patch + require_relative 'monitor' + ::Karafka::App.config.monitor = Monitor.new ::Karafka::Messages::Messages.prepend(MessagesPatch) end From f79c7fbf55eb86f5d732ea11e91c930bb3cd54d3 Mon Sep 17 00:00:00 2001 From: nvh0412 Date: Thu, 28 Nov 2024 23:02:19 +1100 Subject: [PATCH 7/8] chore: Fix typo --- lib/datadog/tracing/contrib/karafka/patcher.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/datadog/tracing/contrib/karafka/patcher.rb b/lib/datadog/tracing/contrib/karafka/patcher.rb index 09fef798086..8af66db243f 100644 --- a/lib/datadog/tracing/contrib/karafka/patcher.rb +++ b/lib/datadog/tracing/contrib/karafka/patcher.rb @@ -15,7 +15,7 @@ def configuration end def propagation - @propagation ||= Contrib::Sidekiq::Distributed::Propagation.new + @propagation ||= Contrib::Karafka::Distributed::Propagation.new end def each(&block) From 27e5711ff68d457fa8d2a3820fe51fabb8ba31b7 Mon Sep 17 00:00:00 2001 From: nvh0412 Date: Mon, 2 Dec 2024 09:01:59 +1100 Subject: [PATCH 8/8] chore: fix wrong config --- lib/datadog/tracing/contrib/karafka/patcher.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/datadog/tracing/contrib/karafka/patcher.rb b/lib/datadog/tracing/contrib/karafka/patcher.rb index 8af66db243f..1d7efbe925e 100644 --- a/lib/datadog/tracing/contrib/karafka/patcher.rb +++ b/lib/datadog/tracing/contrib/karafka/patcher.rb @@ -11,7 +11,7 @@ module Karafka # Patch to add tracing to Karafka::Messages::Messages module MessagesPatch def configuration - Datadog.configuration.tracing[:sidekiq] + Datadog.configuration.tracing[:karafka] end def propagation