cosmos-sdk/telemetry/testing.go
Aaron Craelius f2d4a98039
feat: OpenTelemetry configuration and BaseApp instrumentation (#25516)
Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com>
Co-authored-by: Alex | Cosmos Labs <alex@cosmoslabs.io>
2025-12-10 23:15:18 +00:00

28 lines
635 B
Go

package telemetry
import (
"context"
"fmt"
"os"
"testing"
)
// TestingMain should be used in tests where you want to run telemetry and need clean shutdown
// behavior at the end of the test, for instance to collect benchmark metrics.
// If ctx is nil, context.Background() is used.
// Example:
//
// func TestMain(m *testing.M) {
// telemetry.TestingMain(m, nil)
// }
func TestingMain(m *testing.M, ctx context.Context) {
code := m.Run()
if ctx == nil {
ctx = context.Background()
}
if err := Shutdown(ctx); err != nil {
fmt.Printf("failed to shutdown telemetry after test completion: %v\n", err)
}
os.Exit(code)
}