Skip to content

Commit

Permalink
auto add exporter endpoint and insecure flag
Browse files Browse the repository at this point in the history
  • Loading branch information
dawkaka committed Dec 10, 2024
1 parent f87ca91 commit c89bcb1
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 40 deletions.
3 changes: 1 addition & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
OTEL_SERVICE_NAME="apitoolkit-otel-go-demo"
OTEL_SERVICE_VERSION="0.0.1"
OTEL_RESOURCE_ATTRIBUTES="at-project-key=wKUZLJBKayszzIdJhaZsGDYc9DieSdqetLy8071Z8D8H/d7H"
OTEL_LOG_LEVEL="debug"
OTEL_RESOURCE_ATTRIBUTES=at-project-key=wKUZLJBKayszzIdJhaZsGDYc9DieSdqetLy8071Z8D8H/d7H
OTEL_EXPORTER_OTLP_ENDPOINT="localhost:4317"
9 changes: 2 additions & 7 deletions chi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,13 @@ import (

apitoolkit "github.com/apitoolkit/apitoolkit-go/chi"
"github.com/go-chi/chi/v5"
"github.com/joho/godotenv"
_ "github.com/joho/godotenv/autoload"
)

func main() {
err := godotenv.Load(".env")
if err != nil {
log.Printf("Error loading .env file: %v", err)
}
shutdown, err := apitoolkit.ConfigureOpenTelemetry()
shutdown, err := apitoolkit.ConfigureOpenTelemetry()
if err != nil {
log.Printf("error configuring openTelemetry: %v", err)

}
defer shutdown()

Expand Down
1 change: 1 addition & 0 deletions chi/chi.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func Middleware(config Config) func(http.Handler) http.Handler {
}

func ConfigureOpenTelemetry(opts ...otelconfig.Option) (func(), error) {
opts = append([]otelconfig.Option{otelconfig.WithExporterEndpoint("otelcol.apitoolkit.io:4317"), otelconfig.WithExporterInsecure(true)}, opts...)
return otelconfig.ConfigureOpenTelemetry(opts...)
}

Expand Down
9 changes: 2 additions & 7 deletions echo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,14 @@ import (

apitoolkit "github.com/apitoolkit/apitoolkit-go/echo"
"github.com/labstack/echo/v4"
"github.com/joho/godotenv"
_ "github.com/joho/godotenv/autoload"
)


func main() {
err := godotenv.Load(".env")
if err != nil {
log.Printf("Error loading .env file: %v", err)
}
shutdown, err := apitoolkit.ConfigureOpenTelemetry()
shutdown, err := apitoolkit.ConfigureOpenTelemetry()
if err != nil {
log.Printf("error configuring openTelemetry: %v", err)

}
defer shutdown()

Expand Down
1 change: 1 addition & 0 deletions echo/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func Middleware(config Config) echo.MiddlewareFunc {
}

func ConfigureOpenTelemetry(opts ...otelconfig.Option) (func(), error) {
opts = append([]otelconfig.Option{otelconfig.WithExporterEndpoint("otelcol.apitoolkit.io:4317"), otelconfig.WithExporterInsecure(true)}, opts...)
return otelconfig.ConfigureOpenTelemetry(opts...)
}

Expand Down
7 changes: 1 addition & 6 deletions fiber/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,13 @@ import (

apitoolkit "github.com/apitoolkit/apitoolkit-go/fiber"
"github.com/gofiber/fiber/v2"
"github.com/joho/godotenv"
_ "github.com/joho/godotenv/autoload"
)

func main() {
err := godotenv.Load(".env")
if err != nil {
log.Printf("Error loading .env file: %v", err)
}
shutdown, err := apitoolkit.ConfigureOpenTelemetry()
if err != nil {
log.Printf("error configuring openTelemetry: %v", err)

}
defer shutdown()

Expand Down
1 change: 1 addition & 0 deletions fiber/fiber.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func ReportError(ctx context.Context, err error) {
}

func ConfigureOpenTelemetry(opts ...otelconfig.Option) (func(), error) {
opts = append([]otelconfig.Option{otelconfig.WithExporterEndpoint("otelcol.apitoolkit.io:4317"), otelconfig.WithExporterInsecure(true)}, opts...)
return otelconfig.ConfigureOpenTelemetry(opts...)
}

Expand Down
7 changes: 1 addition & 6 deletions gin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,13 @@ import (

apitoolkit "github.com/apitoolkit/apitoolkit-go/gin"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
_ "github.com/joho/godotenv/autoload"
)

func main() {
err := godotenv.Load(".env")
if err != nil {
log.Printf("Error loading .env file: %v", err)
}
shutdown, err := apitoolkit.ConfigureOpenTelemetry()
if err != nil {
log.Printf("error configuring openTelemetry: %v", err)

}
defer shutdown()

Expand Down
1 change: 1 addition & 0 deletions gin/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func getAptConfig(config Config) apt.Config {
}

func ConfigureOpenTelemetry(opts ...otelconfig.Option) (func(), error) {
opts = append([]otelconfig.Option{otelconfig.WithExporterEndpoint("otelcol.apitoolkit.io:4317"), otelconfig.WithExporterInsecure(true)}, opts...)
return otelconfig.ConfigureOpenTelemetry(opts...)
}

Expand Down
7 changes: 1 addition & 6 deletions gorilla/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,13 @@ import (

apitoolkit "github.com/apitoolkit/apitoolkit-go/gorilla"
"github.com/gorilla/mux"
"github.com/joho/godotenv"
_ "github.com/joho/godotenv/autoload"
)

func main() {
err := godotenv.Load(".env")
if err != nil {
log.Printf("Error loading .env file: %v", err)
}
shutdown, err := apitoolkit.ConfigureOpenTelemetry(apitoolkit.WithMetricsEnabled(false))
if err != nil {
log.Printf("error configuring openTelemetry: %v", err)

}
defer shutdown()

Expand Down
1 change: 1 addition & 0 deletions gorilla/gorilla.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func Middleware(config Config) func(next http.Handler) http.Handler {
}

func ConfigureOpenTelemetry(opts ...otelconfig.Option) (func(), error) {
opts = append([]otelconfig.Option{otelconfig.WithExporterEndpoint("otelcol.apitoolkit.io:4317"), otelconfig.WithExporterInsecure(true)}, opts...)
return otelconfig.ConfigureOpenTelemetry(opts...)
}

Expand Down
7 changes: 1 addition & 6 deletions native/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,10 @@ import (
"log"

apitoolkit "github.com/apitoolkit/apitoolkit-go/native"
"github.com/joho/godotenv"
_ "github.com/joho/godotenv/autoload"
)

func main() {

err := godotenv.Load(".env")
if err != nil {
log.Printf("Error loading .env file: %v", err)
}
shutdown, err := apitoolkit.ConfigureOpenTelemetry()
if err != nil {
log.Printf("error configuring openTelemetry: %v", err)
Expand Down
1 change: 1 addition & 0 deletions native/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func Middleware(config Config) func(http.Handler) http.Handler {
}

func ConfigureOpenTelemetry(opts ...otelconfig.Option) (func(), error) {
opts = append([]otelconfig.Option{otelconfig.WithExporterEndpoint("otelcol.apitoolkit.io:4317"), otelconfig.WithExporterInsecure(true)}, opts...)
return otelconfig.ConfigureOpenTelemetry(opts...)
}

Expand Down

0 comments on commit c89bcb1

Please sign in to comment.