Skip to content

Commit

Permalink
Merge branch 'main' into record-dropped
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Apr 11, 2024
2 parents 549567e + 1297d5f commit 666ac20
Show file tree
Hide file tree
Showing 7 changed files with 493 additions and 8 deletions.
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Added

- Add `Recorder` in `go.opentelemetry.io/otel/log/logtest` to facilitate testing the log bridge implementations. (#5134)
- The `DroppedAttributes` is added to the `"go.opentelemetry.io/otel/sdk/log".Record` type.
This method can be used to determine how many log attributes were dropped from the `Record` due to limits being exceeded. (#TBD)
This method can be used to determine how many log attributes were dropped from the `Record` due to limits being exceeded. (#5190)

### Changed

- Update `go.opentelemetry.io/proto/otlp` from v1.1.0 to v1.2.0. (#5177)

### Removed

- The `AttributeCountLimit` on the `"go.opentelemetry.io/otel/sdk/log".Record` type is removed. (#TBD)
- The `AttributeValueLengthLimit` on the `"go.opentelemetry.io/otel/sdk/log".Record` type is removed. (#TBD)
- The `AttributeCountLimit` on the `"go.opentelemetry.io/otel/sdk/log".Record` type is removed. (#5190)
- The `AttributeValueLengthLimit` on the `"go.opentelemetry.io/otel/sdk/log".Record` type is removed. (#5190)

## [1.25.0/0.47.0/0.0.8/0.1.0-alpha] 2024-04-05

Expand All @@ -43,7 +44,6 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Add `String` method to `Value` and `KeyValue` in `go.opentelemetry.io/otel/log`. (#5117)
- Add Exemplar support to `go.opentelemetry.io/otel/exporters/prometheus`. (#5111)
- Add metric semantic conventions to `go.opentelemetry.io/otel/semconv/v1.24.0`. Future `semconv` packages will include metric semantic conventions as well. (#4528)
- Add `Recorder` in `go.opentelemetry.io/otel/log/logtest` to facilitate testing the log bridge implementations. (#5134)

### Changed

Expand Down
6 changes: 3 additions & 3 deletions exporters/stdout/stdoutlog/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
)

var (
defaultWriter = os.Stdout
defaultPrettyPrint = false
defaultTimestamps = true
defaultWriter io.Writer = os.Stdout
defaultPrettyPrint = false
defaultTimestamps = true
)

// config contains options for the STDOUT exporter.
Expand Down
72 changes: 72 additions & 0 deletions exporters/stdout/stdoutlog/exporter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package stdoutlog // import "go.opentelemetry.io/otel/exporters/stdout/stdoutlog"

import (
"context"
"encoding/json"
"sync/atomic"

"go.opentelemetry.io/otel/sdk/log"
)

var _ log.Exporter = &Exporter{}

// Exporter writes JSON-encoded log records to an [io.Writer] ([os.Stdout] by default).
// Exporter must be created with [New].
type Exporter struct {
encoder atomic.Pointer[json.Encoder]
timestamps bool
}

// New creates an [Exporter].
func New(options ...Option) (*Exporter, error) {
cfg := newConfig(options)

enc := json.NewEncoder(cfg.Writer)
if cfg.PrettyPrint {
enc.SetIndent("", "\t")
}

e := Exporter{
timestamps: cfg.Timestamps,
}
e.encoder.Store(enc)

return &e, nil
}

// Export exports log records to writer.
func (e *Exporter) Export(ctx context.Context, records []log.Record) error {
enc := e.encoder.Load()
if enc == nil {
return nil
}

for _, record := range records {
// Honor context cancellation.
if err := ctx.Err(); err != nil {
return err
}

// Encode record, one by one.
recordJSON := e.newRecordJSON(record)
if err := enc.Encode(recordJSON); err != nil {
return err
}
}
return nil
}

// Shutdown shuts down the Exporter.
// Calls to Export will perform no operation after this is called.
func (e *Exporter) Shutdown(context.Context) error {
e.encoder.Store(nil)
return nil
}

// ForceFlush performs no action.
func (e *Exporter) ForceFlush(context.Context) error {
return nil
}
Loading

0 comments on commit 666ac20

Please sign in to comment.