ddtrace 0.25.1 → 0.26.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -2
- data/docs/GettingStarted.md +30 -30
- data/lib/ddtrace/contrib/http/circuit_breaker.rb +0 -4
- data/lib/ddtrace/ext/metrics.rb +5 -0
- data/lib/ddtrace/ext/transport.rb +17 -0
- data/lib/ddtrace/metrics.rb +14 -10
- data/lib/ddtrace/runtime/cgroup.rb +44 -0
- data/lib/ddtrace/runtime/container.rb +73 -0
- data/lib/ddtrace/transport/http.rb +22 -16
- data/lib/ddtrace/version.rb +2 -2
- data/lib/ddtrace/writer.rb +12 -42
- metadata +5 -3
- data/lib/ddtrace/transport.rb +0 -233
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afb28eea48bf86f3cac41970e8b600e2f6daed82
|
4
|
+
data.tar.gz: 1a712a917211717bb409754fcffda978f7146522
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be061d7e43faaafb0f1f3b45d78e556eda4bdacca67d8ac471f0588066152d84f53a4e88143dcfca4b1ea58cb4be1e74f3a75f143196a345966b8099704bf329
|
7
|
+
data.tar.gz: 7b805cd9b5a623f7100f0572ab281e999e1f3e18879a0b3ddb951d30572023058d6465fd78e4d67b4011c5ec84af6a668992232217ea60ba1ac9d513cf3c40f8
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,32 @@
|
|
4
4
|
|
5
5
|
## [Unreleased (beta)]
|
6
6
|
|
7
|
+
## [0.26.0] - 2019-08-06
|
8
|
+
|
9
|
+
Release notes: https://github.com/DataDog/dd-trace-rb/releases/tag/v0.26.0
|
10
|
+
|
11
|
+
Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.25.1...v0.26.0
|
12
|
+
|
13
|
+
Support for Ruby < 2.0 is *deprecated*. Plan for timeline is as follows:
|
14
|
+
|
15
|
+
- 0.25.0: Support for Ruby < 2.0 is deprecated; retains full feature support.
|
16
|
+
- 0.26.0: Last version to support Ruby < 2.0; any new features will not support 1.9.
|
17
|
+
- 0.27.0: Support for Ruby < 2.0 is removed.
|
18
|
+
|
19
|
+
Version 0.26.x will receive only critical bugfixes for 1 year following the release of 0.26.0 (August 6th, 2020.)
|
20
|
+
|
21
|
+
### Added
|
22
|
+
|
23
|
+
- Container ID tagging for containerized environments (#784)
|
24
|
+
|
25
|
+
### Refactored
|
26
|
+
|
27
|
+
- Datadog::Metrics constants (#789)
|
28
|
+
|
29
|
+
### Removed
|
30
|
+
|
31
|
+
- Datadog::HTTPTransport and related components (#782)
|
32
|
+
|
7
33
|
## [0.25.1] - 2019-07-16
|
8
34
|
|
9
35
|
Release notes: https://github.com/DataDog/dd-trace-rb/releases/tag/v0.25.1
|
@@ -876,8 +902,9 @@ Release notes: https://github.com/DataDog/dd-trace-rb/releases/tag/v0.3.1
|
|
876
902
|
|
877
903
|
Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
|
878
904
|
|
879
|
-
[Unreleased (stable)]: https://github.com/DataDog/dd-trace-rb/compare/v0.
|
880
|
-
[Unreleased (beta)]: https://github.com/DataDog/dd-trace-rb/compare/v0.
|
905
|
+
[Unreleased (stable)]: https://github.com/DataDog/dd-trace-rb/compare/v0.26.0...master
|
906
|
+
[Unreleased (beta)]: https://github.com/DataDog/dd-trace-rb/compare/v0.26.0...0.27-dev
|
907
|
+
[0.26.0]: https://github.com/DataDog/dd-trace-rb/compare/v0.25.1...v0.26.0
|
881
908
|
[0.25.1]: https://github.com/DataDog/dd-trace-rb/compare/v0.25.0...v0.25.1
|
882
909
|
[0.25.0]: https://github.com/DataDog/dd-trace-rb/compare/v0.24.0...v0.25.0
|
883
910
|
[0.24.0]: https://github.com/DataDog/dd-trace-rb/compare/v0.23.3...v0.24.0
|
data/docs/GettingStarted.md
CHANGED
@@ -240,7 +240,7 @@ get '/posts' do
|
|
240
240
|
end
|
241
241
|
```
|
242
242
|
|
243
|
-
|
243
|
+
### Asynchronous tracing
|
244
244
|
|
245
245
|
It might not always be possible to wrap `Datadog.tracer.trace` around a block of code. Some event or notification based instrumentation might only notify you when an event begins or ends.
|
246
246
|
|
@@ -279,7 +279,7 @@ def finish(name, id, payload)
|
|
279
279
|
end
|
280
280
|
end
|
281
281
|
```
|
282
|
-
|
282
|
+
### Enriching traces from nested methods
|
283
283
|
|
284
284
|
You can tag additional information to the current active span from any method. Note however that if the method is called and there is no span currently active `active_span` will be nil.
|
285
285
|
|
@@ -344,7 +344,7 @@ For a list of available integrations, and their configuration options, please re
|
|
344
344
|
| Sinatra | `sinatra` | `>= 1.4.5` | *[Link](#sinatra)* | *[Link](https://github.com/sinatra/sinatra)* |
|
345
345
|
| Sucker Punch | `sucker_punch` | `>= 2.0` | *[Link](#sucker-punch)* | *[Link](https://github.com/brandonhilkert/sucker_punch)* |
|
346
346
|
|
347
|
-
|
347
|
+
### Active Model Serializers
|
348
348
|
|
349
349
|
The Active Model Serializers integration traces the `serialize` event for version 0.9+ and the `render` event for version 0.10+.
|
350
350
|
|
@@ -366,7 +366,7 @@ ActiveModelSerializers::SerializableResource.new(test_obj).serializable_hash
|
|
366
366
|
| `service_name` | Service name used for `active_model_serializers` instrumentation. | `'active_model_serializers'` |
|
367
367
|
| `tracer` | `Datadog::Tracer` used to perform instrumentation. Usually you don't need to set this. | `Datadog.tracer` |
|
368
368
|
|
369
|
-
|
369
|
+
### Active Record
|
370
370
|
|
371
371
|
Most of the time, Active Record is set up as part of a web framework (Rails, Sinatra...) however, it can be set up alone:
|
372
372
|
|
@@ -434,7 +434,7 @@ end
|
|
434
434
|
|
435
435
|
If ActiveRecord traces an event that uses a connection that matches a key defined by `describes`, it will use the trace settings assigned to that connection. If the connection does not match any of the described connections, it will use default settings defined by `c.use :active_record` instead.
|
436
436
|
|
437
|
-
|
437
|
+
### AWS
|
438
438
|
|
439
439
|
The AWS integration will trace every interaction (e.g. API calls) with AWS services (S3, ElastiCache etc.).
|
440
440
|
|
@@ -458,7 +458,7 @@ Where `options` is an optional `Hash` that accepts the following parameters:
|
|
458
458
|
| `service_name` | Service name used for `aws` instrumentation | `'aws'` |
|
459
459
|
| `tracer` | `Datadog::Tracer` used to perform instrumentation. Usually you don't need to set this. | `Datadog.tracer` |
|
460
460
|
|
461
|
-
|
461
|
+
### Concurrent Ruby
|
462
462
|
|
463
463
|
The Concurrent Ruby integration adds support for context propagation when using `::Concurrent::Future`.
|
464
464
|
Making sure that code traced within the `Future#execute` will have correct parent set.
|
@@ -485,7 +485,7 @@ Where `options` is an optional `Hash` that accepts the following parameters:
|
|
485
485
|
| `service_name` | Service name used for `concurrent-ruby` instrumentation | `'concurrent-ruby'` |
|
486
486
|
| `tracer` | `Datadog::Tracer` used to perform instrumentation. Usually you don't need to set this. | `Datadog.tracer` |
|
487
487
|
|
488
|
-
|
488
|
+
### Dalli
|
489
489
|
|
490
490
|
Dalli integration will trace all calls to your `memcached` server:
|
491
491
|
|
@@ -511,7 +511,7 @@ Where `options` is an optional `Hash` that accepts the following parameters:
|
|
511
511
|
| `service_name` | Service name used for `dalli` instrumentation | `'memcached'` |
|
512
512
|
| `tracer` | `Datadog::Tracer` used to perform instrumentation. Usually you don't need to set this. | `Datadog.tracer` |
|
513
513
|
|
514
|
-
|
514
|
+
### DelayedJob
|
515
515
|
|
516
516
|
The DelayedJob integration uses lifecycle hooks to trace the job executions.
|
517
517
|
|
@@ -533,7 +533,7 @@ Where `options` is an optional `Hash` that accepts the following parameters:
|
|
533
533
|
| `service_name` | Service name used for `DelayedJob` instrumentation | `'delayed_job'` |
|
534
534
|
| `tracer` | `Datadog::Tracer` used to perform instrumentation. Usually you don't need to set this. | `Datadog.tracer` |
|
535
535
|
|
536
|
-
|
536
|
+
### Elastic Search
|
537
537
|
|
538
538
|
The Elasticsearch integration will trace any call to `perform_request` in the `Client` object:
|
539
539
|
|
@@ -559,7 +559,7 @@ Where `options` is an optional `Hash` that accepts the following parameters:
|
|
559
559
|
| `service_name` | Service name used for `elasticsearch` instrumentation | `'elasticsearch'` |
|
560
560
|
| `tracer` | `Datadog::Tracer` used to perform instrumentation. Usually you don't need to set this. | `Datadog.tracer` |
|
561
561
|
|
562
|
-
|
562
|
+
### Excon
|
563
563
|
|
564
564
|
The `excon` integration is available through the `ddtrace` middleware:
|
565
565
|
|
@@ -612,7 +612,7 @@ Excon.new(
|
|
612
612
|
|
613
613
|
Where `options` is a Hash that contains any of the parameters listed in the table above.
|
614
614
|
|
615
|
-
|
615
|
+
### Faraday
|
616
616
|
|
617
617
|
The `faraday` integration is available through the `ddtrace` middleware:
|
618
618
|
|
@@ -645,7 +645,7 @@ Where `options` is an optional `Hash` that accepts the following parameters:
|
|
645
645
|
| `split_by_domain` | Uses the request domain as the service name when set to `true`. | `false` |
|
646
646
|
| `tracer` | `Datadog::Tracer` used to perform instrumentation. Usually, you don't need to set this. | `Datadog.tracer` |
|
647
647
|
|
648
|
-
|
648
|
+
### Grape
|
649
649
|
|
650
650
|
The Grape integration adds the instrumentation to Grape endpoints and filters. This integration can work side by side with other integrations like Rack and Rails.
|
651
651
|
|
@@ -678,7 +678,7 @@ Where `options` is an optional `Hash` that accepts the following parameters:
|
|
678
678
|
| `service_name` | Service name used for `grape` instrumentation | `'grape'` |
|
679
679
|
| `tracer` | `Datadog::Tracer` used to perform instrumentation. Usually you don't need to set this. | `Datadog.tracer` |
|
680
680
|
|
681
|
-
|
681
|
+
### GraphQL
|
682
682
|
|
683
683
|
The GraphQL integration activates instrumentation for GraphQL queries.
|
684
684
|
|
@@ -729,7 +729,7 @@ end
|
|
729
729
|
|
730
730
|
Do *NOT* `use :graphql` in `Datadog.configure` if you choose to configure manually, as to avoid double tracing. These two means of configuring GraphQL tracing are considered mutually exclusive.
|
731
731
|
|
732
|
-
|
732
|
+
### gRPC
|
733
733
|
|
734
734
|
The `grpc` integration adds both client and server interceptors, which run as middleware before executing the service's remote procedure call. As gRPC applications are often distributed, the integration shares trace information between client and server.
|
735
735
|
|
@@ -780,7 +780,7 @@ alternate_client = Demo::Echo::Service.rpc_stub_class.new(
|
|
780
780
|
|
781
781
|
The integration will ensure that the `configured_interceptor` establishes a unique tracing setup for that client instance.
|
782
782
|
|
783
|
-
|
783
|
+
### MongoDB
|
784
784
|
|
785
785
|
The integration traces any `Command` that is sent from the [MongoDB Ruby Driver](https://github.com/mongodb/mongo-ruby-driver) to a MongoDB cluster. By extension, Object Document Mappers (ODM) such as Mongoid are automatically instrumented if they use the official Ruby driver. To activate the integration, simply:
|
786
786
|
|
@@ -810,7 +810,7 @@ Where `options` is an optional `Hash` that accepts the following parameters:
|
|
810
810
|
| `service_name` | Service name used for `mongo` instrumentation | `'mongodb'` |
|
811
811
|
| `tracer` | `Datadog::Tracer` used to perform instrumentation. Usually you don't need to set this. | `Datadog.tracer` |
|
812
812
|
|
813
|
-
|
813
|
+
### MySQL2
|
814
814
|
|
815
815
|
The MySQL2 integration traces any SQL command sent through `mysql2` gem.
|
816
816
|
|
@@ -834,7 +834,7 @@ Where `options` is an optional `Hash` that accepts the following parameters:
|
|
834
834
|
| `service_name` | Service name used for `mysql2` instrumentation | `'mysql2'` |
|
835
835
|
| `tracer` | `Datadog::Tracer` used to perform instrumentation. Usually you don't need to set this. | `Datadog.tracer` |
|
836
836
|
|
837
|
-
|
837
|
+
### Net/HTTP
|
838
838
|
|
839
839
|
The Net/HTTP integration will trace any HTTP call using the standard lib Net::HTTP module.
|
840
840
|
|
@@ -870,7 +870,7 @@ client = Net::HTTP.new(host, port)
|
|
870
870
|
Datadog.configure(client, options)
|
871
871
|
```
|
872
872
|
|
873
|
-
|
873
|
+
### Racecar
|
874
874
|
|
875
875
|
The Racecar integration provides tracing for Racecar jobs.
|
876
876
|
|
@@ -892,7 +892,7 @@ Where `options` is an optional `Hash` that accepts the following parameters:
|
|
892
892
|
| `service_name` | Service name used for `racecar` instrumentation | `'racecar'` |
|
893
893
|
| `tracer` | `Datadog::Tracer` used to perform instrumentation. Usually you don't need to set this. | `Datadog.tracer` |
|
894
894
|
|
895
|
-
|
895
|
+
### Rack
|
896
896
|
|
897
897
|
The Rack integration provides a middleware that traces all requests before they reach the underlying framework or application. It responds to the Rack minimal interface, providing reasonable values that can be retrieved at the Rack level.
|
898
898
|
|
@@ -965,7 +965,7 @@ Datadog.configure do |c|
|
|
965
965
|
end
|
966
966
|
```
|
967
967
|
|
968
|
-
|
968
|
+
### Rails
|
969
969
|
|
970
970
|
The Rails integration will trace requests, database calls, templates rendering, and cache read/write/delete operations. The integration makes use of the Active Support Instrumentation, listening to the Notification API so that any operation instrumented by the API is traced.
|
971
971
|
|
@@ -1005,7 +1005,7 @@ Where `options` is an optional `Hash` that accepts the following parameters:
|
|
1005
1005
|
| 2.2 - 2.3 | 3.0 - 5.2 |
|
1006
1006
|
| 2.4 - 2.5 | 4.2.8 - 5.2 |
|
1007
1007
|
|
1008
|
-
|
1008
|
+
### Rake
|
1009
1009
|
|
1010
1010
|
You can add instrumentation around your Rake tasks by activating the `rake` integration. Each task and its subsequent subtasks will be traced.
|
1011
1011
|
|
@@ -1071,7 +1071,7 @@ Datadog.configure do |c|
|
|
1071
1071
|
end
|
1072
1072
|
```
|
1073
1073
|
|
1074
|
-
|
1074
|
+
### Redis
|
1075
1075
|
|
1076
1076
|
The Redis integration will trace simple calls as well as pipelines.
|
1077
1077
|
|
@@ -1111,7 +1111,7 @@ customer_cache.get(...)
|
|
1111
1111
|
invoice_cache.get(...)
|
1112
1112
|
```
|
1113
1113
|
|
1114
|
-
|
1114
|
+
### Resque
|
1115
1115
|
|
1116
1116
|
The Resque integration uses Resque hooks that wraps the `perform` method.
|
1117
1117
|
|
@@ -1140,7 +1140,7 @@ Where `options` is an optional `Hash` that accepts the following parameters:
|
|
1140
1140
|
| `tracer` | `Datadog::Tracer` used to perform instrumentation. Usually, you don't need to set this. | `Datadog.tracer` |
|
1141
1141
|
| `workers` | An array including all worker classes you want to trace (e.g. `[MyJob]`) | `[]` |
|
1142
1142
|
|
1143
|
-
|
1143
|
+
### Rest Client
|
1144
1144
|
|
1145
1145
|
The `rest-client` integration is available through the `ddtrace` middleware:
|
1146
1146
|
|
@@ -1162,7 +1162,7 @@ Where `options` is an optional `Hash` that accepts the following parameters:
|
|
1162
1162
|
| `service_name` | Service name for `rest_client` instrumentation. | `'rest_client'` |
|
1163
1163
|
| `tracer` | `Datadog::Tracer` used to perform instrumentation. Usually you don't need to set this. | `Datadog.tracer` |
|
1164
1164
|
|
1165
|
-
|
1165
|
+
### Sequel
|
1166
1166
|
|
1167
1167
|
The Sequel integration traces queries made to your database.
|
1168
1168
|
|
@@ -1211,7 +1211,7 @@ Datadog.configure(sqlite_database, service_name: 'my-sqlite-db')
|
|
1211
1211
|
Datadog.configure(postgres_database, service_name: 'my-postgres-db')
|
1212
1212
|
```
|
1213
1213
|
|
1214
|
-
|
1214
|
+
### Shoryuken
|
1215
1215
|
|
1216
1216
|
The Shoryuken integration is a server-side middleware which will trace job executions.
|
1217
1217
|
|
@@ -1233,7 +1233,7 @@ Where `options` is an optional `Hash` that accepts the following parameters:
|
|
1233
1233
|
| `service_name` | Service name used for `shoryuken` instrumentation | `'shoryuken'` |
|
1234
1234
|
| `tracer` | `Datadog::Tracer` used to perform instrumentation. Usually you don't need to set this. | `Datadog.tracer` |
|
1235
1235
|
|
1236
|
-
|
1236
|
+
### Sidekiq
|
1237
1237
|
|
1238
1238
|
The Sidekiq integration is a client-side & server-side middleware which will trace job queuing and executions respectively.
|
1239
1239
|
|
@@ -1256,7 +1256,7 @@ Where `options` is an optional `Hash` that accepts the following parameters:
|
|
1256
1256
|
| `service_name` | Service name used for server-side `sidekiq` instrumentation | `'sidekiq'` |
|
1257
1257
|
| `tracer` | `Datadog::Tracer` used to perform instrumentation. Usually you don't need to set this. | `Datadog.tracer` |
|
1258
1258
|
|
1259
|
-
|
1259
|
+
### Sinatra
|
1260
1260
|
|
1261
1261
|
The Sinatra integration traces requests and template rendering.
|
1262
1262
|
|
@@ -1286,7 +1286,7 @@ Where `options` is an optional `Hash` that accepts the following parameters:
|
|
1286
1286
|
| `service_name` | Service name used for `sinatra` instrumentation | `'sinatra'` |
|
1287
1287
|
| `tracer` | `Datadog::Tracer` used to perform instrumentation. Usually you don't need to set this. | `Datadog.tracer` |
|
1288
1288
|
|
1289
|
-
|
1289
|
+
### Sucker Punch
|
1290
1290
|
|
1291
1291
|
The `sucker_punch` integration traces all scheduled jobs:
|
1292
1292
|
|
@@ -1516,7 +1516,7 @@ Service C:
|
|
1516
1516
|
|
1517
1517
|
**Activating distributed tracing for integrations**
|
1518
1518
|
|
1519
|
-
Many integrations included in `ddtrace` support distributed tracing. Distributed tracing is
|
1519
|
+
Many integrations included in `ddtrace` support distributed tracing. Distributed tracing is enabled by default, but can be activated via configuration settings.
|
1520
1520
|
|
1521
1521
|
- If your application receives requests from services with distributed tracing activated, you must activate distributed tracing on the integrations that handle these requests (e.g. Rails)
|
1522
1522
|
- If your application send requests to services with distributed tracing activated, you must activate distributed tracing on the integrations that send these requests (e.g. Faraday)
|
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
module Datadog
|
3
2
|
module Contrib
|
4
3
|
module HTTP
|
@@ -27,9 +26,6 @@ module Datadog
|
|
27
26
|
|
28
27
|
# Get settings from transport, if available.
|
29
28
|
case transport
|
30
|
-
when Datadog::HTTPTransport
|
31
|
-
transport_hostname = transport.hostname.to_s
|
32
|
-
transport_port = transport.port.to_i
|
33
29
|
when Datadog::Transport::HTTP::Client
|
34
30
|
adapter = transport.current_api.adapter
|
35
31
|
if adapter.is_a?(Datadog::Transport::HTTP::Adapters::Net)
|
data/lib/ddtrace/ext/metrics.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
module Datadog
|
2
2
|
module Ext
|
3
3
|
module Metrics
|
4
|
+
DEFAULT_HOST = '127.0.0.1'.freeze
|
5
|
+
DEFAULT_PORT = 8125
|
6
|
+
ENV_DEFAULT_HOST = 'DD_AGENT_HOST'.freeze
|
7
|
+
ENV_DEFAULT_PORT = 'DD_METRIC_AGENT_PORT'.freeze
|
8
|
+
|
4
9
|
TAG_LANG = 'language'.freeze
|
5
10
|
TAG_LANG_INTERPRETER = 'language-interpreter'.freeze
|
6
11
|
TAG_LANG_VERSION = 'language-version'.freeze
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Datadog
|
2
|
+
module Ext
|
3
|
+
module Transport
|
4
|
+
module HTTP
|
5
|
+
DEFAULT_HOST = '127.0.0.1'.freeze
|
6
|
+
DEFAULT_PORT = 8126
|
7
|
+
ENV_DEFAULT_HOST = 'DD_AGENT_HOST'.freeze
|
8
|
+
ENV_DEFAULT_PORT = 'DD_TRACE_AGENT_PORT'.freeze
|
9
|
+
HEADER_CONTAINER_ID = 'Datadog-Container-ID'.freeze
|
10
|
+
HEADER_META_LANG = 'Datadog-Meta-Lang'.freeze
|
11
|
+
HEADER_META_LANG_VERSION = 'Datadog-Meta-Lang-Version'.freeze
|
12
|
+
HEADER_META_LANG_INTERPRETER = 'Datadog-Meta-Lang-Interpreter'.freeze
|
13
|
+
HEADER_META_TRACER_VERSION = 'Datadog-Meta-Tracer-Version'.freeze
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/ddtrace/metrics.rb
CHANGED
@@ -8,9 +8,6 @@ module Datadog
|
|
8
8
|
# Acts as client for sending metrics (via Statsd)
|
9
9
|
# Wraps a Statsd client with default tags and additional configuration.
|
10
10
|
class Metrics
|
11
|
-
DEFAULT_AGENT_HOST = '127.0.0.1'.freeze
|
12
|
-
DEFAULT_METRIC_AGENT_PORT = '8125'.freeze
|
13
|
-
|
14
11
|
attr_reader :statsd
|
15
12
|
|
16
13
|
def initialize(options = {})
|
@@ -19,8 +16,10 @@ module Datadog
|
|
19
16
|
end
|
20
17
|
|
21
18
|
def supported?
|
22
|
-
Gem.loaded_specs['dogstatsd-ruby'] \
|
23
|
-
|
19
|
+
version = Gem.loaded_specs['dogstatsd-ruby'] \
|
20
|
+
&& Gem.loaded_specs['dogstatsd-ruby'].version
|
21
|
+
|
22
|
+
!version.nil? && (version >= Gem::Version.new('3.3.0'))
|
24
23
|
end
|
25
24
|
|
26
25
|
def enabled?
|
@@ -31,19 +30,24 @@ module Datadog
|
|
31
30
|
@enabled = (enabled == true)
|
32
31
|
end
|
33
32
|
|
33
|
+
def default_hostname
|
34
|
+
ENV.fetch(Datadog::Ext::Metrics::ENV_DEFAULT_HOST, Datadog::Ext::Metrics::DEFAULT_HOST)
|
35
|
+
end
|
36
|
+
|
37
|
+
def default_port
|
38
|
+
ENV.fetch(Datadog::Ext::Metrics::ENV_DEFAULT_PORT, Datadog::Ext::Metrics::DEFAULT_PORT).to_i
|
39
|
+
end
|
40
|
+
|
34
41
|
def default_statsd_client
|
35
42
|
require 'datadog/statsd' unless defined?(::Datadog::Statsd)
|
36
43
|
|
37
44
|
# Create a StatsD client that points to the agent.
|
38
|
-
Datadog::Statsd.new(
|
39
|
-
ENV.fetch('DD_AGENT_HOST', DEFAULT_AGENT_HOST),
|
40
|
-
ENV.fetch('DD_METRIC_AGENT_PORT', DEFAULT_METRIC_AGENT_PORT)
|
41
|
-
)
|
45
|
+
Datadog::Statsd.new(default_hostname, default_port)
|
42
46
|
end
|
43
47
|
|
44
48
|
def configure(options = {})
|
45
49
|
@statsd = options[:statsd] if options.key?(:statsd)
|
46
|
-
|
50
|
+
self.enabled = options[:enabled] if options.key?(:enabled)
|
47
51
|
end
|
48
52
|
|
49
53
|
def send_stats?
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'ddtrace/ext/runtime'
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module Runtime
|
5
|
+
# For control groups
|
6
|
+
module Cgroup
|
7
|
+
LINE_REGEX = /^(\d+):([^:]*):(.+)$/
|
8
|
+
|
9
|
+
Descriptor = Struct.new(
|
10
|
+
:id,
|
11
|
+
:groups,
|
12
|
+
:path,
|
13
|
+
:controllers
|
14
|
+
)
|
15
|
+
|
16
|
+
module_function
|
17
|
+
|
18
|
+
def descriptors(process = 'self')
|
19
|
+
[].tap do |descriptors|
|
20
|
+
begin
|
21
|
+
filepath = "/proc/#{process}/cgroup"
|
22
|
+
|
23
|
+
if File.exist?(filepath)
|
24
|
+
File.open("/proc/#{process}/cgroup").each do |line|
|
25
|
+
line = line.strip
|
26
|
+
descriptors << parse(line) unless line.empty?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
rescue StandardError => e
|
30
|
+
Datadog::Tracer.log.error("Error while parsing cgroup. Cause: #{e.message} Location: #{e.backtrace.first}")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def parse(line)
|
36
|
+
id, groups, path = line.scan(LINE_REGEX).first
|
37
|
+
|
38
|
+
Descriptor.new(id, groups, path).tap do |descriptor|
|
39
|
+
descriptor.controllers = groups.split(',') unless groups.nil?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'ddtrace/ext/runtime'
|
2
|
+
require 'ddtrace/runtime/cgroup'
|
3
|
+
|
4
|
+
module Datadog
|
5
|
+
module Runtime
|
6
|
+
# For container environments
|
7
|
+
module Container
|
8
|
+
UUID_PATTERN = '[0-9a-f]{8}[-_]?[0-9a-f]{4}[-_]?[0-9a-f]{4}[-_]?[0-9a-f]{4}[-_]?[0-9a-f]{12}'.freeze
|
9
|
+
CONTAINER_PATTERN = '[0-9a-f]{64}'.freeze
|
10
|
+
|
11
|
+
POD_REGEX = /(pod)?(#{UUID_PATTERN})(?:.slice)?$/
|
12
|
+
CONTAINER_REGEX = /(#{UUID_PATTERN}|#{CONTAINER_PATTERN})(?:.scope)?$/
|
13
|
+
|
14
|
+
Descriptor = Struct.new(
|
15
|
+
:platform,
|
16
|
+
:container_id,
|
17
|
+
:task_uid
|
18
|
+
)
|
19
|
+
|
20
|
+
module_function
|
21
|
+
|
22
|
+
def platform
|
23
|
+
descriptor.platform
|
24
|
+
end
|
25
|
+
|
26
|
+
def container_id
|
27
|
+
descriptor.container_id
|
28
|
+
end
|
29
|
+
|
30
|
+
def task_uid
|
31
|
+
descriptor.task_uid
|
32
|
+
end
|
33
|
+
|
34
|
+
def descriptor
|
35
|
+
@descriptor ||= begin
|
36
|
+
Descriptor.new.tap do |descriptor|
|
37
|
+
begin
|
38
|
+
Cgroup.descriptors.each do |cgroup_descriptor|
|
39
|
+
# Parse container data from cgroup descriptor
|
40
|
+
path = cgroup_descriptor.path
|
41
|
+
next if path.nil?
|
42
|
+
|
43
|
+
# Split path into parts
|
44
|
+
parts = path.split('/')
|
45
|
+
parts.shift # Remove leading empty part
|
46
|
+
next if parts.length < 2
|
47
|
+
|
48
|
+
# Read info from path
|
49
|
+
platform = parts[0]
|
50
|
+
container_id = parts[-1][CONTAINER_REGEX]
|
51
|
+
task_uid = parts[-2][POD_REGEX]
|
52
|
+
|
53
|
+
# If container ID wasn't found, ignore.
|
54
|
+
# Path might describe a non-container environment.
|
55
|
+
next if container_id.nil?
|
56
|
+
|
57
|
+
descriptor.platform = platform
|
58
|
+
descriptor.container_id = container_id
|
59
|
+
descriptor.task_uid = task_uid
|
60
|
+
|
61
|
+
break
|
62
|
+
end
|
63
|
+
rescue StandardError => e
|
64
|
+
Datadog::Tracer.log.error(
|
65
|
+
"Error while parsing container info. Cause: #{e.message} Location: #{e.backtrace.first}"
|
66
|
+
)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'ddtrace/version'
|
2
2
|
require 'ddtrace/ext/runtime'
|
3
|
+
require 'ddtrace/ext/transport'
|
4
|
+
|
5
|
+
require 'ddtrace/runtime/container'
|
3
6
|
|
4
7
|
require 'ddtrace/transport/http/builder'
|
5
8
|
require 'ddtrace/transport/http/api'
|
@@ -12,15 +15,6 @@ module Datadog
|
|
12
15
|
module Transport
|
13
16
|
# Namespace for HTTP transport components
|
14
17
|
module HTTP
|
15
|
-
DEFAULT_AGENT_HOST = '127.0.0.1'.freeze
|
16
|
-
DEFAULT_TRACE_AGENT_PORT = 8126
|
17
|
-
DEFAULT_HEADERS = {
|
18
|
-
'Datadog-Meta-Lang'.freeze => Datadog::Ext::Runtime::LANG,
|
19
|
-
'Datadog-Meta-Lang-Version'.freeze => Datadog::Ext::Runtime::LANG_VERSION,
|
20
|
-
'Datadog-Meta-Lang-Interpreter'.freeze => Datadog::Ext::Runtime::LANG_INTERPRETER,
|
21
|
-
'Datadog-Meta-Tracer-Version'.freeze => Datadog::Ext::Runtime::TRACER_VERSION
|
22
|
-
}.freeze
|
23
|
-
|
24
18
|
module_function
|
25
19
|
|
26
20
|
# Builds a new Transport::HTTP::Client
|
@@ -32,11 +26,8 @@ module Datadog
|
|
32
26
|
# Pass a block to override any settings.
|
33
27
|
def default(options = {})
|
34
28
|
new do |transport|
|
35
|
-
transport.adapter :net_http,
|
36
|
-
|
37
|
-
ENV.fetch('DD_TRACE_AGENT_PORT', DEFAULT_TRACE_AGENT_PORT)
|
38
|
-
|
39
|
-
transport.headers DEFAULT_HEADERS
|
29
|
+
transport.adapter :net_http, default_hostname, default_port
|
30
|
+
transport.headers default_headers
|
40
31
|
|
41
32
|
apis = API.defaults
|
42
33
|
|
@@ -68,12 +59,27 @@ module Datadog
|
|
68
59
|
end
|
69
60
|
end
|
70
61
|
|
62
|
+
def default_headers
|
63
|
+
{
|
64
|
+
Datadog::Ext::Transport::HTTP::HEADER_META_LANG => Datadog::Ext::Runtime::LANG,
|
65
|
+
Datadog::Ext::Transport::HTTP::HEADER_META_LANG_VERSION => Datadog::Ext::Runtime::LANG_VERSION,
|
66
|
+
Datadog::Ext::Transport::HTTP::HEADER_META_LANG_INTERPRETER => Datadog::Ext::Runtime::LANG_INTERPRETER,
|
67
|
+
Datadog::Ext::Transport::HTTP::HEADER_META_TRACER_VERSION => Datadog::Ext::Runtime::TRACER_VERSION
|
68
|
+
}.tap do |headers|
|
69
|
+
# Add container ID, if present.
|
70
|
+
container_id = Datadog::Runtime::Container.container_id
|
71
|
+
unless container_id.nil?
|
72
|
+
headers[Datadog::Ext::Transport::HTTP::HEADER_CONTAINER_ID] = container_id
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
71
77
|
def default_hostname
|
72
|
-
ENV.fetch(
|
78
|
+
ENV.fetch(Datadog::Ext::Transport::HTTP::ENV_DEFAULT_HOST, Datadog::Ext::Transport::HTTP::DEFAULT_HOST)
|
73
79
|
end
|
74
80
|
|
75
81
|
def default_port
|
76
|
-
ENV.fetch(
|
82
|
+
ENV.fetch(Datadog::Ext::Transport::HTTP::ENV_DEFAULT_PORT, Datadog::Ext::Transport::HTTP::DEFAULT_PORT).to_i
|
77
83
|
end
|
78
84
|
|
79
85
|
# Add adapters to registry
|
data/lib/ddtrace/version.rb
CHANGED
data/lib/ddtrace/writer.rb
CHANGED
@@ -3,7 +3,6 @@ require 'json'
|
|
3
3
|
require 'ddtrace/ext/net'
|
4
4
|
require 'ddtrace/runtime/socket'
|
5
5
|
|
6
|
-
require 'ddtrace/transport'
|
7
6
|
require 'ddtrace/transport/http'
|
8
7
|
require 'ddtrace/encoding'
|
9
8
|
require 'ddtrace/workers'
|
@@ -79,29 +78,20 @@ module Datadog
|
|
79
78
|
# Inject hostname if configured to do so
|
80
79
|
inject_hostname!(traces) if Datadog.configuration.report_hostname
|
81
80
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
88
|
-
else
|
89
|
-
# For newer Datadog::Transports...
|
90
|
-
# Send traces an get a response.
|
91
|
-
response = transport.send_traces(traces)
|
92
|
-
|
93
|
-
unless response.internal_error?
|
94
|
-
@traces_flushed += traces.length unless response.server_error?
|
95
|
-
|
96
|
-
# Update priority sampler
|
97
|
-
unless priority_sampler.nil? || response.service_rates.nil?
|
98
|
-
priority_sampler.update(response.service_rates)
|
99
|
-
end
|
100
|
-
end
|
81
|
+
# Send traces an get a response.
|
82
|
+
response = transport.send_traces(traces)
|
83
|
+
|
84
|
+
unless response.internal_error?
|
85
|
+
@traces_flushed += traces.length unless response.server_error?
|
101
86
|
|
102
|
-
#
|
103
|
-
|
87
|
+
# Update priority sampler
|
88
|
+
unless priority_sampler.nil? || response.service_rates.nil?
|
89
|
+
priority_sampler.update(response.service_rates)
|
90
|
+
end
|
104
91
|
end
|
92
|
+
|
93
|
+
# Return if server error occurred.
|
94
|
+
!response.server_error?
|
105
95
|
end
|
106
96
|
|
107
97
|
def send_runtime_metrics
|
@@ -151,26 +141,6 @@ module Datadog
|
|
151
141
|
}
|
152
142
|
end
|
153
143
|
|
154
|
-
# Updates the priority sampler with rates from transport response.
|
155
|
-
# action (Symbol): Symbol representing data submitted.
|
156
|
-
# response: A Datadog::Transport::Response object.
|
157
|
-
# api: API version used to process this request.
|
158
|
-
#
|
159
|
-
# NOTE: Used only by old Datadog::HTTPTransport; will be removed.
|
160
|
-
def sampling_updater(action, response, api)
|
161
|
-
return unless action == :traces && response.is_a?(Net::HTTPOK)
|
162
|
-
|
163
|
-
if api[:version] == HTTPTransport::V4
|
164
|
-
body = JSON.parse(response.body)
|
165
|
-
if body.is_a?(Hash) && body.key?('rate_by_service')
|
166
|
-
@priority_sampler.update(body['rate_by_service'])
|
167
|
-
end
|
168
|
-
true
|
169
|
-
else
|
170
|
-
false
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
144
|
private
|
175
145
|
|
176
146
|
def inject_hostname!(traces)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddtrace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.26.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Datadog, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|
@@ -538,6 +538,7 @@ files:
|
|
538
538
|
- lib/ddtrace/ext/priority.rb
|
539
539
|
- lib/ddtrace/ext/runtime.rb
|
540
540
|
- lib/ddtrace/ext/sql.rb
|
541
|
+
- lib/ddtrace/ext/transport.rb
|
541
542
|
- lib/ddtrace/forced_tracing.rb
|
542
543
|
- lib/ddtrace/logger.rb
|
543
544
|
- lib/ddtrace/metrics.rb
|
@@ -568,7 +569,9 @@ files:
|
|
568
569
|
- lib/ddtrace/provider.rb
|
569
570
|
- lib/ddtrace/quantization/hash.rb
|
570
571
|
- lib/ddtrace/quantization/http.rb
|
572
|
+
- lib/ddtrace/runtime/cgroup.rb
|
571
573
|
- lib/ddtrace/runtime/class_count.rb
|
574
|
+
- lib/ddtrace/runtime/container.rb
|
572
575
|
- lib/ddtrace/runtime/gc.rb
|
573
576
|
- lib/ddtrace/runtime/identity.rb
|
574
577
|
- lib/ddtrace/runtime/metrics.rb
|
@@ -578,7 +581,6 @@ files:
|
|
578
581
|
- lib/ddtrace/span.rb
|
579
582
|
- lib/ddtrace/sync_writer.rb
|
580
583
|
- lib/ddtrace/tracer.rb
|
581
|
-
- lib/ddtrace/transport.rb
|
582
584
|
- lib/ddtrace/transport/http.rb
|
583
585
|
- lib/ddtrace/transport/http/adapters/net.rb
|
584
586
|
- lib/ddtrace/transport/http/adapters/registry.rb
|
data/lib/ddtrace/transport.rb
DELETED
@@ -1,233 +0,0 @@
|
|
1
|
-
require 'thread'
|
2
|
-
require 'net/http'
|
3
|
-
|
4
|
-
require 'ddtrace/encoding'
|
5
|
-
require 'ddtrace/version'
|
6
|
-
|
7
|
-
module Datadog
|
8
|
-
# Transport class that handles the spans delivery to the
|
9
|
-
# local trace-agent. The class wraps a Net:HTTP instance
|
10
|
-
# so that the Transport is thread-safe.
|
11
|
-
# rubocop:disable Metrics/ClassLength
|
12
|
-
class HTTPTransport
|
13
|
-
attr_accessor :hostname, :port
|
14
|
-
attr_reader :traces_endpoint
|
15
|
-
|
16
|
-
DEFAULT_AGENT_HOST = '127.0.0.1'.freeze
|
17
|
-
DEFAULT_TRACE_AGENT_PORT = '8126'.freeze
|
18
|
-
|
19
|
-
DEPRECATION_WARNING = %(
|
20
|
-
Datadog::HTTPTransport is deprecated as of version 0.24.0.
|
21
|
-
It has been replaced by Datadog::Transport:HTTP, which is the new default.
|
22
|
-
You can create one with `Datadog::Transport::HTTP.default`
|
23
|
-
Datadog::HTTPTransport will be REMOVED in version 0.25.0).freeze
|
24
|
-
|
25
|
-
# seconds before the transport timeout
|
26
|
-
TIMEOUT = 1
|
27
|
-
|
28
|
-
# header containing the number of traces in a payload
|
29
|
-
TRACE_COUNT_HEADER = 'X-Datadog-Trace-Count'.freeze
|
30
|
-
RUBY_INTERPRETER = RUBY_VERSION > '1.9' ? RUBY_ENGINE + '-' + RUBY_PLATFORM : 'ruby-' + RUBY_PLATFORM
|
31
|
-
|
32
|
-
API = {
|
33
|
-
V4 = 'v0.4'.freeze => {
|
34
|
-
version: V4,
|
35
|
-
traces_endpoint: '/v0.4/traces'.freeze,
|
36
|
-
encoder: Encoding::MsgpackEncoder,
|
37
|
-
fallback: 'v0.3'.freeze
|
38
|
-
}.freeze,
|
39
|
-
V3 = 'v0.3'.freeze => {
|
40
|
-
version: V3,
|
41
|
-
traces_endpoint: '/v0.3/traces'.freeze,
|
42
|
-
encoder: Encoding::MsgpackEncoder,
|
43
|
-
fallback: 'v0.2'.freeze
|
44
|
-
}.freeze,
|
45
|
-
V2 = 'v0.2'.freeze => {
|
46
|
-
version: V2,
|
47
|
-
traces_endpoint: '/v0.2/traces'.freeze,
|
48
|
-
encoder: Encoding::JSONEncoder
|
49
|
-
}.freeze
|
50
|
-
}.freeze
|
51
|
-
|
52
|
-
private_constant :API
|
53
|
-
|
54
|
-
def initialize(options = {})
|
55
|
-
# Log deprecation warning
|
56
|
-
Datadog::Tracer.log.warn(DEPRECATION_WARNING)
|
57
|
-
|
58
|
-
api_version = options.fetch(:api_version, V3)
|
59
|
-
|
60
|
-
@hostname = options[:hostname] || ENV['DD_AGENT_HOST'] || DEFAULT_AGENT_HOST
|
61
|
-
@port = options[:port] || ENV['DD_TRACE_AGENT_PORT'] || DEFAULT_TRACE_AGENT_PORT
|
62
|
-
@api = API.fetch(api_version)
|
63
|
-
@encoder = options[:encoder] || @api[:encoder]
|
64
|
-
@response_callback = options[:response_callback]
|
65
|
-
|
66
|
-
# overwrite the Content-type with the one chosen in the Encoder
|
67
|
-
@headers = options.fetch(:headers, {})
|
68
|
-
@headers['Content-Type'] = @encoder.content_type
|
69
|
-
@headers['Datadog-Meta-Lang'] = 'ruby'
|
70
|
-
@headers['Datadog-Meta-Lang-Version'] = RUBY_VERSION
|
71
|
-
@headers['Datadog-Meta-Lang-Interpreter'] = RUBY_INTERPRETER
|
72
|
-
@headers['Datadog-Meta-Tracer-Version'] = Datadog::VERSION::STRING
|
73
|
-
|
74
|
-
# stats
|
75
|
-
@mutex = Mutex.new
|
76
|
-
@count_success = 0
|
77
|
-
@count_client_error = 0
|
78
|
-
@count_server_error = 0
|
79
|
-
@count_internal_error = 0
|
80
|
-
@count_consecutive_errors = 0
|
81
|
-
end
|
82
|
-
|
83
|
-
# route the send to the right endpoint
|
84
|
-
def send(endpoint, data)
|
85
|
-
case endpoint
|
86
|
-
when :services
|
87
|
-
return nil
|
88
|
-
when :traces
|
89
|
-
count = data.length
|
90
|
-
payload = @encoder.encode_traces(data)
|
91
|
-
status_code = post(@api[:traces_endpoint], payload, count) do |response|
|
92
|
-
process_callback(:traces, response)
|
93
|
-
end
|
94
|
-
else
|
95
|
-
Datadog::Tracer.log.error("Unsupported endpoint: #{endpoint}")
|
96
|
-
return nil
|
97
|
-
end
|
98
|
-
|
99
|
-
if downgrade?(status_code)
|
100
|
-
downgrade!
|
101
|
-
send(endpoint, data)
|
102
|
-
else
|
103
|
-
status_code
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
# send data to the trace-agent; the method is thread-safe
|
108
|
-
def post(url, data, count = nil)
|
109
|
-
begin
|
110
|
-
Datadog::Tracer.log.debug("Sending data from process: #{Process.pid}")
|
111
|
-
headers = count.nil? ? {} : { TRACE_COUNT_HEADER => count.to_s }
|
112
|
-
headers = headers.merge(@headers)
|
113
|
-
request = Net::HTTP::Post.new(url, headers)
|
114
|
-
request.body = data
|
115
|
-
|
116
|
-
response = Net::HTTP.start(@hostname, @port, open_timeout: TIMEOUT, read_timeout: TIMEOUT) do |http|
|
117
|
-
http.request(request)
|
118
|
-
end
|
119
|
-
handle_response(response)
|
120
|
-
rescue StandardError => e
|
121
|
-
log_error_once(e.message)
|
122
|
-
500
|
123
|
-
end.tap do
|
124
|
-
yield(response) if block_given?
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
# Downgrade the connection to a compatibility version of the HTTPTransport;
|
129
|
-
# this method should target a stable API that works whatever is the agent
|
130
|
-
# or the tracing client versions.
|
131
|
-
def downgrade!
|
132
|
-
@mutex.synchronize do
|
133
|
-
fallback_version = @api.fetch(:fallback)
|
134
|
-
|
135
|
-
@api = API.fetch(fallback_version)
|
136
|
-
@encoder = @api[:encoder]
|
137
|
-
@headers['Content-Type'] = @encoder.content_type
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
def informational?(code)
|
142
|
-
code.between?(100, 199)
|
143
|
-
end
|
144
|
-
|
145
|
-
def success?(code)
|
146
|
-
code.between?(200, 299)
|
147
|
-
end
|
148
|
-
|
149
|
-
def redirect?(code)
|
150
|
-
code.between?(300, 399)
|
151
|
-
end
|
152
|
-
|
153
|
-
def client_error?(code)
|
154
|
-
code.between?(400, 499)
|
155
|
-
end
|
156
|
-
|
157
|
-
def server_error?(code)
|
158
|
-
code.between?(500, 599)
|
159
|
-
end
|
160
|
-
|
161
|
-
# receiving a 404 means that we're targeting an endpoint that is not available
|
162
|
-
# in the trace agent. Usually this means that we've an up-to-date tracing client,
|
163
|
-
# while running an obsolete agent.
|
164
|
-
# receiving a 415 means that we're using an unsupported content-type with an existing
|
165
|
-
# endpoint. Usually this means that we're using a newer encoder with a previous
|
166
|
-
# endpoint. In both cases, we're going to downgrade the transporter encoder so that
|
167
|
-
# it will target a stable API.
|
168
|
-
def downgrade?(code)
|
169
|
-
return unless @api[:fallback]
|
170
|
-
|
171
|
-
code == 404 || code == 415
|
172
|
-
end
|
173
|
-
|
174
|
-
# handles the server response; here you can log the trace-agent response
|
175
|
-
# or do something more complex to recover from a possible error. This
|
176
|
-
# function is handled within the HTTP mutex.synchronize so it's thread-safe.
|
177
|
-
def handle_response(response)
|
178
|
-
status_code = response.code.to_i
|
179
|
-
|
180
|
-
if success?(status_code)
|
181
|
-
Datadog::Tracer.log.debug('Payload correctly sent to the trace agent.')
|
182
|
-
@mutex.synchronize { @count_consecutive_errors = 0 }
|
183
|
-
@mutex.synchronize { @count_success += 1 }
|
184
|
-
elsif downgrade?(status_code)
|
185
|
-
Datadog::Tracer.log.debug("calling the endpoint but received #{status_code}; downgrading the API")
|
186
|
-
elsif client_error?(status_code)
|
187
|
-
log_error_once("Client error: #{response.message}")
|
188
|
-
@mutex.synchronize { @count_client_error += 1 }
|
189
|
-
elsif server_error?(status_code)
|
190
|
-
log_error_once("Server error: #{response.message}")
|
191
|
-
end
|
192
|
-
|
193
|
-
status_code
|
194
|
-
rescue StandardError => e
|
195
|
-
log_error_once(e.message)
|
196
|
-
@mutex.synchronize { @count_internal_error += 1 }
|
197
|
-
|
198
|
-
500
|
199
|
-
end
|
200
|
-
|
201
|
-
def stats
|
202
|
-
@mutex.synchronize do
|
203
|
-
{
|
204
|
-
success: @count_success,
|
205
|
-
client_error: @count_client_error,
|
206
|
-
server_error: @count_server_error,
|
207
|
-
internal_error: @count_internal_error
|
208
|
-
}
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
private
|
213
|
-
|
214
|
-
def log_error_once(*args)
|
215
|
-
if @count_consecutive_errors > 0
|
216
|
-
Datadog::Tracer.log.debug(*args)
|
217
|
-
else
|
218
|
-
Datadog::Tracer.log.error(*args)
|
219
|
-
end
|
220
|
-
|
221
|
-
@mutex.synchronize { @count_consecutive_errors += 1 }
|
222
|
-
end
|
223
|
-
|
224
|
-
def process_callback(action, response)
|
225
|
-
return unless @response_callback && @response_callback.respond_to?(:call)
|
226
|
-
|
227
|
-
@response_callback.call(action, response, @api)
|
228
|
-
rescue => e
|
229
|
-
Tracer.log.debug("Error processing callback: #{e}")
|
230
|
-
@mutex.synchronize { @count_internal_error += 1 }
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|