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

feat: Expose logging feature to micro agent loader #1210

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/post-release-updates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ if (args.openPullRequest) {
'third_party_manifest.json',
'THIRD_PARTY_NOTICES.md',
'tools/test-builds/**/package.json',
'tools/webview-asset-ids.js'
'tools/lambda-test/webview-asset-ids.mjs'
],
COMMIT_MESSAGE,
true
Expand Down
3 changes: 2 additions & 1 deletion src/loaders/micro-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import { AgentBase } from './agent-base'
const nonAutoFeatures = [
FEATURE_NAMES.jserrors,
FEATURE_NAMES.genericEvents,
FEATURE_NAMES.metrics
FEATURE_NAMES.metrics,
FEATURE_NAMES.logging
]

/**
Expand Down
26 changes: 19 additions & 7 deletions tests/specs/npm/micro-agent.e2e.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/* globals MicroAgent */

import { testErrorsRequest, testInsRequest, testRumRequest } from '../../../tools/testing-server/utils/expect-tests'
import { testErrorsRequest, testInsRequest, testLogsRequest, testRumRequest } from '../../../tools/testing-server/utils/expect-tests'

describe('micro-agent', () => {
it('Smoke Test - Can send distinct payloads of all relevant data types to 2 distinct app IDs', async () => {
const [rumCapture, errorsCapture, insightsCapture] = await browser.testHandle.createNetworkCaptures('bamServer', [
const [rumCapture, errorsCapture, insightsCapture, logsCapture] = await browser.testHandle.createNetworkCaptures('bamServer', [
{ test: testRumRequest },
{ test: testErrorsRequest },
{ test: testInsRequest }
{ test: testInsRequest },
{ test: testLogsRequest }
])
await browser.url(await browser.testHandle.assetURL('test-builds/browser-agent-wrapper/micro-agent.html'))

Expand All @@ -30,19 +31,24 @@ describe('micro-agent', () => {
// each payload in this test is decorated with data that matches its appId for ease of testing
window.agent1.addPageAction('1', { val: 1 })
window.agent2.addPageAction('2', { val: 2 })

// each payload in this test is decorated with data that matches its appId for ease of testing
window.agent1.log('1')
window.agent2.log('2')
})
const [rumHarvests, errorsHarvests, insightsHarvests] = await Promise.all([
const [rumHarvests, errorsHarvests, insightsHarvests, logsHarvest] = await Promise.all([
rumCapture.waitForResult({ totalCount: 2 }),
errorsCapture.waitForResult({ totalCount: 2 }),
insightsCapture.waitForResult({ totalCount: 2 })
insightsCapture.waitForResult({ totalCount: 2 }),
logsCapture.waitForResult({ totalCount: 2 })
])

// these props will get set to true once a test has matched it
// if it gets tried again, the test will fail, since these should all
// only have one distinct matching payload
const tests = {
1: { rum: false, err: false, pa: false },
2: { rum: false, err: false, pa: false }
1: { rum: false, err: false, pa: false, log: false },
2: { rum: false, err: false, pa: false, log: false }
}

// each type of test should check that:
Expand All @@ -64,6 +70,12 @@ describe('micro-agent', () => {
expect(payloadMatchesAppId(query.a, data.val, data.actionName, data.customAttr)).toEqual(true)
})

logsHarvest.forEach(({ request: { query, body } }) => {
const data = JSON.parse(body)[0]
expect(ranOnce(data.common.attributes.appId, 'log')).toEqual(true)
expect(payloadMatchesAppId(data.common.attributes.appId, data.logs[0].message)).toEqual(true)
})

function payloadMatchesAppId (appId, ...props) {
// each payload in this test is decorated with data that matches its appId for ease of testing
return props.every(p => Number(appId) === Number(p))
Expand Down
2 changes: 1 addition & 1 deletion tools/lambda-test/upload-webview-assets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exec(iosUpload, (error, stdout, stderr) => {
function checkDone () {
if (androidID && iosID) {
console.log('uploaded...', androidID, iosID)
fs.writeFileSync(`${outputDir}/webview-asset-ids.js`, `export default { androidID: '${androidID}', iosID: '${iosID}' }\n`)
fs.writeFileSync(`${outputDir}/webview-asset-ids.mjs`, `export default { androidID: '${androidID}', iosID: '${iosID}' }\n`)
process.exit()
}
}
Expand Down
2 changes: 1 addition & 1 deletion tools/wdio/config/lambdatest.conf.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import child_process from 'node:child_process'
import browsersList from '../../browsers-lists/lt-browsers-list.mjs'
import args from '../args.mjs'
import { getBrowserName } from '../../browsers-lists/utils.mjs'
import webviewAssetIds from '../../lambda-test/webview-asset-ids'
import webviewAssetIds from '../../lambda-test/webview-asset-ids.mjs'

const require = module.createRequire(import.meta.url)
const supportedDesktop = require('../../browsers-lists/lt-desktop-supported.json')
Expand Down
Loading