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

Logging Bridge For ZeroLog #5761

Closed
wants to merge 14 commits into from

Conversation

AkhigbeEromo
Copy link
Contributor

part of #5405

  • Worked on the zerolog.Hook log bridge.
  • Wrote Some tests for the functions

@AkhigbeEromo AkhigbeEromo requested a review from a team June 12, 2024 14:06
@MrAlias

This comment was marked as outdated.

@MrAlias MrAlias closed this Jun 17, 2024
@MrAlias MrAlias reopened this Jun 17, 2024
@AkhigbeEromo
Copy link
Contributor Author

Hello @MrAlias, i have made the corrections. Is there anything you would like me to add

Copy link
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

versions.yaml needs to be updated

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A changelog entry is required.

@@ -0,0 +1,23 @@
module go.opentelemetry.io/contrib/bridges/otelzerolog

go 1.22.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repo currently needs to support Go 1.21.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I resolved this in #5782

bridges/otelzerolog/hook.go Outdated Show resolved Hide resolved

// Levels returns the list of log levels we want to be sent to OpenTelemetry.
func (h *SeverityHook) Levels() zerolog.Level {
return h.levels
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is never set, it will always be empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just set it in the Severity Struct

record.SetTimestamp(zerolog.TimestampFunc())
record.SetBody(log.StringValue(msg))
const sevOffset = zerolog.Level(log.SeverityDebug) - zerolog.DebugLevel
record.SetSeverity(log.Severity(level + sevOffset))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func extractFields(_ *zerolog.Event) map[string]interface{} {
// Here you would implement the logic to extract fields from the zerolog event
// This might involve using reflection or zerolog internals if necessary
fields := make(map[string]interface{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ... worrying, it is allocating a map just to make a conversion. Can the zero log fields not be directly converted sent to SetAttribute and skip this allocation?

}

func convertAttribute(key string, value interface{}) log.KeyValue {
switch v := value.(type) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing cases:

  • map
  • slice

}

func convertFields(fields map[string]interface{}, msg string) []log.KeyValue {
kvs := make([]log.KeyValue, 0, len(fields))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar here, this is making an allocation that is going to be potentially thrown away every time a message is emitted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a fair amount of test coverage missing. If we plan to implement a method or function in the PR it should be accompanied with comprehensive tests.

If you need to break this into smaller PRs, adding a method/function stub that you will implement and test in a follow-up PR is acceptable. You will need to track that as an issue though and keep the bridge unreleased until all parts are complete.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @MrAlias
I will do just that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to check in regarding this PR. While I haven't finished all the implementations yet, are the functions I've initialized sufficient, or do I need to add any additional functions? @MrAlias

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am more asking about adding test coverage for the functions that are included in this PR. There is a considerable amount of functionality being introduced here that is not tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood
Thank you

Copy link

codecov bot commented Jun 17, 2024

Codecov Report

Attention: Patch coverage is 48.00000% with 39 lines in your changes missing coverage. Please review.

Project coverage is 64.3%. Comparing base (10c3117) to head (5b9f918).

Current head 5b9f918 differs from pull request most recent head 946d0f8

Please upload reports for the commit 946d0f8 to get more accurate results.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #5761     +/-   ##
=======================================
- Coverage   64.6%   64.3%   -0.3%     
=======================================
  Files        202     201      -1     
  Lines      12591   12615     +24     
=======================================
- Hits        8134    8118     -16     
- Misses      4221    4260     +39     
- Partials     236     237      +1     
Files Coverage Δ
bridges/otelzerolog/hook.go 48.0% <48.0%> (ø)

... and 20 files with indirect coverage changes

@AkhigbeEromo AkhigbeEromo marked this pull request as draft June 24, 2024 20:05
@pellared pellared closed this Jul 22, 2024
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 this pull request may close these issues.

3 participants