Skip to content
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

Lots of tracing changes to make things easier to understand #1

Merged
merged 9 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 0 additions & 180 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,96 +4,13 @@ PATH
degica_datadog (0.1.0)
ddtrace (~> 1.0)
dogstatsd-ruby (~> 5)
rails

GEM
remote: https://rubygems.org/
specs:
actioncable (7.1.2)
actionpack (= 7.1.2)
activesupport (= 7.1.2)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
zeitwerk (~> 2.6)
actionmailbox (7.1.2)
actionpack (= 7.1.2)
activejob (= 7.1.2)
activerecord (= 7.1.2)
activestorage (= 7.1.2)
activesupport (= 7.1.2)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.1.2)
actionpack (= 7.1.2)
actionview (= 7.1.2)
activejob (= 7.1.2)
activesupport (= 7.1.2)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.2)
actionpack (7.1.2)
actionview (= 7.1.2)
activesupport (= 7.1.2)
nokogiri (>= 1.8.5)
racc
rack (>= 2.2.4)
rack-session (>= 1.0.1)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
actiontext (7.1.2)
actionpack (= 7.1.2)
activerecord (= 7.1.2)
activestorage (= 7.1.2)
activesupport (= 7.1.2)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.1.2)
activesupport (= 7.1.2)
builder (~> 3.1)
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
activejob (7.1.2)
activesupport (= 7.1.2)
globalid (>= 0.3.6)
activemodel (7.1.2)
activesupport (= 7.1.2)
activerecord (7.1.2)
activemodel (= 7.1.2)
activesupport (= 7.1.2)
timeout (>= 0.4.0)
activestorage (7.1.2)
actionpack (= 7.1.2)
activejob (= 7.1.2)
activerecord (= 7.1.2)
activesupport (= 7.1.2)
marcel (~> 1.0)
activesupport (7.1.2)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.5)
builder (3.2.4)
coderay (1.1.3)
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
crass (1.0.6)
datadog-ci (0.5.1)
msgpack
date (3.3.4)
ddtrace (1.18.0)
datadog-ci (~> 0.5.0)
debase-ruby_core_source (= 3.2.3)
Expand All @@ -103,105 +20,20 @@ GEM
debase-ruby_core_source (3.2.3)
diff-lcs (1.5.0)
dogstatsd-ruby (5.6.1)
drb (2.2.0)
ruby2_keywords
erubi (1.12.0)
ffi (1.16.3)
globalid (1.2.1)
activesupport (>= 6.1)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
io-console (0.7.1)
irb (1.11.1)
rdoc
reline (>= 0.4.2)
json (2.7.1)
language_server-protocol (3.17.0.3)
libdatadog (5.0.0.1.0)
libddwaf (1.14.0.0.0)
ffi (~> 1.0)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
mail (2.8.1)
mini_mime (>= 0.1.1)
net-imap
net-pop
net-smtp
marcel (1.0.2)
method_source (1.0.0)
mini_mime (1.1.5)
mini_portile2 (2.8.5)
minitest (5.20.0)
msgpack (1.7.2)
mutex_m (0.2.0)
net-imap (0.4.9.1)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.2)
timeout
net-smtp (0.4.0.1)
net-protocol
nio4r (2.7.0)
nokogiri (1.16.0)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
parallel (1.23.0)
parser (3.2.2.4)
ast (~> 2.4.1)
racc
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
psych (5.1.2)
stringio
racc (1.7.3)
rack (3.0.8)
rack-session (2.0.0)
rack (>= 3.0.0)
rack-test (2.1.0)
rack (>= 1.3)
rackup (2.1.0)
rack (>= 3)
webrick (~> 1.8)
rails (7.1.2)
actioncable (= 7.1.2)
actionmailbox (= 7.1.2)
actionmailer (= 7.1.2)
actionpack (= 7.1.2)
actiontext (= 7.1.2)
actionview (= 7.1.2)
activejob (= 7.1.2)
activemodel (= 7.1.2)
activerecord (= 7.1.2)
activestorage (= 7.1.2)
activesupport (= 7.1.2)
bundler (>= 1.15.0)
railties (= 7.1.2)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (7.1.2)
actionpack (= 7.1.2)
activesupport (= 7.1.2)
irb
rackup (>= 1.0.0)
rake (>= 12.2)
thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.1.0)
rdoc (6.6.2)
psych (>= 4.0.0)
regexp_parser (2.8.3)
reline (0.4.2)
io-console (~> 0.5)
rexml (3.2.6)
rspec (3.12.0)
rspec-core (~> 3.12.0)
Expand Down Expand Up @@ -230,26 +62,14 @@ GEM
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
stringio (3.1.0)
thor (1.3.0)
timeout (0.4.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
webrick (1.8.1)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.6.12)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 2.0)
degica_datadog!
pry
rspec (~> 3.0)
rubocop

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ Internal library for StatsD and tracing.
```ruby
require "degica_datadog"

# Config.init is optional if you don't need to set any special config.
DegicaDatadog::Config.init(
service_name: "hats",
version: "1.3",
environment: "staging",
repository_url: "github.com/degica/not-hats"
)
Comment on lines +17 to +22

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

DegicaDatadog::Tracing.init
```

