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

Test optional resource load attributes #236

Open
wants to merge 8 commits into
base: next
Choose a base branch
from
2 changes: 2 additions & 0 deletions test/browser/features/lib/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def initialize(browser_spec)
end
end

attr_reader :name, :version

# is this a mobile device?
# we assume that android devices are always using the latest version of chrome
def mobile?
Expand Down
30 changes: 28 additions & 2 deletions test/browser/features/resource-load-spans.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,32 @@ Feature: Resource Load Spans
Then the trace payload field "resourceSpans.0.scopeSpans.0.spans.2.name" equals "[Custom]/resource-load-spans"
And the trace payload field "resourceSpans.0.scopeSpans.0.spans.2.spanId" is stored as the value "parent_span_id"

# App bundle
# App bundle resource load
And the trace payload field "resourceSpans.0.scopeSpans.0.spans.0.name" matches the regex "^\[ResourceLoad\]http:\/\/.*:[0-9]{4}\/resource-load-spans\/dist\/bundle\.js$"
And the trace payload field "resourceSpans.0.scopeSpans.0.spans.0.parentSpanId" equals the stored value "parent_span_id"
And the trace payload field "resourceSpans.0.scopeSpans.0.spans.0" string attribute "bugsnag.span.category" equals "resource_load"
And the trace payload field "resourceSpans.0.scopeSpans.0.spans.0" string attribute "http.flavor" equals "1.1"

# Image
# Image resource load
And the trace payload field "resourceSpans.0.scopeSpans.0.spans.1.name" matches the regex "^\[ResourceLoad\]http:\/\/.*:[0-9]{4}\/favicon.png$"
And the trace payload field "resourceSpans.0.scopeSpans.0.spans.1.parentSpanId" equals the stored value "parent_span_id"
And the trace payload field "resourceSpans.0.scopeSpans.0.spans.1" string attribute "bugsnag.span.category" equals "resource_load"
And the trace payload field "resourceSpans.0.scopeSpans.0.spans.1" string attribute "http.url" matches the regex "^http:\/\/.*:[0-9]{4}\/favicon\.png\?height=100&width=100$"
And the trace payload field "resourceSpans.0.scopeSpans.0.spans.1" string attribute "http.flavor" equals "1.1"

# Image status code and body size have patchy browser coverage
And on Chrome versions >= 109:
"""
the trace payload field "resourceSpans.0.scopeSpans.0.spans.1" integer attribute "http.status_code" equals 200
"""

# Actually Safari 16.4 but our test devices currently use 16.3, this can be dropped to 16 when the devices update
And on Chrome versions >= 54, Android versions >= 54, Safari versions >= 17, iOS versions >= 17, Firefox versions >= 45, Edge versions >= 17:
"""
the trace payload field "resourceSpans.0.scopeSpans.0.spans.1" integer attribute "http.response_content_length" equals 2202
the trace payload field "resourceSpans.0.scopeSpans.0.spans.1" integer attribute "http.response_content_length_uncompressed" equals 2202
"""

@skip_on_npm_build
@requires_resource_load_spans
Scenario: Resource load spans are automatically instrumented (CDN build)
Expand Down Expand Up @@ -55,3 +68,16 @@ Feature: Resource Load Spans
And the trace payload field "resourceSpans.0.scopeSpans.0.spans.2" string attribute "bugsnag.span.category" equals "resource_load"
And the trace payload field "resourceSpans.0.scopeSpans.0.spans.2" string attribute "http.url" matches the regex "^http:\/\/.*:[0-9]{4}\/favicon\.png\?height=100&width=100$"
And the trace payload field "resourceSpans.0.scopeSpans.0.spans.2" string attribute "http.flavor" equals "1.1"

# Image status code and body size have patchy browser coverage
And on Chrome versions >= 109:
"""
the trace payload field "resourceSpans.0.scopeSpans.0.spans.1" integer attribute "http.status_code" equals 200
"""

# Actually Safari 16.4 but our test devices currently use 16.3, this can be dropped to 16 when the devices update
And on Chrome versions >= 54, Android versions >= 54, Safari versions >= 17, iOS versions >= 17, Firefox versions >= 45, Edge versions >= 17:
"""
the trace payload field "resourceSpans.0.scopeSpans.0.spans.1" integer attribute "http.response_content_length" equals 2202
the trace payload field "resourceSpans.0.scopeSpans.0.spans.1" integer attribute "http.response_content_length_uncompressed" equals 2202
"""
37 changes: 37 additions & 0 deletions test/browser/features/steps/browser-steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,43 @@
end
end

def check_attribute_equal_if_present(field, attribute, attr_type, expected)
actual = get_attribute_value field, attribute, attr_type
if actual != nil
Maze.check.equal(expected, actual)
end
end

Then(/^on ((?:[A-Za-z]+ versions (?:>=?|<=?|==) [0-9.]+(?:, )?)+):$/) do |browser_specs, steps_to_run|
spec_matcher = /^([A-Za-z]+) versions (>=?|<=?|==) ([0-9.]+)$/
run_steps = false

browser_specs.split(", ").each do |browser_spec|
browser_spec.scan(spec_matcher) do |name, operator, version|
should_run_steps = $browser.name.casecmp?(name) && $browser.version.send(operator, version.to_i)

# make sure this step is debuggable!
$logger.debug("#{$browser.name} == #{name} && v#{$browser.version} #{operator} #{version}? #{should_run_steps}")

if should_run_steps
run_steps = true
end
end
end

if run_steps
steps_to_run.each_line(chomp: true) do |step_to_run|
step(step_to_run)
end
else
indent = " " * 4
# e.g. "a step\nanother step\n" -> " 1) a step\n 2) another step"
steps_indented = steps_to_run.each_line.map.with_index(1) { |step, i| "#{indent}#{i}) #{step.chomp}" }.join("\n")

$logger.info("Skipping steps on #{$browser.name} v#{$browser.version}:\n#{steps_indented}")
end
end

module Maze
module Driver
class Browser
Expand Down

This file was deleted.

This file was deleted.