Skip to content

Commit d3dcb39

Browse files
authored
Add initial Logs Bridge API scaffolding (open-telemetry#4907)
* Add go.mod * Exclude otel/log in versions.yaml * Add package documentation stub * Update dependabot config * Add initial log API scaffolding
1 parent 02b6123 commit d3dcb39

12 files changed

+487
-0
lines changed

.github/dependabot.yml

+9
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,15 @@ updates:
217217
schedule:
218218
interval: weekly
219219
day: sunday
220+
- package-ecosystem: gomod
221+
directory: /log
222+
labels:
223+
- dependencies
224+
- go
225+
- Skip Changelog
226+
schedule:
227+
interval: weekly
228+
day: sunday
220229
- package-ecosystem: gomod
221230
directory: /metric
222231
labels:

log/doc.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/*
16+
Package log provides the OpenTelemetry Logs Bridge API.
17+
*/
18+
19+
// TODO (#4908): expand documentation stub.
20+
21+
package log // import "go.opentelemetry.io/otel/log"

log/go.mod

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module go.opentelemetry.io/otel/log
2+
3+
go 1.20
4+
5+
require go.opentelemetry.io/otel v1.23.1
6+
7+
replace go.opentelemetry.io/otel/metric => ../metric
8+
9+
replace go.opentelemetry.io/otel => ../
10+
11+
replace go.opentelemetry.io/otel/trace => ../trace

log/go.sum

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
3+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
5+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

log/keyvalue.go

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:generate stringer -type=Kind -trimprefix=Kind
16+
17+
package log // import "go.opentelemetry.io/otel/log"
18+
19+
// Kind is the kind of a [Value].
20+
type Kind int
21+
22+
// Kind values.
23+
const (
24+
KindEmpty Kind = iota
25+
KindBool
26+
KindFloat64
27+
KindInt64
28+
KindString
29+
KindBytes
30+
KindList
31+
KindMap
32+
)
33+
34+
// A Value represents a structured log value.
35+
type Value struct{} // TODO (#4914): implement.
36+
37+
// StringValue returns a new [Value] for a string.
38+
func StringValue(v string) Value { return Value{} } // TODO (#4914): implement.
39+
40+
// IntValue returns a [Value] for an int.
41+
func IntValue(v int) Value { return Value{} } // TODO (#4914): implement.
42+
43+
// Int64Value returns a [Value] for an int64.
44+
func Int64Value(v int64) Value { return Value{} } // TODO (#4914): implement.
45+
46+
// Float64Value returns a [Value] for a float64.
47+
func Float64Value(v float64) Value { return Value{} } // TODO (#4914): implement.
48+
49+
// BoolValue returns a [Value] for a bool.
50+
func BoolValue(v bool) Value { //nolint:revive // Not a control flag.
51+
// TODO (#4914): implement.
52+
return Value{}
53+
}
54+
55+
// BytesValue returns a [Value] for a byte slice. The passed slice must not be
56+
// changed after it is passed.
57+
func BytesValue(v []byte) Value { return Value{} } // TODO (#4914): implement.
58+
59+
// ListValue returns a [Value] for a slice of [Value]. The passed slice must
60+
// not be changed after it is passed.
61+
func ListValue(vs ...Value) Value { return Value{} } // TODO (#4914): implement.
62+
63+
// MapValue returns a new [Value] for a slice of key-value pairs. The passed
64+
// slice must not be changed after it is passed.
65+
func MapValue(kvs ...KeyValue) Value { return Value{} } // TODO (#4914): implement.
66+
67+
// AsAny returns the value held by v as an any.
68+
func (v Value) AsAny() any { return nil } // TODO (#4914): implement
69+
70+
// AsString returns the value held by v as a string.
71+
func (v Value) AsString() string { return "" } // TODO (#4914): implement
72+
73+
// AsInt64 returns the value held by v as an int64.
74+
func (v Value) AsInt64() int64 { return 0 } // TODO (#4914): implement
75+
76+
// AsBool returns the value held by v as a bool.
77+
func (v Value) AsBool() bool { return false } // TODO (#4914): implement
78+
79+
// AsFloat64 returns the value held by v as a float64.
80+
func (v Value) AsFloat64() float64 { return 0 } // TODO (#4914): implement
81+
82+
// AsBytes returns the value held by v as a []byte.
83+
func (v Value) AsBytes() []byte { return nil } // TODO (#4914): implement
84+
85+
// AsList returns the value held by v as a []Value.
86+
func (v Value) AsList() []Value { return nil } // TODO (#4914): implement
87+
88+
// AsMap returns the value held by v as a []KeyValue.
89+
func (v Value) AsMap() []KeyValue { return nil } // TODO (#4914): implement
90+
91+
// Kind returns the Kind of v.
92+
func (v Value) Kind() Kind { return KindEmpty } // TODO (#4914): implement.
93+
94+
// Empty returns if v does not hold any value.
95+
func (v Value) Empty() bool { return false } // TODO (#4914): implement
96+
97+
// Equal returns if v is equal to w.
98+
func (v Value) Equal(w Value) bool { return false } // TODO (#4914): implement
99+
100+
// An KeyValue is a key-value pair used to represent a log attribute (a
101+
// superset of [go.opentelemetry.io/otel/attribute.KeyValue]) and map item.
102+
type KeyValue struct {
103+
Key string
104+
Value Value
105+
}
106+
107+
// Equal returns if a is equal to b.
108+
func (a KeyValue) Equal(b KeyValue) bool { return false } // TODO (#4914): implement
109+
110+
// String returns an KeyValue for a string value.
111+
func String(key, value string) KeyValue { return KeyValue{} } // TODO (#4914): implement
112+
113+
// Int64 returns an KeyValue for an int64 value.
114+
func Int64(key string, value int64) KeyValue { return KeyValue{} } // TODO (#4914): implement
115+
116+
// Int returns an KeyValue for an int value.
117+
func Int(key string, value int) KeyValue { return KeyValue{} } // TODO (#4914): implement
118+
119+
// Float64 returns an KeyValue for a float64 value.
120+
func Float64(key string, v float64) KeyValue { return KeyValue{} } // TODO (#4914): implement
121+
122+
// Bool returns an KeyValue for a bool value.
123+
func Bool(key string, v bool) KeyValue { return KeyValue{} } // TODO (#4914): implement
124+
125+
// Bytes returns an KeyValue for a []byte value.
126+
func Bytes(key string, v []byte) KeyValue { return KeyValue{} } // TODO (#4914): implement
127+
128+
// List returns an KeyValue for a []Value value.
129+
func List(key string, args ...Value) KeyValue { return KeyValue{} } // TODO (#4914): implement
130+
131+
// Map returns an KeyValue for a map value.
132+
func Map(key string, args ...KeyValue) KeyValue { return KeyValue{} } // TODO (#4914): implement

log/kind_string.go

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

log/logger.go

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package log // import "go.opentelemetry.io/otel/log"
16+
17+
import (
18+
"context"
19+
20+
"go.opentelemetry.io/otel/attribute"
21+
)
22+
23+
// Logger emits log records.
24+
//
25+
// Warning: Methods may be added to this interface in minor releases. See
26+
// package documentation on API implementation for information on how to set
27+
// default behavior for unimplemented methods.
28+
type Logger interface {
29+
// TODO (#4909): embed an embedded type from otel/log/embedded.
30+
31+
// Emit emits a log record.
32+
//
33+
// The record may be held by the implementation. Callers should not mutate
34+
// the record after passed.
35+
//
36+
// Implementations of this method need to be safe for a user to call
37+
// concurrently.
38+
Emit(ctx context.Context, record Record)
39+
}
40+
41+
// LoggerOption applies configuration options to a [Logger].
42+
type LoggerOption interface {
43+
// applyLogger is used to set a LoggerOption value of a LoggerConfig.
44+
applyLogger(LoggerConfig) LoggerConfig
45+
}
46+
47+
// LoggerConfig contains options for a [Logger].
48+
type LoggerConfig struct {
49+
// Ensure forward compatibility by explicitly making this not comparable.
50+
noCmp [0]func() //nolint: unused // This is indeed used.
51+
}
52+
53+
// NewLoggerConfig returns a new [LoggerConfig] with all the opts applied.
54+
func NewLoggerConfig(opts ...LoggerOption) LoggerConfig { return LoggerConfig{} } // TODO (#4911): implement.
55+
56+
// InstrumentationVersion returns the version of the library providing
57+
// instrumentation.
58+
func (cfg LoggerConfig) InstrumentationVersion() string { return "" } // TODO (#4911): implement.
59+
60+
// InstrumentationAttributes returns the attributes associated with the library
61+
// providing instrumentation.
62+
func (cfg LoggerConfig) InstrumentationAttributes() attribute.Set { return attribute.NewSet() } // TODO (#4911): implement.
63+
64+
// SchemaURL returns the schema URL of the library providing instrumentation.
65+
func (cfg LoggerConfig) SchemaURL() string { return "" } // TODO (#4911): implement.

log/provider.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package log // import "go.opentelemetry.io/otel/log"
16+
17+
// LoggerProvider provides access to [Logger].
18+
//
19+
// Warning: Methods may be added to this interface in minor releases. See
20+
// package documentation on API implementation for information on how to set
21+
// default behavior for unimplemented methods.
22+
type LoggerProvider interface {
23+
// TODO (#4909): embed an embedded type from otel/log/embedded.
24+
25+
// Logger returns a new [Logger] with the provided name and configuration.
26+
//
27+
// If name is empty, implementations need to provide a default name.
28+
//
29+
// Implementations of this method need to be safe for a user to call
30+
// concurrently.
31+
Logger(name string, options ...LoggerOption) Logger
32+
}

log/record.go

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package log // import "go.opentelemetry.io/otel/log"
16+
17+
import "time"
18+
19+
// Record represents a log record.
20+
type Record struct{} // TODO (#4913): implement.
21+
22+
// Timestamp returns the time when the log record occurred.
23+
func (r *Record) Timestamp() time.Time { return time.Time{} } // TODO (#4913): implement.
24+
25+
// SetTimestamp sets the time when the log record occurred.
26+
func (r *Record) SetTimestamp(t time.Time) {} // TODO (#4913): implement.
27+
28+
// ObservedTimestamp returns the time when the log record was observed.
29+
func (r *Record) ObservedTimestamp() time.Time { return time.Time{} } // TODO (#4913): implement.
30+
31+
// SetObservedTimestamp sets the time when the log record was observed.
32+
func (r *Record) SetObservedTimestamp(t time.Time) {} // TODO (#4913): implement.
33+
34+
// Severity returns the [Severity] of the log record.
35+
func (r *Record) Severity() Severity { return 0 } // TODO (#4913): implement.
36+
37+
// SetSeverity sets the [Severity] level of the log record.
38+
func (r *Record) SetSeverity(level Severity) {} // TODO (#4913): implement.
39+
40+
// SeverityText returns severity (also known as log level) text. This is the
41+
// original string representation of the severity as it is known at the source.
42+
func (r *Record) SeverityText() string { return "" } // TODO (#4913): implement.
43+
44+
// SetSeverityText sets severity (also known as log level) text. This is the
45+
// original string representation of the severity as it is known at the source.
46+
func (r *Record) SetSeverityText(text string) {} // TODO (#4913): implement.
47+
48+
// Body returns the body of the log record.
49+
func (r *Record) Body() Value { return Value{} } // TODO (#4913): implement.
50+
51+
// SetBody sets the body of the log record.
52+
func (r *Record) SetBody(v Value) {} // TODO (#4913): implement.
53+
54+
// WalkAttributes walks all attributes the log record holds by calling f for
55+
// each on each [KeyValue] in the [Record]. Iteration stops if f returns false.
56+
func (r *Record) WalkAttributes(f func(KeyValue) bool) {} // TODO (#4913): implement.
57+
58+
// AddAttributes adds attributes to the log record.
59+
func (r *Record) AddAttributes(attributes ...KeyValue) {} // TODO (#4913): implement.
60+
61+
// AttributesLen returns the number of attributes in the log record.
62+
func (r *Record) AttributesLen() int { return 0 } // TODO (#4913): implement.

0 commit comments

Comments
 (0)