Skip to content

Commit

Permalink
Merge branch 'main' into otlploggrpc-draft
Browse files Browse the repository at this point in the history
  • Loading branch information
XSAM authored Jul 11, 2024
2 parents b69ae60 + d595dab commit b418591
Show file tree
Hide file tree
Showing 42 changed files with 728 additions and 213 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ jobs:
arch: "386"
- os: ubuntu-latest
arch: amd64
- os: macos-latest
- os: macos-13
arch: amd64
- os: macos-latest
arch: arm64
- os: windows-latest
arch: "386"
- os: windows-latest
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/protect-released-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This action against that any PR targeting the main branch touches released
# sections in CHANGELOG file. If change to released CHANGELOG is required, like
# doing a release, add the \"Unlock Released Changelog\" label to disable this action.

name: Protect released changelog

on:
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
jobs:
protect-released-changelog:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.pull_request.labels.*.name, 'Unlock Released Changelog')}}

steps:
- uses: actions/checkout@v4

- name: Protect the released changelog
run: |
./verify_released_changelog.sh ${{ github.base_ref }}
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Added

- Add macOS ARM64 platform to the compatibility testing suite. (#5577)

### Fixed

- Correct comments for the priority of the `WithEndpoint` and `WithEndpointURL` options and their corresponding environment variables in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`. (#5584)

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

## [1.28.0/0.50.0/0.4.0] 2024-07-02

### Added
Expand Down Expand Up @@ -49,6 +60,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Fix stale timestamps reported by the last-value aggregation. (#5517)
- Indicate the `Exporter` in `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp` must be created by the `New` method. (#5521)
- Improved performance in all `{Bool,Int64,Float64,String}SliceValue` functions of `go.opentelemetry.io/attributes` by reducing the number of allocations. (#5549)
- Replace invalid percent-encoded octet sequences with replacement char in `go.opentelemetry.io/otel/baggage`. (#5528)

## [1.27.0/0.49.0/0.3.0] 2024-05-21

Expand Down Expand Up @@ -175,7 +187,7 @@ The next release will require at least [Go 1.21].
This module includes OpenTelemetry Go's implementation of the Logs Bridge API.
This module is in an alpha state, it is subject to breaking changes.
See our [versioning policy](./VERSIONING.md) for more info. (#4961)
- ARM64 platform to the compatibility testing suite. (#4994)
- Add ARM64 platform to the compatibility testing suite. (#4994)

### Fixed

Expand Down Expand Up @@ -3086,6 +3098,8 @@ It contains api and sdk for trace and meter.
[0.1.1]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.1.1
[0.1.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.1.0

<!-- Released section ended -->

[Go 1.22]: https://go.dev/doc/go1.22
[Go 1.21]: https://go.dev/doc/go1.21
[Go 1.20]: https://go.dev/doc/go1.20
Expand Down
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,22 @@ stop ensuring compatibility with these versions in the following manner:

Currently, this project supports the following environments.

| OS | Go Version | Architecture |
|---------|------------|--------------|
| Ubuntu | 1.22 | amd64 |
| Ubuntu | 1.21 | amd64 |
| Ubuntu | 1.22 | 386 |
| Ubuntu | 1.21 | 386 |
| Linux | 1.22 | arm64 |
| Linux | 1.21 | arm64 |
| MacOS | 1.22 | amd64 |
| MacOS | 1.21 | amd64 |
| Windows | 1.22 | amd64 |
| Windows | 1.21 | amd64 |
| Windows | 1.22 | 386 |
| Windows | 1.21 | 386 |
| OS | Go Version | Architecture |
|----------|------------|--------------|
| Ubuntu | 1.22 | amd64 |
| Ubuntu | 1.21 | amd64 |
| Ubuntu | 1.22 | 386 |
| Ubuntu | 1.21 | 386 |
| Linux | 1.22 | arm64 |
| Linux | 1.21 | arm64 |
| macOS 13 | 1.22 | amd64 |
| macOS 13 | 1.21 | amd64 |
| macOS | 1.22 | arm64 |
| macOS | 1.21 | arm64 |
| Windows | 1.22 | amd64 |
| Windows | 1.21 | amd64 |
| Windows | 1.22 | 386 |
| Windows | 1.21 | 386 |

While this project should work for other systems, no compatibility guarantees
are made for those systems currently.
Expand Down
1 change: 1 addition & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Update go.mod for submodules to depend on the new release which will happen in t
```
- Move all the `Unreleased` changes into a new section following the title scheme (`[<new tag>] - <date of release>`).
- Make sure the new section is under the comment for released section, like `<!-- Released section -->`, so it is protected from being overwritten in the future.
- Update all the appropriate links at the bottom.
4. Push the changes to upstream and create a Pull Request on GitHub.
Expand Down
36 changes: 32 additions & 4 deletions baggage/baggage.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,19 +294,45 @@ func parseMember(member string) (Member, error) {
return newInvalidMember(), fmt.Errorf("%w: %q", errInvalidKey, key)
}

val := strings.TrimSpace(v)
if !validateValue(val) {
rawVal := strings.TrimSpace(v)
if !validateValue(rawVal) {
return newInvalidMember(), fmt.Errorf("%w: %q", errInvalidValue, v)
}

// Decode a percent-encoded value.
value, err := url.PathUnescape(val)
unescapeVal, err := url.PathUnescape(rawVal)
if err != nil {
return newInvalidMember(), fmt.Errorf("%w: %w", errInvalidValue, err)
}

value := replaceInvalidUTF8Sequences(len(rawVal), unescapeVal)
return Member{key: key, value: value, properties: props, hasData: true}, nil
}

// replaceInvalidUTF8Sequences replaces invalid UTF-8 sequences with '�'.
func replaceInvalidUTF8Sequences(cap int, unescapeVal string) string {
if utf8.ValidString(unescapeVal) {
return unescapeVal
}
// W3C baggage spec:
// https://github.com/w3c/baggage/blob/8c215efbeebd3fa4b1aceb937a747e56444f22f3/baggage/HTTP_HEADER_FORMAT.md?plain=1#L69

var b strings.Builder
b.Grow(cap)
for i := 0; i < len(unescapeVal); {
r, size := utf8.DecodeRuneInString(unescapeVal[i:])
if r == utf8.RuneError && size == 1 {
// Invalid UTF-8 sequence found, replace it with '�'
_, _ = b.WriteString("�")
} else {
_, _ = b.WriteRune(r)
}
i += size
}

return b.String()
}

// validate ensures m conforms to the W3C Baggage specification.
// A key must be an ASCII string, returning an error otherwise.
func (m Member) validate() error {
Expand Down Expand Up @@ -607,10 +633,12 @@ func parsePropertyInternal(s string) (p Property, ok bool) {
}

// Decode a percent-encoded value.
value, err := url.PathUnescape(s[valueStart:valueEnd])
rawVal := s[valueStart:valueEnd]
unescapeVal, err := url.PathUnescape(rawVal)
if err != nil {
return
}
value := replaceInvalidUTF8Sequences(len(rawVal), unescapeVal)

ok = true
p.key = s[keyStart:keyEnd]
Expand Down
62 changes: 61 additions & 1 deletion baggage/baggage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"slices"
"strings"
"testing"
"unicode/utf8"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -469,6 +470,18 @@ func TestBaggageParse(t *testing.T) {
in: tooManyMembers,
err: errMemberNumber,
},
{
name: "percent-encoded octet sequences do not match the UTF-8 encoding scheme",
in: "k=aa%ffcc;p=d%fff",
want: baggage.List{
"k": {
Value: "aa�cc",
Properties: []baggage.Property{
{Key: "p", Value: "d�f", HasValue: true},
},
},
},
},
}

for _, tc := range testcases {
Expand All @@ -480,6 +493,53 @@ func TestBaggageParse(t *testing.T) {
}
}

func TestBaggageParseValue(t *testing.T) {
testcases := []struct {
name string
in string
valueWant string
valueWantSize int
}{
{
name: "percent encoded octet sequence matches UTF-8 encoding scheme",
in: "k=aa%26cc",
valueWant: "aa&cc",
valueWantSize: 5,
},
{
name: "percent encoded octet sequence doesn't match UTF-8 encoding scheme",
in: "k=aa%ffcc",
valueWant: "aa�cc",
valueWantSize: 7,
},
{
name: "multiple percent encoded octet sequences don't match UTF-8 encoding scheme",
in: "k=aa%ffcc%fedd%fa",
valueWant: "aa�cc�dd�",
valueWantSize: 15,
},
{
name: "raw value",
in: "k=aacc",
valueWant: "aacc",
valueWantSize: 4,
},
}

for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
b, err := Parse(tc.in)
assert.Empty(t, err)

val := b.Members()[0].Value()

assert.EqualValues(t, val, tc.valueWant)
assert.Equal(t, len(val), tc.valueWantSize)
assert.True(t, utf8.ValidString(val))
})
}
}

