Skip to content

Commit

Permalink
Merge branch 'main' into request-codeowners-review
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu authored Nov 19, 2024
2 parents 2072577 + 6e79f7c commit 6e08323
Show file tree
Hide file tree
Showing 72 changed files with 818 additions and 447 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Generate
run: make generate
- name: Run linters
run: make license-check lint vanity-import-check
run: make toolchain-check license-check lint vanity-import-check
- name: Build
run: make build
- name: Check clean repository
Expand Down Expand Up @@ -86,11 +86,10 @@ jobs:
cp coverage.txt $TEST_RESULTS
cp coverage.html $TEST_RESULTS
- name: Upload coverage report
uses: codecov/codecov-action@v4.6.0
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
uses: codecov/codecov-action@v5.0.2
with:
file: ./coverage.txt
fail_ci_if_error: true
files: ./coverage.txt
verbose: true
- name: Store coverage test output
uses: actions/upload-artifact@v4
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/links-fail-fast.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ jobs:
restore-keys: cache-lychee-

- name: Link Checker
uses: lycheeverse/lychee-action@v1.10.0
uses: lycheeverse/lychee-action@v2.1.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
fail: true
# TODO: Remove 429s exception once https://github.com/open-telemetry/opentelemetry-go-contrib/issues/6183 is resolved
args: --max-concurrency 5 --cache --max-cache-age 1d --accept 100..=103,200..=299,429 .
args: --max-concurrency 5 --cache --max-cache-age 1d --cache-exclude-status 300..=599 .
5 changes: 2 additions & 3 deletions .github/workflows/links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ jobs:

- name: Link Checker
id: lychee
uses: lycheeverse/lychee-action@v1.10.0
uses: lycheeverse/lychee-action@v2.1.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# TODO: Remove 429s exception once https://github.com/open-telemetry/opentelemetry-go-contrib/issues/6183 is resolved
args: --max-concurrency 1 --cache --max-cache-age 1d --accept 100..=103,200..=299,429 .
args: --max-concurrency 1 --cache --max-cache-age 1d --cache-exclude-status 300..=599 .

- name: Create Issue From File
if: steps.lychee.outputs.exit_code != 0
Expand Down
10 changes: 9 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ linters:
- govet
- ineffassign
- misspell
- perfsprint
- revive
- staticcheck
- tenv
Expand Down Expand Up @@ -62,10 +63,11 @@ issues:
text: "calls to (.+) only in main[(][)] or init[(][)] functions"
linters:
- revive
# It's okay to not run gosec in a test.
# It's okay to not run gosec and perfsprint in a test.
- path: _test\.go
linters:
- gosec
- perfsprint
include:
# revive exported should have comment or be unexported.
- EXC0012
Expand Down Expand Up @@ -109,6 +111,12 @@ linters-settings:
locale: US
ignore-words:
- cancelled
perfsprint:
err-error: true
errorf: true
int-conversion: true
sprintf1: true
strconcat: true
revive:
# Sets the default failure confidence.
# This means that linting errors with less than 0.8 confidence will be ignored.
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Added

