ddtrace 0.34.1 → 0.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +58 -9
  3. data/.circleci/images/primary/Dockerfile-jruby-9.2 +77 -0
  4. data/.rubocop.yml +4 -0
  5. data/Appraisals +9 -7
  6. data/CHANGELOG.md +89 -3
  7. data/Rakefile +11 -2
  8. data/ddtrace.gemspec +5 -3
  9. data/docker-compose.yml +35 -0
  10. data/docs/DevelopmentGuide.md +1 -1
  11. data/docs/GettingStarted.md +89 -36
  12. data/lib/ddtrace.rb +1 -1
  13. data/lib/ddtrace/buffer.rb +9 -9
  14. data/lib/ddtrace/chunker.rb +34 -0
  15. data/lib/ddtrace/configuration.rb +28 -5
  16. data/lib/ddtrace/configuration/base.rb +1 -1
  17. data/lib/ddtrace/configuration/components.rb +154 -0
  18. data/lib/ddtrace/configuration/options.rb +1 -1
  19. data/lib/ddtrace/configuration/settings.rb +131 -63
  20. data/lib/ddtrace/context.rb +6 -6
  21. data/lib/ddtrace/context_flush.rb +1 -1
  22. data/lib/ddtrace/contrib/action_cable/instrumentation.rb +1 -1
  23. data/lib/ddtrace/contrib/action_pack/action_controller/instrumentation.rb +2 -2
  24. data/lib/ddtrace/contrib/action_view/events/render_partial.rb +1 -1
  25. data/lib/ddtrace/contrib/action_view/events/render_template.rb +1 -1
  26. data/lib/ddtrace/contrib/action_view/instrumentation/partial_renderer.rb +1 -1
  27. data/lib/ddtrace/contrib/action_view/instrumentation/template_renderer.rb +2 -2
  28. data/lib/ddtrace/contrib/action_view/patcher.rb +1 -1
  29. data/lib/ddtrace/contrib/active_record/events/instantiation.rb +1 -1
  30. data/lib/ddtrace/contrib/active_record/events/sql.rb +1 -1
  31. data/lib/ddtrace/contrib/active_support/cache/instrumentation.rb +2 -2
  32. data/lib/ddtrace/contrib/active_support/notifications/subscription.rb +2 -2
  33. data/lib/ddtrace/contrib/analytics.rb +1 -1
  34. data/lib/ddtrace/contrib/configuration/settings.rb +1 -1
  35. data/lib/ddtrace/contrib/dalli/patcher.rb +1 -1
  36. data/lib/ddtrace/contrib/dalli/quantize.rb +1 -1
  37. data/lib/ddtrace/contrib/elasticsearch/patcher.rb +1 -1
  38. data/lib/ddtrace/contrib/excon/middleware.rb +2 -2
  39. data/lib/ddtrace/contrib/extensions.rb +29 -5
  40. data/lib/ddtrace/contrib/faraday/patcher.rb +1 -1
  41. data/lib/ddtrace/contrib/grape/endpoint.rb +5 -5
  42. data/lib/ddtrace/contrib/grape/patcher.rb +1 -1
  43. data/lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb +1 -1
  44. data/lib/ddtrace/contrib/grpc/datadog_interceptor/server.rb +2 -2
  45. data/lib/ddtrace/contrib/grpc/patcher.rb +1 -1
  46. data/lib/ddtrace/contrib/http/circuit_breaker.rb +8 -32
  47. data/lib/ddtrace/contrib/http/instrumentation.rb +2 -2
  48. data/lib/ddtrace/contrib/mongodb/subscribers.rb +2 -2
  49. data/lib/ddtrace/contrib/patchable.rb +1 -1
  50. data/lib/ddtrace/contrib/patcher.rb +3 -3
  51. data/lib/ddtrace/contrib/presto/instrumentation.rb +3 -3
  52. data/lib/ddtrace/contrib/presto/patcher.rb +1 -1
  53. data/lib/ddtrace/contrib/rack/middlewares.rb +2 -2
  54. data/lib/ddtrace/contrib/rack/patcher.rb +2 -2
  55. data/lib/ddtrace/contrib/rack/request_queue.rb +1 -1
  56. data/lib/ddtrace/contrib/rails/configuration/settings.rb +14 -0
  57. data/lib/ddtrace/contrib/rails/framework.rb +54 -48
  58. data/lib/ddtrace/contrib/rails/integration.rb +1 -1
  59. data/lib/ddtrace/contrib/rake/instrumentation.rb +2 -2
  60. data/lib/ddtrace/contrib/redis/quantize.rb +1 -1
  61. data/lib/ddtrace/contrib/resque/resque_job.rb +2 -2
  62. data/lib/ddtrace/contrib/sidekiq/tracing.rb +1 -1
  63. data/lib/ddtrace/contrib/sinatra/env.rb +20 -0
  64. data/lib/ddtrace/contrib/sinatra/ext.rb +6 -0
  65. data/lib/ddtrace/contrib/sinatra/patcher.rb +1 -0
  66. data/lib/ddtrace/contrib/sinatra/tracer.rb +98 -35
  67. data/lib/ddtrace/contrib/sinatra/tracer_middleware.rb +16 -13
  68. data/lib/ddtrace/correlation.rb +9 -6
  69. data/lib/ddtrace/diagnostics/health.rb +2 -6
  70. data/lib/ddtrace/encoding.rb +13 -39
  71. data/lib/ddtrace/event.rb +1 -1
  72. data/lib/ddtrace/ext/correlation.rb +1 -0
  73. data/lib/ddtrace/ext/diagnostics.rb +2 -0
  74. data/lib/ddtrace/ext/environment.rb +1 -0
  75. data/lib/ddtrace/ext/forced_tracing.rb +1 -1
  76. data/lib/ddtrace/logger.rb +3 -44
  77. data/lib/ddtrace/metrics.rb +5 -5
  78. data/lib/ddtrace/monkey.rb +1 -1
  79. data/lib/ddtrace/opentracer/global_tracer.rb +1 -1
  80. data/lib/ddtrace/pin.rb +18 -17
  81. data/lib/ddtrace/pipeline.rb +1 -1
  82. data/lib/ddtrace/propagation/http_propagator.rb +2 -2
  83. data/lib/ddtrace/runtime/cgroup.rb +1 -1
  84. data/lib/ddtrace/runtime/container.rb +1 -1
  85. data/lib/ddtrace/runtime/metrics.rb +5 -2
  86. data/lib/ddtrace/sampler.rb +2 -2
  87. data/lib/ddtrace/sampling/rule.rb +1 -1
  88. data/lib/ddtrace/sampling/rule_sampler.rb +1 -1
  89. data/lib/ddtrace/span.rb +4 -4
  90. data/lib/ddtrace/sync_writer.rb +3 -8
  91. data/lib/ddtrace/tracer.rb +26 -31
  92. data/lib/ddtrace/transport/http.rb +1 -1
  93. data/lib/ddtrace/transport/http/api/instance.rb +4 -0
  94. data/lib/ddtrace/transport/http/builder.rb +3 -5
  95. data/lib/ddtrace/transport/http/client.rb +7 -64
  96. data/lib/ddtrace/transport/http/response.rb +1 -1
  97. data/lib/ddtrace/transport/http/statistics.rb +1 -1
  98. data/lib/ddtrace/transport/http/traces.rb +10 -7
  99. data/lib/ddtrace/transport/io.rb +1 -1
  100. data/lib/ddtrace/transport/io/client.rb +2 -2
  101. data/lib/ddtrace/transport/io/response.rb +3 -1
  102. data/lib/ddtrace/transport/io/traces.rb +50 -3
  103. data/lib/ddtrace/transport/parcel.rb +0 -4
  104. data/lib/ddtrace/transport/statistics.rb +2 -2
  105. data/lib/ddtrace/transport/traces.rb +160 -10
  106. data/lib/ddtrace/utils.rb +1 -1
  107. data/lib/ddtrace/version.rb +2 -2
  108. data/lib/ddtrace/workers.rb +5 -13
  109. data/lib/ddtrace/workers/async.rb +2 -2
  110. data/lib/ddtrace/workers/runtime_metrics.rb +47 -0
  111. data/lib/ddtrace/workers/trace_writer.rb +199 -0
  112. data/lib/ddtrace/writer.rb +20 -27
  113. metadata +22 -32