func TestBaggageString(t *testing.T) {
testcases := []struct {
name string
Expand Down Expand Up @@ -979,7 +1039,7 @@ func BenchmarkParse(b *testing.B) {
b.ReportAllocs()

for i := 0; i < b.N; i++ {
benchBaggage, _ = Parse(`userId=alice,serverNode = DF28 , isProduction = false,hasProp=stuff;propKey;propWValue=value`)
benchBaggage, _ = Parse("userId=alice,serverNode = DF28 , isProduction = false,hasProp=stuff;propKey;propWValue=value, invalidUtf8=pr%ffo%ffp%fcValue")
}
}

Expand Down
2 changes: 1 addition & 1 deletion bridge/opentracing/test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
4 changes: 2 additions & 2 deletions bridge/opentracing/test/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 h1:BwIjyKYGsK9dMCBOorzRri8MQwmi7mT9rGHsCEinZkA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d h1:JU0iKnSg02Gmb5ZdV8nYsKEKsP6o/FGVWTrw4i1DA9A=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
Expand Down
4 changes: 2 additions & 2 deletions example/otel-collector/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ services:
- 4317:4317

prometheus:
image: prom/prometheus:v2.53.0
image: prom/prometheus:v2.53.1
volumes:
- ./prometheus.yaml:/etc/prometheus/prometheus.yml
ports:
- 9090:9090

jaeger:
image: jaegertracing/all-in-one:1.58
image: jaegertracing/all-in-one:1.59
ports:
- 16686:16686
4 changes: 2 additions & 2 deletions example/otel-collector/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ require (
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d // indirect
google.golang.org/protobuf v1.34.2 // indirect
)

Expand Down
8 changes: 4 additions & 4 deletions example/otel-collector/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 h1:0+ozOGcrp+Y8Aq8TLNN2Aliibms5LEzsq99ZZmAGYm0=
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094/go.mod h1:fJ/e3If/Q67Mj99hin0hMhiNyCRmt6BQ2aWIJshUSJw=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 h1:BwIjyKYGsK9dMCBOorzRri8MQwmi7mT9rGHsCEinZkA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d h1:kHjw/5UfflP/L5EbledDrcG4C2597RtymmGRZvHiCuY=
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d/go.mod h1:mw8MG/Qz5wfgYr6VqVCiZcHe/GJEfI+oGGDCohaVgB0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d h1:JU0iKnSg02Gmb5ZdV8nYsKEKsP6o/FGVWTrw4i1DA9A=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
Expand Down
1 change: 1 addition & 0 deletions exporters/otlp/otlplog/otlploggrpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ func (c *grpcCollector) Collect() *storage {
}

func clientFactory(t *testing.T, rCh <-chan exportResult) (*client, *grpcCollector) {
t.Helper()
coll, err := newGRPCCollector("", rCh)
require.NoError(t, err)

Expand Down
5 changes: 4 additions & 1 deletion exporters/otlp/otlplog/otlploggrpc/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ type Exporter struct {
var _ log.Exporter = (*Exporter)(nil)

// New returns a new [Exporter].
//
// It is recommended to use it with a [BatchProcessor]
// or other processor exporting records asynchronously.
func New(_ context.Context, options ...Option) (*Exporter, error) {
cfg := newConfig(options)
c, err := newClient(cfg)
Expand All @@ -51,7 +54,7 @@ var transformResourceLogs = transform.ResourceLogs

// Export transforms and transmits log records to an OTLP receiver.
//
// This method returns nil error if called after Shutdown.
// This method returns nil and drops records if called after Shutdown.
// This method returns an error if the method is canceled by the passed context.
func (e *Exporter) Export(ctx context.Context, records []log.Record) error {
if e.stopped.Load() {
Expand Down
8 changes: 6 additions & 2 deletions exporters/otlp/otlplog/otlploggrpc/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"go.opentelemetry.io/otel/log"
sdklog "go.opentelemetry.io/otel/sdk/log"
collogpb "go.opentelemetry.io/proto/otlp/collector/logs/v1"
"go.opentelemetry.io/otel/log"
sdklog "go.opentelemetry.io/otel/sdk/log"
logpb "go.opentelemetry.io/proto/otlp/logs/v1"
)

Expand Down Expand Up @@ -50,6 +52,8 @@ func (m *mockClient) Shutdown(context.Context) error {
}

func TestExporterExport(t *testing.T) {
errClient := errors.New("client")

testCases := []struct {
name string
logs []sdklog.Record
Expand All @@ -66,8 +70,8 @@ func TestExporterExport(t *testing.T) {
{
name: "Error",
logs: make([]sdklog.Record, 2),
err: errors.New("test"),
wantErr: errors.New("test"),
err: errClient,
wantErr: errClient,
},
}

Expand Down
Loading

0 comments on commit b418591

Please sign in to comment.