MCPcopy
hub / github.com/PostHog/posthog / apiGetWithTimeToSeeDataTracking

Function apiGetWithTimeToSeeDataTracking

frontend/src/lib/internalMetrics.ts:42–72  ·  view source on GitHub ↗
(
    url: string,
    teamId: number | null,
    timeToSeeDataPayload: Omit<
        TimeToSeeDataPayload,
        'api_url' | 'time_to_see_data_ms' | 'status' | 'api_response_bytes'
    >
)

Source from the content-addressed store, hash-verified

40 * This is not in api.ts to avoid circular dependencies, but the principle is the same.
41 */
42export async function apiGetWithTimeToSeeDataTracking<T extends any>(
43 url: string,
44 teamId: number | null,
45 timeToSeeDataPayload: Omit<
46 TimeToSeeDataPayload,
47 'api_url' | 'time_to_see_data_ms' | 'status' | 'api_response_bytes'
48 >
49): Promise<T> {
50 let response: Response | undefined
51 let responseData: T | undefined
52 let error: any
53 const requestStartMs = performance.now()
54 try {
55 response = await api.getResponse(url)
56 responseData = await getJSONOrThrow(response)
57 } catch (e) {
58 error = e
59 }
60 const requestDurationMs = performance.now() - requestStartMs
61 captureTimeToSeeData(teamId, {
62 ...timeToSeeDataPayload,
63 api_url: url,
64 status: error ? 'failure' : 'success',
65 api_response_bytes: response && getResponseBytes(response),
66 time_to_see_data_ms: requestDurationMs,
67 })
68 if (!responseData) {
69 throw error // If there's no response data, there must have been an error - rethrow it
70 }
71 return responseData
72}

Callers

nothing calls this directly

Calls 4

getJSONOrThrowFunction · 0.90
getResponseBytesFunction · 0.90
captureTimeToSeeDataFunction · 0.85
getResponseMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…