@@ -47,12 +47,14 @@ Gem::Specification.new do |spec|
47
47
  spec.add_development_dependency 'rspec-collection_matchers', '~> 1.1'
48
48
  spec.add_development_dependency 'minitest', '= 5.10.1'
49
49
  spec.add_development_dependency 'appraisal', '~> 2.2'
50
- spec.add_development_dependency 'bundler', '<= 2.1.2' # Remove when https://github.com/thoughtbot/appraisal/issues/162 is fixed
51
50
  spec.add_development_dependency 'yard', '~> 0.9'
52
51
  spec.add_development_dependency 'webmock', '~> 2.0'
53
52
  spec.add_development_dependency 'builder'
54
- spec.add_development_dependency 'ruby-prof'
55
- spec.add_development_dependency 'sqlite3', '~> 1.3.6'
53
+ if RUBY_PLATFORM != 'java'
54
+ spec.add_development_dependency 'sqlite3', '~> 1.3.6'
55
+ else
56
+ spec.add_development_dependency 'jdbc-sqlite3', '~> 3'
57
+ end
56
58
  spec.add_development_dependency 'climate_control', '~> 0.2.0'
57
59
 
58
60
  # locking transitive dependency of webmock
@@ -1,5 +1,6 @@
1
1
  version: '3.2'
