Skip to content

Commit

Permalink
Add initial log API scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Feb 12, 2024
1 parent c9bb618 commit 3f995f0
Show file tree
Hide file tree
Showing 9 changed files with 453 additions and 0 deletions.
8 changes: 8 additions & 0 deletions log/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
module go.opentelemetry.io/otel/log

go 1.20

require go.opentelemetry.io/otel v1.23.1

replace go.opentelemetry.io/otel/metric => ../metric

replace go.opentelemetry.io/otel => ../

replace go.opentelemetry.io/otel/trace => ../trace
5 changes: 5 additions & 0 deletions log/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
132 changes: 132 additions & 0 deletions log/keyvalue.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:generate stringer -type=Kind -trimprefix=Kind

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

// Kind is the kind of a [Value].
type Kind int

// Kind values.
const (
KindEmpty Kind = iota
KindBool
KindFloat64
KindInt64
KindString
KindBytes
KindList
KindMap
)

// A Value represents a structured log value.
type Value struct{} // TODO (#4914): implement.

// StringValue returns a new [Value] for a string.
func StringValue(v string) Value { return Value{} } // TODO (#4914): implement.

Check warning on line 38 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L38

Added line #L38 was not covered by tests

// IntValue returns a [Value] for an int.
func IntValue(v int) Value { return Value{} } // TODO (#4914): implement.

Check warning on line 41 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L41

Added line #L41 was not covered by tests

// Int64Value returns a [Value] for an int64.
func Int64Value(v int64) Value { return Value{} } // TODO (#4914): implement.

Check warning on line 44 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L44

Added line #L44 was not covered by tests

// Float64Value returns a [Value] for a float64.
func Float64Value(v float64) Value { return Value{} } // TODO (#4914): implement.

Check warning on line 47 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L47

Added line #L47 was not covered by tests

// BoolValue returns a [Value] for a bool.
func BoolValue(v bool) Value { //nolint:revive // Not a control flag.
// TODO (#4914): implement.
return Value{}

Check warning on line 52 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L50-L52

Added lines #L50 - L52 were not covered by tests
}

// BytesValue returns a [Value] for a byte slice. The passed slice must not be
// changed after it is passed.
func BytesValue(v []byte) Value { return Value{} } // TODO (#4914): implement.

Check warning on line 57 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L57

Added line #L57 was not covered by tests

// ListValue returns a [Value] for a slice of [Value]. The passed slice must
// not be changed after it is passed.
func ListValue(vs ...Value) Value { return Value{} } // TODO (#4914): implement.

Check warning on line 61 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L61

Added line #L61 was not covered by tests

// MapValue returns a new [Value] for a slice of key-value pairs. The passed
// slice must not be changed after it is passed.
func MapValue(kvs ...KeyValue) Value { return Value{} } // TODO (#4914): implement.

Check warning on line 65 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L65

Added line #L65 was not covered by tests

// AsAny returns the value held by v as an any.
func (v Value) AsAny() any { return nil } // TODO (#4914): implement

Check warning on line 68 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L68

Added line #L68 was not covered by tests

// AsString returns the value held by v as a string.
func (v Value) AsString() string { return "" } // TODO (#4914): implement

Check warning on line 71 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L71

Added line #L71 was not covered by tests

// AsInt64 returns the value held by v as an int64.
func (v Value) AsInt64() int64 { return 0 } // TODO (#4914): implement

Check warning on line 74 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L74

Added line #L74 was not covered by tests

// AsBool returns the value held by v as a bool.
func (v Value) AsBool() bool { return false } // TODO (#4914): implement

Check warning on line 77 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L77

Added line #L77 was not covered by tests

// AsFloat64 returns the value held by v as a float64.
func (v Value) AsFloat64() float64 { return 0 } // TODO (#4914): implement

Check warning on line 80 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L80

Added line #L80 was not covered by tests

// AsBytes returns the value held by v as a []byte.
func (v Value) AsBytes() []byte { return nil } // TODO (#4914): implement

Check warning on line 83 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L83

Added line #L83 was not covered by tests

// AsList returns the value held by v as a []Value.
func (v Value) AsList() []Value { return nil } // TODO (#4914): implement

Check warning on line 86 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L86

Added line #L86 was not covered by tests

// AsMap returns the value held by v as a []KeyValue.
func (v Value) AsMap() []KeyValue { return nil } // TODO (#4914): implement

Check warning on line 89 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L89

Added line #L89 was not covered by tests

// Kind returns the Kind of v.
func (v Value) Kind() Kind { return KindEmpty } // TODO (#4914): implement.

Check warning on line 92 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L92

Added line #L92 was not covered by tests

// Empty returns if v does not hold any value.
func (v Value) Empty() bool { return false } // TODO (#4914): implement

Check warning on line 95 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L95

Added line #L95 was not covered by tests

