1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00

Add initial Logs Bridge API scaffolding (#4907)

* Add go.mod

* Exclude otel/log in versions.yaml

* Add package documentation stub

* Update dependabot config

* Add initial log API scaffolding
This commit is contained in:
Tyler Yahn
2024-02-16 07:09:58 -08:00
committed by GitHub
parent 02b61239cd
commit d3dcb3999c
12 changed files with 487 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
// 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 provides the OpenTelemetry Logs Bridge API.
*/
// TODO (#4908): expand documentation stub.
package log // import "go.opentelemetry.io/otel/log"
+11
View File
@@ -0,0 +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
View File
@@ -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
View File
@@ -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.
// IntValue returns a [Value] for an int.
func IntValue(v int) Value { return Value{} } // TODO (#4914): implement.
// Int64Value returns a [Value] for an int64.
func Int64Value(v int64) Value { return Value{} } // TODO (#4914): implement.
// Float64Value returns a [Value] for a float64.
func Float64Value(v float64) Value { return Value{} } // TODO (#4914): implement.
// BoolValue returns a [Value] for a bool.
func BoolValue(v bool) Value { //nolint:revive // Not a control flag.
// TODO (#4914): implement.
return Value{}
}
// 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.
// 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.
// 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.
// AsAny returns the value held by v as an any.
func (v Value) AsAny() any { return nil } // TODO (#4914): implement
// AsString returns the value held by v as a string.
func (v Value) AsString() string { return "" } // TODO (#4914): implement
// AsInt64 returns the value held by v as an int64.
func (v Value) AsInt64() int64 { return 0 } // TODO (#4914): implement
// AsBool returns the value held by v as a bool.
func (v Value) AsBool() bool { return false } // TODO (#4914): implement
// AsFloat64 returns the value held by v as a float64.
func (v Value) AsFloat64() float64 { return 0 } // TODO (#4914): implement
// AsBytes returns the value held by v as a []byte.
func (v Value) AsBytes() []byte { return nil } // TODO (#4914): implement
// AsList returns the value held by v as a []Value.
func (v Value) AsList() []Value { return nil } // TODO (#4914): implement
// AsMap returns the value held by v as a []KeyValue.
func (v Value) AsMap() []KeyValue { return nil } // TODO (#4914): implement
// Kind returns the Kind of v.
func (v Value) Kind() Kind { return KindEmpty } // TODO (#4914): implement.
// Empty returns if v does not hold any value.
func (v Value) Empty() bool { return false } // TODO (#4914): implement
// Equal returns if v is equal to w.
func (v Value) Equal(w Value) bool { return false } // TODO (#4914): implement
// 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
// String returns an KeyValue for a string value.
func String(key, value string) KeyValue { return KeyValue{} } // TODO (#4914): implement
// Int64 returns an KeyValue for an int64 value.
func Int64(key string, value int64) KeyValue { return KeyValue{} } // TODO (#4914): implement
// Int returns an KeyValue for an int value.
func Int(key string, value int) KeyValue { return KeyValue{} } // TODO (#4914): implement
// Float64 returns an KeyValue for a float64 value.
func Float64(key string, v float64) KeyValue { return KeyValue{} } // TODO (#4914): implement
// Bool returns an KeyValue for a bool value.
func Bool(key string, v bool) KeyValue { return KeyValue{} } // TODO (#4914): implement
// Bytes returns an KeyValue for a []byte value.
func Bytes(key string, v []byte) KeyValue { return KeyValue{} } // TODO (#4914): implement
// List returns an KeyValue for a []Value value.
func List(key string, args ...Value) KeyValue { return KeyValue{} } // TODO (#4914): implement
// Map returns an KeyValue for a map value.
func Map(key string, args ...KeyValue) KeyValue { return KeyValue{} } // TODO (#4914): implement
+30
View File
@@ -0,0 +1,30 @@
// Code generated by "stringer -type=Kind -trimprefix=Kind"; DO NOT EDIT.
package log
import "strconv"
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[KindEmpty-0]
_ = x[KindBool-1]
_ = x[KindFloat64-2]
_ = x[KindInt64-3]
_ = x[KindString-4]
_ = x[KindBytes-5]
_ = x[KindList-6]
_ = x[KindMap-7]
}
const _Kind_name = "EmptyBoolFloat64Int64StringBytesListMap"
var _Kind_index = [...]uint8{0, 5, 9, 16, 21, 27, 32, 36, 39}
func (i Kind) String() string {
if i < 0 || i >= Kind(len(_Kind_index)-1) {
return "Kind(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _Kind_name[_Kind_index[i]:_Kind_index[i+1]]
}
+65
View File
@@ -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.
// InstrumentationVersion returns the version of the library providing
// instrumentation.
func (cfg LoggerConfig) InstrumentationVersion() string { return "" } // TODO (#4911): implement.
// InstrumentationAttributes returns the attributes associated with the library
// providing instrumentation.
func (cfg LoggerConfig) InstrumentationAttributes() attribute.Set { return attribute.NewSet() } // TODO (#4911): implement.
// SchemaURL returns the schema URL of the library providing instrumentation.
func (cfg LoggerConfig) SchemaURL() string { return "" } // TODO (#4911): implement.
+32
View File
@@ -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
View File
@@ -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.
// SetTimestamp sets the time when the log record occurred.
func (r *Record) SetTimestamp(t time.Time) {} // TODO (#4913): implement.
// ObservedTimestamp returns the time when the log record was observed.
func (r *Record) ObservedTimestamp() time.Time { return time.Time{} } // TODO (#4913): implement.
// SetObservedTimestamp sets the time when the log record was observed.
func (r *Record) SetObservedTimestamp(t time.Time) {} // TODO (#4913): implement.
// Severity returns the [Severity] of the log record.
func (r *Record) Severity() Severity { return 0 } // TODO (#4913): implement.
// SetSeverity sets the [Severity] level of the log record.
func (r *Record) SetSeverity(level Severity) {} // TODO (#4913): implement.
// 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.
// 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.
// Body returns the body of the log record.
func (r *Record) Body() Value { return Value{} } // TODO (#4913): implement.
// SetBody sets the body of the log record.
func (r *Record) SetBody(v Value) {} // TODO (#4913): implement.
// 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.
// AddAttributes adds attributes to the log record.
func (r *Record) AddAttributes(attributes ...KeyValue) {} // TODO (#4913): implement.
// AttributesLen returns the number of attributes in the log record.
func (r *Record) AttributesLen() int { return 0 } // TODO (#4913): implement.
+72
View File
@@ -0,0 +1,72 @@
// 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=Severity -linecomment
package log // import "go.opentelemetry.io/otel/log"
// Severity represents a log record severity (also known as log level). Smaller
// numerical values correspond to less severe log records (such as debug
// events), larger numerical values correspond to more severe log records (such
// as errors and critical events).
type Severity int
// Severity values defined by OpenTelemetry.
const (
// A fine-grained debugging log record. Typically disabled in default
// configurations.
SeverityTrace1 Severity = 1 // TRACE
SeverityTrace2 Severity = 2 // TRACE2
SeverityTrace3 Severity = 3 // TRACE3
SeverityTrace4 Severity = 4 // TRACE4
// A debugging log record.
SeverityDebug1 Severity = 5 // DEBUG
SeverityDebug2 Severity = 6 // DEBUG2
SeverityDebug3 Severity = 7 // DEBUG3
SeverityDebug4 Severity = 8 // DEBUG4
// An informational log record. Indicates that an event happened.
SeverityInfo1 Severity = 9 // INFO
SeverityInfo2 Severity = 10 // INFO2
SeverityInfo3 Severity = 11 // INFO3
SeverityInfo4 Severity = 12 // INFO4
// A warning log record. Not an error but is likely more important than an
// informational event.
SeverityWarn1 Severity = 13 // WARN
SeverityWarn2 Severity = 14 // WARN2
SeverityWarn3 Severity = 15 // WARN3
SeverityWarn4 Severity = 16 // WARN4
// An error log record. Something went wrong.
SeverityError1 Severity = 17 // ERROR
SeverityError2 Severity = 18 // ERROR2
SeverityError3 Severity = 19 // ERROR3
SeverityError4 Severity = 20 // ERROR4
// A fatal log record such as application or system crash.
SeverityFatal1 Severity = 21 // FATAL
SeverityFatal2 Severity = 22 // FATAL2
SeverityFatal3 Severity = 23 // FATAL3
SeverityFatal4 Severity = 24 // FATAL4
// Convenience definitions for the base severity of each level.
SeverityTrace = SeverityTrace1
SeverityDebug = SeverityDebug1
SeverityInfo = SeverityInfo1
SeverityWarn = SeverityWarn1
SeverityError = SeverityError1
SeverityFatal = SeverityFatal1
)
+47
View File
@@ -0,0 +1,47 @@
// Code generated by "stringer -type=Severity -linecomment"; DO NOT EDIT.
package log
import "strconv"
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[SeverityTrace1-1]
_ = x[SeverityTrace2-2]
_ = x[SeverityTrace3-3]
_ = x[SeverityTrace4-4]
_ = x[SeverityDebug1-5]
_ = x[SeverityDebug2-6]
_ = x[SeverityDebug3-7]
_ = x[SeverityDebug4-8]
_ = x[SeverityInfo1-9]
_ = x[SeverityInfo2-10]
_ = x[SeverityInfo3-11]
_ = x[SeverityInfo4-12]
_ = x[SeverityWarn1-13]
_ = x[SeverityWarn2-14]
_ = x[SeverityWarn3-15]
_ = x[SeverityWarn4-16]
_ = x[SeverityError1-17]
_ = x[SeverityError2-18]
_ = x[SeverityError3-19]
_ = x[SeverityError4-20]
_ = x[SeverityFatal1-21]
_ = x[SeverityFatal2-22]
_ = x[SeverityFatal3-23]
_ = x[SeverityFatal4-24]
}
const _Severity_name = "TRACETRACE2TRACE3TRACE4DEBUGDEBUG2DEBUG3DEBUG4INFOINFO2INFO3INFO4WARNWARN2WARN3WARN4ERRORERROR2ERROR3ERROR4FATALFATAL2FATAL3FATAL4"
var _Severity_index = [...]uint8{0, 5, 11, 17, 23, 28, 34, 40, 46, 50, 55, 60, 65, 69, 74, 79, 84, 89, 95, 101, 107, 112, 118, 124, 130}
func (i Severity) String() string {
i -= 1
if i < 0 || i >= Severity(len(_Severity_index)-1) {
return "Severity(" + strconv.FormatInt(int64(i+1), 10) + ")"
}
return _Severity_name[_Severity_index[i]:_Severity_index[i+1]]
}