feat: refactor authorization handling across files

- Remove the unused import for `encoding/base64`
- Update the authorization header handling in the `InitOtelAPM` function

Signed-off-by: Sinh <luuvansinh555@gmail.com>
This commit is contained in:
Sinh 2024-07-09 11:07:53 +07:00
parent 5e7d6743a1
commit ac71d2f5e3
1 changed files with 3 additions and 5 deletions

8
apm.go
View File

@ -2,7 +2,6 @@ package apm
import (
"context"
"encoding/base64"
"github.com/labstack/echo/v4"
"go.mongodb.org/mongo-driver/event"
@ -29,8 +28,7 @@ var (
type OtelConfig struct {
Endpoint string
Path string
AuthUser string
AuthPwd string
AuthHeader string
ServiceName string
ServiceVersion string
Env string
@ -45,8 +43,8 @@ func InitOtelAPM(config OtelConfig) error {
otlptracehttp.NewClient()
authHeaders := map[string]string{}
if config.AuthUser != "" && config.AuthPwd != "" {
authHeaders["Authorization"] = "Basic " + base64.StdEncoding.EncodeToString([]byte(config.AuthUser+":"+config.AuthPwd))
if config.AuthHeader != "" {
authHeaders["Authorization"] = config.AuthHeader
}
otlpHTTPExporter, err := otlptracehttp.New(context.Background(),
otlptracehttp.WithEndpoint(config.Endpoint),