-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
1,643 additions
and
283 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,25 @@ | ||
require 'ddtrace/contrib/configuration/settings' | ||
require 'ddtrace/contrib/kafka/ext' | ||
|
||
module Datadog | ||
module Contrib | ||
module Kafka | ||
module Configuration | ||
# Custom settings for the Kafka integration | ||
class Settings < Contrib::Configuration::Settings | ||
option :analytics_enabled do |o| | ||
o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) } | ||
o.lazy | ||
end | ||
|
||
option :analytics_sample_rate do |o| | ||
o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) } | ||
o.lazy | ||
end | ||
|
||
option :service_name, default: Ext::SERVICE_NAME | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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,14 @@ | ||
module Datadog | ||
module Contrib | ||
module Kafka | ||
# Defines basic behaviors for an event for a consumer. | ||
module ConsumerEvent | ||
def process(span, _event, _id, payload) | ||
super | ||
|
||
span.set_tag(Ext::TAG_GROUP, payload[:group_id]) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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,14 @@ | ||
module Datadog | ||
module Contrib | ||
module Kafka | ||
# Defines basic behaviors for an event for a consumer group. | ||
module ConsumerGroupEvent | ||
def process(span, _event, _id, payload) | ||
super | ||
|
||
span.resource = payload[:group_id] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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,51 @@ | ||
require 'ddtrace/contrib/analytics' | ||
require 'ddtrace/contrib/active_support/notifications/event' | ||
require 'ddtrace/contrib/kafka/ext' | ||
|
||
module Datadog | ||
module Contrib | ||
module Kafka | ||
# Defines basic behaviors for an ActiveSupport event. | ||
module Event | ||
def self.included(base) | ||
base.send(:include, ActiveSupport::Notifications::Event) | ||
base.send(:extend, ClassMethods) | ||
end | ||
|
||
# Class methods for Kafka events. | ||
module ClassMethods | ||
def event_name | ||
self::EVENT_NAME | ||
end | ||
|
||
def span_options | ||
{ service: configuration[:service_name] } | ||
end | ||
|
||
def tracer | ||
-> { configuration[:tracer] } | ||
end | ||
|
||
def configuration | ||
Datadog.configuration[:kafka] | ||
end | ||
|
||
def process(span, _event, _id, payload) | ||
span.service = configuration[:service_name] | ||
span.set_tag(Ext::TAG_CLIENT, payload[:client_id]) | ||
|
||
# Set analytics sample rate | ||
if Contrib::Analytics.enabled?(configuration[:analytics_enabled]) | ||
Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate]) | ||
end | ||
|
||
# Measure service stats | ||
Contrib::Analytics.set_measured(span) | ||
|
||
span.set_error(payload[:exception_object]) if payload[:exception_object] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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,44 @@ | ||
require 'ddtrace/contrib/kafka/events/connection/request' | ||
require 'ddtrace/contrib/kafka/events/consumer/process_batch' | ||
require 'ddtrace/contrib/kafka/events/consumer/process_message' | ||
require 'ddtrace/contrib/kafka/events/consumer_group/heartbeat' | ||
require 'ddtrace/contrib/kafka/events/consumer_group/join_group' | ||
require 'ddtrace/contrib/kafka/events/consumer_group/leave_group' | ||
require 'ddtrace/contrib/kafka/events/consumer_group/sync_group' | ||
require 'ddtrace/contrib/kafka/events/produce_operation/send_messages' | ||
require 'ddtrace/contrib/kafka/events/producer/deliver_messages' | ||
|
||
module Datadog | ||
module Contrib | ||
module Kafka | ||
# Defines collection of instrumented Kafka events | ||
module Events | ||
ALL = [ | ||
Events::Connection::Request, | ||
Events::Consumer::ProcessBatch, | ||
Events::Consumer::ProcessMessage, | ||
Events::ConsumerGroup::Heartbeat, | ||
Events::ConsumerGroup::JoinGroup, | ||
Events::ConsumerGroup::LeaveGroup, | ||
Events::ConsumerGroup::SyncGroup, | ||
Events::ProduceOperation::SendMessages, | ||
Events::Producer::DeliverMessages | ||
].freeze | ||
|
||
module_function | ||
|
||
def all | ||
self::ALL | ||
end | ||
|
||
def subscriptions | ||
all.collect(&:subscriptions).collect(&:to_a).flatten | ||
end | ||
|
||
def subscribe! | ||
all.each(&:subscribe!) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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,34 @@ | ||
require 'ddtrace/contrib/kafka/ext' | ||
require 'ddtrace/contrib/kafka/event' | ||
|
||
module Datadog | ||
module Contrib | ||
module Kafka | ||
module Events | ||
module Connection | ||
# Defines instrumentation for request.connection.kafka event | ||
module Request | ||
include Kafka::Event | ||
|
||
EVENT_NAME = 'request.connection.kafka'.freeze | ||
|
||
def self.process(span, _event, _id, payload) | ||
super | ||
|
||
span.resource = payload[:api] | ||
|
||
span.set_tag(Ext::TAG_REQUEST_SIZE, payload[:request_size]) if payload.key?(:request_size) | ||
span.set_tag(Ext::TAG_RESPONSE_SIZE, payload[:response_size]) if payload.key?(:response_size) | ||
end | ||
|
||
module_function | ||
|
||
def span_name | ||
Ext::SPAN_CONNECTION_REQUEST | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.