2
2
  services:
3
+ # MRI
3
4
  tracer-2.0:
4
5
  image: palazzem/docker-library:ddtrace_rb_2_0_0
5
6
  command: /bin/bash
@@ -247,6 +248,38 @@ services:
247
248
  - .:/app
248
249
  - bundle-2.7:/usr/local/bundle
249
250
  - gemfiles-2.7:/app/gemfiles
251
+ # JRuby
252
+ tracer-jruby-9.2:
253
+ image: marcotc/docker-library:ddtrace_rb_jruby_9_2
254
+ command: /bin/bash
255
+ depends_on:
256
+ - ddagent
257
+ - elasticsearch
258
+ - memcached
259
+ - mongodb
260
+ - mysql
261
+ - postgres
262
+ - presto
263
+ - redis
264
+ env_file: ./.env
265
+ environment:
266
+ - BUNDLE_GEMFILE=/app/Gemfile
267
+ - DD_AGENT_HOST=ddagent
268
+ - TEST_DATADOG_INTEGRATION=1
269
+ - TEST_ELASTICSEARCH_HOST=elasticsearch
270
+ - TEST_MEMCACHED_HOST=memcached
271
+ - TEST_MONGODB_HOST=mongodb
272
+ - TEST_MYSQL_HOST=mysql
273
+ - TEST_POSTGRES_HOST=postgres
274
+ - TEST_PRESTO_HOST=presto
275
+ - TEST_PRESTO_PORT=8080
276
+ - TEST_REDIS_HOST=redis
277
+ stdin_open: true
278
+ tty: true
279
+ volumes:
280
+ - .:/app
281
+ - bundle-jruby-9.2:/usr/local/bundle
282
+ - gemfiles-jruby-9.2:/app/gemfiles
250
283
  ddagent:
251
284
  image: datadog/docker-dd-agent
252
285
  environment:
@@ -325,6 +358,7 @@ volumes:
325
358
  bundle-2.5:
326
359
  bundle-2.6:
327
360
  bundle-2.7:
361
+ bundle-jruby-9.2:
328
362
  gemfiles-2.0:
329
363
  gemfiles-2.1:
330
364
  gemfiles-2.2:
@@ -333,3 +367,4 @@ volumes:
333
367
  gemfiles-2.5:
334
368
  gemfiles-2.6:
335
369
  gemfiles-2.7:
370
+ gemfiles-jruby-9.2:
@@ -183,7 +183,7 @@ Then pass an adapter instance to the tracer configuration:
183
183
 
184
184
  ```ruby
185
185
  Datadog.configure do |c|
186
- c.tracer transport_options: proc { |t|
186
+ c.tracer.transport_options = proc { |t|
187
187
  # By name
188
188
  t.adapter :custom
189
189
 
@@ -92,7 +92,7 @@ To contribute, check out the [contribution guidelines][contribution docs] and [d
92
92
  | | | 2.0 | Full | Latest |
93
93
  | | | 1.9.3 | Maintenance (until August 6th, 2020) | < 0.27.0 |
94
94
  | | | 1.9.1 | Maintenance (until August 6th, 2020) | < 0.27.0 |
95
- | JRuby | http://jruby.org/ | 9.1.5 | Alpha | Latest |
95
+ | JRuby | http://jruby.org/ | 9.2.0.0 | Alpha | Latest |
96
96
 
97
97
  **Supported web servers**:
98
98
 
@@ -771,7 +771,7 @@ Datadog.configure do |c|
771
771
  end
772
772
  end
773
773
 
774
- # Configure Faraday tracing behavior for single connection
774
+ # In case you want to override the global configuration for a certain client instance
775
775
  connection = Faraday.new('https://example.com') do |builder|
776
776
  builder.use(:ddtrace, options)
777
777
  builder.adapter Faraday.default_adapter
@@ -1498,6 +1498,8 @@ The Sinatra integration traces requests and template rendering.
1498
1498
 
1499
1499
  To start using the tracing client, make sure you import `ddtrace` and `use :sinatra` after either `sinatra` or `sinatra/base`, and before you define your application/routes:
1500
1500
 
1501
+ #### Classic application
1502
+
1501
1503
  ```ruby
