diff --git a/loki_extension/loki/promtail.go b/loki_extension/loki/promtail.go index f5539a0..f7f799c 100644 --- a/loki_extension/loki/promtail.go +++ b/loki_extension/loki/promtail.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "os" + "strconv" "strings" "time" @@ -28,16 +29,33 @@ var ( func init() { labels = []string{"source=\"lambda\""} sendLabels = []string{"source = lambda"} + timeout := 5000 + printLevel := promtail.ERROR + sendLevel := promtail.INFO for _, element := range os.Environ() { - if !strings.HasPrefix(element, "OTEL_LABEL_") { - continue + if strings.HasPrefix(element, "OTEL_EXPORTER_OTLP_TIMEOUT") || strings.HasPrefix(element, "OTEL_EXPORTER_OTLP_LOGS_TIMEOUT"){ + v := strings.Split(element, "=") + if configuredTimeout, err := strconv.Atoi(v[1]); err != nil { + timeout = configuredTimeout + } + } else if strings.HasPrefix(element, "LOKI_SEND_LEVEL") { + v := strings.Split(element, "=") + if configuredSendLevel, err := strconv.Atoi(v[1]); err != nil { + timeout = configuredSendLevel + } + } else if strings.HasPrefix(element, "LOKI_PRINT_LEVEL") { + v := strings.Split(element, "=") + if configuredPrintLevel, err := strconv.Atoi(v[1]); err != nil { + timeout = configuredPrintLevel + } + } else if strings.HasPrefix(element, "OTEL_LABEL_") { + v := strings.Split(strings.TrimPrefix(element, "OTEL_LABEL_"), "=") + key := strings.ToLower(v[0]) + val := v[1] + labels = append(labels, fmt.Sprintf("%s=\"%s\"", key, val)) + sendLabels = append(labels, fmt.Sprintf("%s = %s", key, val)) } - v := strings.Split(strings.TrimPrefix(element, "OTEL_LABEL_"), "=") - key := strings.ToLower(v[0]) - val := v[1] - labels = append(labels, fmt.Sprintf("%s=\"%s\"", key, val)) - sendLabels = append(labels, fmt.Sprintf("%s = %s", key, val)) } lokiIp := os.Getenv("LOKI_IP") @@ -47,10 +65,10 @@ func init() { conf = promtail.ClientConfig{ PushURL: fmt.Sprintf("%s/api/v1/push", lokiIp), Labels: fmt.Sprintf("{%s}", strings.Join(labels, ",")), - BatchWait: 5 * time.Second, + BatchWait: time.Duration(timeout * int(time.Millisecond)), BatchEntriesNumber: 10000, - SendLevel: promtail.INFO, - PrintLevel: promtail.ERROR, + SendLevel: sendLevel, + PrintLevel: printLevel, } loki, err = promtail.NewClientProto(conf) if err != nil {