InfraStack Golang Integration Steps

InfraStack AI provides a comprehensive toolkit for collecting telemetry data within your Golang applications, leveraging OpenTelemetry. This documentation will guide you through the setup process to integrate InfraStack with your Golang applications.

Step 1: Install OpenTelemetry SDKs

First, install the required OpenTelemetry packages for Golang:

go get
go get
go get
go get

Step 2: Configure Environment Variables

Set the necessary environment variables for InfraStack and OpenTelemetry configuration. These variables help secure and authenticate the data transmission to InfraStack. Replace <YOUR_API_KEY> with your actual API key.

Step 3: Initialize OpenTelemetry in Your Application

Create a new file main.go and initialize the OpenTelemetry SDK. You can configure the endpoint and API key either by using environment variables or by hardcoding them within your application.

Import Required Packages

import (

Initialize the Exporter and Tracer Provider

func main() {
    ctx := context.Background()
    // Configure exporter using environment variables
    endpoint := os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT")
    headers := os.Getenv("OTEL_EXPORTER_OTLP_HEADERS")
    serviceName := os.Getenv("OTEL_SERVICE_NAME")
    // Split the headers string into key and value
    headerParts := strings.SplitN(headers, ":", 2)
    headerKey := headerParts[0]
    headerValue := headerParts[1]
    // Create OTLP exporter using environment variables
    exporter, _ := otlptracehttp.New(ctx, otlptracehttp.WithEndpoint(endpoint), otlptracehttp.WithHeaders(map[string]string{headerKey: headerValue}))
    // Create resource
    res := resource.NewWithAttributes(
    // Create trace provider
    tp := trace.NewTracerProvider(
    defer tp.Shutdown(ctx)
    // Set global trace provider
    // Your application code goes here

Step 4: Run Your Application

Build and run your Golang application:

go run main.go

Step 5: Check Your Application Trace Data

You can monitor and analyze the telemetry data collected by visiting the InfraStack Dashboard (opens in a new tab), providing a comprehensive view of your application's performance and health.

Example Trace

To generate and view an example trace, you can instrument specific parts of your application code. Here is how you can do it:

import (
func main() {
    // Initialize OpenTelemetry as shown in Step 3...
    // Create a tracer
    tracer := otel.Tracer("example-tracer")
    // Start a span
    ctx, span := tracer.Start(context.Background(), "example-span")
    defer span.End()
    // Simulate work
    fmt.Println("Doing some work...")
    time.Sleep(2 * time.Second)
    // End the span
    // Continue with the rest of your application code...

This example creates a trace with a single span named "example-span". You can add more spans around different parts of your application to trace various operations.

Additional Instrumentation Options

OpenTelemetry provides specialized instrumentation options for various libraries. For example:

  • HTTP requests: To monitor client and server HTTP requests, use
  • SQL database queries: To monitor interactions with SQL databases, use
  • gRPC calls: To track gRPC requests, use

[!NOTE] You can find all the information about OpenTelemetry and SDK (opens in a new tab).

These instrumentations allow you to collect detailed data from different components of your application, which is critical for performance analysis and troubleshooting.

By following these steps, you can successfully integrate InfraStack AI with your Golang application, enabling powerful observability and monitoring capabilities with minimal setup.