Skip to content

Commit

Permalink
Merge branch 'main' into add-views
Browse files Browse the repository at this point in the history
  • Loading branch information
MadVikingGod authored Jun 4, 2024
2 parents bf974a6 + fbbdb68 commit a43093f
Show file tree
Hide file tree
Showing 93 changed files with 753 additions and 503 deletions.
3 changes: 3 additions & 0 deletions .codespellignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ot
fo

10 changes: 10 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# https://github.com/codespell-project/codespell
[codespell]
builtin = clear,rare,informal
check-filenames =
check-hidden =
ignore-words = .codespellignore
interactive = 1
skip = .git,go.mod,go.sum,go.work,go.work.sum,semconv,venv,.tools
uri-ignore-words-list = *
write =
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/owner.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Module: [e.g. go.opentelemetry.io/contrib/zpages]

[member of the OpenTelemetry organization]: https://github.com/open-telemetry/community/blob/main/community-membership.md#member

### Relvant experience
### Relevant experience

List any PRs/Issues you have interacted with in this repository for this module.

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This action requires that any PR targeting the main branch should touch at
# least one CHANGELOG file. If a CHANGELOG entry is not required, or if
# performing maintance on the Changelog, add either \"[chore]\" to the title of
# performing maintenance on the Changelog, add either \"[chore]\" to the title of
# the pull request or add the \"Skip Changelog\" label to disable this action.

name: changelog
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ jobs:
cp coverage.html $TEST_RESULTS
- name: Upload coverage report
uses: codecov/[email protected]
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
file: ./coverage.txt
fail_ci_if_error: true
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}
- name: Store coverage test output
uses: actions/upload-artifact@v4
with:
Expand All @@ -104,7 +105,7 @@ jobs:
go-version: ["~1.22.3", "~1.21.10"]
os: [ubuntu-latest, macos-latest, windows-latest]
# GitHub Actions does not support arm* architectures on default
# runners. It is possible to acomplish this with a self-hosted runner
# runners. It is possible to accomplish this with a self-hosted runner
# if we want to add this in the future:
# https://docs.github.com/en/actions/hosting-your-own-runners/using-self-hosted-runners-in-a-workflow
arch: ["386", amd64]
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: codespell
on:
push:
branches:
- main
pull_request:
jobs:
codespell:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Codespell
run: make codespell
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Thumbs.db

