diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index d713ebc..4c315a4 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -12,6 +12,8 @@ jobs: - uses: actions/setup-go@v2 with: go-version: '1.18' + - name: Checkout peers + run: make ci_checkout_peers CLONE_DEPTH=2 - name: Run coverage run: make calculate_coverage diff --git a/Makefile b/Makefile index 7a8ab8b..71e3275 100644 --- a/Makefile +++ b/Makefile @@ -1,31 +1,12 @@ -GOHOME ?= ${HOME} -GOPATH ?= ${GOHOME} -GOBIN ?= ${GOPATH}/bin - -ZZZGO = $(wildcard ../xop*-go/*.zzzgo ../xop*-go/*/*.zzzgo ../xop*-go/*/*/*.zzzgo) -ZZZGENERATED = $(patsubst %.zzzgo, %.go, $(ZZZGO)) -PB = xopproto/ingest.pb.go xopproto/ingest_grpc.pb.go -TOOLS = ${GOBIN}/gofumpt ${GOBIN}/goimports ${GOBIN}/enumer -TEST_ONLY ?= - +ME = xop-go RELATED = xopresty-go xopotel-go +EXTRA_TEST_DEPS = testadjuster -all: $(ZZZGENERATED) $(PB) .gitattributes - go generate ./... - go build ./... - for i in $(RELATED); do (echo $$i ...; cd ../$$i && go generate ./... && go build ./...); done - +include Makefile.common ci_checkout_peers:; - branch="$${GITHUB_REF##*/}"; for i in $(RELATED); do (cd ..; git clone https://github.com/xoplog/$$i --depth 1 -b $$branch || git clone https://github.com/xoplog/$$i --depth 1); done - -.gitattributes: $(ZZZGENERATED) - echo '*.zzzgo linguist-language=Go' > $@ - echo 'doc.go linguist-documentation' >> $@ - echo '*.md linguist-documentation' >> $@ - echo '*.pb.go linguist-generated' >> $@ - for i in $(ZZZGENERATED); do echo "$$i linguist-generated" >> $@; done + branch="$${GITHUB_REF##*/}"; for i in $(RELATED); do (cd ..; git clone https://github.com/xoplog/$$i --depth $(CLONE_DEPTH) -b $$branch || git clone https://github.com/xoplog/$$i --depth $(CLONE_DEPTH)); done test: $(ZZZGENERATED) testadjuster go generate ./... @@ -49,23 +30,6 @@ citest: XOPLEVEL_xoptestutil=warn XOPLEVEL_foo=debug go test -tags xoptesting ./xoptest/xoptestutil -run TestAdjuster -count 1 XOPLEVEL_xoptestutil=debug XOPLEVEL_foo=warn go test -tags xoptesting ./xoptest/xoptestutil -run TestAdjuster -count 1 -${GOBIN}/gofumpt:; - go install mvdan.cc/gofumpt@latest - -${GOBIN}/goimports:; - go install golang.org/x/tools/cmd/goimports@latest - -${GOBIN}/enumer:; - go install github.com/dmarkham/enumer@latest - -%.go : %.zzzgo tools/xopzzz/xopzzz.go $(TOOLS) Makefile - go run tools/xopzzz/xopzzz.go < $< > $@.tmp - -chmod +w $@ - gofumpt -w $@.tmp - goimports -w $@.tmp - -mv $@.tmp $@ - -chmod -w $@ - calculate_coverage: echo "mode: atomic" > coverage.txt for d in $$(go list ./...); do \ @@ -84,21 +48,6 @@ calculate_coverage: egrep -v 'xoptestutil/|xopoteltest/' > coverage.txt.tmp mv coverage.txt.tmp coverage.txt -coverage: calculate_coverage - go tool cover -html=coverage.txt - -golanglint: - # binary will be $(go env GOPATH)/bin/golangci-lint - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.52.2 - golangci-lint --version - -lint:; - golangci-lint run - -misspell:; - go install github.com/client9/misspell/cmd/misspell@latest - misspell -w `find . -name \*.md` - OTEL_TAG="v1.12.0" ../opentelemetry-specification: diff --git a/Makefile.common b/Makefile.common new file mode 100644 index 0000000..7250059 --- /dev/null +++ b/Makefile.common @@ -0,0 +1,55 @@ + +GOHOME ?= ${HOME} +GOPATH ?= ${GOHOME} +GOBIN ?= ${GOPATH}/bin + +ZZZGO = $(wildcard ../xop*-go/*.zzzgo ../xop*-go/*/*.zzzgo ../xop*-go/*/*/*.zzzgo) +ZZZGENERATED = $(patsubst %.zzzgo, %.go, $(ZZZGO)) +PB = xopproto/ingest.pb.go xopproto/ingest_grpc.pb.go +TOOLS = ${GOBIN}/gofumpt ${GOBIN}/goimports ${GOBIN}/enumer +TEST_ONLY ?= +CLONE_DEPTH ?= 1 + +all: $(ZZZGENERATED) $(PB) .gitattributes + go generate ./... + go build ./... + for i in $(RELATED); do (echo $$i ...; cd ../$$i && go generate ./... && go build ./...); done + +.gitattributes: $(ZZZGENERATED) + echo '*.zzzgo linguist-language=Go' > $@ + echo 'doc.go linguist-documentation' >> $@ + echo '*.md linguist-documentation' >> $@ + echo '*.pb.go linguist-generated' >> $@ + for i in $(ZZZGENERATED); do echo "$$i linguist-generated" >> $@; done + +${GOBIN}/gofumpt:; + go install mvdan.cc/gofumpt@latest + +${GOBIN}/goimports:; + go install golang.org/x/tools/cmd/goimports@latest + +${GOBIN}/enumer:; + go install github.com/dmarkham/enumer@latest + +%.go : %.zzzgo tools/xopzzz/xopzzz.go $(TOOLS) Makefile + go run tools/xopzzz/xopzzz.go < $< > $@.tmp + -chmod +w $@ + gofumpt -w $@.tmp + goimports -w $@.tmp + -mv $@.tmp $@ + -chmod -w $@ + +coverage: calculate_coverage + go tool cover -html=coverage.txt + +golanglint: + # binary will be $(go env GOPATH)/bin/golangci-lint + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.52.2 + golangci-lint --version + +lint:; + golangci-lint run + +misspell:; + go install github.com/client9/misspell/cmd/misspell@latest + misspell -w `find . -name \*.md` diff --git a/Makefile.peer b/Makefile.peer new file mode 100644 index 0000000..25e1723 --- /dev/null +++ b/Makefile.peer @@ -0,0 +1,25 @@ + +include ../xop-go/Makefile.common + +test: $(ZZZGENERATED) + go generate ./... + go test -tags xoptesting ./... -failfast $(TEST_ONLY) + go test -tags xoptesting -race ./... -failfast $(TEST_ONLY) + +citest: + go test ./... -failfast + go test -race ./... -failfast + +calculate_coverage: + echo "mode: atomic" > coverage.txt + for d in $$(go list ./...); do \ + go test -race -covermode=atomic -coverprofile=profile.out -coverpkg=github.com/xoplog/$(ME)/... $$d; \ + if [ -f profile.out ]; then \ + grep -v ^mode profile.out >> coverage.txt; \ + rm profile.out; \ + fi; \ + done + grep -v '\.pb.go:' coverage.txt | \ + egrep -v 'xoptestutil/|xopoteltest/' > coverage.txt.tmp + mv coverage.txt.tmp coverage.txt + diff --git a/README.md b/README.md index a6a9ab5..250f3a0 100644 --- a/README.md +++ b/README.md @@ -56,20 +56,11 @@ to open pull requests, especially to added base loggers or propagators. Expect the following changes as development continues: -- Log line keys (for key/value attributes) will become typed and - pre-registered (cheap, inline-possible registrations, not complex) - - API changes as additional features are added Currently xop has no metrics support. That will change and adding metrics will probably be the biggest API change -- xopresty and xopotel will split off to their own repos. - -- Additional base loggers are coming - - A full-fidelity console logger is expected soon. - - Additional gateway base loggers will be written To make xop the best logging library for library writers, a full compliment @@ -109,6 +100,28 @@ to strike a blance between safety and usability. Metadata on spans are fully type-safe and keywords must be pre-registered. Data elements on log lines are mostly type-safe but do not need to be pre-registered. +## Base loggers + +Xop is a two-level logger. The top-level logger provides the API for +logging lines and spans, etc. The bottom-level loggers translate the logs +to different formats. + +Some of the bottom-level loggers are "full fidelity" which means that +they are bundled with a function that can consume their own output and +re-log it to a different bottom-level logger thus translating from one +format to another. Xop bottom-level loggers must implement the +[xopbase](https://pkg.go.dev/github.com/xoplog/xop-go/xopbase) Logger interface. + +| name | full fidelity | description | +| -- | -- | -- | +| [xopjson](https://pkg.go.dev/github.com/xoplog/xop-go/xopjson) | yes | JSON output | +| [xopotel](https://pkg.go.dev/github.com/xoplog/xopotel-go | yes | Output though OpenTelemetry spans (Go logger not available) | +| [xopcon](https://pkg.go.dev/github.com/xoplog/xop-go/xopcon) | no | Console/text logger emphasizing human readability | +| [xopconsole](https://pkg.go.dev/github.com/xoplog/xop-go/xopconsole) | yes | Console/text logger with no information loss | +| [xoppb](https://pkg.go.dev/github.com/xoplog/xop-go/xoppb) | yes | Protobuf output | +| [xoprecorder](https://pkg.go.dev/github.com/xoplog/xop-go/xoprecorder) | yes | Output into a structured in-memory buffer | +| [xoptest](https://pkg.go.dev/github.com/xoplog/xop-go/xoptest) | no | Output to testing.T logger | + ## Using xop To log, you must have a `*Log` object. To create one you must start with a @@ -218,11 +231,12 @@ into various http router frameworks. Outgoing propagation is sharing the current trace id as the parent request to another server when making a request. Xop currently only supports HTTP and that only with [resty](https://github.com/go-resty/resty) in the -xopmiddle package. Adding additional outgoing propagators is an outstanding priority. +[xopresty](https://github.com/xoplog/xopresty-go) package. Adding additional +outgoing propagators is an outstanding priority. ### Version compatibility -xop is currently tested with go1.18 and go1.19. It is probably +xop is currently tested with go1.18 through go1.20. It is probably compatible with go1.17 and perhaps earlier. ## Terminology