-
Notifications
You must be signed in to change notification settings - Fork 399
DSM Implementation for Ruby with Karafka instrumented #4901
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
Merged
Merged
Changes from 63 commits
Commits
Show all changes
71 commits
Select commit
Hold shift + click to select a range
fe953e6
Add DSM and Karafka integration support
ericfirth 063adef
Add periodic scheduler and comprehensive tests for DataStreams
ericfirth e3ad6e1
Add API consistency methods for DataStreams checkpoints
ericfirth 7b0998d
Update integrations to use new API methods with idiomatic Ruby blocks
ericfirth bff020c
Remove redundant pathway context encoding in Kafka producer
ericfirth 540733c
Replace noisy puts statements with proper debug logging
ericfirth fc17a47
Fix Kafka consumer DSM implementation and remove noisy logging
ericfirth 6a8352c
Implement proper DSM in Kafka event handlers
ericfirth 66b2df8
Restore proper DSM implementation in Kafka consumer instrumentation
ericfirth 9965af0
Use prepend instead of include for better readability
ericfirth ca3881c
Remove comments and make changes for readability suggested by reviewer
ericfirth ac0b0eb
Update set_consume_checkpoint & set_produce_checkpoint to use keyword…
ericfirth b3feabd
Type, as best as we can, the methods
ericfirth 7b1c1a6
Move data_streams so that its not namespaced by tracing
ericfirth 29b8d8f
Add debug logs to DSM processor to trace periodic flush
ericfirth e52e571
Add more debug logs to trace checkpoint creation
ericfirth 3d00638
Fix DSM agent host/port handling and add debug logs
ericfirth 2b12c4d
Clean up debug logs from DSM processor
ericfirth d806b80
Remove many superfluous comments
ericfirth f3b715d
Remove excess comments and move full_pathway calculation to where it …
ericfirth b87dc9c
Add an bucket stats test
ericfirth b57bd32
Make public API more grokable and stop exposing via the core/configur…
ericfirth 763c19e
A bunch of fixes to pass in constants to Data Streams at initializati…
ericfirth c3e5eb3
Use Time as an object rather than as a float representing seconds
ericfirth 55351d8
Set checkpoint uses keyword args to better signal the arguments that …
ericfirth a405486
Privatize the encoding
ericfirth 2109feb
Make it so Data Streams is safer so that when enabled is true but DDS…
ericfirth 33ee888
Rescue any errors setting checkpoints sends
ericfirth 0d5dc58
Add transport layer to be able to transport on UDP, etc
ericfirth 4d93f01
Remove a change that doesn't need to be there
ericfirth b6d9f8e
Add a return instead of a raise when decoding
ericfirth e0c577c
Remove circular dependency
ericfirth d7b1dda
CI fixes
ericfirth d47e60b
Apply suggestions from code review
ericfirth 1a8310c
Address DSM PR review comments
ericfirth 70c6520
Add skip_if_data_streams_not_supported helper to prevent silent test …
ericfirth dd96c21
Fix Steep type checking errors
ericfirth 647f453
Move require 'datadog' to top of kafka data_streams_spec.rb
ericfirth 9b9cfb8
Skip Data Streams tests instead of raising when DDSketch unavailable
ericfirth 0ee4cb1
Exclude Data Streams tests from :main rake task (Nix environments)
ericfirth 10cc108
Exclude entire data_streams directory from :main rake task
ericfirth 14d1b75
Add Data Streams tests to CORE_WITH_LIBDATADOG_API
ericfirth fa38e10
Remove contrib data_streams_spec from CORE_WITH_LIBDATADOG_API
ericfirth ca3f8db
Fix processor_spec to pass required interval and logger arguments
ericfirth a9171b2
Add require 'msgpack' and 'zlib' to transport/stats.rb
ericfirth 4425a6a
Fix Kafka tests and clean up DataStreams Processor
ericfirth 68130b3
Fix AgentSettings constant and steep type signature
ericfirth 350a0dc
Fix processor spec mocks and HTTP transport stubbing
ericfirth 2f79488
Update lib/datadog/tracing/contrib/karafka/patcher.rb
ericfirth e02ed61
Update Rakefile
ericfirth 43e1f23
Change the requires such that there is no circular dependency but tes…
ericfirth 9de9c05
Remove flake
ericfirth 0e42715
Clean up Kafka DSM test mocks and improve skip helper usage
ericfirth d29df4c
Refactor Data Streams configuration to follow AppSec pattern
ericfirth b43d2f0
Change Data Streams tags parameter from Array to Hash
ericfirth 90d7b3e
Make DataStreams.processor private
ericfirth d02e7d2
Add LEB128 encoding documentation to pathway_context
ericfirth 3e209e1
Fix track_kafka_produce and track_kafka_commit to write to correct da…
ericfirth 5342cd3
Standard fixes
ericfirth 182ce81
Add buffering so that we don't block the main thread to do dsm work
ericfirth c8ff0cd
Remove unnecessary file
ericfirth d71238f
Remove track_kafka_commit as we dont use it
ericfirth 0963f4d
CI Fixes due to removed methods and emptying buckets manually
ericfirth 10c9527
Add debug logs for debugging
ericfirth 11695d1
Fix ruby-kafka instrumentation bug
ericfirth a862b3b
Figure out a bug in the transport layer added with typing
ericfirth 8cbec59
Fix DSM Kafka instrumentation bugs
ericfirth 30b3bf9
Standard fixes
ericfirth 1400140
Make track_kafka_* non-visible
ericfirth 2ae6bf8
Document the initialize params for the dsm processor
ericfirth 728b9c7
Remove a disabled from a test
ericfirth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,5 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'datadog/core' | ||
|
|
||
| module Datadog | ||
| module Core | ||
| # Used to access ddsketch APIs. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative 'data_streams/processor' | ||
| require_relative 'data_streams/pathway_context' | ||
| require_relative 'data_streams/configuration/settings' | ||
| require_relative 'data_streams/extensions' | ||
| require_relative 'core/utils/time' | ||
|
|
||
| module Datadog | ||
| # Datadog Data Streams Monitoring public API. | ||
| # | ||
| # The Datadog team ensures that public methods in this module | ||
| # only receive backwards compatible changes, and breaking changes | ||
| # will only occur in new major versions releases. | ||
| # @public_api | ||
| module DataStreams | ||
| class << self | ||
| # Set a produce checkpoint for Data Streams Monitoring | ||
| # | ||
| # @param type [String] The type of the checkpoint (e.g., 'kafka', 'kinesis', 'sns') | ||
| # @param destination [String] The destination (e.g., topic, exchange, stream name) | ||
| # @param auto_instrumentation [Boolean] Whether this checkpoint was set by auto-instrumentation (default: false) | ||
| # @param tags [Hash] Additional tags to include | ||
| # @yield [key, value] Block to inject context into carrier | ||
| # @return [String, nil] Base64 encoded pathway context or nil if disabled | ||
| # @public_api | ||
| def set_produce_checkpoint(type:, destination:, auto_instrumentation: false, tags: {}, &block) | ||
| processor&.set_produce_checkpoint( | ||
| type: type, | ||
| destination: destination, | ||
| manual_checkpoint: !auto_instrumentation, | ||
| tags: tags, | ||
| &block | ||
| ) | ||
| end | ||
|
|
||
| # Set a consume checkpoint for Data Streams Monitoring | ||
| # | ||
| # @param type [String] The type of the checkpoint (e.g., 'kafka', 'kinesis', 'sns') | ||
| # @param source [String] The source (e.g., topic, exchange, stream name) | ||
| # @param auto_instrumentation [Boolean] Whether this checkpoint was set by auto-instrumentation (default: false) | ||
| # @param tags [Hash] Additional tags to include | ||
| # @yield [key] Block to extract context from carrier | ||
| # @return [String, nil] Base64 encoded pathway context or nil if disabled | ||
| # @public_api | ||
| def set_consume_checkpoint(type:, source:, auto_instrumentation: false, tags: {}, &block) | ||
| processor&.set_consume_checkpoint( | ||
| type: type, | ||
| source: source, | ||
| manual_checkpoint: !auto_instrumentation, | ||
| tags: tags, | ||
| &block | ||
| ) | ||
| end | ||
|
|
||
| # Track Kafka produce offset for lag monitoring | ||
| # | ||
| # @param topic [String] The Kafka topic name | ||
| # @param partition [Integer] The partition number | ||
| # @param offset [Integer] The offset of the produced message | ||
| # @return [Boolean, nil] true if tracking succeeded, nil if disabled | ||
| # @public_api | ||
| def track_kafka_produce(topic, partition, offset) | ||
ericfirth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| processor&.track_kafka_produce(topic, partition, offset, Core::Utils::Time.now) | ||
| end | ||
|
|
||
| # Track Kafka message consumption for consumer lag monitoring | ||
| # | ||
| # @param topic [String] The Kafka topic name | ||
| # @param partition [Integer] The partition number | ||
| # @param offset [Integer] The offset of the consumed message | ||
| # @return [Boolean, nil] true if tracking succeeded, nil if disabled | ||
| # @public_api | ||
| def track_kafka_consume(topic, partition, offset) | ||
| processor&.track_kafka_consume(topic, partition, offset, Core::Utils::Time.now) | ||
| end | ||
|
|
||
| # Check if Data Streams Monitoring is enabled and available | ||
| # | ||
| # @return [Boolean] true if the processor is available | ||
| # @public_api | ||
| def enabled? | ||
| !processor.nil? | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def processor | ||
ericfirth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| components.data_streams | ||
| end | ||
|
|
||
| def components | ||
| Datadog.send(:components) | ||
| end | ||
| end | ||
|
|
||
| # Expose Data Streams to global shared objects | ||
| Extensions.activate! | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative 'configuration/settings' | ||
|
|
||
| module Datadog | ||
| module DataStreams | ||
| # Configuration for Data Streams Monitoring | ||
| module Configuration | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative '../../core/environment/variable_helpers' | ||
| require_relative '../ext' | ||
|
|
||
| module Datadog | ||
| module DataStreams | ||
| module Configuration | ||
| # Configuration settings for Data Streams Monitoring. | ||
| module Settings | ||
| def self.extended(base) | ||
| base = base.singleton_class unless base.is_a?(Class) | ||
| add_settings!(base) | ||
| end | ||
|
|
||
| def self.add_settings!(base) | ||
| base.class_eval do | ||
| # Data Streams Monitoring configuration | ||
| # @public_api | ||
| settings :data_streams do | ||
| # Whether Data Streams Monitoring is enabled. When enabled, the library will | ||
| # collect and report data lineage information for messaging systems. | ||
| # | ||
| # @default `DD_DATA_STREAMS_ENABLED` environment variable, otherwise `false`. | ||
| # @return [Boolean] | ||
| option :enabled do |o| | ||
| o.type :bool | ||
| o.env Ext::ENV_ENABLED | ||
| o.default false | ||
| end | ||
|
|
||
| # The interval (in seconds) at which Data Streams Monitoring stats are flushed. | ||
| # | ||
| # @default 10.0 | ||
| # @env '_DD_TRACE_STATS_WRITER_INTERVAL' | ||
| # @return [Float] | ||
| # @!visibility private | ||
| option :interval do |o| | ||
| o.type :float | ||
| o.env '_DD_TRACE_STATS_WRITER_INTERVAL' | ||
ericfirth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| o.default 10.0 | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Datadog | ||
| module DataStreams | ||
| # Constants for Data Streams Monitoring configuration | ||
| # @public_api | ||
| module Ext | ||
| ENV_ENABLED = 'DD_DATA_STREAMS_ENABLED' | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative 'configuration' | ||
| require_relative '../core/configuration' | ||
|
|
||
| module Datadog | ||
| module DataStreams | ||
| # Extends Datadog with Data Streams Monitoring features | ||
| module Extensions | ||
| # Inject Data Streams settings into global configuration. | ||
| def self.activate! | ||
| Core::Configuration::Settings.extend(Configuration::Settings) | ||
| end | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.