-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nicole White
committed
Aug 16, 2023
1 parent
6fe4d5d
commit b565185
Showing
8 changed files
with
871 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import crypto from 'crypto'; | ||
import { AutoblocksAPIClient, AutoblocksTracer } from '../src'; | ||
|
||
const { AUTOBLOCKS_API_KEY, AUTOBLOCKS_INGESTION_KEY } = process.env; | ||
|
||
// We've created a view in our demo org to be used in CI tests. | ||
// It has one filter, message == 'sdk.e2e', and its timespan is "last 1 hour" | ||
const E2E_TESTS_VIEW_ID = 'clldzryfx0001i908okbbe5pf'; | ||
const E2E_TESTS_EXPECTED_MESSAGE = 'sdk.e2e'; | ||
|
||
const sleep = (seconds: number) => | ||
new Promise((resolve) => setTimeout(resolve, seconds * 1000)); | ||
|
||
const main = async () => { | ||
if (!AUTOBLOCKS_API_KEY) { | ||
throw new Error('AUTOBLOCKS_API_KEY env var is required.'); | ||
} | ||
if (!AUTOBLOCKS_INGESTION_KEY) { | ||
throw new Error('AUTOBLOCKS_INGESTION_KEY env var is required.'); | ||
} | ||
|
||
const traceId = crypto.randomUUID(); | ||
const tracer = new AutoblocksTracer(AUTOBLOCKS_INGESTION_KEY, { traceId }); | ||
const client = new AutoblocksAPIClient(AUTOBLOCKS_API_KEY); | ||
|
||
await tracer.sendEvent(E2E_TESTS_EXPECTED_MESSAGE); | ||
|
||
// Make sure our view exists | ||
const views = await client.getViews(); | ||
if (!views.some((view) => view.id === E2E_TESTS_VIEW_ID)) { | ||
throw new Error(`View ${E2E_TESTS_VIEW_ID} not found!`); | ||
} | ||
|
||
// Find the test event we just sent | ||
let cursor: string | undefined = undefined; | ||
let retries = 10; | ||
|
||
while (retries > 0) { | ||
const { nextCursor, traces } = await client.getTracesFromView({ | ||
viewId: E2E_TESTS_VIEW_ID, | ||
pageSize: 10, | ||
cursor, | ||
}); | ||
|
||
console.log('Found traces:'); | ||
console.log(traces.map((t) => t.id)); | ||
|
||
if (traces.some((t) => t.id === traceId)) { | ||
console.log(`Found trace ${traceId}!`); | ||
break; | ||
} | ||
|
||
retries--; | ||
|
||
if (retries === 0) { | ||
throw new Error(`Couldn't find trace ${traceId}.`); | ||
} | ||
|
||
cursor = nextCursor; | ||
|
||
const sleepSeconds = 5; | ||
console.log( | ||
`Couldn't find trace ${traceId} yet, waiting ${sleepSeconds} seconds. ${retries} tries left.`, | ||
); | ||
await sleep(sleepSeconds); | ||
} | ||
}; | ||
|
||
main(); |
Oops, something went wrong.