Skip to content

Commit

Permalink
Ignore track and route names for now
Browse files Browse the repository at this point in the history
  • Loading branch information
AGMETEOR committed Jan 24, 2025
1 parent 61a5f77 commit 9f475bf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
9 changes: 2 additions & 7 deletions http-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (

var (
// log = golog.LoggerFor("lantern-proxy")
log = logger.InitLogger("lantern-proxy", nil)
log = logger.InitLogger("lantern-proxy", logger.Opts{})
revision = "unknown" // overridden by Makefile
build_type = "unknown" // overriden by Makefile

Expand Down Expand Up @@ -218,13 +218,8 @@ func main() {
return
}

// golog.SetOpts(&golog.Opts{
// HostMachine: *proxyName,
// TrackName: *track,
// })

// flags are now available and we can build OTEL logger with opts
log = logger.InitLogger("lantern-proxy", &logger.Opts{
log = logger.InitLogger("lantern-proxy", logger.Opts{
HostMachine: *proxyName,
TrackName: *track,
})
Expand Down
45 changes: 22 additions & 23 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Opts struct {
RouteName string
}

func (o *Opts) attrKV() []attribute.KeyValue {
func (o Opts) attrKV() []attribute.KeyValue {
return []attribute.KeyValue{
attribute.String("phost", o.HostMachine),
attribute.String("track", o.TrackName),
Expand Down Expand Up @@ -101,51 +101,50 @@ func kvAttributes(vs []any) []otelLog.KeyValue {
}

var InitializedLogger = &ProxyLogger{}
var loggerOpts *Opts

func GetLogger() *ProxyLogger {
return InitializedLogger
}

func (pl *ProxyLogger) SetStdLogger(logger golog.Logger) *ProxyLogger {
nL := &ProxyLogger{
initializedOtel: pl.initializedOtel,
otelLogger: pl.otelLogger,
stdLogger: logger,
}

otelLogger, _ := BuildOtelLogger(Opts{})
nL.otelLogger = otelLogger
return nL
}

func InitLogger(stdLoggerPrefix string, opts *Opts) *ProxyLogger {
goLog := golog.LoggerFor(stdLoggerPrefix)
p := &ProxyLogger{
stdLogger: goLog,
}

if opts == nil {
return p
}

loggerOpts = opts

func BuildOtelLogger(opts Opts) (otelLog.Logger, error) {
expLog, err := otlpLog.New(context.Background(),
otlpLog.WithEndpoint(otelEndpoint),
otlpLog.WithInsecure(), // the endpoint is on the lo interface, so this "might" be safe
)
if err != nil {
return p
return nil, err
}

resourceAttributes := []attribute.KeyValue{semconv.ServiceNameKey.String(otelServiceName)}
resourceAttributes = append(resourceAttributes, loggerOpts.attrKV()...)
resourceAttributes = append(resourceAttributes, opts.attrKV()...)

r := resource.NewWithAttributes(semconv.SchemaURL, resourceAttributes...)
provider := otelLogSdk.NewLoggerProvider(
otelLogSdk.WithProcessor(otelLogSdk.NewBatchProcessor(expLog)),
otelLogSdk.WithResource(r),
)

p.otelLogger = provider.Logger(otelServiceName)
return provider.Logger(otelServiceName), nil
}

func InitLogger(stdLoggerPrefix string, opts Opts) *ProxyLogger {
goLog := golog.LoggerFor(stdLoggerPrefix)
p := &ProxyLogger{
stdLogger: goLog,
}

oLogger, err := BuildOtelLogger(opts)
if err != nil {
return p
}

p.otelLogger = oLogger
p.initializedOtel = true

InitializedLogger = p
Expand Down
3 changes: 2 additions & 1 deletion sessionticketkey
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
���c&���LO���bC;A �<����Q��G�vC

�C�g�p���y��9v��վ�T��\�ꆶO!���c&���LO���bC;A �<����Q��G�vC
Expand Down

0 comments on commit 9f475bf

Please sign in to comment.