- Added support for providing `endpoint`, `pollingIntervalMs` and `initialSamplingRate` using environment variable `OTEL_TRACES_SAMPLER_ARG` in `go.opentelemetry.io/contrib/samples/jaegerremote`. (#6310)
- Added support exporting logs via OTLP over gRPC in `go.opentelemetry.io/contrib/config`. (#6340)

### Fixed

- Fixed the value for configuring the OTLP exporter to use `grpc` instead of `grpc/protobuf` in `go.opentelemetry.io/contrib/config`. (#6338)

<!-- Released section -->
<!-- Don't change this section unless doing release -->

Expand Down
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ TIMEOUT = 60
.DEFAULT_GOAL := precommit

.PHONY: precommit ci
precommit: generate license-check misspell go-mod-tidy golangci-lint-fix test-default
ci: generate license-check lint vanity-import-check build test-default check-clean-work-tree test-coverage
precommit: generate toolchain-check license-check misspell go-mod-tidy golangci-lint-fix test-default
ci: generate toolchain-check license-check lint vanity-import-check build test-default check-clean-work-tree test-coverage

# Tools

Expand Down Expand Up @@ -189,6 +189,16 @@ vanity-import-check: | $(PORTO)
.PHONY: lint
lint: go-mod-tidy golangci-lint misspell govulncheck

.PHONY: toolchain-check
toolchain-check:
@toolchainRes=$$(for f in $(ALL_GO_MOD_DIRS); do \
awk '/^toolchain/ { found=1; next } END { if (found) print FILENAME }' $$f/go.mod; \
done); \
if [ -n "$${toolchainRes}" ]; then \
echo "toolchain checking failed:"; echo "$${toolchainRes}"; \
exit 1; \
fi

.PHONY: license-check
license-check:
@licRes=$$(for f in $$(find . -type f \( -iname '*.go' -o -iname '*.sh' \) ! -path './vendor/*' ! -path './exporters/otlp/internal/opentelemetry-proto/*') ; do \
Expand Down
2 changes: 1 addition & 1 deletion bridges/otellogr/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ go 1.22
require (
github.com/go-logr/logr v1.4.2
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/otel v1.32.0
go.opentelemetry.io/otel/log v0.8.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/otel v1.32.0 // indirect
go.opentelemetry.io/otel/metric v1.32.0 // indirect
go.opentelemetry.io/otel/trace v1.32.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
25 changes: 22 additions & 3 deletions bridges/otellogr/logsink.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// - Level is transformed and set as the Severity. The SeverityText is not
// set.
// - KeyAndValues are transformed and set as Attributes.
// - Error is always logged as an additional attribute with the key
// "exception.message" and with the severity [log.SeverityError].
// - The [context.Context] value in KeyAndValues is propagated to OpenTelemetry
// log record. All non-nested [context.Context] values are ignored and not
// added as attributes. If there are multiple [context.Context] the last one
Expand Down Expand Up @@ -59,6 +61,7 @@ import (

"go.opentelemetry.io/otel/log"
"go.opentelemetry.io/otel/log/global"
semconv "go.opentelemetry.io/otel/semconv/v1.27.0"
)

type config struct {
Expand Down Expand Up @@ -206,7 +209,20 @@ func (l *LogSink) Enabled(level int) bool {

// Error logs an error, with the given message and key/value pairs.
func (l *LogSink) Error(err error, msg string, keysAndValues ...any) {
// TODO
var record log.Record
record.SetBody(log.StringValue(msg))
record.SetSeverity(log.SeverityError)

record.AddAttributes(
log.String(string(semconv.ExceptionMessageKey), err.Error()),
)

record.AddAttributes(l.attr...)

ctx, attr := convertKVs(l.ctx, keysAndValues...)
record.AddAttributes(attr...)

l.logger.Emit(ctx, record)
}

// Info logs a non-error message with the given key/value pairs.
Expand All @@ -223,9 +239,12 @@ func (l *LogSink) Info(level int, msg string, keysAndValues ...any) {
l.logger.Emit(ctx, record)
}

// Init initializes the LogSink.
// Init receives optional information about the logr library this
// implementation does not use it.
func (l *LogSink) Init(info logr.RuntimeInfo) {
// TODO
// We don't need to do anything here.
// CallDepth is used to calculate the caller's PC.
// PC is dropped as part of the conversion to the OpenTelemetry log.Record.
}

// WithName returns a new LogSink with the specified name appended.
Expand Down
44 changes: 44 additions & 0 deletions bridges/otellogr/logsink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package otellogr

import (
"context"
"errors"
"testing"
"time"

Expand Down Expand Up @@ -277,6 +278,49 @@ func TestLogSink(t *testing.T) {
},
},
},
{
name: "error",
f: func(l *logr.Logger) {
l.Error(errors.New("test"), "error message")
},
wantRecords: map[string][]log.Record{
name: {
buildRecord(log.StringValue("error message"), time.Time{}, log.SeverityError, []log.KeyValue{
{Key: "exception.message", Value: log.StringValue("test")},
}),
},
},
},
{
name: "error_multi_attrs",
f: func(l *logr.Logger) {
l.Error(errors.New("test error"), "msg",
"struct", struct{ data int64 }{data: 1},
"bool", true,
"duration", time.Minute,
"float64", 3.14159,
"int64", -2,
"string", "str",
"time", time.Unix(1000, 1000),
"uint64", uint64(3),
)
},
wantRecords: map[string][]log.Record{
name: {
buildRecord(log.StringValue("msg"), time.Time{}, log.SeverityError, []log.KeyValue{
{Key: "exception.message", Value: log.StringValue("test error")},
log.String("struct", "{data:1}"),
log.Bool("bool", true),
log.Int64("duration", 60_000_000_000),
log.Float64("float64", 3.14159),
log.Int64("int64", -2),
log.String("string", "str"),
log.Int64("time", time.Unix(1000, 1000).UnixNano()),
log.Int64("uint64", 3),
}),
},
},
},
} {
t.Run(tt.name, func(t *testing.T) {
rec := logtest.NewRecorder()
Expand Down
4 changes: 2 additions & 2 deletions bridges/otelzap/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ type objectEncoder struct {
cur *namespace
}

func newObjectEncoder(len int) *objectEncoder {
keyval := make([]log.KeyValue, 0, len)
func newObjectEncoder(n int) *objectEncoder {
keyval := make([]log.KeyValue, 0, n)
m := &namespace{
attrs: keyval,
}
Expand Down
2 changes: 1 addition & 1 deletion bridges/prometheus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ require (
go.opentelemetry.io/otel/metric v1.32.0 // indirect
go.opentelemetry.io/otel/trace v1.32.0 // indirect
golang.org/x/sys v0.27.0 // indirect
google.golang.org/protobuf v1.35.1 // indirect
google.golang.org/protobuf v1.35.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 2 additions & 2 deletions bridges/prometheus/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ go.opentelemetry.io/otel/trace v1.32.0 h1:WIC9mYrXf8TmY/EXuULKc8hR17vE+Hjv2cssQD
go.opentelemetry.io/otel/trace v1.32.0/go.mod h1:+i4rkvCraA+tG6AzwloGaCtkx53Fa+L+V8e9a7YvhT8=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

const (
protocolProtobufHTTP = "http/protobuf"
protocolProtobufGRPC = "grpc/protobuf"
protocolProtobufGRPC = "grpc"

compressionGzip = "gzip"
compressionNone = "none"
Expand Down
Loading

0 comments on commit 6e08323

Please sign in to comment.