-
Notifications
You must be signed in to change notification settings - Fork 396
Add WaterDrop integration (i.e.: trace messages produced by Karafka) #4874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
6a5c86b
025d7d7
8725d0c
47f6f12
ba11317
6b654d4
7d87fcd
b2651c5
a51106d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,12 +97,10 @@ | |
| build_coverage_matrix('rest-client') | ||
| build_coverage_matrix('mongo', min: '2.1.0') | ||
| build_coverage_matrix('dalli', [2]) | ||
| build_coverage_matrix('karafka', min: '2.3.0') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This should still be okay for Ruby 3.1 as long as we don't update the lockfiles, we can do that on our end. |
||
| build_coverage_matrix('waterdrop', min: '2.8.8.rc1') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| build_coverage_matrix('devise', min: '3.2.1') | ||
|
|
||
| appraise 'karafka-min' do | ||
| gem 'karafka', '= 2.3.0' | ||
| end | ||
|
|
||
| appraise 'relational_db' do | ||
| gem 'activerecord', '~> 7' | ||
| gem 'delayed_job' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,6 +98,7 @@ | |
| build_coverage_matrix('mongo', min: '2.1.0') | ||
| build_coverage_matrix('dalli', [2]) | ||
| build_coverage_matrix('karafka', min: '2.3.0') | ||
| build_coverage_matrix('waterdrop', min: '2.8.8.rc1') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please run |
||
| build_coverage_matrix('devise', min: '3.2.1') | ||
|
|
||
| appraise 'relational_db' do | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Datadog | ||
| module Tracing | ||
| module Contrib | ||
| module Karafka | ||
| # Karafka framework code, used to essentially: | ||
| # - handle configuration entries which are specific to Datadog tracing | ||
| # - instrument parts of the framework when needed | ||
| module Framework | ||
| def self.setup | ||
| Datadog.configure do |datadog_config| | ||
| karafka_config = datadog_config.tracing[:karafka] | ||
| activate_waterdrop!(datadog_config, karafka_config) | ||
| end | ||
| end | ||
|
|
||
| # Apply relevant configuration from Karafka to WaterDrop | ||
| def self.activate_waterdrop!(datadog_config, karafka_config) | ||
| datadog_config.tracing.instrument( | ||
| :waterdrop, | ||
| service_name: karafka_config[:service_name], | ||
| distributed_tracing: karafka_config[:distributed_tracing], | ||
| ) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative 'component' | ||
| require_relative 'waterdrop/integration' | ||
| require_relative 'waterdrop/distributed/propagation' | ||
|
|
||
| module Datadog | ||
| module Tracing | ||
| module Contrib | ||
| # `WaterDrop` integration public API | ||
| module WaterDrop | ||
| 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('waterdrop') do |config| | ||
| tracing = config.tracing | ||
| tracing.propagation_style | ||
|
|
||
| @propagation = WaterDrop::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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative '../../configuration/settings' | ||
| require_relative '../ext' | ||
|
|
||
| module Datadog | ||
| module Tracing | ||
| module Contrib | ||
| module WaterDrop | ||
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # 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 WaterDrop | ||
| 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_BAGGAGE => | ||
| Tracing::Distributed::Baggage.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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Datadog | ||
| module Tracing | ||
| module Contrib | ||
| module WaterDrop | ||
| module Ext | ||
| ENV_ENABLED = 'DD_TRACE_WATERDROP_ENABLED' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add this environment variable in |
||
|
|
||
| SPAN_PRODUCER = 'karafka.produce' | ||
|
|
||
| TAG_PRODUCER = 'kafka.producer' | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative '../integration' | ||
| require_relative 'configuration/settings' | ||
| require_relative 'patcher' | ||
|
|
||
| module Datadog | ||
| module Tracing | ||
| module Contrib | ||
| module WaterDrop | ||
| # Description of WaterDrop integration | ||
| class Integration | ||
| include Contrib::Integration | ||
|
|
||
| # WaterDrop added class-level instrumentation in version 2.8.8.rc1 | ||
| MINIMUM_VERSION = Gem::Version.new('2.8.8.rc1') | ||
|
|
||
| register_as :waterdrop, auto_patch: false | ||
|
|
||
| def self.version | ||
| Gem.loaded_specs['waterdrop']&.version | ||
| end | ||
|
|
||
| def self.loaded? | ||
| !defined?(::WaterDrop).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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative 'ext' | ||
|
|
||
| module Datadog | ||
| module Tracing | ||
| module Contrib | ||
| module WaterDrop | ||
| # Middleware to propagate tracing context in messages produced by WaterDrop | ||
| module Middleware | ||
| class << self | ||
| def call(message) | ||
| trace_op = Datadog::Tracing.active_trace | ||
|
|
||
| if trace_op && Datadog::Tracing::Distributed::PropagationPolicy.enabled?( | ||
| global_config: configuration, | ||
| trace: trace_op | ||
| ) | ||
| WaterDrop.inject(trace_op.to_digest, message[:headers] ||= {}) | ||
| end | ||
|
|
||
| message | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def configuration | ||
| Datadog.configuration.tracing[:waterdrop] | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the
build_coverage_matrixresults in two appraisals:waterdrop-minandwaterdrop-latest. Also, the resulting appraisals will not contain karafka, so these should be in their own hash or it will try to run karafka tests and fail. You'd also need to add it to the Rakefile in the list of integrations