-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd2d070
commit 0ce035b
Showing
5 changed files
with
191 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "something_that_converts_traces" | ||
require "datadog/core/encoding" | ||
# use it to chunk payloads by size | ||
# require "datadog/core/chunker" | ||
|
||
module Datadog | ||
module CI | ||
module TestVisibility | ||
class Transport | ||
def initialize | ||
@encoder = Datadog::Core::Encoding::MsgpackEncoder | ||
end | ||
|
||
def send_traces(traces) | ||
# convert traces to events and construct payload | ||
events = traces.flat_map { |trace| SomethingThatConvertsTraces.convert(trace) } | ||
payload = Payload.new(events) | ||
# @encoder.encode(payload) | ||
end | ||
|
||
private | ||
|
||
# represents payload with some subset of serializable events to be sent to CI-APP intake | ||
class Payload | ||
def initialize(events) | ||
@events = events | ||
end | ||
|
||
def to_msgpack(packer) | ||
packer ||= MessagePack::Packer.new | ||
|
||
packer.write_map_header(3) # Set header with how many elements in the map | ||
packer.write("version") | ||
packer.write(1) | ||
|
||
packer.write("metadata") | ||
packer.write_map_header(3) | ||
|
||
packer.write("runtime-id") | ||
packer.write(@events.first.runtime_id) | ||
|
||
packer.write("language") | ||
packer.write("ruby") | ||
|
||
packer.write("library_version") | ||
packer.write(Datadog::CI::VERSION::STRING) | ||
|
||
packer.write_array_header(@events.size) | ||
packer.write(@events) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
# # frozen_string_literal: true | ||
|
||
# require_relative "something_that_converts_traces" | ||
# require "datadog/core/encoding" | ||
# # use it to chunk payloads by size | ||
# # require "datadog/core/chunker" | ||
|
||
# module Datadog | ||
# module CI | ||
# module TestVisibility | ||
# class Transport | ||
# def initialize | ||
# @encoder = Datadog::Core::Encoding::MsgpackEncoder | ||
# end | ||
|
||
# def send_traces(traces) | ||
# # convert traces to events and construct payload | ||
# events = traces.flat_map { |trace| SomethingThatConvertsTraces.convert(trace) } | ||
# payload = Payload.new(events) | ||
# # @encoder.encode(payload) | ||
# end | ||
|
||
# private | ||
|
||
# # represents payload with some subset of serializable events to be sent to CI-APP intake | ||
# class Payload | ||
# def initialize(events) | ||
# @events = events | ||
# end | ||
|
||
# def to_msgpack(packer) | ||
# packer ||= MessagePack::Packer.new | ||
|
||
# packer.write_map_header(3) # Set header with how many elements in the map | ||
# packer.write("version") | ||
# packer.write(1) | ||
|
||
# packer.write("metadata") | ||
# packer.write_map_header(3) | ||
|
||
# packer.write("runtime-id") | ||
# packer.write(@events.first.runtime_id) | ||
|
||
# packer.write("language") | ||
# packer.write("ruby") | ||
|
||
# packer.write("library_version") | ||
# packer.write(Datadog::CI::VERSION::STRING) | ||
|
||
# packer.write_array_header(@events.size) | ||
# packer.write(@events) | ||
# end | ||
# end | ||
# end | ||
# end | ||
# end | ||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
require_relative "../../../../../lib/datadog/ci/test_visibility/serializer/span" | ||
require_relative "../../../../../lib/datadog/ci/recorder" | ||
|
||
RSpec.describe Datadog::CI::TestVisibility::Serializer::Span do | ||
include_context "CI mode activated" do | ||
let(:integration_name) { :rspec } | ||
end | ||
|
||
let(:test_span) do | ||
spans.find { |span| span.type == "test" } | ||
end | ||
|
||
let(:tracer_span) do | ||
spans.find { |span| span.type != "test" } | ||
end | ||
subject { described_class.new(trace, tracer_span) } | ||
|
||
describe "#to_msgpack" do | ||
context "traced a single test execution with Recorder" do | ||
before do | ||
Datadog::CI::Recorder.trace( | ||
"rspec.example", | ||
{ | ||
span_options: { | ||
resource: "test_add", | ||
service: "rspec-test-suite" | ||
}, | ||
framework: "rspec", | ||
framework_version: "3.0.0", | ||
test_name: "test_add", | ||
test_suite: "calculator_tests.rb", | ||
test_type: "test" | ||
} | ||
) do |span| | ||
Datadog::Tracing.trace("http-call", type: "http", service: "net-http") do |span, trace| | ||
span.set_tag("custom_tag", "custom_tag_value") | ||
end | ||
|
||
Datadog::CI::Recorder.passed!(span) | ||
end | ||
end | ||
|
||
let(:payload) { MessagePack.unpack(MessagePack.pack(subject)) } | ||
|
||
it "serializes test event to messagepack" do | ||
expect(payload).to include( | ||
{ | ||
"version" => 1, | ||
"type" => "span" | ||
} | ||
) | ||
content = payload["content"] | ||
expect(content).to include( | ||
{ | ||
"trace_id" => trace.id, | ||
"span_id" => tracer_span.id, | ||
"parent_id" => test_span.id, | ||
"name" => "http-call", | ||
"service" => "net-http", | ||
"type" => "http", | ||
"error" => 0, | ||
"resource" => "http-call" | ||
} | ||
) | ||
|
||
tags = content["meta"] | ||
expect(tags).to include( | ||
{ | ||
"custom_tag" => "custom_tag_value", | ||
"_dd.origin" => "ciapp-test" | ||
} | ||
) | ||
# TODO: test start and duration with timecop | ||
# expect(content["start"]).to eq(1) | ||
# expect(content["duration"]).to eq(1) | ||
# | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters