Skip to content

internal: create cloud studio session ID to group telemetry and errors #31833

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

Merged
merged 3 commits into from
Jun 12, 2025
Merged
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
1 change: 1 addition & 0 deletions packages/app/src/runner/SpecRunnerOpenMode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
<StudioPanel
v-if="shouldShowStudioPanel"
data-cy="studio-panel"
:cloud-studio-session-id="studioStore.cloudStudioSessionId"
:can-access-studio-a-i="studioStore.canAccessStudioAI"
:on-studio-panel-close="handleStudioPanelClose"
:event-manager="eventManager"
Expand Down
6 changes: 4 additions & 2 deletions packages/app/src/runner/event-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,27 +283,29 @@ export class EventManager {
this.studioStore.setSuiteId(suiteId)
this.studioStore.setShowUrlPrompt(showUrlPrompt)

this.ws.emit('studio:init', ({ canAccessStudioAI, error }) => {
this.ws.emit('studio:init', ({ canAccessStudioAI, cloudStudioSessionId, error }) => {
if (error) {
// eslint-disable-next-line no-console
console.error(error)
}

this.studioStore.setCanAccessStudioAI(canAccessStudioAI)
this.studioStore.setCloudStudioSessionId(cloudStudioSessionId)
studioInit()
})
}

this.reporterBus.on('studio:init:test', (testId) => {
this.studioStore.setTestId(testId)

this.ws.emit('studio:init', ({ canAccessStudioAI, error }) => {
this.ws.emit('studio:init', ({ canAccessStudioAI, cloudStudioSessionId, error }) => {
if (error) {
// eslint-disable-next-line no-console
console.error(error)
}

this.studioStore.setCanAccessStudioAI(canAccessStudioAI)
this.studioStore.setCloudStudioSessionId(cloudStudioSessionId)
studioInit()
})
})
Expand Down
6 changes: 6 additions & 0 deletions packages/app/src/store/studio-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ interface StudioRecorderState {

canAccessStudioAI: boolean
showUrlPrompt: boolean
cloudStudioSessionId?: string
}

export const useStudioStore = defineStore('studioRecorder', {
Expand All @@ -138,6 +139,7 @@ export const useStudioStore = defineStore('studioRecorder', {
_currentId: 1,
canAccessStudioAI: false,
showUrlPrompt: true,
cloudStudioSessionId: undefined,
}
},

Expand All @@ -161,6 +163,10 @@ export const useStudioStore = defineStore('studioRecorder', {
this.canAccessStudioAI = canAccessStudioAI
},

setCloudStudioSessionId (cloudStudioSessionId: string) {
this.cloudStudioSessionId = cloudStudioSessionId
},

clearRunnableIds () {
this.testId = undefined
this.suiteId = undefined
Expand Down
8 changes: 7 additions & 1 deletion packages/app/src/studio/StudioPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const props = defineProps<{
onStudioPanelClose: () => void
eventManager: EventManager
studioStatus: string | null
cloudStudioSessionId?: string
}>()

interface StudioApp { default: StudioAppDefaultShape }
Expand All @@ -71,7 +72,11 @@ const maybeRenderReactComponent = () => {
return
}

const panel = window.UnifiedRunner.React.createElement(ReactStudioPanel.value, { canAccessStudioAI: props.canAccessStudioAI, onStudioPanelClose: props.onStudioPanelClose })
const panel = window.UnifiedRunner.React.createElement(ReactStudioPanel.value, {
canAccessStudioAI: props.canAccessStudioAI,
onStudioPanelClose: props.onStudioPanelClose,
studioSessionId: props.cloudStudioSessionId,
})

if (!reactRoot.value) {
reactRoot.value = window.UnifiedRunner.ReactDOM.createRoot(container.value)
Expand All @@ -81,6 +86,7 @@ const maybeRenderReactComponent = () => {
}

watch(() => props.canAccessStudioAI, maybeRenderReactComponent)
watch(() => props.cloudStudioSessionId, maybeRenderReactComponent)

const unmountReactComponent = () => {
if (!ReactStudioPanel.value || !container.value) {
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/studio/studio-app-types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface StudioPanelProps {
canAccessStudioAI: boolean
onStudioPanelClose?: () => void
studioSessionId?: string
useRunnerStatus?: RunnerStatusShape
useTestContentRetriever?: TestContentRetrieverShape
useStudioAIStream?: StudioAIStreamShape
Expand Down
8 changes: 8 additions & 0 deletions packages/server/lib/cloud/studio/studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ export class StudioManager implements StudioManagerShape {
await this.invokeAsync('initializeStudioAI', { isEssential: true }, options)
}

updateSessionId (sessionId: string): void {
if (this._studioServer && typeof this._studioServer.updateSessionId === 'function') {
this.invokeSync('updateSessionId', { isEssential: false }, sessionId)
} else {
debug('updateSessionId method not available on studio server')
}
}

async destroy (): Promise<void> {
await this.invokeAsync('destroy', { isEssential: true })
}
Expand Down
14 changes: 8 additions & 6 deletions packages/server/lib/project-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ export class ProjectBase extends EE {
})
}

const cloudStudioSessionId = v4()

try {
const isStudioReady = this.ctx.coreData.studioLifecycleManager?.isStudioReady()

Expand All @@ -442,7 +444,7 @@ export class ProjectBase extends EE {

endTelemetry({ status: 'studio-not-ready', canAccessStudioAI: false })

return { canAccessStudioAI: false }
return { canAccessStudioAI: false, cloudStudioSessionId }
}

const studio = await this.ctx.coreData.studioLifecycleManager?.getStudio()
Expand Down Expand Up @@ -476,7 +478,7 @@ export class ProjectBase extends EE {
if (!canAccessStudioAI) {
endTelemetry({ status: 'success', canAccessStudioAI })

return { canAccessStudioAI }
return { canAccessStudioAI, cloudStudioSessionId }
}

this.protocolManager = studio.protocolManager
Expand All @@ -495,7 +497,7 @@ export class ProjectBase extends EE {

endTelemetry({ status: 'protocol-db-path-not-set', canAccessStudioAI: false })

return { canAccessStudioAI: false }
return { canAccessStudioAI: false, cloudStudioSessionId }
}

telemetryManager.mark(INITIALIZATION_MARK_NAMES.INITIALIZE_STUDIO_AI_START)
Expand All @@ -507,18 +509,18 @@ export class ProjectBase extends EE {

endTelemetry({ status: 'success', canAccessStudioAI: true })

return { canAccessStudioAI: true }
return { canAccessStudioAI: true, cloudStudioSessionId }
}

this.protocolManager = undefined

endTelemetry({ status: 'success', canAccessStudioAI: false })

return { canAccessStudioAI: false }
return { canAccessStudioAI: false, cloudStudioSessionId }
} catch (error) {
endTelemetry({ status: 'exception', canAccessStudioAI: false })

return { canAccessStudioAI: false }
return { canAccessStudioAI: false, cloudStudioSessionId }
}
},

Expand Down
4 changes: 2 additions & 2 deletions packages/server/lib/socket-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,9 @@ export class SocketBase {

socket.on('studio:init', async (cb) => {
try {
const { canAccessStudioAI } = await options.onStudioInit()
const { canAccessStudioAI, cloudStudioSessionId } = await options.onStudioInit()

cb({ canAccessStudioAI })
cb({ canAccessStudioAI, cloudStudioSessionId })
} catch (error) {
cb({ error: errors.cloneErr(error) })
}
Expand Down
19 changes: 17 additions & 2 deletions packages/server/test/unit/socket_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,12 +542,27 @@ describe('lib/socket', () => {

context('on(studio:init)', () => {
it('calls onStudioInit', async function () {
this.options.onStudioInit.resolves({ canAccessStudioAI: true })
this.options.onStudioInit.resolves({ canAccessStudioAI: true, cloudStudioSessionId: 'test-session-id' })

await new Promise((resolve) => {
this.client.emit('studio:init', ({ canAccessStudioAI }) => {
this.client.emit('studio:init', ({ canAccessStudioAI, cloudStudioSessionId }) => {
expect(this.options.onStudioInit).to.be.called
expect(canAccessStudioAI).to.be.true
expect(cloudStudioSessionId).to.eq('test-session-id')

resolve()
})
})
})

it('calls onStudioInit and handles undefined cloudStudioSessionId', async function () {
this.options.onStudioInit.resolves({ canAccessStudioAI: false, cloudStudioSessionId: undefined })

await new Promise((resolve) => {
this.client.emit('studio:init', ({ canAccessStudioAI, cloudStudioSessionId }) => {
expect(this.options.onStudioInit).to.be.called
expect(canAccessStudioAI).to.be.false
expect(cloudStudioSessionId).to.be.undefined

resolve()
})
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/studio/studio-server-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface StudioServerShape {
canAccessStudioAI(browser: Cypress.Browser): Promise<boolean>
addSocketListeners(socket: Socket): void
initializeStudioAI(options: StudioAIInitializeOptions): Promise<void>
updateSessionId(sessionId: string): void
reportError(
error: unknown,
studioMethod: string,
Expand Down
Loading