1502
1504
  require 'sinatra'
1503
1505
  require 'ddtrace'
@@ -1511,7 +1513,40 @@ get '/' do
1511
1513
  end
1512
1514
  ```
1513
1515
 
1514
- Where `options` is an optional `Hash` that accepts the following parameters:
1516
+ #### Modular application
1517
+
1518
+ ```ruby
1519
+ require 'sinatra/base'
1520
+ require 'ddtrace'
1521
+
1522
+ Datadog.configure do |c|
1523
+ c.use :sinatra, options
1524
+ end
1525
+
1526
+ class NestedApp < Sinatra::Base
1527
+ register Datadog::Contrib::Sinatra::Tracer
1528
+
1529
+ get '/nested' do
1530
+ 'Hello from nested app!'
1531
+ end
1532
+ end
1533
+
1534
+ class App < Sinatra::Base
1535
+ register Datadog::Contrib::Sinatra::Tracer
1536
+
1537
+ use NestedApp
1538
+
1539
+ get '/' do
1540
+ 'Hello world!'
1541
+ end
1542
+ end
1543
+ ```
1544
+
1545
+ Ensure you register `Datadog::Contrib::Sinatra::Tracer` as a middleware before you mount your nested applications.
1546
+
1547
+ #### Instrumentation options
1548
+
1549
+ `options` is an optional `Hash` that accepts the following parameters:
1515
1550
 
1516
1551
  | Key | Description | Default |
1517
1552
  | --- | ----------- | ------- |
@@ -1555,20 +1590,28 @@ To change the default behavior of the Datadog tracer, you can provide custom opt
1555
1590
  # config/initializers/datadog-tracer.rb
1556
1591
 
1557
1592
  Datadog.configure do |c|
1558
- c.tracer option_name: option_value, ...
1593
+ c.tracer.enabled = true
1594
+ c.tracer.hostname = 'my-agent'
1595
+ c.tracer.port = 8126
1596
+ c.tracer.partial_flush.enabled = false
1597
+ c.tracer.sampler = Datadog::AllSampler.new
1598
+
1599
+ # OR for advanced use cases, you can specify your own tracer:
1600
+ c.tracer.instance = Datadog::Tracer.new
1601
+
1602
+ # To enable debug mode:
1603
+ c.diagnostics.debug = true
1559
1604
  end
1560
1605
  ```
1561
1606
 
1562
1607
  Available options are:
1563
1608
 
1564
- - `enabled`: defines if the `tracer` is enabled or not. If set to `false` the code could be still instrumented because of other settings, but no spans are sent to the local trace agent.
1565
- - `debug`: set to true to enable debug logging.
1609
+ - `enabled`: defines if the `tracer` is enabled or not. If set to `false` instrumentation will still run, but no spans are sent to the trace agent.
1566
1610
  - `hostname`: set the hostname of the trace agent.
1611
+ - `instance`: set to a custom `Datadog::Tracer` instance. If provided, other trace settings are ignored (you must configure it manually.)
1612
+ - `partial_flush.enabled`: set to `true` to enable partial trace flushing (for long running traces.) Disabled by default. *Experimental.*
1567
1613
  - `port`: set the port the trace agent is listening on.
1568
- - `env`: set the environment. Rails users may set it to `Rails.env` to use their application settings.
1569
- - `tags`: set global tags that should be applied to all spans. Defaults to an empty hash
1570
- - `log`: defines a custom logger.
1571
- - `partial_flush`: set to `true` to enable partial trace flushing (for long running traces.) Disabled by default. *Experimental.*
1614
+ - `sampler`: set to a custom `Datadog::Sampler` instance. If provided, the tracer will use this sampler to determine sampling behavior.
1572
1615
 
1573
1616
  #### Custom logging
1574
1617
 
@@ -1576,15 +1619,16 @@ By default, all logs are processed by the default Ruby logger. When using Rails,
1576
1619
 
1577
1620
  Datadog client log messages are marked with `[ddtrace]` so you should be able to isolate them from other messages.
1578
1621
 
1579
- Additionally, it is possible to override the default logger and replace it by a custom one. This is done using the `log` attribute of the tracer.
1622
+ Additionally, it is possible to override the default logger and replace it by a custom one. This is done using the `log` setting.
1580
1623
 
