Skip to content

Commit 251031f

Browse files
authored
Merge branch 'main' into Implementation-of-Run-Method(Zerolog)
2 parents 86c709e + f3b7018 commit 251031f

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

bridges/otellogrus/hook.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
// The Level is transformed by using the static offset to the OpenTelemetry
2020
// Severity types. For example:
2121
//
22-
// - [slog.LevelDebug] is transformed to [log.SeverityDebug]
23-
// - [slog.LevelInfo] is transformed to [log.SeverityInfo]
24-
// - [slog.LevelWarn] is transformed to [log.SeverityWarn]
25-
// - [slog.LevelError] is transformed to [log.SeverityError]
22+
// - [logrus.DebugLevel] is transformed to [log.SeverityDebug]
23+
// - [logrus.InfoLevel] is transformed to [log.SeverityTrace4]
24+
// - [logrus.WarnLevel] is transformed to [log.SeverityTrace3]
25+
// - [logrus.ErrorLevel] is transformed to [log.SeverityTrace2]
2626
//
27-
// Attribute values are transformed based on their type into log attributes, or
27+
// Field values are transformed based on their type into log attributes, or
2828
// into a string value if there is no matching type.
2929
//
3030
// [OpenTelemetry]: https://opentelemetry.io/docs/concepts/signals/logs/

bridges/otelzap/core.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,36 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
// Package otelzap provides a bridge between the [go.uber.org/zap] and
5-
// OpenTelemetry logging.
5+
// [OpenTelemetry].
6+
7+
// # Record Conversion
8+
//
9+
// The [zapcore.Entry] and [zapcore.Field] are converted to OpenTelemetry [log.Record] in the following
10+
// way:
11+
//
12+
// - Time is set as the Timestamp.
13+
// - Message is set as the Body using a [log.StringValue].
14+
// - Level is transformed and set as the Severity. The SeverityText is also
15+
// set.
16+
// - Fields are transformed and set as the Attributes.
17+
// - Field value of type `context.Context` is used as context when emitting log records.
18+
// - For named loggers, LoggerName is used to access [log.Logger] from [log.LoggerProvider]
19+
20+
//
21+
// The Level is transformed to the OpenTelemetry Severity types in the following way.
22+
//
23+
// - [zapcore.DebugLevel] is transformed to [log.SeverityDebug]
24+
// - [zapcore.InfoLevel] is transformed to [log.SeverityInfo]
25+
// - [zapcore.WarnLevel] is transformed to [log.SeverityWarn]
26+
// - [zapcore.ErrorLevel] is transformed to [log.SeverityError]
27+
// - [zapcore.DPanicLevel] is transformed to [log.SeverityFatal1]
28+
// - [zapcore.PanicLevel] is transformed to [log.SeverityFatal2]
29+
// - [zapcore.FatalLevel] is transformed to [log.SeverityFatal3]
30+
//
31+
// Fields are transformed based on their type into log attributes, or into a string value if there is no matching type.
32+
//
33+
// [OpenTelemetry]: https://opentelemetry.io/docs/concepts/signals/logs/
34+
635
package otelzap // import "go.opentelemetry.io/contrib/bridges/otelzap"
736

837
import (

bridges/otelzap/example_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package otelzap_test
55

66
import (
7+
"context"
78
"os"
89

910
"go.opentelemetry.io/contrib/bridges/otelzap"
@@ -24,6 +25,10 @@ func Example() {
2425

2526
// You can now use your logger in your code.
2627
logger.Info("something really cool")
28+
29+
// You can set context for trace correlation using zap.Any or zap.Reflect
30+
ctx := context.Background()
31+
logger.Info("setting context", zap.Any("context", ctx))
2732
}
2833

2934
func Example_multiple() {

0 commit comments

Comments
 (0)