Skip to content

Browserstack Turboscale Observability Integration#13437

Merged
christian-bromann merged 6 commits intowebdriverio:mainfrom
amaanbs:O11y_ATS_Integration_V9
Sep 5, 2024
Merged

Browserstack Turboscale Observability Integration#13437
christian-bromann merged 6 commits intowebdriverio:mainfrom
amaanbs:O11y_ATS_Integration_V9

Conversation

@amaanbs
Copy link
Contributor

@amaanbs amaanbs commented Aug 21, 2024

Proposed changes

These changes are to enable Browserstack Observability Reporting for users running sessions on Browserstack Turboscale.

Types of changes

  • Polish (an improvement for an existing feature)
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (improvements to the project's docs)
  • Specification changes (updates to WebDriver command specifications)
  • Internal updates (everything related to internal scripts, governance documentation and CI files)

Checklist

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)
  • I have added proper type definitions for new commands (if appropriate)

Backport Request

//: # (The current main branch is the development branch for WebdriverIO v9. If your change should be released to the current major version of WebdriverIO (v8), please raise another PR with the same changes against the v8 branch.)

Further comments

Reviewers: @webdriverio/project-committers

if (process.env.BROWSERSTACK_TURBOSCALE) {
this._turboScale = process.env.BROWSERSTACK_TURBOSCALE === 'true'
}
process.env.BROWSERSTACK_TURBOSCALE_INTERNAL = this._turboScale + ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the + '' can we properly type _turboScale?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_turboScale is meant to be of type boolean so to have the environment variable use this, I've added an explicit cast to data type string.

if (this._observability) {
patchConsoleLogs()

process.env.BROWSERSTACK_OBSERVABILITY_PRODUCT = this._isAppAutomate() ? 'app-automate' : (process.env.BROWSERSTACK_TURBOSCALE_INTERNAL === 'true' ? 'turboscale' : 'automate')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we refactor this into a utility function that takes WebdriverIO.Capabilities and returns the value for the product? Writing into environment variables to pass along data across multiple classes is a not a good approach

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the intention however we don't make modifications to WebdriverIO.Capabilities when running sessions on the turboscale grid so we can't use those capabilities to fetch the product name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can have 3 static utility methods, e.g.

export function isAppAutomate(caps: WebdriverIO.Capabilities): boolean {
    return !!caps['appium:app'] || !!caps['appium:options']?.app
}

export function isTurboScale(options: BrowserstackConfig): boolean {
    return Boolean(options.turboscale)
}

export function getProduct(options: BrowserstackConfig, caps: WebdriverIO.Capabilities): boolean {
    return isAppAutomate(caps)
        ? 'app-automate'
        : (isTurboScale(options) ? 'turboscale' : 'automate')
}

I strongly discouraged to just apply values to environment variables as you have no control as to if or when these values are assigned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made the code changes recommended above.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 28, 2024

Open in Stackblitz

eslint-plugin-wdio

pnpm add https://pkg.pr.new/webdriverio/webdriverio/eslint-plugin-wdio@13437

@wdio/allure-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/allure-reporter@13437

@wdio/browserstack-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/browserstack-service@13437

@wdio/cli

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/cli@13437

@wdio/browser-runner

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/browser-runner@13437

@wdio/config

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/config@13437

@wdio/concise-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/concise-reporter@13437

@wdio/cucumber-framework

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/cucumber-framework@13437

@wdio/firefox-profile-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/firefox-profile-service@13437

@wdio/dot-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/dot-reporter@13437

@wdio/globals

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/globals@13437

@wdio/json-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/json-reporter@13437

@wdio/jasmine-framework

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/jasmine-framework@13437

@wdio/local-runner

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/local-runner@13437

@wdio/lighthouse-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/lighthouse-service@13437

@wdio/junit-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/junit-reporter@13437

@wdio/logger

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/logger@13437

@wdio/protocols

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/protocols@13437

@wdio/mocha-framework

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/mocha-framework@13437

@wdio/repl

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/repl@13437

@wdio/runner

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/runner@13437

@wdio/reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/reporter@13437

@wdio/shared-store-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/shared-store-service@13437

@wdio/sauce-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/sauce-service@13437

@wdio/smoke-test-cjs-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-cjs-service@13437

@wdio/smoke-test-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-reporter@13437

@wdio/smoke-test-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-service@13437

@wdio/spec-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/spec-reporter@13437

@wdio/static-server-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/static-server-service@13437

@wdio/sumologic-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/sumologic-reporter@13437

@wdio/types

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/types@13437

@wdio/utils

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/utils@13437

@wdio/testingbot-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/testingbot-service@13437

@wdio/webdriver-mock-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/webdriver-mock-service@13437

webdriver

pnpm add https://pkg.pr.new/webdriverio/webdriverio/webdriver@13437

webdriverio

pnpm add https://pkg.pr.new/webdriverio/webdriverio@13437

@wdio/appium-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/appium-service@13437

commit: 332572f

@amaanbs
Copy link
Contributor Author

amaanbs commented Aug 28, 2024

@christian-bromann I've addressed the comments. Please re-review.

@amaanbs
Copy link
Contributor Author

amaanbs commented Sep 1, 2024

@christian-bromann I've made changes as per the review comments shared above. Please re-review.

private _cbtQueue: Array<CBTData> = []

constructor (private _browser: WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser, isAppAutomate?: boolean, private _framework?: string, _userCaps?: Capabilities.ResolvedTestrunnerCapabilities) {
constructor (private _browser: WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser, isAppAutomate?: boolean, private _framework?: string, _userCaps?: Capabilities.ResolvedTestrunnerCapabilities, _options?: BrowserstackConfig & BrowserstackOptions) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we refactor isAppAutomate as well as the function doesn't require any scope and only takes a capability object. There is not reason to pass this into the class if you have the capabilities given here as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the capabilities object we have inside this class & that does not have any key value pair we can use to identify if the session is an app automation session. Hence we're making use of the isAppAutomate boolean.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually since the browser & the capability object are both passed here, we can simply move that method over here instead of passing the boolean inside the constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved the isAppAutomate method from service.ts to insights-handles.ts & as a result, we're not passing the boolean isAppAutomate to the constructor of this class.

@pri-gadhiya
Copy link
Contributor

@christian-bromann are we good here? Can this be merged and deployed?

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pri-gadhiya
Copy link
Contributor

pri-gadhiya commented Sep 3, 2024

@christian-bromann Could you please help us know by when can we expect this to be deployed for all v7, v8, v9?

@christian-bromann
Copy link
Member

@amaanbs @pri-gadhiya can we please re-apply the feedback to the other PRs?

@christian-bromann christian-bromann added the PR: Polish 💅 PRs that contain improvements on existing features label Sep 5, 2024
@christian-bromann christian-bromann merged commit 7bb29b8 into webdriverio:main Sep 5, 2024
@amaanbs
Copy link
Contributor Author

amaanbs commented Sep 9, 2024

@christian-bromann I've incorporated the changes suggested here into the PRs to be merged in branches V7 & V8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Polish 💅 PRs that contain improvements on existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants