Overview

Send data from Go app to Axiom

The Axiom Go SDK is an open-source project and welcomes your contributions. For more information, see the GitHub repository.

Prerequisites#

Install SDK#

To install the SDK, run the following:

go get github.com/axiomhq/axiom-go/axiom

Import the package:

import "github.com/axiomhq/axiom-go/axiom"

If you use the Axiom CLI, run eval $(axiom config export -f) to configure your environment variables. Otherwise, create an API token and export it as AXIOM_TOKEN.

Alternatively, configure the client using options passed to the axiom.NewClient function:

client, err := axiom.NewClient(
    axiom.SetPersonalTokenConfig("AXIOM_TOKEN"),
)

Use client#

Create and use a client in the following way:

package main
 
import (
    "context"
    "fmt"
    "log"
 
    "github.com/axiomhq/axiom-go/axiom"
    "github.com/axiomhq/axiom-go/axiom/ingest"
)
 
func main() {
    ctx := context.Background()
 
    client, err := axiom.NewClient()
    if err != nil {
        log.Fatal(err)
    }
 
    if _, err = client.IngestEvents(ctx, "my-dataset", []axiom.Event{
        {ingest.TimestampField: time.Now(), "foo": "bar"},
        {ingest.TimestampField: time.Now(), "bar": "foo"},
    }); err != nil {
        log.Fatal(err)
    }
 
    res, err := client.Query(ctx, "['my-dataset'] | where foo == 'bar' | limit 100")
    if err != nil {
        log.Fatal(err)
    } else if res.Status.RowsMatched == 0 {
        log.Fatal("No matches found")
    }
 
    rows := res.Tables[0].Rows()
    if err := rows.Range(ctx, func(_ context.Context, row query.Row) error {
        _, err := fmt.Println(row)
        return err
    }); err != nil {
        log.Fatal(err)
    }
}

For more examples, see the examples in GitHub.

Configure region#

By default, the client sends data to api.axiom.co. To target a specific edge region, pass the SetEdge option with the edge domain that matches the region your dataset lives in:

client, err := axiom.NewClient(
    axiom.SetEdge("eu-central-1.aws.edge.axiom.co"),
)
client, err := axiom.NewClient(
    axiom.SetEdge("us-east-1.aws.edge.axiom.co"),
)

This relies on AXIOM_TOKEN being set in your environment. To set the token in code as well, add axiom.SetToken("xaat-...").

The following edge domains are available:

Edge deployment Base domain for ingest and query
US East 1 (AWS) us-east-1.aws.edge.axiom.co
EU Central 1 (AWS) eu-central-1.aws.edge.axiom.co

For more information about edge deployments, see Edge deployments.

You can also configure the region without changing code by exporting environment variables:

export AXIOM_EDGE="eu-central-1.aws.edge.axiom.co"
# or, for a full URL (takes precedence over AXIOM_EDGE):
export AXIOM_EDGE_URL="https://eu-central-1.aws.edge.axiom.co"

To point at a custom edge endpoint such as a proxy or load balancer, use axiom.SetEdgeURL("https://your-edge-host"). SetEdgeURL takes precedence over SetEdge if both are set.

Edge endpoints require an API token (xaat-), not a personal token (xapt-). Ingest and query calls with a personal token against an edge endpoint return personal tokens are not supported for edge operations, use an API token (xaat-).

Adapters#

To use a logging package, see the following adapters:

Updated

Was this page helpful?