Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exporters: add otlplogfile exporter #5743

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

thomasgouveia
Copy link

@thomasgouveia thomasgouveia commented Aug 27, 2024

This PR introduces an experimental otlplogfile exporter based on the following specification: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/file-exporter.md.

For the implementation, I decided to use a buffered file writer based on the existing fileexporter available in the opentelemetry-collector to reduce I/O and improve performance. Below is benchmark result:

goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/otel/exporters/otlp/otlplog/otlplogfile/internal/writer
cpu: Apple M1 Pro
BenchmarkBufferedWriter
BenchmarkBufferedWriter/raw-file_10485760_bytes
BenchmarkBufferedWriter/raw-file_10485760_bytes-8         	36347986	        31.49 ns/op	      48 B/op	       1 allocs/op
BenchmarkBufferedWriter/buffered-file_10485760_bytes
BenchmarkBufferedWriter/buffered-file_10485760_bytes-8    	442928779	         2.704 ns/op	       0 B/op	       0 allocs/op
BenchmarkBufferedWriter/raw-file_104857600_bytes
BenchmarkBufferedWriter/raw-file_104857600_bytes-8        	34564147	        31.50 ns/op	      48 B/op	       1 allocs/op
BenchmarkBufferedWriter/buffered-file_104857600_bytes
BenchmarkBufferedWriter/buffered-file_104857600_bytes-8   	439031508	         2.703 ns/op	       0 B/op	       0 allocs/op
BenchmarkBufferedWriter/buffered-file_1073741824_bytes
BenchmarkBufferedWriter/buffered-file_1073741824_bytes-8  	400000000	         2.681 ns/op	       0 B/op	       0 allocs/op
BenchmarkBufferedWriter/raw-file_1073741824_bytes
BenchmarkBufferedWriter/raw-file_1073741824_bytes-8       	31952744	        35.17 ns/op	      48 B/op	       1 allocs/op
BenchmarkBufferedWriter/raw-file_10737418240_bytes
BenchmarkBufferedWriter/raw-file_10737418240_bytes-8      	       1	5706859250 ns/op	      32 B/op	       2 allocs/op
BenchmarkBufferedWriter/buffered-file_10737418240_bytes
BenchmarkBufferedWriter/buffered-file_10737418240_bytes-8 	       1	5981516417 ns/op	       0 B/op	       0 allocs/op
PASS

To serialize the records to the OTLP JSON format, I used protojson.

Closes #5408

This commit adds a new experimental exporter `otlplogfile`, that outputs log records to a JSON line file.
It is based on the following specification: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/file-exporter.md

Signed-off-by: thomasgouveia <[email protected]>
CHANGELOG.md Outdated Show resolved Hide resolved
exporters/otlp/otlplog/otlplogfile/exporter.go Outdated Show resolved Hide resolved
exporters/otlp/otlplog/otlplogfile/exporter.go Outdated Show resolved Hide resolved
}

// As stated in the specification, line separator is \n.
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/file-exporter.md#json-lines-file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/file-exporter.md#json-lines-file
// https://github.com/open-telemetry/opentelemetry-specification/blob/v1.36.0/specification/protocol/file-exporter.md#json-lines-file

exporters/otlp/otlplog/otlplogfile/go.mod Show resolved Hide resolved
thomasgouveia and others added 2 commits September 3, 2024 09:08
Co-authored-by: Damien Mathieu <[email protected]>
Co-authored-by: Damien Mathieu <[email protected]>

// WithWriter configures the destination where the exporter should output
// the records. By default, if not specified, stdout is used.
func WithWriter(w io.WriteCloser) Option {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exporter must not be responsible for closing the writer (like e.g. stdoutlog)
Would you want to close stdout? Or what if someone uses one file for multiple purposes?
The caller should be responsible for closing the writer.


// WithFile configures a file where the records will be exported.
// An error is returned if the file could not be created or opened.
func WithFile(path string) Option {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need such option.

)

// Option configures a field of the configuration or return an error if needed.
type Option func(*config) (*config, error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please implement Option as described in https://github.com/open-telemetry/opentelemetry-go/blob/main/CONTRIBUTING.md#option. Consistency makes the maintenance easier for us.

)

// Writer writes data to the configured io.WriteCloser.
// It is buffered to reduce I/O operations to improve performance.
Copy link
Member

@pellared pellared Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Processors e.g. BatchProcessor (see here) are responsible for buffering. Can we remove the WithFlushInterval option and startFlusher? The user can do it by himself, It is good enough if exporter.ForceFlush will call a Flush.

@@ -8,6 +8,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Added

- Add `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlplogfile ` experimental logs exporter. (#5743)
Copy link
Member

@pellared pellared Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Add `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlplogfile ` experimental logs exporter. (#5743)
- Add `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlplogfile` experimental OTLP logs file exporter. (#5743)

@MrAlias
Copy link
Contributor

MrAlias commented Sep 10, 2024

I do not think we should accept this change. It adds an exporter that has not been stabilized at the specification level. This addition will add churn to our stabilization efforts of the log signal.

I do not see why this cannot live in a fork as a PoC for the specification, or as an independent repository with its own maintainers outside of OTel. Adding this to the OTel development teams maintenance burden does not seem warranted at this time.

@dashpole
Copy link
Contributor

From the SIG meeting:

  • This is currently in development, and we aren't required to implement it
  • This is a large amount of code, and will likely be a burden on maintainers as it evolves
  • We would prefer if this lived in its own repository until it is stabilized and required for us to implement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add otlplogfile exporter
5 participants