1581
1624
  ```ruby
1582
- f = File.new("my-custom.log", "w+") # Log messages should go there
1625
+ f = File.new("my-custom.log", "w+") # Log messages should go there
1583
1626
  Datadog.configure do |c|
1584
- c.tracer log: Logger.new(f) # Overriding the default tracer
1627
+ c.logger = Logger.new(f) # Overriding the default logger
1628
+ c.logger.level = ::Logger::INFO
1585
1629
  end
1586
1630
 
1587
- Datadog::Logger.log.info { "this is typically called by tracing code" }
1631
+ Datadog.logger.info { "this is typically called by tracing code" }
1588
1632
  ```
1589
1633
 
1590
1634
  ### Environment and tags
@@ -1594,9 +1638,11 @@ By default, the trace agent (not this library, but the program running in the ba
1594
1638
  You can configure the application to automatically tag your traces and metrics, using the following environment variables:
1595
1639
 
1596
1640
  - `DD_ENV`: Your application environment (e.g. `production`, `staging`, etc.)
1641
+ - `DD_SERVICE`: Your application's default service name (e.g. `billing-api`)
1597
1642
  - `DD_VERSION`: Your application version (e.g. `2.5`, `202003181415`, `1.3-alpha`, etc.)
1598
1643
  - `DD_TAGS`: Custom tags in value pairs separated by `,` (e.g. `layer:api,team:intake`)
1599
- - If `DD_ENV` or `DD_VERSION`, it will override any `env` or `version` tag defined in `DD_TAGS`.
1644
+ - If `DD_ENV`, `DD_SERVICE` or `DD_VERSION` are set, it will override any respective `env`/`service`/`version` tag defined in `DD_TAGS`.
1645
+ - If `DD_ENV`, `DD_SERVICE` or `DD_VERSION` are NOT set, tags defined in `DD_TAGS` will be used to populate `env`/`service`/`version` respectively.
1600
1646
 
1601
1647
  These values can also be overridden at the tracer level:
1602
1648
 
@@ -1609,9 +1655,9 @@ Datadog.configure do |c|
1609
1655
  end
1610
1656
  ```
1611
1657
 
1612
- This enables you to set this value on a per tracer basis, so you can have for example several applications reporting for different environments on the same host.
1658
+ This enables you to set this value on a per application basis, so you can have for example several applications reporting for different environments on the same host.
1613
1659
 
1614
- Ultimately, tags can be set per span, but `env` should typically be the same for all spans belonging to a given trace.
1660
+ Tags can also be set directly on individual spans, which will supersede any conflicting tags defined at the application level.
1615
1661
 
1616
1662
  ### Sampling
1617
1663
 
@@ -1622,8 +1668,9 @@ Ultimately, tags can be set per span, but `env` should typically be the same for
1622
1668
  ```ruby
1623
1669
  # Sample rate is between 0 (nothing sampled) to 1 (everything sampled).
1624
1670
  sampler = Datadog::RateSampler.new(0.5) # sample 50% of the traces
1671
+
1625
1672
  Datadog.configure do |c|
1626
- c.tracer sampler: sampler
1673
+ c.tracer.sampler = sampler
1627
1674
  end
1628
1675
  ```
1629
1676
 
@@ -1900,6 +1947,7 @@ Datadog.tracer.trace('correlation.example') do
1900
1947
  correlation.trace_id # => 5963550561812073440
1901
1948
  correlation.span_id # => 2232727802607726424
1902
1949
  correlation.env # => 'production' (derived from DD_ENV)
1950
+ correlation.service # => 'billing-api' (derived from DD_SERVICE)
1903
1951
  correlation.version # => '2.5.17' (derived from DD_VERSION)
1904
1952
  end
1905
1953
 
@@ -1909,8 +1957,9 @@ correlation = Datadog.tracer.active_correlation
1909
1957
  correlation = Datadog.tracer.active_correlation
1910
1958
  correlation.trace_id # => 0
1911
1959
  correlation.span_id # => 0
1912
- correlation.trace_id # => nil
1913
- correlation.span_id # => nil
1960
+ correlation.env # => 'production' (derived from DD_ENV)
1961
+ correlation.service # => 'billing-api' (derived from DD_SERVICE)
1962
+ correlation.version # => '2.5.17' (derived from DD_VERSION)
1914
1963
  ```
1915
1964
 
1916
1965
  #### For logging in Rails applications using Lograge (recommended)
@@ -1929,6 +1978,7 @@ config.lograge.custom_options = lambda do |event|
1929
1978
  :trace_id => correlation.trace_id.to_s,
1930
1979
  :span_id => correlation.span_id.to_s,
1931
1980
  :env => correlation.env.to_s,
1981
+ :service => correlation.service.to_s,
1932
1982
  :version => correlation.version.to_s
1933
1983
  },
