File tree Expand file tree Collapse file tree 3 files changed +40
-6
lines changed Expand file tree Collapse file tree 3 files changed +40
-6
lines changed Original file line number Diff line number Diff line change 19
19
// The Level is transformed by using the static offset to the OpenTelemetry
20
20
// Severity types. For example:
21
21
//
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 ]
26
26
//
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
28
28
// into a string value if there is no matching type.
29
29
//
30
30
// [OpenTelemetry]: https://opentelemetry.io/docs/concepts/signals/logs/
Original file line number Diff line number Diff line change 2
2
// SPDX-License-Identifier: Apache-2.0
3
3
4
4
// 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
+
6
35
package otelzap // import "go.opentelemetry.io/contrib/bridges/otelzap"
7
36
8
37
import (
Original file line number Diff line number Diff line change 4
4
package otelzap_test
5
5
6
6
import (
7
+ "context"
7
8
"os"
8
9
9
10
"go.opentelemetry.io/contrib/bridges/otelzap"
@@ -24,6 +25,10 @@ func Example() {
24
25
25
26
// You can now use your logger in your code.
26
27
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 ))
27
32
}
28
33
29
34
func Example_multiple () {
You can’t perform that action at this time.
0 commit comments