Skip to content

Commit

Permalink
[WIP] Tracing Remote Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc committed May 15, 2023
1 parent f9b0f45 commit 2ad7381
Show file tree
Hide file tree
Showing 3 changed files with 541 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/datadog/core/remote/client/capabilities.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require_relative '../../../appsec/remote'
require_relative '../../../tracing/remote'

module Datadog
module Core
Expand Down Expand Up @@ -28,6 +29,10 @@ def register(settings)
register_products(Datadog::AppSec::Remote.products)
register_receivers(Datadog::AppSec::Remote.receivers)
end

register_capabilities(Datadog::Tracing::Remote.capabilities)
register_products(Datadog::Tracing::Remote.products)
register_receivers(Datadog::Tracing::Remote.receivers)
end

def register_capabilities(capabilities)
Expand Down
65 changes: 65 additions & 0 deletions lib/datadog/tracing/remote.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# frozen_string_literal: true

require_relative '../core/remote/dispatcher'

module Datadog
module Tracing
# Remote configuration declaration
module Remote
class ReadError < StandardError; end

class << self
PRODUCT = 'APM_LIBRARY'

def products
[PRODUCT]
end

def capabilities
[]
end

def receivers
receiver do |repository, _changes|
config = []

# DEV: Filter our by product. Given it will be very common
# DEV: we can filter this out before we receive the data in this method.
# DEV: Apply this refactor to AppSec as well if implemented.
repository.contents.each do |content|
case content.path.product
when PRODUCT
config << parse_content(content)
end
end

# TODO: Make the magic happen!
# Tracing::Component.reconfigure(config)
end
end

def receiver(products = [PRODUCT], &block)
matcher = Core::Remote::Dispatcher::Matcher::Product.new(products)
[Core::Remote::Dispatcher::Receiver.new(matcher) do |repository, changes|
changes.each do |change|
Datadog.logger.debug { "remote config change: '#{change.path}'" }
end
yield(repository, changes)
end]
end

private

def parse_content(content)
data = content.data.read

content.data.rewind

raise ReadError, 'EOF reached' if data.nil?

JSON.parse(data)
end
end
end
end
end
Loading

0 comments on commit 2ad7381

Please sign in to comment.