Skip to content

Commit

Permalink
instrument additional integrations on test session start
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed May 24, 2024
1 parent de0f496 commit 6093a55
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 59 deletions.
1 change: 1 addition & 0 deletions lib/datadog/ci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ def itr_runner
require_relative "ci/contrib/cucumber/integration"
require_relative "ci/contrib/rspec/integration"
require_relative "ci/contrib/minitest/integration"
require_relative "ci/contrib/selenium/integration"

# Configuration extensions
require_relative "ci/configuration/extensions"
Expand Down
31 changes: 31 additions & 0 deletions lib/datadog/ci/contrib/contrib.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require_relative "integration"

module Datadog
module CI
module Contrib
# This method auto instruments all test libraries (ex: selenium-webdriver).
# It is intended to be called when test session starts to add additional capabilities to test visibility.
#
# This method does not automatically instrument test frameworks (ex: RSpec, Cucumber, etc), it requires
# test framework to be already instrumented.
def self.auto_instrument_on_session_start!
Datadog.logger.debug("Auto instrumenting all integrations...")

Integration.registry.each do |name, integration|
next unless integration.auto_instrument?

Datadog.logger.debug "#{name} is allowed to be auto instrumented"

patch_results = integration.patch
if patch_results == true
Datadog.logger.debug("#{name} is patched")
else
Datadog.logger.debug("#{name} is not patched (#{patch_results})")
end
end
end
end
end
end
4 changes: 4 additions & 0 deletions lib/datadog/ci/test_visibility/recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require_relative "context/local"

require_relative "../codeowners/parser"
require_relative "../contrib/contrib"
require_relative "../ext/app_types"
require_relative "../ext/test"
require_relative "../ext/environment"
Expand Down Expand Up @@ -57,6 +58,9 @@ def shutdown!
def start_test_session(service: nil, tags: {})
return skip_tracing unless test_suite_level_visibility_enabled

# finds and instruments additional test libraries that we support (ex: selenium-webdriver)
Contrib.auto_instrument_on_session_start!

@global_context.fetch_or_activate_test_session do
tracer_span = start_datadog_tracer_span(
"test.session", build_span_options(service, Ext::AppTypes::TYPE_TEST_SESSION)
Expand Down
7 changes: 7 additions & 0 deletions sig/datadog/ci/contrib/contrib.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Datadog
module CI
module Contrib
def self.auto_instrument_on_session_start!: () -> void
end
end
end
2 changes: 1 addition & 1 deletion sig/datadog/ci/contrib/integration.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Datadog

def self.register: (untyped integration, Symbol name) -> void

def self.registry: () -> Hash[Symbol, Struct[untyped]]
def self.registry: () -> Hash[Symbol, untyped]

module ClassMethods
def register_as: (Symbol name) -> void
Expand Down

This file was deleted.

10 changes: 5 additions & 5 deletions vendor/rbs/selenium-webdriver/0/webdriver/common/driver.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Selenium

def self.for: (untyped browser, Hash[untyped, untyped] opts) -> untyped

def initialize: (?bridge: Support::EventFiringBridge? bridge, ?listener: Support::AbstractEventListener? listener, **untyped opts) -> void
def initialize: (?bridge: untyped? bridge, ?listener: untyped? listener, **untyped opts) -> void

def inspect: () -> String

Expand All @@ -23,7 +23,7 @@ module Selenium

def manage: () -> Manager

def action: (**untyped opts) -> ActionBuilder
def action: (**untyped opts) -> untyped

def get: (String url) -> untyped

Expand All @@ -33,9 +33,9 @@ module Selenium

def page_source: () -> String

def quit: () -> WebDriver::Remote::Response?
def quit: () -> untyped

def close: () -> WebDriver::Remote::Response?
def close: () -> untyped

def window_handles: () -> Array[String]

Expand All @@ -45,7 +45,7 @@ module Selenium

def execute_async_script: (String script, *untyped args) -> untyped

def add_virtual_authenticator: (untyped options) -> VirtualAuthenticator
def add_virtual_authenticator: (untyped options) -> untyped

alias first find_element

Expand Down
4 changes: 2 additions & 2 deletions vendor/rbs/selenium-webdriver/0/webdriver/common/element.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Selenium

include SearchContext

def initialize: (Remote::Bridge | Support::EventFiringBridge bridge, String id) -> void
def initialize: (untyped bridge, String id) -> void

def inspect: () -> untyped

Expand Down Expand Up @@ -76,7 +76,7 @@ module Selenium

private

attr_reader bridge: Remote::Bridge
attr_reader bridge: untyped

def selectable?: () -> bool

Expand Down
4 changes: 2 additions & 2 deletions vendor/rbs/selenium-webdriver/0/webdriver/common/manager.rbs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module Selenium
module WebDriver
class Manager
attr_reader bridge: Remote::Bridge
attr_reader bridge: untyped

@timeouts: Timeouts

@window: Window

def initialize: (Remote::Bridge bridge) -> void
def initialize: (untyped bridge) -> void

def add_cookie: (?Hash[Symbol, untyped] opts) -> void

Expand Down

0 comments on commit 6093a55

Please sign in to comment.