( session: TelemetryIdentitySession, )
| 42 | | undefined |
| 43 | |
| 44 | export function buildTelemetryIdentityAttributes( |
| 45 | session: TelemetryIdentitySession, |
| 46 | ): Attributes { |
| 47 | const telemetrySession = |
| 48 | session == null |
| 49 | ? { |
| 50 | isOauthBackedFirstPartySession: false, |
| 51 | subscriptionType: null, |
| 52 | isEnterpriseOrTeam: false, |
| 53 | } |
| 54 | : buildTelemetrySessionState(session) |
| 55 | |
| 56 | if (!telemetrySession.isOauthBackedFirstPartySession) { |
| 57 | return {} |
| 58 | } |
| 59 | |
| 60 | const attributes: Attributes = {} |
| 61 | const orgId = session?.identity.organizationUuid ?? null |
| 62 | const email = session?.identity.email ?? null |
| 63 | const accountUuid = session?.identity.accountUuid ?? null |
| 64 | |
| 65 | if (orgId) attributes['organization.id'] = orgId |
| 66 | if (email) attributes['user.email'] = email |
| 67 | |
| 68 | if ( |
| 69 | accountUuid && |
| 70 | shouldIncludeAttribute('OTEL_METRICS_INCLUDE_ACCOUNT_UUID') |
| 71 | ) { |
| 72 | attributes['user.account_uuid'] = accountUuid |
| 73 | attributes['user.account_id'] = |
| 74 | process.env.CLAUDE_CODE_ACCOUNT_TAGGED_ID || |
| 75 | toTaggedId('user', accountUuid) |
| 76 | } |
| 77 | |
| 78 | return attributes |
| 79 | } |
| 80 | |
| 81 | export function getTelemetryAttributes(): Attributes { |
| 82 | const userId = getOrCreateUserID() |
no test coverage detected