Back to snippets
axiom_typescript_client_init_and_single_event_ingest.ts
typescriptThis quickstart initializes the Axiom client and sends a single event to a
Agent Votes
0
0
axiom_typescript_client_init_and_single_event_ingest.ts
1import { Axiom } from '@axiomhq/js';
2
3// Initialize the Axiom client with your API Token
4// You can also set AXIOM_TOKEN as an environment variable
5const axiom = new Axiom({
6 token: process.env.AXIOM_TOKEN,
7});
8
9async function sendLog() {
10 // Replace 'my-dataset' with your actual dataset name
11 axiom.ingest('my-dataset', [
12 {
13 level: 'info',
14 message: 'Hello from Axiom TypeScript quickstart!',
15 fields: {
16 user_id: 123,
17 action: 'login',
18 },
19 },
20 ]);
21
22 // Ensure all events are sent before the process exits
23 await axiom.flush();
24}
25
26sendLog().catch(console.error);