Expand Down
2 changes: 0 additions & 2 deletions degica_datadog.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ Gem::Specification.new do |spec|

spec.add_dependency "ddtrace", "~> 1.0"
spec.add_dependency "dogstatsd-ruby", "~> 5"
spec.add_dependency "rails"
spec.add_development_dependency "bundler", "~> 2.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "rubocop"
spec.add_development_dependency "pry"
end
19 changes: 15 additions & 4 deletions lib/degica_datadog/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ module DegicaDatadog
# Configuration for the Datadog agent.
module Config
class << self
def init(service_name: nil, version: nil, environment: nil, repository_url: nil)
@service = service_name
@version = version
@environment = environment
@repository_url = repository_url
end

def enabled?
%w[production staging].include?(environment) || ENV.fetch("DD_AGENT_URI", nil)
end
Expand All @@ -17,19 +24,19 @@ def statsd_client
end

def service
ENV.fetch("SERVICE_NAME", nil)
@service || ENV.fetch("SERVICE_NAME", "unknown")
end

def version
ENV.fetch("_GIT_REVISION", nil)
@version || ENV.fetch("_GIT_REVISION", "unknown")
end

def environment
ENV.fetch("RAILS_ENV", nil)
@environment || ENV.fetch("RAILS_ENV", "unknown")
end

def repository_url
"github.com/degica/#{service}"
@repository_url || "github.com/degica/#{service}"
end

# URI including http:// prefix & port for the tracing endpoint, or nil.
Expand Down Expand Up @@ -57,6 +64,10 @@ def statsd_port
def tracing_port
datadog_agent_uri&.port || 8126
end

def inspect
"DegicaDatadog::Config<enabled?=#{!!enabled?} service=#{service} version=#{version} environment=#{environment} repository_url=#{repository_url} datadog_agent_host=#{datadog_agent_host} statsd_port=#{statsd_port} tracing_port=#{tracing_port}>" # rubocop:disable Layout/LineLength

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, where on DD will we be able to see this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't be on DD, but it's what you get when you open up an irb and check out DegicaDatadog::Config. I ended up checking a lot of these values over and over while tweaking settings, so having them all easily accessible might help in the future when we're debugging something like data not coming through or being wrongly tagged.

end
end
end
end
17 changes: 13 additions & 4 deletions lib/degica_datadog/tracing.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require "ddtrace"
require "rails"

module DegicaDatadog
# Tracing related functionality.
Expand Down Expand Up @@ -32,10 +31,20 @@ def init # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
c.tracing.partial_flush.enabled = true
c.tracing.partial_flush.min_spans_threshold = 2_000

c.tracing.instrument :rails,
service_name: Config.service,
request_queueing: true
# Enabling additional settings for these instrumentations.
c.tracing.instrument :rails, request_queueing: true
c.tracing.instrument :rack, request_queueing: true
c.tracing.instrument :rake
c.tracing.instrument :sidekiq, { tag_args: true }
c.tracing.instrument :active_record, service_name: Config.service
c.tracing.instrument :mysql2, service_name: "#{Config.service}-#{Config.environment}"

# All of these are HTTP clients.
c.tracing.instrument :ethon, split_by_domain: true
c.tracing.instrument :faraday, split_by_domain: true
c.tracing.instrument :http, split_by_domain: true
c.tracing.instrument :httpclient, split_by_domain: true
c.tracing.instrument :httprb, split_by_domain: true
end
end

Expand Down
Loading