.tools/
venv/
.idea/
.vscode/
*.iml
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ linters-settings:
- name: constant-logical-expr
disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#context-as-argument
# TODO (#2877) reenable linter when it is compatible. https://github.com/golangci/golangci-lint/issues/3280
# TODO (#2877) re-enable linter when it is compatible. https://github.com/golangci/golangci-lint/issues/3280
- name: context-as-argument
disabled: true
arguments:
Expand Down
9 changes: 0 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- The `go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo` package is deprecated.
If you would like to become a Code Owner of this module and prevent it from being removed, see [#5551]. (#5598)
- The `go.opentelemetry.io/contrib/detectors/aws/ec2` package is deprecated.
If you would like to become a Code Owner of this module and prevent it from being removed, see [#5542]. (#5636)
- The `go.opentelemetry.io/contrib/detectors/aws/ecs` package is deprecated.
If you would like to become a Code Owner of this module and prevent it from being removed, see [#5543]. (#5637)
- The `go.opentelemetry.io/contrib/detectors/aws/eks` package is deprecated.
If you would like to become a Code Owner of this module and prevent it from being removed, see [#5544]. (#5640)
- The `go.opentelemetry.io/contrib/detectors/aws/lambda` package is deprecated.
If you would like to become a Code Owner of this module and prevent it from being removed, see [#5545]. (#5641)
- The `go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda` package is deprecated.
Expand All @@ -45,9 +39,6 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- The `go.opentelemetry.io/contrib/samplers/aws/xray` package is deprecated.
If you would like to become a Code Owner of this module and prevent it from being removed, see [#5554]. (#5647)

[#5542]: https://github.com/open-telemetry/opentelemetry-go-contrib/issues/5542
[#5543]: https://github.com/open-telemetry/opentelemetry-go-contrib/issues/5543
[#5544]: https://github.com/open-telemetry/opentelemetry-go-contrib/issues/5544
[#5545]: https://github.com/open-telemetry/opentelemetry-go-contrib/issues/5545
[#5546]: https://github.com/open-telemetry/opentelemetry-go-contrib/issues/5546
[#5547]: https://github.com/open-telemetry/opentelemetry-go-contrib/issues/5547
Expand Down
8 changes: 7 additions & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# Learn about membership in OpenTelemetry community:
# https://github.com/open-telemetry/community/blob/main/community-membership.md
#
# Learn about Code Owners policy in OpenTelemetry Go Contrib:
# https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/CONTRIBUTING.md#code-owners
#
#
# Learn about CODEOWNERS file format:
# https://help.github.com/en/articles/about-code-owners
Expand All @@ -29,7 +32,10 @@ bridges/otelzap/ @open-te

config/ @open-telemetry/go-approvers @MadVikingGod @pellared @codeboten

detectors/aws/ @open-telemetry/go-approvers
detectors/aws/ec2 @open-telemetry/go-approvers @pyohannes
detectors/aws/ecs @open-telemetry/go-approvers @pyohannes
detectors/aws/eks @open-telemetry/go-approvers @pyohannes
detectors/aws/lambda @open-telemetry/go-approvers
detectors/gcp/ @open-telemetry/go-approvers @dashpole

exporters/autoexport @open-telemetry/go-approvers @MikeGoldsmith @pellared
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ A pull request is considered ready to merge when the following criteria are meet
Any Maintainer can merge the pull request once it is ready to merge.

[^1]: The `go.opentelemetry.io/contrib/instrgen` module is exempt from the two approvals and one day requirement.
Only one approval is needed to merge a Pull Request for that module and there is no minimum amout of time required for the PR to be open before merging.
Only one approval is needed to merge a Pull Request for that module and there is no minimum amount of time required for the PR to be open before merging.
This exemption is to be removed when that package makes its first tagged release.

### Draft Pull Requests
Expand Down
37 changes: 37 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,39 @@ $(GOVULNCHECK): PACKAGE=golang.org/x/vuln/cmd/govulncheck

tools: $(GOLANGCI_LINT) $(MISSPELL) $(GOCOVMERGE) $(STRINGER) $(PORTO) $(MULTIMOD) $(CROSSLINK) $(GOTMPL) $(GORELEASE) $(GOJSONSCHEMA) $(GOVULNCHECK)

# Virtualized python tools via docker

# The directory where the virtual environment is created.
VENVDIR := venv

# The directory where the python tools are installed.
PYTOOLS := $(VENVDIR)/bin

# The pip executable in the virtual environment.
PIP := $(PYTOOLS)/pip

# The directory in the docker image where the current directory is mounted.
WORKDIR := /workdir

# The python image to use for the virtual environment.
PYTHONIMAGE := python:3.11.3-slim-bullseye

# Run the python image with the current directory mounted.
DOCKERPY := docker run --rm -v "$(CURDIR):$(WORKDIR)" -w $(WORKDIR) $(PYTHONIMAGE)

# Create a virtual environment for Python tools.
$(PYTOOLS):
# The `--upgrade` flag is needed to ensure that the virtual environment is
# created with the latest pip version.
@$(DOCKERPY) bash -c "python3 -m venv $(VENVDIR) && $(PIP) install --upgrade pip"

# Install python packages into the virtual environment.
$(PYTOOLS)/%: $(PYTOOLS)
@$(DOCKERPY) $(PIP) install -r requirements.txt

CODESPELL = $(PYTOOLS)/codespell
$(CODESPELL): PACKAGE=codespell

# Generate

.PHONY: generate
Expand Down Expand Up @@ -315,3 +348,7 @@ genjsonschema: genjsonschema-cleanup $(GOJSONSCHEMA)
mv ${GENERATED_CONFIG}.tmp ${GENERATED_CONFIG}
$(MAKE) lint
$(MAKE) genjsonschema-cleanup

.PHONY: codespell
codespell: $(CODESPELL)
@$(DOCKERPY) $(CODESPELL)
2 changes: 1 addition & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ go.opentelemetry.io/otel packages are compatible with the contrib repository.
Follow the following steps to verify the changes.

1. Pick the GIT SHA on the [main branch](https://github.com/open-telemetry/opentelemetry-go/commits/main) that you want to verify.
2. Run the following command to update the OTel depencies with the GIT SHA picked in step 1.
2. Run the following command to update the OTel dependencies with the GIT SHA picked in step 1.

```sh
export GITSHA=<the GIT SHA you want to verify>
Expand Down
44 changes: 34 additions & 10 deletions bridges/otelzap/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package otelzap // import "go.opentelemetry.io/contrib/bridges/otelzap"

import (
"context"
"slices"

"go.uber.org/zap/zapcore"

Expand Down Expand Up @@ -88,6 +89,8 @@ func WithLoggerProvider(provider log.LoggerProvider) Option {
// Core is a [zapcore.Core] that sends logging records to OpenTelemetry.
type Core struct {
logger log.Logger
attr []log.KeyValue
ctx context.Context
}

// Compile-time check *Core implements zapcore.Core.
Expand All @@ -98,6 +101,7 @@ func NewCore(name string, opts ...Option) *Core {
cfg := newConfig(opts)
return &Core{
logger: cfg.logger(name),
ctx: context.Background(),
}
}

Expand All @@ -108,10 +112,25 @@ func (o *Core) Enabled(level zapcore.Level) bool {
return o.logger.Enabled(context.Background(), r)
}

// TODO
// With adds structured context to the Core.
func (o *Core) With(fields []zapcore.Field) zapcore.Core {
return o
cloned := o.clone()
if len(fields) > 0 {
ctx, attrbuf := convertField(fields)
if ctx != nil {
cloned.ctx = ctx
}
cloned.attr = append(cloned.attr, attrbuf...)
}
return cloned
}

func (o *Core) clone() *Core {
return &Core{
logger: o.logger,
attr: slices.Clone(o.attr),
ctx: o.ctx,
}
}

// TODO
Expand All @@ -136,30 +155,35 @@ func (o *Core) Write(ent zapcore.Entry, fields []zapcore.Field) error {
r.SetBody(log.StringValue(ent.Message))
r.SetSeverity(convertLevel(ent.Level))

// TODO: Handle attributes passed via With (exceptions: context.Context and zap.Namespace).
// TODO: Handle context.Context containing trace context.
// TODO: Handle zap.Namespace.
// TODO: Handle zap.Object.
// TODO: Handle zap.Array.
// TODO: Handle ent.LoggerName.

r.AddAttributes(o.attr...)
if len(fields) > 0 {
attrbuf := convertField(fields)
ctx, attrbuf := convertField(fields)
if ctx != nil {
o.ctx = ctx
}
r.AddAttributes(attrbuf...)
}

o.logger.Emit(context.Background(), r)
o.logger.Emit(o.ctx, r)
return nil
}

func convertField(fields []zapcore.Field) []log.KeyValue {
func convertField(fields []zapcore.Field) (context.Context, []log.KeyValue) {
// TODO: Use objectEncoder from a pool instead of newObjectEncoder.
var ctx context.Context
enc := newObjectEncoder(len(fields))
for _, field := range fields {
if ctxFld, ok := field.Interface.(context.Context); ok {
ctx = ctxFld
continue
}
field.AddTo(enc)
}

return enc.kv
return ctx, enc.kv
}

func convertLevel(level zapcore.Level) log.Severity {
Expand Down
66 changes: 57 additions & 9 deletions bridges/otelzap/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,64 @@ func TestCore(t *testing.T) {
zc := NewCore(loggerName, WithLoggerProvider(rec))
logger := zap.New(zc)

logger.Info(testMessage, zap.String(testKey, testValue))
t.Run("Write", func(t *testing.T) {
logger.Info(testMessage, zap.String(testKey, testValue))
got := rec.Result()[0].Records[0]
assert.Equal(t, testMessage, got.Body().AsString())
assert.Equal(t, log.SeverityInfo, got.Severity())
assert.Equal(t, 1, got.AttributesLen())
got.WalkAttributes(func(kv log.KeyValue) bool {
assert.Equal(t, testKey, string(kv.Key))
assert.Equal(t, testValue, value2Result(kv.Value))
return true
})
})

got := rec.Result()[0].Records[0]
assert.Equal(t, testMessage, got.Body().AsString())
assert.Equal(t, log.SeverityInfo, got.Severity())
assert.Equal(t, 1, got.AttributesLen())
got.WalkAttributes(func(kv log.KeyValue) bool {
assert.Equal(t, testKey, string(kv.Key))
assert.Equal(t, testValue, value2Result(kv.Value))
return true
rec.Reset()

// TODO: Add WriteContext test case.
// TODO: Add WithContext test case.

// test child logger with accumulated fields
t.Run("With", func(t *testing.T) {
testCases := [][]string{{"test1", "value1"}, {"test2", "value2"}}
childlogger := logger.With(zap.String(testCases[0][0], testCases[0][1]))
childlogger.Info(testMessage, zap.String(testCases[1][0], testCases[1][1]))

got := rec.Result()[0].Records[0]
assert.Equal(t, testMessage, got.Body().AsString())
assert.Equal(t, log.SeverityInfo, got.Severity())
assert.Equal(t, 2, got.AttributesLen())

index := 0
got.WalkAttributes(func(kv log.KeyValue) bool {
assert.Equal(t, testCases[index][0], string(kv.Key))
assert.Equal(t, testCases[index][1], value2Result(kv.Value))
index++
return true
})
})

rec.Reset()

t.Run("WithMultiple", func(t *testing.T) {
testCases := [][]string{{"test1", "value1"}, {"test2", "value2"}, {"test3", "value3"}}
childlogger := logger.With(zap.String(testCases[0][0], testCases[0][1]))
childlogger2 := childlogger.With(zap.String(testCases[1][0], testCases[1][1]))
childlogger2.Info(testMessage, zap.String(testCases[2][0], testCases[2][1]))

got := rec.Result()[0].Records[0]
assert.Equal(t, testMessage, got.Body().AsString())
assert.Equal(t, log.SeverityInfo, got.Severity())
assert.Equal(t, 3, got.AttributesLen())

index := 0
got.WalkAttributes(func(kv log.KeyValue) bool {
assert.Equal(t, testCases[index][0], string(kv.Key))
assert.Equal(t, testCases[index][1], value2Result(kv.Value))
index++
return true
})
})
}

Expand Down
Loading

0 comments on commit a43093f

Please sign in to comment.