1934
1984
  :ddsource => ["ruby"],
@@ -1950,27 +2000,29 @@ end
1950
2000
 
1951
2001
  # Given:
1952
2002
  # DD_ENV = 'production' (The name of the environment your application is running in.)
2003
+ # DD_SERVICE = 'billing-api' (Default service name of your application.)
1953
2004
  # DD_VERSION = '2.5.17' (The version of your application.)
1954
2005
 
1955
2006
  # Web requests will produce:
1956
- # [dd.trace_id=7110975754844687674 dd.span_id=7518426836986654206 dd.env=production dd.version=2.5.17] Started GET "/articles" for 172.22.0.1 at 2019-01-16 18:50:57 +0000
1957
- # [dd.trace_id=7110975754844687674 dd.span_id=7518426836986654206 dd.env=production dd.version=2.5.17] Processing by ArticlesController#index as */*
1958
- # [dd.trace_id=7110975754844687674 dd.span_id=7518426836986654206 dd.env=production dd.version=2.5.17] Article Load (0.5ms) SELECT "articles".* FROM "articles"
1959
- # [dd.trace_id=7110975754844687674 dd.span_id=7518426836986654206 dd.env=production dd.version=2.5.17] Completed 200 OK in 7ms (Views: 5.5ms | ActiveRecord: 0.5ms)
2007
+ # [dd.env=production dd.service=billing-api dd.version=2.5.17 dd.trace_id=7110975754844687674 dd.span_id=7518426836986654206] Started GET "/articles" for 172.22.0.1 at 2019-01-16 18:50:57 +0000
2008
+ # [dd.env=production dd.service=billing-api dd.version=2.5.17 dd.trace_id=7110975754844687674 dd.span_id=7518426836986654206] Processing by ArticlesController#index as */*
2009
+ # [dd.env=production dd.service=billing-api dd.version=2.5.17 dd.trace_id=7110975754844687674 dd.span_id=7518426836986654206] Article Load (0.5ms) SELECT "articles".* FROM "articles"
2010
+ # [dd.env=production dd.service=billing-api dd.version=2.5.17 dd.trace_id=7110975754844687674 dd.span_id=7518426836986654206] Completed 200 OK in 7ms (Views: 5.5ms | ActiveRecord: 0.5ms)
1960
2011
  ```
1961
2012
 
1962
2013
  #### For logging in Ruby applications
1963
2014
 
1964
2015
  To add correlation IDs to your logger, add a log formatter which retrieves the correlation IDs with `Datadog.tracer.active_correlation`, then add them to the message.
1965
2016
 
1966
- To properly correlate with Datadog logging, be sure the following is present in the log message:
2017
+ To properly correlate with Datadog logging, be sure the following is present in the log message, in order as they appear:
1967
2018
 
2019
+ - `dd.env=<ENV>`: Where `<ENV>` is equal to `Datadog.tracer.active_correlation.env`. Omit if no environment is configured.
2020
+ - `dd.service=<SERVICE>`: Where `<SERVICE>` is equal to `Datadog.tracer.active_correlation.service`. Omit if no default service name is configured.
2021
+ - `dd.version=<VERSION>`: Where `<VERSION>` is equal to `Datadog.tracer.active_correlation.version`. Omit if no application version is configured.
1968
2022
  - `dd.trace_id=<TRACE_ID>`: Where `<TRACE_ID>` is equal to `Datadog.tracer.active_correlation.trace_id` or `0` if no trace is active during logging.
1969
2023
  - `dd.span_id=<SPAN_ID>`: Where `<SPAN_ID>` is equal to `Datadog.tracer.active_correlation.span_id` or `0` if no trace is active during logging.
1970
- - `dd.env=<ENV>`: Where `<ENV>` is equal to `Datadog.tracer.active_correlation.env` or empty string (no quotes) if no environment name is configured.
1971
- - `dd.version=<SPAN_ID>`: Where `<SPAN_ID>` is equal to `Datadog.tracer.active_correlation.version` or empty string (no quotes) if no application version is configured.
1972
2024
 
1973
- By default, `Datadog::Correlation::Identifier#to_s` will return `dd.trace_id=<TRACE_ID> dd.span_id=<SPAN_ID> dd.env=<ENV> dd.version=<VERSION>`.
2025
+ By default, `Datadog::Correlation::Identifier#to_s` will return `dd.env=<ENV> dd.service=<SERVICE> dd.version=<VERSION> dd.trace_id=<TRACE_ID> dd.span_id=<SPAN_ID>`.
1974
2026
 
