Skip to content
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"consola": "^3.4.2",
"ofetch": "^2.0.0-alpha.3",
"rc9": "^3.0.0",
"std-env": "^3.10.0"
"std-env": "^4.0.0-rc.1"
},
"devDependencies": {
"@nuxt/eslint-config": "^1.15.1",
Expand Down
9 changes: 7 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import os from 'node:os'
import { existsSync, readFileSync } from 'node:fs'
import { execSync } from 'node:child_process'
import { getNuxtVersion, isNuxtMajorVersion } from '@nuxt/kit'
import { provider } from 'std-env'
import { provider, detectAgent, isAgent } from 'std-env'
import type { Nuxt } from '@nuxt/schema'
import type { Context, GitData, TelemetryOptions } from './types'
import { hash } from './utils/hash'
Expand Down Expand Up @@ -30,6 +30,7 @@ export async function createContext(nuxt: Nuxt, options: Required<TelemetryOptio
const nuxtMajorVersion = getNuxtMajorVersion(nuxt)
const nodeVersion = process.version.replace('v', '')
const isEdge = nuxtVersion.includes('edge')
const agent = detectAgent()

return {
nuxt,
Expand All @@ -45,6 +46,8 @@ export async function createContext(nuxt: Nuxt, options: Required<TelemetryOptio
os: os.type().toLocaleLowerCase(),
environment: getEnv(),
packageManager: packageManager || 'unknown',
isAgent: isAgent,
agentName: agent.name || null,
concent: options.consent,
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export class Telemetry {
'environment',
'projectHash',
'projectSession',
'isAgent',
'agentName',
] as const) {
eventContext[key] = context[key]
}
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface Context {
git?: { url: string }
environment: string | null
packageManager: string
isAgent: boolean
agentName: string | null
concent: number
}

Expand Down
4 changes: 4 additions & 0 deletions test/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const app = createApp().use(defineEventHandler(async (event) => {
delete body.context.projectSession
expect(body.context.environment).toEqual(isCI ? 'github_actions' : 'unknown')
delete body.context.environment
expect(body.context.isAgent).toEqual(expect.any(Boolean))
delete body.context.isAgent
expect([null, expect.any(String)]).toContainEqual(body.context.agentName)
delete body.context.agentName
expect(body.timestamp).toBeGreaterThan(0)
delete body.timestamp
for (const event of body.events) {
Expand Down