-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
refactor(sbom): add sbom prefix + filepaths for decode log messages #7074
refactor(sbom): add sbom prefix + filepaths for decode log messages #7074
Conversation
logger with
sbom
prefixsbom
prefix + filepaths for decode log messages
pkg/sbom/cyclonedx/unmarshal_test.go
Outdated
ctx := log.WithContextAttrs(context.Background(), log.String("filepath", tt.inputFile)) | ||
err = sbomio.NewDecoder(cdx.BOM).Decode(ctx, &got) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to pass attributes in tests.
ctx := log.WithContextAttrs(context.Background(), log.String("filepath", tt.inputFile)) | |
err = sbomio.NewDecoder(cdx.BOM).Decode(ctx, &got) | |
err = sbomio.NewDecoder(cdx.BOM).Decode(context.Background(), &got) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed e0b36ca
pkg/sbom/spdx/unmarshal_test.go
Outdated
ctx := log.WithContextAttrs(context.Background(), log.String("filepath", tt.inputFile)) | ||
err = sbomio.NewDecoder(v.BOM).Decode(ctx, &got) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed in e0b36ca
pkg/fanal/analyzer/sbom/sbom.go
Outdated
// Format auto-detection | ||
format, err := sbom.DetectFormat(input.Content) | ||
if err != nil { | ||
return nil, xerrors.Errorf("failed to detect SBOM format: %w", err) | ||
} | ||
|
||
bom, err := sbom.Decode(input.Content, format) | ||
ctx = log.WithContextAttrs(ctx, log.String("file", input.FilePath)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if adding log.FilePath(filePath string)
in pkg/log
and using it so we can use the consistent key name?
func FilePath(filePath string) slog.Attr {
return String("file_path", filePath)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. The number of filepaths used was more than i expected.
I created #7080
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Merged #7080.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated this PR
sbom
prefix + filepaths for decode log messageslog.FilePath()
function
log.FilePath()
functionlog.FilePath()
function for logger
log.FilePath()
function for loggerae1e4d8
to
cf30a86
Compare
Description
Add
file_path
+sbom
prefix for log messages indecode.go
.before:
after:
2024-07-02T14:44:45+06:00 WARN [sbom] Ignore the OS package as no OS is detected. file_path="var/lib/db/sbom/apk-tools-2.14.4-r0.spdx.json"
Related discussions
Checklist