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 cd9cde2 commit 8c5a496
Show file tree
Hide file tree
Showing 9 changed files with 583 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=
216 changes: 216 additions & 0 deletions log/keyvalue.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
// 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"

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

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

// Kind values.
const (
KindEmpty Kind = iota
KindBool
KindFloat64
KindInt64
KindString
KindBytes
// TODO: determine if this should be renamed to "slice".
KindList
KindMap
)

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

Check warning on line 43 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L41-L43

Added lines #L41 - L43 were not covered by tests
}

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

Check warning on line 49 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L47-L49

Added lines #L47 - L49 were not covered by tests
}

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

Check warning on line 55 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L53-L55

Added lines #L53 - L55 were not covered by tests
}

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

Check warning on line 61 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L59-L61

Added lines #L59 - L61 were not covered by tests
}

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

Check warning on line 67 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L65-L67

Added lines #L65 - L67 were not covered by tests
}

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

Check warning on line 73 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L71-L73

Added lines #L71 - L73 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 {
// TODO: implement.
return Value{}

Check warning on line 80 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L78-L80

Added lines #L78 - L80 were 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 {
// TODO: implement.
return Value{}

Check warning on line 87 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L85-L87

Added lines #L85 - L87 were 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 {
// TODO: implement.
return Value{}

Check warning on line 94 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L92-L94

Added lines #L92 - L94 were not covered by tests
}

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

Check warning on line 100 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L98-L100

Added lines #L98 - L100 were not covered by tests
}

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

Check warning on line 106 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L104-L106

Added lines #L104 - L106 were not covered by tests
}

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

Check warning on line 112 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L110-L112

Added lines #L110 - L112 were not covered by tests
}

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

Check warning on line 118 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L116-L118

Added lines #L116 - L118 were not covered by tests
}

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

Check warning on line 124 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L122-L124

Added lines #L122 - L124 were not covered by tests
}

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

Check warning on line 130 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L128-L130

Added lines #L128 - L130 were not covered by tests
}

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

Check warning on line 136 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L134-L136

Added lines #L134 - L136 were not covered by tests
}

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

Check warning on line 142 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L140-L142

Added lines #L140 - L142 were not covered by tests
}

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

Check warning on line 148 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L146-L148

Added lines #L146 - L148 were not covered by tests
}

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

Check warning on line 154 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L152-L154

Added lines #L152 - L154 were 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
}

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

Check warning on line 167 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L165-L167

Added lines #L165 - L167 were not covered by tests
}

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

Check warning on line 173 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L171-L173

Added lines #L171 - L173 were not covered by tests
}

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

Check warning on line 179 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L177-L179

Added lines #L177 - L179 were not covered by tests
}

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

Check warning on line 185 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L183-L185

Added lines #L183 - L185 were not covered by tests
}

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

Check warning on line 191 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L189-L191

Added lines #L189 - L191 were not covered by tests
}

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

Check warning on line 197 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L195-L197

Added lines #L195 - L197 were not covered by tests
}

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

Check warning on line 203 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L201-L203

Added lines #L201 - L203 were not covered by tests
}

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

Check warning on line 209 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L207-L209

Added lines #L207 - L209 were not covered by tests
}

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

Check warning on line 215 in log/keyvalue.go

View check run for this annotation

Codecov / codecov/patch

log/keyvalue.go#L213-L215

Added lines #L213 - L215 were 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.

77 changes: 77 additions & 0 deletions log/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// 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: 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 {
// TODO: implement.
return LoggerConfig{}

Check warning on line 56 in log/logger.go

View check run for this annotation

Codecov / codecov/patch

log/logger.go#L54-L56

Added lines #L54 - L56 were not covered by tests
}

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

Check warning on line 63 in log/logger.go

View check run for this annotation

Codecov / codecov/patch

log/logger.go#L61-L63

Added lines #L61 - L63 were not covered by tests
}

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

Check warning on line 70 in log/logger.go

View check run for this annotation

Codecov / codecov/patch

log/logger.go#L68-L70

Added lines #L68 - L70 were not covered by tests
}

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

Check warning on line 76 in log/logger.go

View check run for this annotation

Codecov / codecov/patch

log/logger.go#L74-L76

Added lines #L74 - L76 were 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: 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
}
Loading

0 comments on commit 8c5a496

Please sign in to comment.