Skip to content

Commit

Permalink
Merge pull request #737 from DataDog/brettlangdon/0.22.0-release
Browse files Browse the repository at this point in the history
Bump to version 0.22.0
  • Loading branch information
brettlangdon authored Apr 15, 2019
2 parents b45815e + 8d7d691 commit 67bc474
Show file tree
Hide file tree
Showing 42 changed files with 1,345 additions and 61 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
DD_AGENT_HOST=localhost
DD_METRIC_AGENT_PORT=8125
DD_TRACE_AGENT_PORT=8126
TEST_DDAGENT_API_KEY=invalid_key_but_this_is_fine
TEST_ELASTICSEARCH_HOST=127.0.0.1
Expand Down
21 changes: 19 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@

## [Unreleased (beta)]

## [0.22.0] - 2019-04-15

Release notes: https://github.com/DataDog/dd-trace-rb/releases/tag/v0.22.0

Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.21.2...v0.22.0

In this release we are adding initial support for the **beta** [Runtime metrics collection](https://docs.datadoghq.com/tracing/advanced/runtime_metrics/?tab=ruby) feature.

### Changed

- Add warning log if an integration is incompatible (#722) (@ericmustin)

### Added

- Initial beta support for Runtime metrics collection (#677)

## [0.21.2] - 2019-04-10

Release notes: https://github.com/DataDog/dd-trace-rb/releases/tag/v0.21.2
Expand Down Expand Up @@ -751,8 +767,9 @@ Release notes: https://github.com/DataDog/dd-trace-rb/releases/tag/v0.3.1

Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1

[Unreleased (stable)]: https://github.com/DataDog/dd-trace-rb/compare/v0.21.2...master
[Unreleased (beta)]: https://github.com/DataDog/dd-trace-rb/compare/v0.21.2...0.22-dev
[Unreleased (stable)]: https://github.com/DataDog/dd-trace-rb/compare/v0.22.0...master
[Unreleased (beta)]: https://github.com/DataDog/dd-trace-rb/compare/v0.22.0...0.23-dev
[0.22.0]: https://github.com/DataDog/dd-trace-rb/compare/v0.21.2...v0.22.0
[0.21.2]: https://github.com/DataDog/dd-trace-rb/compare/v0.21.1...v0.21.2
[0.21.1]: https://github.com/DataDog/dd-trace-rb/compare/v0.21.0...v0.21.1
[0.21.0]: https://github.com/DataDog/dd-trace-rb/compare/v0.20.0...v0.21.0
Expand Down
27 changes: 18 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,47 @@ namespace :spec do
:rails, :railsredis, :railssidekiq, :railsactivejob,
:elasticsearch, :http, :redis, :sidekiq, :sinatra]

RSpec::Core::RakeTask.new(:main) do |t|
RSpec::Core::RakeTask.new(:main) do |t, args|
t.pattern = 'spec/**/*_spec.rb'
t.exclude_pattern = 'spec/**/{contrib,benchmark,redis,opentracer}/**/*_spec.rb'
t.rspec_opts = args.to_a.join(' ')
end

RSpec::Core::RakeTask.new(:opentracer) do |t|
RSpec::Core::RakeTask.new(:opentracer) do |t, args|
t.pattern = 'spec/ddtrace/opentracer/**/*_spec.rb'
t.rspec_opts = args.to_a.join(' ')
end

RSpec::Core::RakeTask.new(:rails) do |t|
RSpec::Core::RakeTask.new(:rails) do |t, args|
t.pattern = 'spec/ddtrace/contrib/rails/**/*_spec.rb'
t.exclude_pattern = 'spec/ddtrace/contrib/rails/**/*{sidekiq,active_job,disable_env}*_spec.rb'
t.rspec_opts = args.to_a.join(' ')
end

RSpec::Core::RakeTask.new(:railsredis) do |t|
RSpec::Core::RakeTask.new(:railsredis) do |t, args|
t.pattern = 'spec/ddtrace/contrib/rails/**/*redis*_spec.rb'
t.rspec_opts = args.to_a.join(' ')
end

RSpec::Core::RakeTask.new(:railssidekiq) do |t|
RSpec::Core::RakeTask.new(:railssidekiq) do |t, args|
t.pattern = 'spec/ddtrace/contrib/rails/**/*sidekiq*_spec.rb'
t.rspec_opts = args.to_a.join(' ')
end

RSpec::Core::RakeTask.new(:railsactivejob) do |t|
RSpec::Core::RakeTask.new(:railsactivejob) do |t, args|
t.pattern = 'spec/ddtrace/contrib/rails/**/*active_job*_spec.rb'
t.rspec_opts = args.to_a.join(' ')
end

RSpec::Core::RakeTask.new(:railsdisableenv) do |t|
RSpec::Core::RakeTask.new(:railsdisableenv) do |t, args|
t.pattern = 'spec/ddtrace/contrib/rails/**/*disable_env*_spec.rb'
t.rspec_opts = args.to_a.join(' ')
end

RSpec::Core::RakeTask.new(:contrib) do |t|
RSpec::Core::RakeTask.new(:contrib) do |t, args|
# rubocop:disable Metrics/LineLength
t.pattern = 'spec/**/contrib/{analytics,configurable,integration,patchable,patcher,registerable,registry,configuration/*}_spec.rb'
t.rspec_opts = args.to_a.join(' ')
end

[
Expand Down Expand Up @@ -79,8 +87,9 @@ namespace :spec do
:sucker_punch,
:shoryuken
].each do |contrib|
RSpec::Core::RakeTask.new(contrib) do |t|
RSpec::Core::RakeTask.new(contrib) do |t, args|
t.pattern = "spec/ddtrace/contrib/#{contrib}/**/*_spec.rb"
t.rspec_opts = args.to_a.join(' ')
end
end
end
Expand Down
8 changes: 6 additions & 2 deletions ddtrace.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_dependency 'msgpack'

# Optional extensions
# TODO: Move this to Appraisals?
spec.add_dependency 'opentracing', '>= 0.4.1'
spec.add_development_dependency 'dogstatsd-ruby', '>= 3.3.0'
spec.add_development_dependency 'opentracing', '>= 0.4.1'

spec.add_development_dependency 'climate_control', '~> 0.2.0'
# Development dependencies
spec.add_development_dependency 'rake', '>= 10.5'
spec.add_development_dependency 'rubocop', '= 0.49.1' if RUBY_VERSION >= '2.1.0'
spec.add_development_dependency 'rspec', '~> 3.0'
Expand All @@ -48,6 +51,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'builder'
spec.add_development_dependency 'ruby-prof'
spec.add_development_dependency 'sqlite3', '~> 1.3.6'
spec.add_development_dependency 'climate_control', '~> 0.2.0'

# locking transitive dependency of webmock
spec.add_development_dependency 'addressable', '~> 2.4.0'
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ services:
- DD_BIND_HOST=0.0.0.0
- DD_API_KEY=invalid_key_but_this_is_fine
expose:
- "8125/udp"
- "8126"
ports:
- "${DD_METRIC_AGENT_PORT}:8125/udp"
- "${DD_TRACE_AGENT_PORT}:8126"
elasticsearch:
# Note: ES 5.0 dies with error:
Expand Down
52 changes: 52 additions & 0 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ For descriptions of terminology used in APM, take a look at the [official docume
- [Filtering](#filtering)
- [Processing](#processing)
- [Trace correlation](#trace-correlation)
- [Metrics](#metrics)
- [For application runtime](#for-application-runtime)
- [OpenTracing](#opentracing)

## Compatibility
Expand Down Expand Up @@ -1725,6 +1727,56 @@ Datadog.tracer.trace('my.operation') { logger.warn('This is a traced operation.'
# [2019-01-16 18:38:41 +0000][my_app][WARN][dd.trace_id=8545847825299552251 dd.span_id=3711755234730770098] This is a traced operation.
```

### Metrics

The tracer and its integrations can produce some additional metrics that can provide useful insight into the performance of your application. These metrics are collected with `dogstatsd-ruby`, and can be sent to the same Datadog agent to which you send your traces.

To configure your application for metrics collection:

1. [Configure your Datadog agent for StatsD](https://docs.datadoghq.com/developers/dogstatsd/#setup)
2. Add `gem 'dogstatsd-ruby'` to your Gemfile

#### For application runtime

If runtime metrics are configured, the trace library will automatically collect and send metrics about the health of your application.

To configure runtime metrics, add the following configuration:

```ruby
# config/initializers/datadog.rb
require 'datadog/statsd'
require 'ddtrace'

Datadog.configure do |c|
# To enable runtime metrics collection, set `true`. Defaults to `false`
# You can also set DD_RUNTIME_METRICS_ENABLED=true to configure this.
c.runtime_metrics_enabled = true

# Optionally, you can configure the Statsd instance used for sending runtime metrics.
# Statsd is automatically configured with default settings if `dogstatsd-ruby` is available.
# You can configure with host and port of Datadog agent; defaults to 'localhost:8125'.
c.runtime_metrics statsd: Datadog::Statsd.new
end
```

See the [Dogstatsd documentation](https://www.rubydoc.info/github/DataDog/dogstatsd-ruby/master/frames) for more details about configuring `Datadog::Statsd`.

The stats sent will include:

| Name | Type | Description |
| -------------------------- | ------- | -------------------------------------------------------- |
| `runtime.ruby.class_count` | `gauge` | Number of classes in memory space. |
| `runtime.ruby.thread_count` | `gauge` | Number of threads. |
| `runtime.ruby.gc.*`. | `gauge` | Garbage collection statistics (one per value in GC.stat) |

In addition, all metrics will include the following tags:

| Name | Description |
| ------------ | ------------------------------------------------------- |
| `language` | Programming language traced. (e.g. `ruby`) |
| `runtime-id` | Unique identifier of runtime environment (i.e. process) |
| `service` | List of services this metric is associated with. |

### OpenTracing

For setting up Datadog with OpenTracing, see out [Quickstart for OpenTracing](#quickstart-for-opentracing) section for details.
Expand Down
1 change: 1 addition & 0 deletions lib/ddtrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require 'ddtrace/configuration'
require 'ddtrace/patcher'
require 'ddtrace/augmentation'
require 'ddtrace/metrics'

# \Datadog global namespace that includes all tracing functionality for Tracer and Span classes.
module Datadog
Expand Down
4 changes: 4 additions & 0 deletions lib/ddtrace/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ def configure(target = configuration, opts = {})
def tracer
configuration.tracer
end

def runtime_metrics
tracer.writer.runtime_metrics
end
end
end
18 changes: 17 additions & 1 deletion lib/ddtrace/configuration/settings.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
require 'ddtrace/ext/analytics'
require 'ddtrace/environment'
require 'ddtrace/ext/runtime'
require 'ddtrace/configuration/options'

require 'ddtrace/environment'
require 'ddtrace/tracer'
require 'ddtrace/metrics'

module Datadog
module Configuration
# Global configuration settings for the trace library.
Expand All @@ -13,6 +17,10 @@ class Settings
default: -> { env_to_bool(Ext::Analytics::ENV_TRACE_ANALYTICS_ENABLED, nil) },
lazy: true

option :runtime_metrics_enabled,
default: -> { env_to_bool(Ext::Runtime::Metrics::ENV_ENABLED, false) },
lazy: true

option :tracer, default: Tracer.new

def initialize(options = {})
Expand All @@ -28,7 +36,15 @@ def configure(options = {})
yield(self) if block_given?
end

def runtime_metrics(options = nil)
runtime_metrics = get_option(:tracer).writer.runtime_metrics
return runtime_metrics if options.nil?

runtime_metrics.configure(options)
end

# Backwards compatibility for configuring tracer e.g. `c.tracer debug: true`
remove_method :tracer
def tracer(options = nil)
tracer = options && options.key?(:instance) ? set_option(:tracer, options[:instance]) : get_option(:tracer)

Expand Down
4 changes: 2 additions & 2 deletions lib/ddtrace/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,14 @@ def check_finished_spans
end

def attach_sampling_priority
@trace.first.set_metric(
@current_root_span.set_metric(
Ext::DistributedTracing::SAMPLING_PRIORITY_KEY,
@sampling_priority
)
end

def attach_origin
@trace.first.set_tag(
@current_root_span.set_tag(
Ext::DistributedTracing::ORIGIN_KEY,
@origin
)
Expand Down
6 changes: 5 additions & 1 deletion lib/ddtrace/contrib/patchable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ def patcher
end

def patch
return if !self.class.compatible? || patcher.nil?
if !self.class.compatible? || patcher.nil?
Datadog::Tracer.log.warn("Unable to patch #{self.class.name}")
return
end

patcher.patch
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/ddtrace/contrib/rack/middlewares.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def resource_name_for(env, status)
end
end

# rubocop:disable Metrics/AbcSize
def set_request_tags!(request_span, env, status, headers, response, original_env)
# http://www.rubydoc.info/github/rack/rack/file/SPEC
# The source of truth in Rack is the PATH_INFO key that holds the
Expand All @@ -142,6 +143,9 @@ def set_request_tags!(request_span, env, status, headers, response, original_env

request_span.resource ||= resource_name_for(env, status)

# Associate with runtime metrics
Datadog.runtime_metrics.associate_with_span(request_span)

# Set analytics sample rate
if Contrib::Analytics.enabled?(configuration[:analytics_enabled])
Contrib::Analytics.set_sample_rate(request_span, configuration[:analytics_sample_rate])
Expand Down
3 changes: 3 additions & 0 deletions lib/ddtrace/contrib/rails/action_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def self.finish_processing(payload)
# Set analytics sample rate
Utils.set_analytics_sample_rate(span)

# Associate with runtime metrics
Datadog.runtime_metrics.associate_with_span(span)

span.set_tag(Ext::TAG_ROUTE_ACTION, payload.fetch(:action))
span.set_tag(Ext::TAG_ROUTE_CONTROLLER, payload.fetch(:controller))

Expand Down
11 changes: 11 additions & 0 deletions lib/ddtrace/ext/metrics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Datadog
module Ext
module Metrics
TAG_LANG = 'language'.freeze
TAG_LANG_INTERPRETER = 'language-interpreter'.freeze
TAG_LANG_VERSION = 'language-version'.freeze
TAG_RUNTIME_ID = 'runtime-id'.freeze
TAG_TRACER_VERSION = 'tracer-version'.freeze
end
end
end
33 changes: 33 additions & 0 deletions lib/ddtrace/ext/runtime.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'ddtrace/version'

module Datadog
module Ext
module Runtime
# Identity
LANG = 'ruby'.freeze
LANG_INTERPRETER = begin
if Gem::Version.new(RUBY_VERSION) > Gem::Version.new('1.9')
(RUBY_ENGINE + '-' + RUBY_PLATFORM)
else
('ruby-' + RUBY_PLATFORM)
end
end.freeze
LANG_VERSION = RUBY_VERSION
TRACER_VERSION = Datadog::VERSION::STRING

TAG_LANG = 'language'.freeze
TAG_RUNTIME_ID = 'runtime-id'.freeze

# Metrics
module Metrics
ENV_ENABLED = 'DD_RUNTIME_METRICS_ENABLED'.freeze

METRIC_CLASS_COUNT = 'runtime.ruby.class_count'.freeze
METRIC_GC_PREFIX = 'runtime.ruby.gc'.freeze
METRIC_THREAD_COUNT = 'runtime.ruby.thread_count'.freeze

TAG_SERVICE = 'service'.freeze
end
end
end
end
Loading

0 comments on commit 67bc474

Please sign in to comment.