// Equal returns if v is equal to w.
func (v Value) Equal(w Value) bool { return false } // TODO (#4914): implement

Check warning on line 98 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L98

Added line #L98 was not covered by tests

// An KeyValue is a key-value pair used to represent a log attribute (a
// superset of [go.opentelemetry.io/otel/attribute.KeyValue]) and map item.
type KeyValue struct {
Key string
Value Value
}

// Equal returns if a is equal to b.
func (a KeyValue) Equal(b KeyValue) bool { return false } // TODO (#4914): implement

Check warning on line 108 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L108

Added line #L108 was not covered by tests

// String returns an KeyValue for a string value.
func String(key, value string) KeyValue { return KeyValue{} } // TODO (#4914): implement

Check warning on line 111 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L111

Added line #L111 was not covered by tests

// Int64 returns an KeyValue for an int64 value.
func Int64(key string, value int64) KeyValue { return KeyValue{} } // TODO (#4914): implement

Check warning on line 114 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L114

Added line #L114 was not covered by tests

// Int returns an KeyValue for an int value.
func Int(key string, value int) KeyValue { return KeyValue{} } // TODO (#4914): implement

Check warning on line 117 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L117

Added line #L117 was not covered by tests

// Float64 returns an KeyValue for a float64 value.
func Float64(key string, v float64) KeyValue { return KeyValue{} } // TODO (#4914): implement

Check warning on line 120 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L120

Added line #L120 was not covered by tests

// Bool returns an KeyValue for a bool value.
func Bool(key string, v bool) KeyValue { return KeyValue{} } // TODO (#4914): implement

Check warning on line 123 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L123

Added line #L123 was not covered by tests

// Bytes returns an KeyValue for a []byte value.
func Bytes(key string, v []byte) KeyValue { return KeyValue{} } // TODO (#4914): implement

Check warning on line 126 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L126

Added line #L126 was not covered by tests

// List returns an KeyValue for a []Value value.
func List(key string, args ...Value) KeyValue { return KeyValue{} } // TODO (#4914): implement

Check warning on line 129 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L129

Added line #L129 was not covered by tests

// Map returns an KeyValue for a map value.
func Map(key string, args ...KeyValue) KeyValue { return KeyValue{} } // TODO (#4914): implement

Check warning on line 132 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L132

Added line #L132 was not covered by tests
30 changes: 30 additions & 0 deletions log/kind_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions log/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

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

import (
"context"

"go.opentelemetry.io/otel/attribute"
)

// Logger emits log records.
//
// Warning: Methods may be added to this interface in minor releases. See
// package documentation on API implementation for information on how to set
// default behavior for unimplemented methods.
type Logger interface {
// TODO (#4909): embed an embedded type from otel/log/embedded.

// Emit emits a log record.
//
// The record may be held by the implementation. Callers should not mutate
// the record after passed.
//
// Implementations of this method need to be safe for a user to call
// concurrently.
Emit(ctx context.Context, record Record)
}

// LoggerOption applies configuration options to a [Logger].
type LoggerOption interface {
// applyLogger is used to set a LoggerOption value of a LoggerConfig.
applyLogger(LoggerConfig) LoggerConfig
}

// LoggerConfig contains options for a [Logger].
type LoggerConfig struct {
// Ensure forward compatibility by explicitly making this not comparable.
noCmp [0]func() //nolint: unused // This is indeed used.
}

// NewLoggerConfig returns a new [LoggerConfig] with all the opts applied.
func NewLoggerConfig(opts ...LoggerOption) LoggerConfig { return LoggerConfig{} } // TODO (#4911): implement.

Check warning on line 54 in log/logger.go

View check run for this annotation

Codecov / codecov/patch

log/logger.go#L54

Added line #L54 was not covered by tests

// InstrumentationVersion returns the version of the library providing
// instrumentation.
func (cfg LoggerConfig) InstrumentationVersion() string { return "" } // TODO (#4911): implement.

Check warning on line 58 in log/logger.go

View check run for this annotation

Codecov / codecov/patch

log/logger.go#L58

Added line #L58 was not covered by tests

// InstrumentationAttributes returns the attributes associated with the library
// providing instrumentation.
func (cfg LoggerConfig) InstrumentationAttributes() attribute.Set { return attribute.NewSet() } // TODO (#4911): implement.

Check warning on line 62 in log/logger.go

View check run for this annotation

Codecov / codecov/patch

log/logger.go#L62

Added line #L62 was not covered by tests

// SchemaURL returns the schema URL of the library providing instrumentation.
func (cfg LoggerConfig) SchemaURL() string { return "" } // TODO (#4911): implement.

Check warning on line 65 in log/logger.go

View check run for this annotation

Codecov / codecov/patch

log/logger.go#L65

