( profile_id: string, start_timestamp: number | undefined, processed_profile: JSSelfProfile, event: ProfiledEvent, )
| 143 | * Creates a profiling event envelope from a Sentry event. |
| 144 | */ |
| 145 | export function createProfilePayload( |
| 146 | profile_id: string, |
| 147 | start_timestamp: number | undefined, |
| 148 | processed_profile: JSSelfProfile, |
| 149 | event: ProfiledEvent, |
| 150 | ): Profile { |
| 151 | if (event.type !== 'transaction') { |
| 152 | // createProfilingEventEnvelope should only be called for transactions, |
| 153 | // we type guard this behavior with isProfiledTransactionEvent. |
| 154 | throw new TypeError('Profiling events may only be attached to transactions, this should never occur.'); |
| 155 | } |
| 156 | |
| 157 | if (processed_profile === undefined || processed_profile === null) { |
| 158 | throw new TypeError( |
| 159 | `Cannot construct profiling event envelope without a valid profile. Got ${processed_profile} instead.`, |
| 160 | ); |
| 161 | } |
| 162 | |
| 163 | const traceId = getTraceId(event); |
| 164 | const enrichedThreadProfile = enrichWithThreadInformation(processed_profile); |
| 165 | const transactionStartMs = start_timestamp |
| 166 | ? start_timestamp |
| 167 | : typeof event.start_timestamp === 'number' |
| 168 | ? event.start_timestamp * 1000 |
| 169 | : timestampInSeconds() * 1000; |
| 170 | const transactionEndMs = typeof event.timestamp === 'number' ? event.timestamp * 1000 : timestampInSeconds() * 1000; |
| 171 | |
| 172 | const profile: Profile = { |
| 173 | event_id: profile_id, |
| 174 | timestamp: new Date(transactionStartMs).toISOString(), |
| 175 | platform: 'javascript', |
| 176 | version: '1', |
| 177 | release: event.release || '', |
| 178 | environment: event.environment || DEFAULT_ENVIRONMENT, |
| 179 | runtime: { |
| 180 | name: 'javascript', |
| 181 | version: WINDOW.navigator.userAgent, |
| 182 | }, |
| 183 | os: { |
| 184 | name: OS_PLATFORM, |
| 185 | version: OS_PLATFORM_VERSION, |
| 186 | build_number: OS_BROWSER, |
| 187 | }, |
| 188 | device: { |
| 189 | locale: OS_LOCALE, |
| 190 | model: OS_MODEL, |
| 191 | manufacturer: OS_BROWSER, |
| 192 | architecture: OS_ARCH, |
| 193 | is_emulator: false, |
| 194 | }, |
| 195 | debug_meta: { |
| 196 | images: applyDebugMetadata(processed_profile.resources), |
| 197 | }, |
| 198 | profile: enrichedThreadProfile, |
| 199 | transactions: [ |
| 200 | { |
| 201 | name: event.transaction || '', |
| 202 | id: event.event_id || uuid4(), |
no test coverage detected