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

Append Elastic/synthetics to UA string #380

Merged
merged 7 commits into from
Sep 21, 2021
Merged

Append Elastic/synthetics to UA string #380

merged 7 commits into from
Sep 21, 2021

Conversation

shahzad31
Copy link
Contributor

Fixes #232

Appends Elastic/Synthetics to UA string.

This PR uses a pretty ugly way to determin current user agent string and append the desired string into it.

Not sure if there is a way better way to do this. Struggling with playwright docs on how to get the current user agent string without opening a browser context.

@shahzad31 shahzad31 self-assigned this Sep 20, 2021
@shahzad31 shahzad31 added 7.16-candidate enhancement New feature or request labels Sep 20, 2021
@apmmachine
Copy link

apmmachine commented Sep 20, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2021-09-21T16:44:55.853+0000

  • Duration: 19 min 57 sec

  • Commit: 2471481

Test stats 🧪

Test Results
Failed 0
Passed 135
Skipped 0
Total 135

Trends 🧪

Image of Build Times

Image of Tests

Copy link
Member

@vigneshshanmugam vigneshshanmugam left a comment

Choose a reason for hiding this comment

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

Even though this works, This would be the last approach we would need to do as it slows down the startup time of our runner. Please look in to - https://chromedevtools.github.io/devtools-protocol/tot/Browser/#method-getVersion

which can be used to get the version and can be used for setting the global user agent context. Let me know if you need any help.

@vigneshshanmugam
Copy link
Member

We discussed offline and decided to go with using browser based session approach to get the user agent.

Benchmarks if anyone is curious

Session: 3.505ms
Context: 245.072ms

@shahzad31
Copy link
Contributor Author

i tested manualy, it seems to work with iframe and new window as well.

will try to write some tests for those use cases.

@shahzad31
Copy link
Contributor Author

Added tests for iframe and popup

Copy link
Member

@vigneshshanmugam vigneshshanmugam left a comment

Choose a reason for hiding this comment

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

Generally looks good, good to go after removing some bad import statements.

src/core/gatherer.ts Outdated Show resolved Hide resolved
await Gatherer.stop();
});

it('works with iframe content', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

I would remove this iframe test in favor of request test. Or merge it on the previous popup test to look for request to popup.html and check if request.headers.userAgent contains the Elastic identifier.

Iframes tests are unnecessary as they inherit the parent document.


jest.mock('../../src/plugins/network');

describe('Gatherer', () => {
let server: Server;

beforeAll(async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Close the server on afterAll.

@@ -26,10 +26,19 @@
import { Gatherer } from '../../src/core/gatherer';
import { PluginManager } from '../../src/plugins';
import { wsEndpoint } from '../utils/test-config';
import { devices } from 'playwright-chromium';
import { Server } from '../utils/server';
import exp = require('constants');
Copy link
Member

Choose a reason for hiding this comment

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

bad import.

src/core/gatherer.ts Outdated Show resolved Hide resolved
__tests__/core/gatherer.test.ts Outdated Show resolved Hide resolved
Copy link
Member

@vigneshshanmugam vigneshshanmugam left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

@vigneshshanmugam vigneshshanmugam merged commit 1def7c9 into master Sep 21, 2021
@vigneshshanmugam vigneshshanmugam deleted the us-string branch September 21, 2021 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
7.16-candidate enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Elastic Synthetic Identifier In UA String
3 participants