Added line #L65 was not covered by tests
32 changes: 32 additions & 0 deletions log/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

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

// LoggerProvider provides access to [Logger].
//
// Warning: Methods may be added to this interface in minor releases. See
// package documentation on API implementation for information on how to set
// default behavior for unimplemented methods.
type LoggerProvider interface {
// TODO (#4909): embed an embedded type from otel/log/embedded.

// Logger returns a new [Logger] with the provided name and configuration.
//
// If name is empty, implementations need to provide a default name.
//
// Implementations of this method need to be safe for a user to call
// concurrently.
Logger(name string, options ...LoggerOption) Logger
}
62 changes: 62 additions & 0 deletions log/record.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

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

import "time"

// Record represents a log record.
type Record struct{} // TODO (#4913): implement.

// Timestamp returns the time when the log record occurred.
func (r *Record) Timestamp() time.Time { return time.Time{} } // TODO (#4913): implement.

Check warning on line 23 in log/record.go

View check run for this annotation

Codecov / codecov/patch

log/record.go#L23

Added line #L23 was not covered by tests

// SetTimestamp sets the time when the log record occurred.
func (r *Record) SetTimestamp(t time.Time) {} // TODO (#4913): implement.

Check warning on line 26 in log/record.go

View check run for this annotation

Codecov / codecov/patch

log/record.go#L26

Added line #L26 was not covered by tests

// ObservedTimestamp returns the time when the log record was observed.
func (r *Record) ObservedTimestamp() time.Time { return time.Time{} } // TODO (#4913): implement.

Check warning on line 29 in log/record.go

View check run for this annotation

Codecov / codecov/patch

log/record.go#L29

Added line #L29 was not covered by tests

// SetObservedTimestamp sets the time when the log record was observed.
func (r *Record) SetObservedTimestamp(t time.Time) {} // TODO (#4913): implement.

Check warning on line 32 in log/record.go

View check run for this annotation

Codecov / codecov/patch

log/record.go#L32

Added line #L32 was not covered by tests

// Severity returns the [Severity] of the log record.
func (r *Record) Severity() Severity { return 0 } // TODO (#4913): implement.

Check warning on line 35 in log/record.go

View check run for this annotation

Codecov / codecov/patch

log/record.go#L35

Added line #L35 was not covered by tests

// SetSeverity sets the [Severity] level of the log record.
func (r *Record) SetSeverity(level Severity) {} // TODO (#4913): implement.

Check warning on line 38 in log/record.go

View check run for this annotation

Codecov / codecov/patch

log/record.go#L38

Added line #L38 was not covered by tests

// SeverityText returns severity (also known as log level) text. This is the
// original string representation of the severity as it is known at the source.
func (r *Record) SeverityText() string { return "" } // TODO (#4913): implement.

Check warning on line 42 in log/record.go

View check run for this annotation

Codecov / codecov/patch

log/record.go#L42

Added line #L42 was not covered by tests

// SetSeverityText sets severity (also known as log level) text. This is the
// original string representation of the severity as it is known at the source.
func (r *Record) SetSeverityText(text string) {} // TODO (#4913): implement.

Check warning on line 46 in log/record.go

View check run for this annotation

Codecov / codecov/patch

log/record.go#L46

Added line #L46 was not covered by tests

// Body returns the body of the log record.
func (r *Record) Body() Value { return Value{} } // TODO (#4913): implement.

Check warning on line 49 in log/record.go

View check run for this annotation

Codecov / codecov/patch

log/record.go#L49

Added line #L49 was not covered by tests

// SetBody sets the body of the log record.
func (r *Record) SetBody(v Value) {} // TODO (#4913): implement.

Check warning on line 52 in log/record.go

View check run for this annotation

Codecov / codecov/patch

log/record.go#L52

Added line #L52 was not covered by tests

// WalkAttributes walks all attributes the log record holds by calling f for
// each on each [KeyValue] in the [Record]. Iteration stops if f returns false.
func (r *Record) WalkAttributes(f func(KeyValue) bool) {} // TODO (#4913): implement.

Check warning on line 56 in log/record.go

View check run for this annotation

Codecov / codecov/patch

log/record.go#L56

Added line #L56 was not covered by tests

// AddAttributes adds attributes to the log record.
func (r *Record) AddAttributes(attributes ...KeyValue) {} // TODO (#4913): implement.

Check warning on line 59 in log/record.go

View check run for this annotation

Codecov / codecov/patch

log/record.go#L59

Added line #L59 was not covered by tests

// AttributesLen returns the number of attributes in the log record.
func (r *Record) AttributesLen() int { return 0 } // TODO (#4913): implement.

Check warning on line 62 in log/record.go

View check run for this annotation

Codecov / codecov/patch

log/record.go#L62

Added line #L62 was not covered by tests
Loading

0 comments on commit 3f995f0

Please sign in to comment.