Skip to content

Commit 1b3c2a3

Browse files
authored
Use 64-bit trace_ids as required by the current implementation of Datadog. (#4)
1 parent 6c5522e commit 1b3c2a3

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/console/output/datadog/wrapper.rb

+11-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2828
# THE SOFTWARE.
2929

30+
# frozen_string_literal: true
31+
3032
module Console
3133
module Output
3234
# The reason why this is a serialized logger rather than an output filter, is because it needs to directly modify the top level of the record.
@@ -41,17 +43,24 @@ def call(subject = nil, *arguments, **options, &block)
4143
if span = trace.active_span
4244
options[:dd] = {
4345
span_id: span.id.to_s,
44-
trace_id: trace.id.to_s
46+
trace_id: format_trace_id(trace.id)
4547
}
4648
else
4749
options[:dd] = {
48-
trace_id: trace.id.to_s
50+
trace_id: format_trace_id(trace.id)
4951
}
5052
end
5153
end
5254

5355
@output.call(subject, *arguments, **options, &block)
5456
end
57+
58+
private
59+
60+
def format_trace_id(id)
61+
# 128-bit tracing is not supported by the Datadog agent, so we need to convert it to 64-bit. We expect that this will be changed in the future.
62+
::Datadog::Tracing::Utils::TraceId.to_low_order(id)
63+
end
5564
end
5665
end
5766
end

test/console/output/datadog.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
expect(buffer).to receive(:call).with("Hello World",
3030
severity: :info,
3131
dd: {
32-
trace_id: span.trace_id.to_s,
32+
trace_id: ::Datadog::Tracing::Correlation::Identifier.new(trace_id: span.trace_id).trace_id,
3333
span_id: span.id.to_s
3434
}
3535
)
@@ -45,7 +45,7 @@
4545
expect(buffer).to receive(:call).with("Hello World",
4646
severity: :info,
4747
dd: {
48-
trace_id: span.trace_id.to_s
48+
trace_id: ::Datadog::Tracing::Correlation::Identifier.new(trace_id: span.trace_id).trace_id
4949
}
5050
)
5151

0 commit comments

Comments
 (0)