Skip to content

Commit

Permalink
Merge branch 'main' into docs-exporters
Browse files Browse the repository at this point in the history
  • Loading branch information
XSAM committed Mar 23, 2024
2 parents ecca3a6 + a5172ab commit 9fb0065
Show file tree
Hide file tree
Showing 26 changed files with 1,535 additions and 522 deletions.
25 changes: 15 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,22 @@ jobs:
strategy:
matrix:
go-version: ["~1.22.0", "~1.21.3"]
os: [ubuntu-latest, macos-latest, windows-latest]
# GitHub Actions does not support arm* architectures on default
# 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]
exclude:
# Not a supported Go OS/architecture.
platform:
- os: ubuntu-latest
arch: "386"
- os: ubuntu-latest
arch: amd64
- os: macos-latest
arch: amd64
- os: windows-latest
arch: "386"
runs-on: ${{ matrix.os }}
- os: windows-latest
arch: amd64
# ARM64 compatibility tests are using actuated runners
# See https://github.com/open-telemetry/community/blob/main/docs/using-actuated.md
- os: actuated-arm64-2cpu-8gb
arch: arm64
runs-on: ${{ matrix.platform.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -130,7 +135,7 @@ jobs:
cache-dependency-path: "**/go.sum"
- name: Run tests
env:
GOARCH: ${{ matrix.arch }}
GOARCH: ${{ matrix.platform.arch }}
run: make test-short

test-compatibility:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Add `WithProxy` option in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#4906)
- Add `WithProxy` option in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlptracehttp`. (#4906)
- The `Enabled` method is added to the `Logger` interface in `go.opentelemetry.io/otel/log`.
This method is used to notify users if a log record will be emitted or not. (#5071)
- Add `SeverityUndefined` `const` to `go.opentelemetry.io/otel/log`.
This value represents an unset severity level. (#5072)
- Add `Empty` function in `go.opentelemetry.io/otel/log` to return a `KeyValue` for an empty value. (#5076)
- Add `go.opentelemetry.io/otel/log/global` to manage the global `LoggerProvider`.
This package is provided with the anticipation that all functionality will be migrate to `go.opentelemetry.io/otel` when `go.opentelemetry.io/otel/log` stabilizes.
At which point, users will be required to migrage their code, and this package will be deprecated then removed. (#5085)

### Changed

Expand Down Expand Up @@ -47,6 +53,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)

### Fixed

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Currently, this project supports the following environments.
| 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 |
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/otlpmetric/otlpmetrichttp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func WithEndpoint(endpoint string) Option {
// If an invalid URL is provided, the default value will be kept.
//
// By default, if an environment variable is not set, and this option is not
// passed, "localhost:4317" will be used.
// passed, "localhost:4318" will be used.
//
// This option has no effect if WithGRPCConn is used.
func WithEndpointURL(u string) Option {
Expand Down
186 changes: 11 additions & 175 deletions log/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
`go.opentelemetry.io/otel/log` provides
[Logs Bridge API](https://opentelemetry.io/docs/specs/otel/logs/bridge-api/).

The initial version of the design and the prototype
was created in [#4725](https://github.com/open-telemetry/opentelemetry-go/pull/4725).
The prototype was created in
[#4725](https://github.com/open-telemetry/opentelemetry-go/pull/4725).

## Background

Expand Down Expand Up @@ -43,14 +43,7 @@ Rejected alternative:
### LoggerProvider

The [`LoggerProvider` abstraction](https://opentelemetry.io/docs/specs/otel/logs/bridge-api/#loggerprovider)
is defined as an interface:

```go
type LoggerProvider interface {
embedded.LoggerProvider
Logger(name string, options ...LoggerOption) Logger
}
```
is defined as `LoggerProvider` interface in [provider.go](provider.go).

The specification may add new operations to `LoggerProvider`.
The interface may have methods added without a package major version bump.
Expand All @@ -64,13 +57,7 @@ The `Logger` method implements the [`Get a Logger` operation](https://openteleme

The required `name` parameter is accepted as a `string` method argument.

The following options are defined to support optional parameters:

```go
func WithInstrumentationVersion(version string) LoggerOption
func WithInstrumentationAttributes(attr ...attribute.KeyValue) LoggerOption
func WithSchemaURL(schemaURL string) LoggerOption
```
The `LoggerOption` options are defined to support optional parameters.

Implementation requirements:

Expand All @@ -94,14 +81,7 @@ Rejected alternative:
### Logger

The [`Logger` abstraction](https://opentelemetry.io/docs/specs/otel/logs/bridge-api/#logger)
is defined as an interface:

```go
type Logger interface {
embedded.Logger
Emit(ctx context.Context, record Record)
}
```
is defined as `Logger` interface in [logger.go](logger.go).

The specification may add new operations to `Logger`.
The interface may have methods added without a package major version bump.
Expand All @@ -119,23 +99,7 @@ is accepted as a `context.Context` method argument.
Calls to `Emit` are supposed to be on the hot path.
Therefore, in order to reduce the number of heap allocations,
the [`LogRecord` abstraction](https://opentelemetry.io/docs/specs/otel/logs/bridge-api/#emit-a-logrecord),
is defined as a `Record` type:

```go
type Record struct {
timestamp time.Time
observedTimestamp time.Time
severity Severity
severityText string
body Value

// The fields below are for optimizing the implementation of
// attributes.
front [5]KeyValue
nFront int // The number of attributes in front.
back []KeyValue
}
```
is defined as `Record` struct in [record.go](record.go).

[`Timestamp`](https://opentelemetry.io/docs/specs/otel/logs/data-model/#field-timestamp)
is accessed using following methods:
Expand All @@ -161,53 +125,11 @@ func (r *Record) Severity() Severity
func (r *Record) SetSeverity(s Severity)
```

`Severity` type is defined and constants are based on
`Severity` type is defined in [severity.go](severity.go).
The constants are are based on
[Displaying Severity recommendation](https://opentelemetry.io/docs/specs/otel/logs/data-model/#displaying-severity).
Additionally, `Severity[Level]1` constants are defined to make the API more readable and user friendly.

```go
type Severity int

const (
SeverityTrace1 Severity = 1 // TRACE
SeverityTrace2 Severity = 2 // TRACE2
SeverityTrace3 Severity = 3 // TRACE3
SeverityTrace4 Severity = 4 // TRACE4

SeverityDebug1 Severity = 5 // DEBUG
SeverityDebug2 Severity = 6 // DEBUG2
SeverityDebug3 Severity = 7 // DEBUG3
SeverityDebug4 Severity = 8 // DEBUG4

SeverityInfo1 Severity = 9 // INFO
SeverityInfo2 Severity = 10 // INFO2
SeverityInfo3 Severity = 11 // INFO3
SeverityInfo4 Severity = 12 // INFO4

SeverityWarn1 Severity = 13 // WARN
SeverityWarn2 Severity = 14 // WARN2
SeverityWarn3 Severity = 15 // WARN3
SeverityWarn4 Severity = 16 // WARN4

SeverityError1 Severity = 17 // ERROR
SeverityError2 Severity = 18 // ERROR2
SeverityError3 Severity = 19 // ERROR3
SeverityError4 Severity = 20 // ERROR4

SeverityFatal1 Severity = 21 // FATAL
SeverityFatal2 Severity = 22 // FATAL2
SeverityFatal3 Severity = 23 // FATAL3
SeverityFatal4 Severity = 24 // FATAL4

SeverityTrace = SeverityTrace1
SeverityDebug = SeverityDebug1
SeverityInfo = SeverityInfo1
SeverityWarn = SeverityWarn1
SeverityError = SeverityError1
SeverityFatal = SeverityFatal1
)
```

[`SeverityText`](https://opentelemetry.io/docs/specs/otel/logs/data-model/#field-severitytext)
is accessed using following methods:

Expand Down Expand Up @@ -247,95 +169,9 @@ while keeping the API user friendly.
It relieves the user from making his own improvements
for reducing the number of allocations when passing attributes.

The following definitions are implementing the abstractions
described in [the specification](https://opentelemetry.io/docs/specs/otel/logs/#new-first-party-application-logs):

```go
type Value struct{}

type Kind int

const (
KindEmpty Kind = iota
KindBool
KindFloat64
KindInt64
KindString
KindBytes
KindSlice
KindMap
)

func (v Value) Kind() Kind

// Value factories:

func StringValue(value string) Value

func IntValue(v int) Value

func Int64Value(v int64) Value

func Float64Value(v float64) Value

func BoolValue(v bool) Value

func BytesValue(v []byte) Value

func SliceValue(vs ...Value) Value

func MapValue(kvs ...KeyValue) Value

// Value accessors:

func (v Value) AsString() string

func (v Value) AsInt64() int64

func (v Value) AsBool() bool

func (v Value) AsFloat64() float64

func (v Value) AsBytes() []byte

func (v Value) AsSlice() []Value

func (v Value) AsMap() []KeyValue

func (v Value) Empty() bool

// Value equality comparison:

func (v Value) Equal(w Value) bool


type KeyValue struct {
Key string
Value Value
}

// KeyValue factories:

func String(key, value string) KeyValue

func Int64(key string, value int64) KeyValue

func Int(key string, value int) KeyValue

func Float64(key string, v float64) KeyValue

func Bool(key string, v bool) KeyValue

func Bytes(key string, v []byte) KeyValue

func Slice(key string, args ...Value) KeyValue

func Map(key string, args ...KeyValue) KeyValue

// KeyValue equality comparison:

func (a KeyValue) Equal(b KeyValue) bool
```
The abstractions described in
[the specification](https://opentelemetry.io/docs/specs/otel/logs/#new-first-party-application-logs)
are defined in [keyvalue.go](keyvalue.go).

`Value` is representing `any`.
`KeyValue` is representing a key(string)-value(`any`) pair.
Expand Down
49 changes: 49 additions & 0 deletions log/global/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

/*
Package global provides access to a global implementation of the OpenTelemetry
Logs Bridge API.
This package is experimental. It will be deprecated and removed when the [log]
package becomes stable. Its functionality will be migrated to
go.opentelemetry.io/otel.
*/
package global // import "go.opentelemetry.io/otel/log/global"

import (
"go.opentelemetry.io/otel/log"
"go.opentelemetry.io/otel/log/internal/global"
)

// Logger returns a [log.Logger] configured with the provided name and options
// from the globally configured [log.LoggerProvider].
//
// If this is called before a global LoggerProvider is configured, the returned
// Logger will be a No-Op implementation of a Logger. When a global
// LoggerProvider is registered for the first time, the returned Logger is
// updated in-place to report to this new LoggerProvider. There is no need to
// call this function again for an updated instance.
//
// This is a convenience function. It is equivalent to:
//
// GetLoggerProvider().Logger(name, options...)
func Logger(name string, options ...log.LoggerOption) log.Logger {
return GetLoggerProvider().Logger(name, options...)

Check warning on line 32 in log/global/log.go

View check run for this annotation

Codecov / codecov/patch

log/global/log.go#L31-L32

Added lines #L31 - L32 were not covered by tests
}

// GetLoggerProvider returns the globally configured [log.LoggerProvider].
//
// If a global LoggerProvider has not been configured with [SetLoggerProvider],
// the returned Logger will be a No-Op implementation of a LoggerProvider. When
// a global LoggerProvider is registered for the first time, the returned
// LoggerProvider and all of its created Loggers are updated in-place. There is
// no need to call this function again for an updated instance.
func GetLoggerProvider() log.LoggerProvider {
return global.GetLoggerProvider()
}

// SetLoggerProvider configures provider as the global [log.LoggerProvider].
func SetLoggerProvider(provider log.LoggerProvider) {
global.SetLoggerProvider(provider)
}
24 changes: 24 additions & 0 deletions log/global/log_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package global // import "go.opentelemetry.io/otel/log/global"

import (
"testing"

"github.com/stretchr/testify/assert"

"go.opentelemetry.io/otel/log"
"go.opentelemetry.io/otel/log/noop"
)

func TestMultipleGlobalLoggerProvider(t *testing.T) {
type provider struct{ log.LoggerProvider }

p1, p2 := provider{}, noop.NewLoggerProvider()

SetLoggerProvider(&p1)
SetLoggerProvider(p2)

assert.Equal(t, p2, GetLoggerProvider())
}
Loading

0 comments on commit 9fb0065

Please sign in to comment.