-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.go
46 lines (39 loc) · 1.05 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// The purpose of this example is to show how to send events to Axiom.
package main
import (
"context"
"log"
"os"
"time"
"github.com/axiomhq/axiom-go/axiom"
"github.com/axiomhq/axiom-go/axiom/ingest"
)
func main() {
// Export "AXIOM_DATASET" in addition to the required environment variables.
dataset := os.Getenv("AXIOM_DATASET")
if dataset == "" {
log.Fatal("AXIOM_DATASET is required")
}
// 1. Initialize the Axiom API client.
client, err := axiom.NewClient()
if err != nil {
log.Fatal(err)
}
// 2. Ingest ⚡
//
// Set the events timestamp by specifying the "_time" field the server uses
// by default. Can be changed by using the [ingest.SetTimestampField] option
// when ingesting.
events := []axiom.Event{
{ingest.TimestampField: time.Now(), "foo": "bar"},
{ingest.TimestampField: time.Now(), "bar": "foo"},
}
res, err := client.IngestEvents(context.Background(), dataset, events)
if err != nil {
log.Fatal(err)
}
// 3. Make sure everything went smoothly.
for _, fail := range res.Failures {
log.Print(fail.Error)
}
}