Skip to content

Commit

Permalink
otelzap: Add Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
khushijain21 committed Jul 16, 2024
1 parent da85810 commit 5c614c8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
31 changes: 30 additions & 1 deletion bridges/otelzap/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,36 @@
// SPDX-License-Identifier: Apache-2.0

// Package otelzap provides a bridge between the [go.uber.org/zap] and
// OpenTelemetry logging.
// [OpenTelemetry].

// # Record Conversion
//
// The [zapcore.Entry] and [zapcore.Field] is converted to OpenTelemetry [log.Record] in the following
// way:
//
// - Time is set as the Timestamp.
// - Message is set as the Body using a [log.StringValue].
// - Level is transformed and set as the Severity. The SeverityText is also
// set.
// - Fields are transformed and set as the Attributes.
// - For named loggers, LoggerName is used to access [log.Logger] from [log.LoggerProvider]

//
// The Level is transformed by using the static offset to the OpenTelemetry
// Severity types. For example:
//
// - [zapcore.DebugLevel] is transformed to [log.SeverityDebug]
// - [zapcore.InfoLevel] is transformed to [log.SeverityInfo]
// - [zapcore.WarnLevel] is transformed to [log.SeverityWarn]
// - [zapcore.ErrorLevel] is transformed to [log.SeverityError]
// - [zapcore.DPanicLevel] is transformed to [log.SeverityFatal1]
// - [zapcore.PanicLevel] is transformed to [log.SeverityFatal2]
// - [zapcore.FatalLevel] is transformed to [log.SeverityFatal3]
//
// Attribute values are transformed based on their type into log attributes, or into a string value if there is no matching type.
//
// [OpenTelemetry]: https://opentelemetry.io/docs/concepts/signals/logs/

package otelzap // import "go.opentelemetry.io/contrib/bridges/otelzap"

import (
Expand Down
5 changes: 5 additions & 0 deletions bridges/otelzap/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package otelzap_test

import (
"context"
"os"

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

// You can now use your logger in your code.
logger.Info("something really cool")

// You can set context for trace correlation using zap.Any or zap.Reflect
ctx := context.Background()
logger.Info("setting context", zap.Any("context", ctx))
}

func Example_multiple() {
Expand Down

0 comments on commit 5c614c8

Please sign in to comment.