1975
2027
  If a trace is not active and the application environment & version is not configured, it will return `dd.trace_id=0 dd.span_id=0 dd.env= dd.version=`.
1976
2028
 
@@ -1981,6 +2033,7 @@ require 'ddtrace'
1981
2033
  require 'logger'
1982
2034
 
1983
2035
  ENV['DD_ENV'] = 'production'
2036
+ ENV['DD_SERVICE'] = 'billing-api'
1984
2037
  ENV['DD_VERSION'] = '2.5.17'
1985
2038
 
1986
2039
  logger = Logger.new(STDOUT)
@@ -1991,11 +2044,11 @@ end
1991
2044
 
1992
2045
  # When no trace is active
1993
2046
  logger.warn('This is an untraced operation.')
1994
- # [2019-01-16 18:38:41 +0000][my_app][WARN][dd.trace_id=0 dd.span_id=0 dd.env=production dd.version=2.5.17] This is an untraced operation.
2047
+ # [2019-01-16 18:38:41 +0000][my_app][WARN][dd.env=production dd.service=billing-api dd.version=2.5.17 dd.trace_id=0 dd.span_id=0] This is an untraced operation.
1995
2048
 
1996
2049
  # When a trace is active
1997
2050
  Datadog.tracer.trace('my.operation') { logger.warn('This is a traced operation.') }
1998
- # [2019-01-16 18:38:41 +0000][my_app][WARN][dd.trace_id=8545847825299552251 dd.span_id=3711755234730770098 dd.env=production dd.version=2.5.17] This is a traced operation.
2051
+ # [2019-01-16 18:38:41 +0000][my_app][WARN][dd.env=production dd.service=billing-api dd.version=2.5.17 dd.trace_id=8545847825299552251 dd.span_id=3711755234730770098] This is a traced operation.
1999
2052
  ```
2000
2053
 
2001
2054
  ### Configuring the transport layer
@@ -2010,7 +2063,7 @@ The `Net` adapter submits traces using `Net::HTTP` over TCP. It is the default t
2010
2063
 
2011
2064
  ```ruby
2012
2065
  Datadog.configure do |c|
2013
- c.tracer transport_options: proc do |t|
2066
+ c.tracer.transport_options = proc { |t|
2014
2067
  # Hostname, port, and additional options. :timeout is in seconds.
2015
2068
  t.adapter :net_http, '127.0.0.1', 8126, { timeout: 1 }
2016
2069
  }
@@ -2025,7 +2078,7 @@ To use, first configure your trace agent to listen by Unix socket, then configur
2025
2078
 
2026
2079
  ```ruby
2027
2080
  Datadog.configure do |c|
2028
- c.tracer transport_options: proc { |t|
2081
+ c.tracer.transport_options = proc { |t|
2029
2082
  # Provide filepath to trace agent Unix socket
2030
2083
  t.adapter :unix, '/tmp/ddagent/trace.sock'
2031
2084
  }
@@ -2038,7 +2091,7 @@ The `Test` adapter is a no-op transport that can optionally buffer requests. For
2038
2091
 
2039
2092
  ```ruby
2040
2093
  Datadog.configure do |c|
