(
metadata: EventMetadata,
userMetadata: CoreUserData,
additionalMetadata: Record<string, unknown> = {},
)
| 794 | * @returns Metadata formatted for 1P event logging |
| 795 | */ |
| 796 | export function to1PEventFormat( |
| 797 | metadata: EventMetadata, |
| 798 | userMetadata: CoreUserData, |
| 799 | additionalMetadata: Record<string, unknown> = {}, |
| 800 | ): FirstPartyEventLoggingMetadata { |
| 801 | const { |
| 802 | envContext, |
| 803 | processMetrics, |
| 804 | rh, |
| 805 | kairosActive, |
| 806 | skillMode, |
| 807 | observerMode, |
| 808 | ...coreFields |
| 809 | } = metadata |
| 810 | |
| 811 | // Convert envContext to snake_case. |
| 812 | // IMPORTANT: env is typed as the proto-generated EnvironmentMetadata so that |
| 813 | // adding a field here that the proto doesn't define is a compile error. The |
| 814 | // generated toJSON() serializer silently drops unknown keys — a hand-written |
| 815 | // parallel type previously let #11318, #13924, #19448, and coworker_type all |
| 816 | // ship fields that never reached BQ. |
| 817 | // Adding a field? Update the monorepo proto first (go/cc-logging): |
| 818 | // event_schemas/.../claude_code/v1/claude_code_internal_event.proto |
| 819 | // then run `bun run generate:proto` here. |
| 820 | const env: EnvironmentMetadata = { |
| 821 | platform: envContext.platform, |
| 822 | platform_raw: envContext.platformRaw, |
| 823 | arch: envContext.arch, |
| 824 | node_version: envContext.nodeVersion, |
| 825 | terminal: envContext.terminal || 'unknown', |
| 826 | package_managers: envContext.packageManagers, |
| 827 | runtimes: envContext.runtimes, |
| 828 | is_running_with_bun: envContext.isRunningWithBun, |
| 829 | is_ci: envContext.isCi, |
| 830 | is_claubbit: envContext.isClaubbit, |
| 831 | is_claude_code_remote: envContext.isClaudeCodeRemote, |
| 832 | is_local_agent_mode: envContext.isLocalAgentMode, |
| 833 | is_conductor: envContext.isConductor, |
| 834 | is_github_action: envContext.isGithubAction, |
| 835 | is_claude_code_action: envContext.isClaudeCodeAction, |
| 836 | is_claude_ai_auth: envContext.isClaudeAiAuth, |
| 837 | version: envContext.version, |
| 838 | build_time: envContext.buildTime, |
| 839 | deployment_environment: envContext.deploymentEnvironment, |
| 840 | } |
| 841 | |
| 842 | // Add optional env fields |
| 843 | if (envContext.remoteEnvironmentType) { |
| 844 | env.remote_environment_type = envContext.remoteEnvironmentType |
| 845 | } |
| 846 | if (feature('COWORKER_TYPE_TELEMETRY') && envContext.coworkerType) { |
| 847 | env.coworker_type = envContext.coworkerType |
| 848 | } |
| 849 | if (envContext.claudeCodeContainerId) { |
| 850 | env.claude_code_container_id = envContext.claudeCodeContainerId |
| 851 | } |
| 852 | if (envContext.claudeCodeRemoteSessionId) { |
| 853 | env.claude_code_remote_session_id = envContext.claudeCodeRemoteSessionId |
no test coverage detected