Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Add a wrapper to log spans and span interactions #502

Merged
merged 10 commits into from
Apr 21, 2020

Conversation

vprithvi
Copy link
Contributor

@vprithvi vprithvi commented Apr 20, 2020

Part of #501

  • Add zap fields to encode spans
  • Add a wrapped Tracer

Signed-off-by: Prithvi Raj p.r@uber.com

- Add zap fields to encode spans
- [TODO] Add a wrapped Tracer

Signed-off-by: Prithvi Raj <p.r@uber.com>
@codecov
Copy link

codecov bot commented Apr 20, 2020

Codecov Report

Merging #502 into master will increase coverage by 0.18%.
The diff coverage is 92.68%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #502      +/-   ##
==========================================
+ Coverage   88.43%   88.62%   +0.18%     
==========================================
  Files          59       60       +1     
  Lines        3581     3745     +164     
==========================================
+ Hits         3167     3319     +152     
- Misses        303      309       +6     
- Partials      111      117       +6     
Impacted Files Coverage Δ
log/zap/field.go 87.36% <92.30%> (+22.66%) ⬆️
log/zap/tracer.go 93.02% <93.02%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ef8f5ed...af4c167. Read the comment docs.

Signed-off-by: Prithvi Raj <p.r@uber.com>
log/zap/field.go Outdated Show resolved Hide resolved
log/zap/field.go Outdated Show resolved Hide resolved
Signed-off-by: Prithvi Raj <p.r@uber.com>
This reverts commit c53c8de.

Signed-off-by: Prithvi Raj <p.r@uber.com>
Signed-off-by: Prithvi Raj <p.r@uber.com>
Signed-off-by: Prithvi Raj <p.r@uber.com>
@vprithvi vprithvi changed the title [WIP] Add a wrapper to log spans and span interactions Add a wrapper to log spans and span interactions Apr 21, 2020
log/zap/field.go Outdated Show resolved Hide resolved
log/zap/field.go Outdated Show resolved Hide resolved
log/zap/field.go Outdated Show resolved Hide resolved

type span struct {
span opentracing.Span
}
Copy link
Member

Choose a reason for hiding this comment

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

suggest keeping consistent with the rest and use type span opentracing.Span

Also might consider type-checking for *jaeger.Span in the following function rather than in MarshalLogObject

Copy link
Contributor Author

Choose a reason for hiding this comment

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

opentracing.Span is an interface. We can typedef it, but go doesn't allow implementing methods on interfaces

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The approach of declaring a new type, and then converting it to use the old type seems pretty contrived to me. What are the benefits of doing this, as opposed to a plain or embedded struct?

Copy link
Member

Choose a reason for hiding this comment

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

New structs cause memory allocations as they are converted to interface{} when passing through Zap API. stdlib also usually uses type aliases instead of creating wrappers, so you could say it's more idiomatic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ty for the explanation!

package zap

import (
"github.com/golang/mock/gomock"
Copy link
Member

Choose a reason for hiding this comment

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

I strongly prefer not to introduce mock dependencies into this library. The goal of the logging wrapper is to log, the tests should be checking for log content, rather than mock expectations. Zap provides very good testing facilities, including checking for structured JSON.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tests in this file already verify the log message and in cases where appropriate whether the logger contains the specific log field. e.g., context. They don't look at the contents of the the key because that logic is tested in field_test.go.

I agree that the purpose of the logging wrapper is to log - but it is crucial that it forwards calls and responses to and from the delegate. I think it is important to test this functionality.

I don't see a way of using purely the logs in the loggingWrapper to verify that the delegate methods have been called with the correct arguments. What are you proposing?

Copy link
Member

Choose a reason for hiding this comment

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

ok

Signed-off-by: Prithvi Raj <p.r@uber.com>
Signed-off-by: Prithvi Raj <p.r@uber.com>
@vprithvi vprithvi self-assigned this Apr 21, 2020
log/zap/field_test.go Outdated Show resolved Hide resolved
log/zap/tracer_test.go Outdated Show resolved Hide resolved
Signed-off-by: Prithvi Raj <p.r@uber.com>
Signed-off-by: Prithvi Raj <p.r@uber.com>
@vprithvi vprithvi merged commit 715cf73 into jaegertracing:master Apr 21, 2020
@vprithvi vprithvi deleted the add-more-logging branch April 21, 2020 21:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants