Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 64-bit trace_ids as required by the current implementation of Datadog. #4

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/console/output/datadog/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

# frozen_string_literal: true

module Console
module Output
# 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.
Expand All @@ -41,17 +43,24 @@ def call(subject = nil, *arguments, **options, &block)
if span = trace.active_span
options[:dd] = {
span_id: span.id.to_s,
trace_id: trace.id.to_s
trace_id: format_trace_id(trace.id)
}
else
options[:dd] = {
trace_id: trace.id.to_s
trace_id: format_trace_id(trace.id)
}
end
end

@output.call(subject, *arguments, **options, &block)
end

private

def format_trace_id(id)
# 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.
::Datadog::Tracing::Utils::TraceId.to_low_order(id)
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/console/output/datadog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
expect(buffer).to receive(:call).with("Hello World",
severity: :info,
dd: {
trace_id: span.trace_id.to_s,
trace_id: ::Datadog::Tracing::Correlation::Identifier.new(trace_id: span.trace_id).trace_id,
span_id: span.id.to_s
}
)
Expand All @@ -45,7 +45,7 @@
expect(buffer).to receive(:call).with("Hello World",
severity: :info,
dd: {
trace_id: span.trace_id.to_s
trace_id: ::Datadog::Tracing::Correlation::Identifier.new(trace_id: span.trace_id).trace_id
}
)

Expand Down
Loading