-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first version of cuprite integration
- Loading branch information
1 parent
aac60e3
commit b44f9a9
Showing
14 changed files
with
332 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,5 @@ target :lib do | |
library "timecop" | ||
library "webmock" | ||
library "simplecov" | ||
library "cuprite" | ||
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
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,34 @@ | ||
# frozen_string_literal: true | ||
|
||
require "datadog/core" | ||
|
||
require_relative "../ext" | ||
require_relative "../../settings" | ||
|
||
require_relative "../../../ext/rum" | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Cuprite | ||
module Configuration | ||
# Custom settings for the Cuprite integration | ||
# @public_api | ||
class Settings < Datadog::CI::Contrib::Settings | ||
option :enabled do |o| | ||
o.type :bool | ||
o.env Ext::ENV_ENABLED | ||
o.default true | ||
end | ||
|
||
option :rum_flush_wait_millis do |o| | ||
o.type :int | ||
o.env CI::Ext::RUM::ENV_RUM_FLUSH_WAIT_MILLIS | ||
o.default 500 | ||
end | ||
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,90 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../patcher" | ||
|
||
require_relative "../../ext/rum" | ||
require_relative "../../ext/test" | ||
require_relative "../../utils/rum" | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Cuprite | ||
# instruments Capybara::Cuprite::Driver | ||
module Driver | ||
def self.included(base) | ||
base.prepend(InstanceMethods) | ||
end | ||
|
||
module InstanceMethods | ||
def visit(url) | ||
result = super | ||
|
||
return result unless datadog_configuration[:enabled] | ||
|
||
Datadog.logger.debug("[Cuprite] Navigation to #{url}") | ||
|
||
# on session reset Capybara navigates to about:blank | ||
return result if url == "about:blank" | ||
|
||
active_test = Datadog::CI.active_test | ||
Datadog.logger.debug("[Cuprite] Active test: #{active_test}") | ||
|
||
return result unless active_test | ||
|
||
# Set the test's trace id as a cookie in browser session | ||
Datadog.logger.debug do | ||
"[Cuprite] Setting cookie #{CI::Ext::RUM::COOKIE_TEST_EXECUTION_ID} to #{active_test.trace_id}" | ||
end | ||
set_cookie(CI::Ext::RUM::COOKIE_TEST_EXECUTION_ID, active_test.trace_id.to_s) | ||
|
||
# set the test type to browser | ||
active_test.set_tag(CI::Ext::Test::TAG_TYPE, CI::Ext::Test::Type::BROWSER) | ||
|
||
# set the tags specific to the browser test | ||
active_test.set_tag(CI::Ext::Test::TAG_BROWSER_DRIVER, "cuprite") | ||
active_test.set_tag(CI::Ext::Test::TAG_BROWSER_DRIVER_VERSION, datadog_integration.version) | ||
active_test.set_tag(CI::Ext::Test::TAG_BROWSER_NAME, browser.options.browser_name) | ||
active_test.set_tag(CI::Ext::Test::TAG_BROWSER_VERSION, browser.version) | ||
|
||
result | ||
end | ||
|
||
def reset! | ||
datadog_end_rum_session | ||
|
||
super | ||
end | ||
|
||
def quit | ||
datadog_end_rum_session | ||
|
||
super | ||
end | ||
|
||
private | ||
|
||
def datadog_integration | ||
CI::Contrib::Instrumentation.fetch_integration(:cuprite) | ||
end | ||
|
||
def datadog_configuration | ||
Datadog.configuration.ci[:cuprite] | ||
end | ||
|
||
def datadog_end_rum_session | ||
return unless datadog_configuration[:enabled] | ||
|
||
Datadog.logger.debug("[Cuprite] Driver quit event") | ||
|
||
Utils::RUM.stop_rum_session(self) | ||
|
||
Datadog.logger.debug("[Cuprite] RUM session stopped, deleting cookie") | ||
remove_cookie(CI::Ext::RUM::COOKIE_TEST_EXECUTION_ID) | ||
end | ||
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,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Cuprite | ||
# Cuprite integration constants | ||
# @public_api | ||
module Ext | ||
ENV_ENABLED = "DD_CIVISIBILITY_CUPRITE_ENABLED" | ||
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,44 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../integration" | ||
require_relative "configuration/settings" | ||
require_relative "patcher" | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Cuprite | ||
# Description of Cuprite integration | ||
class Integration < Contrib::Integration | ||
MINIMUM_VERSION = Gem::Version.new("0.15.0") | ||
|
||
def version | ||
Gem.loaded_specs["cuprite"]&.version | ||
end | ||
|
||
def loaded? | ||
!defined?(::Capybara).nil? && !defined?(::Capybara::Cuprite).nil? && | ||
!defined?(::Capybara::Cuprite::Driver).nil? | ||
end | ||
|
||
def compatible? | ||
super && version >= MINIMUM_VERSION | ||
end | ||
|
||
# additional instrumentations for test libraries are late instrumented on test session start | ||
def late_instrument? | ||
true | ||
end | ||
|
||
def new_configuration | ||
Configuration::Settings.new | ||
end | ||
|
||
def patcher | ||
Patcher | ||
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,24 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../patcher" | ||
|
||
require_relative "driver" | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Cuprite | ||
# Patcher enables patching of 'Capybara::Cuprite::Driver' class. | ||
module Patcher | ||
include Datadog::CI::Contrib::Patcher | ||
|
||
module_function | ||
|
||
def patch | ||
::Capybara::Cuprite::Driver.include(Driver) | ||
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
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,12 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Cuprite | ||
module Configuration | ||
class Settings < Datadog::CI::Contrib::Settings | ||
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,29 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Cuprite | ||
module Driver | ||
def self.included: (untyped base) -> untyped | ||
|
||
module InstanceMethods | ||
include Capybara::Cuprite::Driver | ||
|
||
def visit: (untyped url) -> untyped | ||
|
||
def reset!: () -> untyped | ||
|
||
def quit: () -> untyped | ||
|
||
private | ||
|
||
def datadog_integration: () -> untyped | ||
|
||
def datadog_configuration: () -> untyped | ||
|
||
def datadog_end_rum_session: () -> (nil | untyped) | ||
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,11 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Cuprite | ||
module Ext | ||
ENV_ENABLED: "DD_CIVISIBILITY_CUPRITE_ENABLED" | ||
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,23 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Cuprite | ||
class Integration < Contrib::Integration | ||
MINIMUM_VERSION: Gem::Version | ||
|
||
def version: () -> untyped | ||
|
||
def loaded?: () -> bool | ||
|
||
def compatible?: () -> bool | ||
|
||
def late_instrument?: () -> true | ||
|
||
def new_configuration: () -> untyped | ||
|
||
def patcher: () -> untyped | ||
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,13 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Cuprite | ||
module Patcher | ||
include Datadog::CI::Contrib::Patcher | ||
|
||
def self?.patch: () -> untyped | ||
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,34 @@ | ||
module Capybara | ||
end | ||
|
||
module Capybara::Cuprite | ||
end | ||
|
||
module Ferrum | ||
end | ||
|
||
class Ferrum::Browser | ||
def version: () -> String | ||
|
||
def options: () -> Ferrum::Browser::Options | ||
end | ||
|
||
class Ferrum::Browser::Options | ||
def browser_name: () -> String | ||
end | ||
|
||
module Capybara::Cuprite::Driver | ||
def visit: (String url) -> untyped | ||
|
||
def reset!: () -> void | ||
|
||
def quit: () -> void | ||
|
||
def set_cookie: (String name, String value, ?Hash[Symbol, untyped] options) -> void | ||
|
||
def remove_cookie: (String name, ?Hash[Symbol, untyped] options) -> void | ||
|
||
def execute_script: (String script, ?untyped args) -> untyped | ||
|
||
def browser: () -> Ferrum::Browser | ||
end |