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