OpenTelemetry Go Installation
Make sure to install the AppSignal collector before proceeding with these instructions.
Configure OpenTelemetry in your application
OpenTelemetry must be initialized before your application starts, to ensure that all telemetry data is sent through the exporter to AppSignal. For example, in a web application, OpenTelemetry must be initialized before the routes are loaded and the server starts.
Create an initTracer()
function like the one in the example below and add it to your application's main file.
Make sure to update the values below with your AppSignal application name, environment and push API key, and to replace the exporter endpoint with the address of your AppSignal collector if needed.
import ( "context" "os" "os/exec" "strings" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/exporters/otlp/otlptrace" "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" "go.opentelemetry.io/otel/sdk/trace" ) func initTracer() func(context.Context) error { // Replace these values with your AppSignal application name, environment // and push API key. These are used by the resource attributes configuration below. name := "My app" push_api_key := "0000-0000-0000-0000" environment := "development" // Set the name of the service that is being monitored. A common choice is the // name of the framework used. This is used to group traces and metrics in AppSignal. service_name := "My service name" // Replace `http://localhost:8099` with the address of your AppSignal collector // if it's running on another host. endpoint := "localhost:8099" client := otlptracehttp.NewClient( otlptracehttp.WithInsecure(), otlptracehttp.WithEndpoint(endpoint), ) exporter, err := otlptrace.New(context.Background(), client) if err != nil { log.Fatal("Error creating OTLP trace exporter: %w") } hostname, err := os.Hostname() if err != nil { hostname = "unknown" } cmd := exec.Command("git", "rev-parse", "--short", "HEAD") output, err := cmd.Output() if err != nil { revision = "unknown" } else { revision = strings.TrimSpace(string(output)) } resource := resource.NewSchemaless( attribute.String("appsignal.config.name", name), attribute.String("appsignal.config.environment", environment), attribute.String("appsignal.config.push_api_key", push_api_key), attribute.String("appsignal.config.revision", revision), attribute.String("appsignal.config.language_integration", "golang"), attribute.String("appsignal.config.app_path", os.Getenv("PWD")), attribute.String("service.name", service_name), attribute.String("host.name", hostname), ) tracerProvider := sdktrace.NewTracerProvider( sdktrace.WithBatcher(exporter), sdktrace.WithBatcher(consoleExporter), sdktrace.WithResource(resource), ) otel.SetTracerProvider(tracerProvider) otel.SetTextMapPropagator( propagation.NewCompositeTextMapPropagator( propagation.TraceContext{}, propagation.Baggage{} ) ) return exporter.Shutdown } func main() { cleanup := initTracer() defer cleanup(context.Background()) // ... your application's initialization code }
Configure OpenTelemetry instrumentation packages
The OpenTelemetry stack will not emit any data by itself. To instrument your application, install and configure the instrumentation packages for the libraries and frameworks used by your application. You can find OpenTelemetry instrumentation packages at the OpenTelemetry registry.
For some popular OpenTelemetry instrumentations, you can find specific configuration instructions in these pages:
Test the app!
Now that all the components are connected, start your app and test if you see data arrive in AppSignal. Check the "Errors > Issue list" and "Performance > Traces" page specifically.
If after following our installation instructions you still don't see data in AppSignal, let us know and we'll help you finalize your OpenTelemetry installation!