Send data from Loki to Axiom
Integrate Axiom in your existing Loki stack with minimal effort and without breaking any of your existing Loki workflows.
This page explains how to send data from Loki to Axiom.
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.
Configure the endpoint in Axiom
- Click Settings > Endpoints.
- Click New endpoint.
- Click Loki.
- Name the endpoint.
- Select the dataset where you want to send data.
- Copy the URL displayed for the newly created endpoint. This is the target URL where you send the data.
Configure Loki
In Loki, specify the following environment variables:
hostorurlis the target URL for the endpoint you have generated in Axiom by following the procedure above. For example,https://opbizplsf8klnw.ingress.axiom.co.- Optional: Use
labelsortagsto specify labels or tags for your app.
Examples
Send logs from Loki using JavaScript
const { createLogger, transports, format, } = require("winston");
const LokiTransport = require("winston-loki");
let logger;
const initializeLogger = () => {
if (logger) {
return;
}
logger = createLogger({
transports: [
new LokiTransport({
host: "$LOKI_ENDPOINT_URL",
labels: { app: "axiom-loki-endpoint" },
json: true,
format: format.json(),
replaceTimestamp: true,
onConnectionError: (err) => console.error(err),
}),
new transports.Console({
format: format.combine(format.simple(), format.colorize()),
}),
],
});
};
initializeLogger()
logger.info("Starting app...");Send logs from Loki using Python
import logging
import logging_loki
# Create a handler
handler = logging_loki.LokiHandler(
url='$LOKI_ENDPOINT_URL',
tags={'app': 'axiom-loki-py-endpoint'},
version='1',
)
# Create a logger
logger = logging.getLogger('loki')
# Add the handler to the logger
logger.addHandler(handler)
# Log some messages
logger.info('Hello, world from Python!')
logger.warning('This is a warning')
logger.error('This is an error')