Send data from Go app to Axiom
This page explains how to send data from a Go app to Axiom.
To send data from a Go app to Axiom, use the Axiom Go SDK.
Prerequisites
- Create an Axiom account.
- Create a dataset in Axiom where you send your data.
- Create an API token in Axiom with permissions to ingest data to the dataset you have created.
Install SDK
To install the SDK, run the following:
Import the package:
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:
Use client
Create and use a client in the following way:
For more examples, see the examples in GitHub.
Query metrics
Query metrics datasets with the Metrics Processing Language (MPL) using client.QueryMPL. MPL queries and metrics discovery run on edge endpoints only; without an edge endpoint, QueryMPL returns axiom.ErrMissingEdge. Dataset.EdgeDeploymentURL holds the edge URL for a dataset.
Use client.Metrics to discover metrics and tags on edge endpoints:
client.Metrics.List(ctx, dataset, start, end): List metric names in a dataset.client.Metrics.Tags(ctx, start, end)andclient.Metrics.DatasetTags(ctx, dataset, start, end): List tag keys.client.Metrics.TagValues(ctx, tag, start, end)andclient.Metrics.DatasetTagValues(ctx, dataset, tag, start, end): List values for a tag key.client.Metrics.Find(ctx, dataset, value, start, end): Find metrics in a dataset that have a tag with the given value.
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:
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:
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.
Adapters
To use a logging package, see the following adapters:
Export OpenTelemetry traces
Use otel.InitTracing to set up tracing for your service. Call the returned shutdown function before the process exits. If your application configures its own tracing pipeline, use otel.TracerProvider or otel.TraceExporter to supply the component you need.