From 635d272a6644646525d3684593e5d80a61464314 Mon Sep 17 00:00:00 2001 From: danushka96 Date: Fri, 14 Aug 2026 08:29:51 +0530 Subject: [PATCH] fix: fixed telemetry issue --- internal/generator/templates.go | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/internal/generator/templates.go b/internal/generator/templates.go index 49e9497..8f0bfb5 100644 --- a/internal/generator/templates.go +++ b/internal/generator/templates.go @@ -193,6 +193,7 @@ import ( {{ if .HasS3 }}"context"{{ end }} "github.com/klass-lk/ginboot" + {{ if .HasTelemetry }}_ "github.com/klass-lk/ginboot/telemetry" // registers telemetry; enable it in ginboot.yml{{ end }} "github.com/klass-lk/ginboot/db/mongo" {{ if .HasLambda }}"github.com/klass-lk/ginboot/runtime/lambda"{{ end }} {{ if .HasS3 }}"github.com/klass-lk/ginboot/storage/s3"{{ end }} @@ -216,7 +217,8 @@ func main() { userService := service.NewUserService(userRepo) userController := controller.NewUserController(userService) - // Initialize Ginboot app (automatically loads .env, ginboot.yml, and configures telemetry) + // Initialize Ginboot app (loads .env and ginboot.yml, and applies the + // telemetry block of ginboot.yml if an instrumentation package is imported) app := ginboot.New() {{ if .HasS3 }} @@ -344,6 +346,7 @@ import ( {{ if .HasS3 }}"context"{{ end }} "github.com/klass-lk/ginboot" + {{ if .HasTelemetry }}_ "github.com/klass-lk/ginboot/telemetry" // registers telemetry; enable it in ginboot.yml{{ end }} "github.com/klass-lk/ginboot/db/sql" {{ if .HasLambda }}"github.com/klass-lk/ginboot/runtime/lambda"{{ end }} {{ if .HasS3 }}"github.com/klass-lk/ginboot/storage/s3"{{ end }} @@ -370,7 +373,8 @@ func main() { userService := service.NewUserService(userRepo) userController := controller.NewUserController(userService) - // Initialize Ginboot app (automatically loads .env, ginboot.yml, and configures telemetry) + // Initialize Ginboot app (loads .env and ginboot.yml, and applies the + // telemetry block of ginboot.yml if an instrumentation package is imported) app := ginboot.New() {{ if .HasS3 }} @@ -415,6 +419,7 @@ import ( {{ if .HasS3 }}"context"{{ end }} "github.com/klass-lk/ginboot" + {{ if .HasTelemetry }}_ "github.com/klass-lk/ginboot/telemetry" // registers telemetry; enable it in ginboot.yml{{ end }} "github.com/klass-lk/ginboot/db/sql" {{ if .HasLambda }}"github.com/klass-lk/ginboot/runtime/lambda"{{ end }} {{ if .HasS3 }}"github.com/klass-lk/ginboot/storage/s3"{{ end }} @@ -441,7 +446,8 @@ func main() { userService := service.NewUserService(userRepo) userController := controller.NewUserController(userService) - // Initialize Ginboot app (automatically loads .env, ginboot.yml, and configures telemetry) + // Initialize Ginboot app (loads .env and ginboot.yml, and applies the + // telemetry block of ginboot.yml if an instrumentation package is imported) app := ginboot.New() {{ if .HasS3 }} @@ -621,6 +627,7 @@ import ( {{ if .HasS3 }}"context"{{ end }} "github.com/klass-lk/ginboot" + {{ if .HasTelemetry }}_ "github.com/klass-lk/ginboot/telemetry" // registers telemetry; enable it in ginboot.yml{{ end }} "github.com/klass-lk/ginboot/db/dynamodb" {{ if .HasLambda }}"github.com/klass-lk/ginboot/runtime/lambda"{{ end }} {{ if .HasS3 }}"github.com/klass-lk/ginboot/storage/s3"{{ end }} @@ -646,7 +653,8 @@ func main() { userService := service.NewUserService(userRepo) userController := controller.NewUserController(userService) - // Initialize Ginboot app (automatically loads .env, ginboot.yml, and configures telemetry) + // Initialize Ginboot app (loads .env and ginboot.yml, and applies the + // telemetry block of ginboot.yml if an instrumentation package is imported) app := ginboot.New() {{ if .HasS3 }} @@ -778,12 +786,14 @@ import ( "{{.ModuleName}}/internal/di" "github.com/klass-lk/ginboot" + {{ if .HasTelemetry }}_ "github.com/klass-lk/ginboot/telemetry" // registers telemetry; enable it in ginboot.yml{{ end }} {{ if .HasLambda }}"github.com/klass-lk/ginboot/runtime/lambda"{{ end }} {{ if .HasS3 }}"github.com/klass-lk/ginboot/storage/s3"{{ end }} ) func main() { - // Initialize Ginboot app (automatically loads .env, ginboot.yml, and configures telemetry) + // Initialize Ginboot app (loads .env and ginboot.yml, and applies the + // telemetry block of ginboot.yml if an instrumentation package is imported) app := ginboot.New() {{ if .HasS3 }} @@ -971,10 +981,17 @@ const ginbootYmlTemplate = `ginboot: url: ${DATABASE_URL:mongodb://localhost:27017} telemetry: + # Requires the blank import of github.com/klass-lk/ginboot/telemetry that + # main.go carries; without it this block has nothing to switch on. enabled: {{.HasTelemetry}} service-name: {{.ProjectName}} exporter: otlp - endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT:localhost:4317} + # Deliberately empty by default. With no endpoint the SDK installs providers + # that export nowhere, which costs nothing and is what you want on a laptop. + # Naming a collector here that is not running does not fail quietly — every + # batch is attempted and every attempt is logged. A deployment supplies the + # real endpoint through OTEL_EXPORTER_OTLP_ENDPOINT, which wins over this. + endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT:} ` const envTemplate = `PORT=8080