ddtrace 0.31.1 → 0.32.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e309cb3f2b41dd7eb6adbf556693cce348c5a3aca91e8502b91b1942a8bd190b
4
- data.tar.gz: fd05f388e6f54eece6950722068f080d7cf85e8e8901af960e930029249b4e44
3
+ metadata.gz: ef2a4e166761426cd1fa60d735bd1c84bba183251754a83686feada009e00e97
4
+ data.tar.gz: c95a0b8677b653d13cde489eba691aff3867ef5fbebfad8323cc2a46fe75a102
5
5
  SHA512:
6
- metadata.gz: fe9c94b6eb5fb1fb951b7b42490193dd3eaf19d45f85ffb22009335c223da9b20786bcef28d23f990ceea3abac0a527d6f69a15debcba8c3b63dac3fe782b747
7
- data.tar.gz: 07e68ddf443811a479d933a0bb5313d307d3433037bebdd6d0b3f27c52b80d8a5c7e23c239b67552045db16cdb53c8fb0ae6cab4d0c6d64104c9c9b96740130a
6
+ metadata.gz: 8c2aadf454ea6acec93c7f25a1ebac84ee8e2f63ea6c9620b6c4623a9ba5e9412faf76240e72a2eaf18b946159600128369e539eb775c1e00274ec96df0567bd
7
+ data.tar.gz: 1094c5c97487b21d69aaf62858f5d9fb40d587678f92c0fa133d9f73b5db8f8d0d4675ca1ddb4b137a58805130617ccbd9de7e1621b8f0338c3136b1f47eaec9
data/CHANGELOG.md CHANGED
@@ -2,6 +2,27 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.32.0] - 2020-01-22
6
+
7
+ Release notes: https://github.com/DataDog/dd-trace-rb/releases/tag/v0.32.0
8
+
9
+ Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.31.1...v0.32.0
10
+
11
+ ### Added
12
+
13
+ - New transport: Datadog::Transport::IO (#910)
14
+ - Dual License (#893, #921)
15
+
16
+ ### Changed
17
+
18
+ - Improved annotation of `net/http` spans during exception (#888, #907) (@djmb, @ericmustin)
19
+ - RuleSampler is now the default sampler; no behavior changes by default (#917)
20
+
21
+ ### Refactored
22
+
23
+ - Improved support for multiple tracer instances (#919)
24
+ - Improvements to test suite (#909, #928, #929)
25
+
5
26
  ## [0.31.1] - 2020-01-15
6
27
 
7
28
  Release notes: https://github.com/DataDog/dd-trace-rb/releases/tag/v0.31.1
@@ -1058,7 +1079,8 @@ Release notes: https://github.com/DataDog/dd-trace-rb/releases/tag/v0.3.1
1058
1079
 
1059
1080
  Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
1060
1081
 
1061
- [Unreleased]: https://github.com/DataDog/dd-trace-rb/compare/v0.31.1...master
1082
+ [Unreleased]: https://github.com/DataDog/dd-trace-rb/compare/v0.32.0...master
1083
+ [0.32.0]: https://github.com/DataDog/dd-trace-rb/compare/v0.31.1...v0.32.0
1062
1084
  [0.31.1]: https://github.com/DataDog/dd-trace-rb/compare/v0.31.0...v0.31.1
1063
1085
  [0.31.0]: https://github.com/DataDog/dd-trace-rb/compare/v0.30.1...v0.31.0
1064
1086
  [0.30.1]: https://github.com/DataDog/dd-trace-rb/compare/v0.30.0...v0.30.1
data/LICENSE CHANGED
@@ -1,24 +1,6 @@
1
- Copyright (c) 2016, Datadog <info@datadoghq.com>
2
- All rights reserved.
1
+ ## License
3
2
 
4
- Redistribution and use in source and binary forms, with or without
5
- modification, are permitted provided that the following conditions are met:
6
- * Redistributions of source code must retain the above copyright
7
- notice, this list of conditions and the following disclaimer.
8
- * Redistributions in binary form must reproduce the above copyright
9
- notice, this list of conditions and the following disclaimer in the
10
- documentation and/or other materials provided with the distribution.
11
- * Neither the name of Datadog nor the
12
- names of its contributors may be used to endorse or promote products
13
- derived from this software without specific prior written permission.
3
+ This work is dual-licensed under Apache 2.0 or BSD3.
4
+ You may select, at your option, one of the above-listed licenses.
14
5
 
15
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
- DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
19
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6
+ `SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause`
data/LICENSE.Apache ADDED
@@ -0,0 +1,200 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2016 Datadog, Inc.
190
+ Licensed under the Apache License, Version 2.0 (the "License");
191
+ you may not use this file except in compliance with the License.
192
+ You may obtain a copy of the License at
193
+
194
+ http://www.apache.org/licenses/LICENSE-2.0
195
+
196
+ Unless required by applicable law or agreed to in writing, software
197
+ distributed under the License is distributed on an "AS IS" BASIS,
198
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
199
+ See the License for the specific language governing permissions and
200
+ limitations under the License.
data/LICENSE.BSD3 ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2016, Datadog <info@datadoghq.com>
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of Datadog nor the
12
+ names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ Datadog dd-trace-rb
2
+ Copyright 2016-Present Datadog, Inc.
3
+
4
+ This product includes software developed at Datadog, Inc. (https://www.datadoghq.com/).
@@ -833,6 +833,17 @@ The `use :graphql` method accepts the following parameters. Additional options c
833
833
  If you prefer to individually configure the tracer settings for a schema (e.g. you have multiple schemas with different service names), in the schema definition, you can add the following [using the GraphQL API](http://graphql-ruby.org/queries/tracing.html):
834
834
 
835
835
  ```ruby
836
+ # Class-based schema
837
+ class YourSchema < GraphQL::Schema
838
+ use(
839
+ GraphQL::Tracing::DataDogTracing,
840
+ service: 'graphql'
841
+ )
842
+ end
843
+ ```
844
+
845
+ ```ruby
846
+ # .define-style schema
836
847
  YourSchema = GraphQL::Schema.define do
837
848
  use(
838
849
  GraphQL::Tracing::DataDogTracing,
@@ -844,6 +855,15 @@ end
844
855
  Or you can modify an already defined schema:
845
856
 
846
857
  ```ruby
858
+ # Class-based schema
859
+ YourSchema.use(
860
+ GraphQL::Tracing::DataDogTracing,
861
+ service: 'graphql'
862
+ )
863
+ ```
864
+
865
+ ```ruby
866
+ # .define-style schema
847
867
  YourSchema.define do
848
868
  use(
849
869
  GraphQL::Tracing::DataDogTracing,
@@ -82,7 +82,8 @@ module Datadog
82
82
  end
83
83
 
84
84
  option :tracer do |o|
85
- o.default Tracer.new
85
+ o.default { Tracer.new }
86
+ o.lazy
86
87
 
87
88
  # On reset, shut down the old tracer,
88
89
  # then instantiate a new one.
@@ -28,18 +28,23 @@ module Datadog
28
28
  # a different \Context for each thread. In synchronous tracer, this
29
29
  # is required to prevent multiple threads sharing the same \Context
30
30
  # in different executions.
31
+ #
32
+ # To support multiple tracers simultaneously, each \ThreadLocalContext
33
+ # instance has its own thread-local variable.
31
34
  def initialize
35
+ @key = "datadog_context_#{object_id}".to_sym
36
+
32
37
  self.local = Datadog::Context.new
33
38
  end
34
39
 
35
40
  # Override the thread-local context with a new context.
36
41
  def local=(ctx)
37
- Thread.current[:datadog_context] = ctx
42
+ Thread.current[@key] = ctx
38
43
  end
39
44
 
40
45
  # Return the thread-local context.
41
46
  def local
42
- Thread.current[:datadog_context] ||= Datadog::Context.new
47
+ Thread.current[@key] ||= Datadog::Context.new
43
48
  end
44
49
  end
45
50
  end
@@ -36,7 +36,7 @@ module Datadog
36
36
  return super(req, body, &block)
37
37
  end
38
38
 
39
- pin.tracer.trace(Ext::SPAN_REQUEST) do |span|
39
+ pin.tracer.trace(Ext::SPAN_REQUEST, on_error: method(:annotate_span_with_error!)) do |span|
40
40
  begin
41
41
  span.service = pin.service
42
42
  span.span_type = Datadog::Ext::HTTP::TYPE_OUTBOUND
@@ -45,14 +45,17 @@ module Datadog
45
45
  if pin.tracer.enabled && !Datadog::Contrib::HTTP.should_skip_distributed_tracing?(pin)
46
46
  Datadog::HTTPPropagator.inject!(span.context, req)
47
47
  end
48
+
49
+ # Add additional request specific tags to the span.
50
+ annotate_span_with_request!(span, req)
48
51
  rescue StandardError => e
49
52
  Datadog::Logger.log.error("error preparing span for http request: #{e}")
50
53
  ensure
51
54
  response = super(req, body, &block)
52
55
  end
53
56
 
54
- # Add additional tags to the span.
55
- annotate_span!(span, req, response)
57
+ # Add additional response specific tags to the span.
58
+ annotate_span_with_response!(span, response)
56
59
 
57
60
  # Invoke hook, if set.
58
61
  unless Contrib::HTTP::Instrumentation.after_request.nil?
@@ -63,10 +66,9 @@ module Datadog
63
66
  end
64
67
  end
65
68
 
66
- def annotate_span!(span, request, response)
69
+ def annotate_span_with_request!(span, request)
67
70
  span.set_tag(Datadog::Ext::HTTP::URL, request.path)
68
71
  span.set_tag(Datadog::Ext::HTTP::METHOD, request.method)
69
- span.set_tag(Datadog::Ext::HTTP::STATUS_CODE, response.code)
70
72
 
71
73
  if request.respond_to?(:uri) && request.uri
72
74
  span.set_tag(Datadog::Ext::NET::TARGET_HOST, request.uri.host)
@@ -78,6 +80,12 @@ module Datadog
78
80
 
79
81
  # Set analytics sample rate
80
82
  Contrib::Analytics.set_sample_rate(span, analytics_sample_rate) if analytics_enabled?
83
+ end
84
+
85
+ def annotate_span_with_response!(span, response)
86
+ return unless response && response.code
87
+
88
+ span.set_tag(Datadog::Ext::HTTP::STATUS_CODE, response.code)
81
89
 
82
90
  case response.code.to_i
83
91
  when 400...599
@@ -85,6 +93,10 @@ module Datadog
85
93
  end
86
94
  end
87
95
 
96
+ def annotate_span_with_error!(span, error)
97
+ span.set_error(error)
98
+ end
99
+
88
100
  def datadog_pin
89
101
  @datadog_pin ||= begin
90
102
  service = Datadog.configuration[:http][:service_name]
@@ -43,6 +43,36 @@ module Datadog
43
43
  def encode(obj)
44
44
  JSON.dump(obj)
45
45
  end
46
+
47
+ # New version of JSON Encoder that is API compliant.
48
+ module V2
49
+ extend JSONEncoder
50
+
51
+ ENCODED_IDS = [
52
+ :trace_id,
53
+ :span_id,
54
+ :parent_id
55
+ ].freeze
56
+
57
+ module_function
58
+
59
+ def encode_traces(traces)
60
+ trace_hashes = traces.collect do |trace|
61
+ # Convert each trace to hash
62
+ trace.map(&:to_hash).tap do |spans|
63
+ # Convert IDs to hexadecimal
64
+ spans.each do |span|
65
+ ENCODED_IDS.each do |id|
66
+ span[id] = span[id].to_s(16) if span.key?(id)
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ # Wrap traces & encode them
73
+ encode(traces: trace_hashes)
74
+ end
75
+ end
46
76
  end
47
77
 
48
78
  # Encoder for the Msgpack format
@@ -53,7 +53,7 @@ module Datadog
53
53
  # because it breaks its current contract to existing users.
54
54
  Datadog::RateSampler.new.tap { |s| s.sample_rate = default_sample_rate }
55
55
  else
56
- Datadog::AllSampler.new
56
+ RateByServiceSampler.new(1.0, env: -> { Datadog.tracer.tags[:env] })
57
57
  end
58
58
  end
59
59
 
@@ -406,7 +406,7 @@ module Datadog
406
406
  else
407
407
  PrioritySampler.new(
408
408
  base_sampler: base_sampler,
409
- post_sampler: Datadog::RateByServiceSampler.new(1.0, env: proc { tags[:env] })
409
+ post_sampler: Sampling::RuleSampler.new
410
410
  )
411
411
  end
412
412
  end
@@ -0,0 +1,26 @@
1
+ require 'ddtrace/encoding'
2
+ require 'ddtrace/transport/io/client'
3
+ require 'ddtrace/transport/io/traces'
4
+
5
+ module Datadog
6
+ module Transport
7
+ # Namespace for IO transport components
8
+ module IO
9
+ module_function
10
+
11
+ # Builds a new Transport::IO::Client
12
+ def new(out, encoder)
13
+ Client.new(out, encoder)
14
+ end
15
+
16
+ # Builds a new Transport::IO::Client with default settings
17
+ # Pass options to override any settings.
18
+ def default(options = {})
19
+ new(
20
+ options.fetch(:out, STDOUT),
21
+ options.fetch(:encoder, Encoding::JSONEncoder::V2)
22
+ )
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,76 @@
1
+ require 'ddtrace/transport/statistics'
2
+ require 'ddtrace/transport/io/response'
3
+
4
+ module Datadog
5
+ module Transport
6
+ module IO
7
+ # Encodes and writes tracer data to IO
8
+ class Client
9
+ include Transport::Statistics
10
+
11
+ attr_reader \
12
+ :encoder,
13
+ :out
14
+
15
+ def initialize(out, encoder)
16
+ @out = out
17
+ @encoder = encoder
18
+ end
19
+
20
+ def send_request(request)
21
+ # Write data to IO
22
+ # If block is given, allow it to handle writing
23
+ # Otherwise use default encoding.
24
+ response = if block_given?
25
+ yield(out, request)
26
+ else
27
+ send_default_request(out, request)
28
+ end
29
+
30
+ # Update statistics
31
+ update_stats_from_response!(response)
32
+
33
+ # Return response
34
+ response
35
+ rescue StandardError => e
36
+ message = "Internal error during IO transport request. Cause: #{e.message} Location: #{e.backtrace.first}"
37
+
38
+ # Log error
39
+ if stats.consecutive_errors > 0
40
+ Datadog::Logger.log.debug(message)
41
+ else
42
+ Datadog::Logger.log.error(message)
43
+ end
44
+
45
+ # Update statistics
46
+ update_stats_from_exception!(e)
47
+
48
+ InternalErrorResponse.new(e)
49
+ end
50
+
51
+ protected
52
+
53
+ def encode_data(encoder, request)
54
+ request.parcel.encode_with(encoder)
55
+ end
56
+
57
+ def write_data(out, data)
58
+ out.puts(data)
59
+ end
60
+
61
+ private
62
+
63
+ def send_default_request(out, request)
64
+ # Encode data
65
+ data = encode_data(encoder, request)
66
+
67
+ # Write to IO
68
+ result = write_data(out, data)
69
+
70
+ # Generate a response
71
+ IO::Response.new(result)
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,23 @@
1
+ require 'ddtrace/transport/response'
2
+
3
+ module Datadog
4
+ module Transport
5
+ module IO
6
+ # Response from HTTP transport for traces
7
+ class Response
8
+ include Transport::Response
9
+
10
+ attr_reader \
11
+ :result
12
+
13
+ def initialize(result)
14
+ @result = result
15
+ end
16
+
17
+ def ok?
18
+ true
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,44 @@
1
+ require 'ddtrace/transport/traces'
2
+
3
+ require 'ddtrace/transport/io/response'
4
+ require 'ddtrace/transport/io/client'
5
+
6
+ module Datadog
7
+ module Transport
8
+ module IO
9
+ # IO transport behavior for traces
10
+ module Traces
11
+ # Response from HTTP transport for traces
12
+ class Response < IO::Response
13
+ include Transport::Traces::Response
14
+ end
15
+
16
+ # Extensions for HTTP client
17
+ module Client
18
+ def send_traces(traces)
19
+ # Build a request
20
+ req = Transport::Traces::Request.new(traces)
21
+
22
+ send_request(req) do |out, request|
23
+ # Encode trace data
24
+ data = encode_data(encoder, request)
25
+
26
+ # Write to IO
27
+ result = if block_given?
28
+ yield(out, data)
29
+ else
30
+ write_data(out, data)
31
+ end
32
+
33
+ # Generate response
34
+ Traces::Response.new(result)
35
+ end
36
+ end
37
+ end
38
+
39
+ # Add traces behavior to transport components
40
+ IO::Client.send(:include, Traces::Client)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -8,6 +8,10 @@ module Datadog
8
8
  def initialize(data)
9
9
  @data = data
10
10
  end
11
+
12
+ def encode_with(encoder)
13
+ encoder.encode(data)
14
+ end
11
15
  end
12
16
  end
13
17
  end
@@ -1,8 +1,8 @@
1
1
  module Datadog
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 31
5
- PATCH = 1
4
+ MINOR = 32
5
+ PATCH = 0
6
6
  PRE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
@@ -4,6 +4,7 @@ require 'ddtrace/ext/net'
4
4
  require 'ddtrace/runtime/socket'
5
5
 
6
6
  require 'ddtrace/transport/http'
7
+ require 'ddtrace/transport/io'
7
8
  require 'ddtrace/encoding'
8
9
  require 'ddtrace/workers'
9
10
 
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.31.1
4
+ version: 0.32.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: 2020-01-16 00:00:00.000000000 Z
11
+ date: 2020-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -335,6 +335,9 @@ files:
335
335
  - CONTRIBUTING.md
336
336
  - Gemfile
337
337
  - LICENSE
338
+ - LICENSE.Apache
339
+ - LICENSE.BSD3
340
+ - NOTICE
338
341
  - README.md
339
342
  - Rakefile
340
343
  - benchmarks/postgres_database.yml
@@ -676,6 +679,10 @@ files:
676
679
  - lib/ddtrace/transport/http/response.rb
677
680
  - lib/ddtrace/transport/http/statistics.rb
678
681
  - lib/ddtrace/transport/http/traces.rb
682
+ - lib/ddtrace/transport/io.rb
683
+ - lib/ddtrace/transport/io/client.rb
684
+ - lib/ddtrace/transport/io/response.rb
685
+ - lib/ddtrace/transport/io/traces.rb
679
686
  - lib/ddtrace/transport/parcel.rb
680
687
  - lib/ddtrace/transport/request.rb
681
688
  - lib/ddtrace/transport/response.rb