2041
- c.tracer transport_options: proc { |t|
2094
+ c.tracer.transport_options = proc { |t|
2042
2095
  # Set transport to no-op mode. Does not retain traces.
2043
2096
  t.adapter :test
2044
2097
 
@@ -2055,7 +2108,7 @@ Custom adapters can be configured with:
2055
2108
 
2056
2109
  ```ruby
2057
2110
  Datadog.configure do |c|
2058
- c.tracer transport_options: proc { |t|
2111
+ c.tracer.transport_options = proc { |t|
2059
2112
  # Initialize and pass an instance of the adapter
2060
2113
  custom_adapter = CustomAdapter.new
2061
2114
  t.adapter custom_adapter
@@ -2086,12 +2139,12 @@ require 'ddtrace'
2086
2139
  Datadog.configure do |c|
2087
2140
  # To enable runtime metrics collection, set `true`. Defaults to `false`
2088
2141
  # You can also set DD_RUNTIME_METRICS_ENABLED=true to configure this.
2089
- c.runtime_metrics_enabled = true
2142
+ c.runtime_metrics.enabled = true
2090
2143
 
2091
2144
  # Optionally, you can configure the Statsd instance used for sending runtime metrics.
2092
2145
  # Statsd is automatically configured with default settings if `dogstatsd-ruby` is available.
2093
2146
  # You can configure with host and port of Datadog agent; defaults to 'localhost:8125'.
2094
- c.runtime_metrics statsd: Datadog::Statsd.new
2147
+ c.runtime_metrics.statsd = Datadog::Statsd.new
2095
2148
  end
2096
2149
  ```
2097
2150
 
@@ -34,7 +34,7 @@ module Datadog
34
34
  # Add shutdown hook:
35
35
  # Ensures the tracer has an opportunity to flush traces
36
36
  # and cleanup before terminating the process.
37
- at_exit { Datadog.tracer.shutdown! }
37
+ at_exit { Datadog.shutdown! }
38
38
  end
39
39
 
40
40
  require 'ddtrace/contrib/action_cable/integration'
@@ -83,7 +83,7 @@ module Datadog
83
83
  @buffer_accepted += 1
84
84
  @buffer_accepted_lengths += trace.length
85
85
  rescue StandardError => e
86
- Datadog::Logger.log.debug("Failed to measure queue accept. Cause: #{e.message} Source: #{e.backtrace.first}")
86
+ Datadog.logger.debug("Failed to measure queue accept. Cause: #{e.message} Source: #{e.backtrace.first}")
87
87
  end
88
88
 
89
89
  def measure_drop(trace)
@@ -91,21 +91,21 @@ module Datadog
91
91
  @buffer_spans -= trace.length
92
92
  @buffer_accepted_lengths -= trace.length
93
93
  rescue StandardError => e
94
- Datadog::Logger.log.debug("Failed to measure queue drop. Cause: #{e.message} Source: #{e.backtrace.first}")
94
+ Datadog.logger.debug("Failed to measure queue drop. Cause: #{e.message} Source: #{e.backtrace.first}")
95
95
  end
96
96
 
97
97
  def measure_pop(traces)
98
98
  # Accepted
99
- Diagnostics::Health.metrics.queue_accepted(@buffer_accepted)
100
- Diagnostics::Health.metrics.queue_accepted_lengths(@buffer_accepted_lengths)
99
+ Datadog.health_metrics.queue_accepted(@buffer_accepted)
100
+ Datadog.health_metrics.queue_accepted_lengths(@buffer_accepted_lengths)
101
101
 
102
102
  # Dropped
103
- Diagnostics::Health.metrics.queue_dropped(@buffer_dropped)
103
+ Datadog.health_metrics.queue_dropped(@buffer_dropped)
104
104
 
105
105
  # Queue gauges
106
- Diagnostics::Health.metrics.queue_max_length(@max_size)
107
- Diagnostics::Health.metrics.queue_spans(@buffer_spans)
108
- Diagnostics::Health.metrics.queue_length(traces.length)
106
+ Datadog.health_metrics.queue_max_length(@max_size)
107
+ Datadog.health_metrics.queue_spans(@buffer_spans)
108
+ Datadog.health_metrics.queue_length(traces.length)
109
109
 
110
110
  # Reset aggregated metrics
111
111
  @buffer_accepted = 0
@@ -113,7 +113,7 @@ module Datadog
113
113
  @buffer_dropped = 0
114
114
  @buffer_spans = 0
115
115
  rescue StandardError => e
116
- Datadog::Logger.log.debug("Failed to measure queue. Cause: #{e.message} Source: #{e.backtrace.first}")
116
+ Datadog.logger.debug("Failed to measure queue. Cause: #{e.message} Source: #{e.backtrace.first}")
117
117
  end
118
118
  end
119
119
  end
@@ -0,0 +1,34 @@
1
+ require 'json'
2
+ require 'msgpack'
3
+
4
+ module Datadog
5
+ # Chunks list of elements into batches
6
+ module Chunker
7
+ module_function
8
+
9
+ # Chunks a list into batches of at most +max_chunk_size+ elements each.
10
+ #
11
+ # An exception can occur if a single element is too large. That single
12
+ # element will be returned in its own chunk. You have to verify by yourself
13
+ # when such elements are returned.
14
+ #
15
+ # @param list [Enumerable] list of elements
16
+ # @param max_chunk_size [Numeric] maximum acceptable chunk size
17
+ # @return [Enumerable] lazy list of chunks
18
+ def chunk_by_size(list, max_chunk_size)
19
+ chunk_agg = 0
20
+ list.slice_before do |elem|
21
+ size = elem.size
22
+ chunk_agg += size
23
+ if chunk_agg > max_chunk_size
24
+ # Can't fit element in current chunk, start a new one.
25
+ chunk_agg = size
26
+ true
27
+ else
28
+ # Add to current chunk
29
+ false
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end