OpenTelemetry
Send logs to Sazabi using OpenTelemetry
OpenTelemetry is the most universal way to send logs to Sazabi. It works with any platform that supports OTLP (OpenTelemetry Protocol).
About this data source
OpenTelemetry is the industry-standard, vendor-neutral way to instrument applications for observability. Sazabi accepts OTLP logs over HTTP, allowing you to use the same instrumentation you already have or add OpenTelemetry to any application.
With OpenTelemetry, you can:
- Send logs from any language with an OpenTelemetry SDK
- Use a single instrumentation standard across your entire stack
- Switch between observability backends without changing your code
- Correlate logs with traces and metrics using shared context
Prerequisites
Before you begin, make sure you have:
- An application with the OpenTelemetry SDK installed for your language
- A Sazabi public API key (project-scoped)
Get your API key
Create a public key
Click Create API key and select Public as the key type. Public keys are safe to use in client-side code and are scoped to a single project.
Copy the key and store it securely. You will not be able to see it again.
Configuration
Configure your OpenTelemetry SDK to export logs to Sazabi using these environment variables:
OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.us-west-2.intake.sazabi.com
OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer YOUR_PUBLIC_API_KEY"
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobufReplace YOUR_PUBLIC_API_KEY with the key you created in the previous step.
These environment variables configure all OTLP exporters (logs, traces, and
metrics). If you only want to send logs to Sazabi, use the logs-specific
variants: OTEL_EXPORTER_OTLP_LOGS_ENDPOINT,
OTEL_EXPORTER_OTLP_LOGS_HEADERS, and OTEL_EXPORTER_OTLP_LOGS_PROTOCOL.
Language-specific examples
Install the OpenTelemetry SDK and OTLP exporter:
npm install @opentelemetry/sdk-node @opentelemetry/exporter-logs-otlp-proto @opentelemetry/sdk-logs @opentelemetry/api-logsCreate a file to initialize OpenTelemetry (e.g., instrumentation.ts):
import { NodeSDK } from "@opentelemetry/sdk-node";
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-proto";
import {
LoggerProvider,
BatchLogRecordProcessor,
} from "@opentelemetry/sdk-logs";
const logExporter = new OTLPLogExporter({
url: "https://otlp.us-west-2.intake.sazabi.com/v1/logs",
headers: {
Authorization: `Bearer ${process.env.SAZABI_PUBLIC_KEY}`,
},
});
const loggerProvider = new LoggerProvider();
loggerProvider.addLogRecordProcessor(
new BatchLogRecordProcessor(logExporter)
);
const sdk = new NodeSDK({
logRecordProcessors: [new BatchLogRecordProcessor(logExporter)],
});
sdk.start();Import this file at the start of your application:
import "./instrumentation";
import { logs, SeverityNumber } from "@opentelemetry/api-logs";
const logger = logs.getLogger("my-app");
logger.emit({
severityNumber: SeverityNumber.INFO,
severityText: "INFO",
body: "Application started",
attributes: {
"service.name": "my-app",
},
});Install the OpenTelemetry SDK and OTLP exporter:
pip install opentelemetry-sdk opentelemetry-exporter-otlp-proto-httpInitialize OpenTelemetry and send logs:
import os
from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler
from opentelemetry.sdk._logs.export import BatchLogRecordProcessor
from opentelemetry.exporter.otlp.proto.http._log_exporter import OTLPLogExporter
from opentelemetry._logs import set_logger_provider
import logging
# Configure the OTLP exporter
exporter = OTLPLogExporter(
endpoint="https://otlp.us-west-2.intake.sazabi.com/v1/logs",
headers={"Authorization": f"Bearer {os.environ.get('SAZABI_PUBLIC_KEY')}"},
)
# Set up the logger provider
logger_provider = LoggerProvider()
logger_provider.add_log_record_processor(BatchLogRecordProcessor(exporter))
set_logger_provider(logger_provider)
# Create a logging handler that sends logs to OpenTelemetry
handler = LoggingHandler(
level=logging.INFO,
logger_provider=logger_provider,
)
# Attach the handler to the root logger
logging.getLogger().addHandler(handler)
logging.getLogger().setLevel(logging.INFO)
# Now you can use standard Python logging
logger = logging.getLogger(__name__)
logger.info("Application started", extra={"service.name": "my-app"})Install the OpenTelemetry SDK and OTLP exporter:
go get go.opentelemetry.io/otel
go get go.opentelemetry.io/otel/sdk/log
go get go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttpInitialize OpenTelemetry and send logs:
package main
import (
"context"
"log"
"os"
"go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp"
sdklog "go.opentelemetry.io/otel/sdk/log"
"go.opentelemetry.io/otel/log/global"
)
func main() {
ctx := context.Background()
// Create the OTLP exporter
exporter, err := otlploghttp.New(ctx,
otlploghttp.WithEndpointURL("https://otlp.us-west-2.intake.sazabi.com/v1/logs"),
otlploghttp.WithHeaders(map[string]string{
"Authorization": "Bearer " + os.Getenv("SAZABI_PUBLIC_KEY"),
}),
)
if err != nil {
log.Fatalf("Failed to create exporter: %v", err)
}
// Create the logger provider
provider := sdklog.NewLoggerProvider(
sdklog.WithProcessor(sdklog.NewBatchProcessor(exporter)),
)
defer provider.Shutdown(ctx)
// Set the global logger provider
global.SetLoggerProvider(provider)
// Get a logger and emit a log record
logger := global.Logger("my-app")
logger.Emit(ctx, sdklog.Record{
Body: "Application started",
Severity: sdklog.SeverityInfo,
Attributes: []sdklog.KeyValue{
sdklog.String("service.name", "my-app"),
},
})
}Example payload
When you send logs using OpenTelemetry, they are formatted as OTLP log records. Here is an example of what a log record looks like:
{
"resourceLogs": [
{
"resource": {
"attributes": [
{
"key": "service.name",
"value": { "stringValue": "my-app" }
}
]
},
"scopeLogs": [
{
"scope": {
"name": "my-app"
},
"logRecords": [
{
"timeUnixNano": "1704067200000000000",
"severityNumber": 9,
"severityText": "INFO",
"body": {
"stringValue": "Application started"
},
"attributes": [
{
"key": "user.id",
"value": { "stringValue": "12345" }
}
]
}
]
}
]
}
]
}Verifying logs are flowing
Once you have configured your application, you can verify that logs are flowing to Sazabi:
-
Ask the assistant: Open a thread in Sazabi and ask "Show me recent logs" or "What logs came in from my-app in the last 5 minutes?"
-
Check the dashboard: Navigate to your project in the Sazabi dashboard to see logs appear in real-time.
Troubleshooting
No logs appearing
- Verify your API key is correct and has the Public scope
- Check that the endpoint URL is
https://otlp.<region>.intake.sazabi.com(e.g.,https://otlp.us-west-2.intake.sazabi.com) - Ensure the
Authorization: Bearerheader is being sent with requests - Confirm your application is calling the logger and flushing before exit
401 Unauthorized errors
- Your API key may be invalid or expired
- Create a new public API key in Settings -> API Keys
- Verify the key is for the correct project
Connection timeout
- Verify the endpoint URL does not have a trailing slash
- Check that your network allows outbound HTTPS connections
- If behind a proxy, configure your HTTP client accordingly
Logs delayed or batched
OpenTelemetry SDKs batch logs by default for efficiency. If you need logs to appear immediately, you can:
- Reduce the batch delay in your SDK configuration
- Call the flush method before your application exits
- For debugging, temporarily switch to a simple log processor