Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logID are duplicated #316

Closed
komuw opened this issue Jul 9, 2023 · 3 comments · Fixed by #317
Closed

logID are duplicated #316

komuw opened this issue Jul 9, 2023 · 3 comments · Fixed by #317

Comments

@komuw
Copy link
Owner

komuw commented Jul 9, 2023

{
    "time": "2023-07-08T15:53:00.104546732Z",
    "level": "ERROR",
    "source": {
        "function": "github.com/komuw/ong/middleware.logger.func1.1",
        "file": "/home/komuw/go/pkg/mod/github.com/komuw/ong@v0.0.62/middleware/log.go",
        "line": 74
    },
    "msg": "http_server",
    "logID": "Xnxs8KAkRxQgBmMM",
    "pid": 173780,
    "env": "production",
    "ver": "9c5b32f3",
    "logID": "g7mxShTgWzBgkC7f",
    "clientIP": "15.22.144.124",
    "clientFingerPrint": "f659afad3573393928e",
    "method": "GET",
    "path": "/",
    "code": 400,
    "status": "Bad Request",
    "durationMS": 0,
    "ongError": "ong/middleware: the HOST http header has an unexpected value",
    "logID": "Xnxs8KAkRxQgBmMM"
}
@komuw
Copy link
Owner Author

komuw commented Jul 9, 2023

repro:

go run -race ./example/...

curl -vkL "https://127.0.0.1:65081/health" -H "Host: badHost.com"
{
    "time": "2023-07-09T18:50:30.771492654Z",
    "level": "ERROR",
    "source": {
        "function": "github.com/komuw/ong/middleware.logger.func1.1",
        "file": "/home/ong/middleware/log.go",
        "line": 74
    },
    "msg": "http_server",
    "logID": "gTXenPA8mXCxQPqh",
    "pid": 301538,
    "logID": "KHxm2cKKfPjGqHDt",
    "clientIP": "127.0.0.1",
    "clientFingerPrint": "0d9kmhf55e80c",
    "method": "GET",
    "path": "/health",
    "code": 400,
    "status": "Bad Request",
    "durationMS": 0,
    "ongError": "ong/middleware: the HOST http header has an unexpected value: badHost.com",
    "logID": "gTXenPA8mXCxQPqh"
}

@komuw
Copy link
Owner Author

komuw commented Jul 9, 2023

repro:

package main

import (
	"context"
	"os"

	"github.com/komuw/ong/log"
)

func main() {
	l := log.New(os.Stdout, 100)(context.Background())
	l.Error("my error")
}
{
    "time": "2009-11-10T23:00:00Z",
    "level": "ERROR",
    "source": {
        "function": "main.main",
        "file": "/tmp/sandbox4189155437/prog.go",
        "line": 12
    },
    "msg": "my error",
    "logID": "cEKmgxtQCeDw7t3G",
    "logID": "cEKmgxtQCeDw7t3G"
}

https://go.dev/play/p/UO6u-ViDQTs

@komuw
Copy link
Owner Author

komuw commented Jul 9, 2023

The following patch seems to fix it;

diff --git a/log/log.go b/log/log.go
index d257025..1636d2a 100644
--- a/log/log.go
+++ b/log/log.go
@@ -149,7 +149,7 @@ func (h handler) Handle(ctx context.Context, r slog.Record) error {
    ctx = context.WithValue(ctx, octx.LogCtxKey, id)

    newAttrs := []slog.Attr{
-       {Key: logIDFieldName, Value: slog.StringValue(id)},
+       // {Key: logIDFieldName, Value: slog.StringValue(id)},
    }
    r.Attrs(func(a slog.Attr) bool {
        if e, ok := a.Value.Any().(error); ok {

komuw added a commit that referenced this issue Jul 10, 2023
- Some logID's are still duplicated, but not all.
  See the testcase added.
- Fixes: #316
komuw added a commit that referenced this issue Jul 10, 2023
- Some logID's are still duplicated, but not all.
  See the testcase added.
  It is kind of hard and non-perfomant[2] to try remove all duplicates.

1. Fixes: #316
2. golang/go#56345 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant