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

fix: print span info with ctx && add CtxKVLog method #16

Merged
merged 6 commits into from
Feb 15, 2023

Conversation

weedge
Copy link
Contributor

@weedge weedge commented Jan 3, 2023

go get go.opentelemetry.io/otel@v1.11.1

CHANGE:

  1. add zap logger for zap fields, log kv pairs
func (l *Logger) CtxKVLog(ctx context.Context, level klog.Level, format string, kvs ...interface{})
  1. fix: print span info with ctx

@CLAassistant
Copy link

CLAassistant commented Jan 3, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@li-jin-gou li-jin-gou left a comment

Choose a reason for hiding this comment

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

need to sign cla

@weedge
Copy link
Contributor Author

weedge commented Jan 3, 2023

need to sign cla
it's ok , signed the CLA

@CoderPoet
Copy link
Member

Please fix the problem with code formatting

@weedge
Copy link
Contributor Author

weedge commented Jan 4, 2023

Please fix the problem with code formatting

golangci-lint run --out-format=github-actions --path-prefix=./logging/zap -E gofumpt, it's ok

@rogerogers
Copy link
Collaborator

Seems not necessary to introduce logger, zap.Any is even slower than sugar.

@weedge
Copy link
Contributor Author

weedge commented Jan 4, 2023

Seems not necessary to introduce logger, zap.Any is even slower than sugar.

I see https://github.com/uber-go/zap#performance performance is good to me;
Please show some benchmark ? i see zap.Any code switch case , if defined type , no reflection, like %v or %+v;

@rogerogers
Copy link
Collaborator

Seems not necessary to introduce logger, zap.Any is even slower than sugar.

I see https://github.com/uber-go/zap#performance performance is good to me; Please show some benchmark ? i see zap.Any code switch case , if defined type , no reflection, like %v or %+v;

func BenchmarkZapAny(b *testing.B) {
	l, _ := zap.NewProduction()
	for i := 0; i < b.N; i++ {
		l.Info("bench", zap.String("key", "value"), zap.Any("key1", "value1"))
	}
}

func BenchmarkZapSugar(b *testing.B) {
	l, _ := zap.NewProduction()
	s := l.Sugar()
	for i := 0; i < b.N; i++ {
		s.Infow("bench", "key", "value", zap.Any("key1", "value1"))
	}
}

https://pkg.go.dev/go.uber.org/zap#hdr-Choosing_a_Logger

sugar has similar methods.

@weedge
Copy link
Contributor Author

weedge commented Jan 5, 2023

Seems not necessary to introduce logger, zap.Any is even slower than sugar.

I see https://github.com/uber-go/zap#performance performance is good to me; Please show some benchmark ? i see zap.Any code switch case , if defined type , no reflection, like %v or %+v;

func BenchmarkZapAny(b *testing.B) {
	l, _ := zap.NewProduction()
	for i := 0; i < b.N; i++ {
		l.Info("bench", zap.String("key", "value"), zap.Any("key1", "value1"))
	}
}

func BenchmarkZapSugar(b *testing.B) {
	l, _ := zap.NewProduction()
	s := l.Sugar()
	for i := 0; i < b.N; i++ {
		s.Infow("bench", "key", "value", zap.Any("key1", "value1"))
	}
}

https://pkg.go.dev/go.uber.org/zap#hdr-Choosing_a_Logger

sugar has similar methods.

3q~, sugar **w method print kv log is ok~

@a76yyyy a76yyyy mentioned this pull request Jan 5, 2023
@ppzqh
Copy link

ppzqh commented Feb 15, 2023

@CoderPoet Seems that all issues are fixed. Please help to take a look at this pr, thanks!

Copy link
Member

@CoderPoet CoderPoet left a comment

Choose a reason for hiding this comment

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

/LGTM

@bytedance-oss-robot bytedance-oss-robot bot added the lgtm Indicates that a PR is ready to be merged. label Feb 15, 2023
@bytedance-oss-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: CoderPoet, weedge

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@bytedance-oss-robot bytedance-oss-robot bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 15, 2023
@bytedance-oss-robot bytedance-oss-robot bot merged commit be92bf6 into kitex-contrib:main Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants