Applying attribute limits in `Record` uses value receiver.
But it should add count of dropped attrs.
In this PR I add using of pointer receiver.
Also it's slightly faster with pointer receiver:
```
goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/otel/sdk/log
│ old.txt │ new.txt │
│ sec/op │ sec/op vs base │
SetAddAttributes-10 175.7n ± 3% 159.8n ± 4% -9.08% (p=0.000 n=10)
│ old.txt │ new.txt │
│ B/op │ B/op vs base │
SetAddAttributes-10 48.00 ± 0% 48.00 ± 0% ~ (p=1.000 n=10) ¹
¹ all samples are equal
│ old.txt │ new.txt │
│ allocs/op │ allocs/op vs base │
SetAddAttributes-10 1.000 ± 0% 1.000 ± 0% ~ (p=1.000 n=10) ¹
¹ all samples are equal
```
Fix#5455
The `math/rand.Rand` type is not safe for concurrent access. Concurrent
measurements, and therefore concurrent exemplar computation, are
allowed. Ensure this concurrent design does not lead to data races with
`rng`.
Towards https://github.com/open-telemetry/opentelemetry-go/issues/5219
Towards https://github.com/open-telemetry/opentelemetry-go/issues/5054
This benchmarks are supposed
- Validate the the `Processor` interface design from performance
perspective. E.g. they are used to check if a processor that is
modifying a log record is causing an additional heap allocations.
- Benchmark the processors supported by the SDK.
These are "almost-end-to-end" benchmarks (with noopExporter) so that it
checks the performance of the SDK log processing without the actual
exporting part.
```
cpu: Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz
BenchmarkProcessor/Simple-16 1990946 644.6 ns/op 417 B/op 1 allocs/op
BenchmarkProcessor/Batch-16 835135 1211 ns/op 597 B/op 0 allocs/op
BenchmarkProcessor/ModifyTimestampSimple-16 1782510 644.3 ns/op 417 B/op 1 allocs/op
BenchmarkProcessor/ModifyTimestampBatch-16 945699 1222 ns/op 637 B/op 0 allocs/op
BenchmarkProcessor/ModifyAttributesSimple-16 1570214 717.6 ns/op 465 B/op 2 allocs/op
BenchmarkProcessor/ModifyAttributesBatch-16 768399 1383 ns/op 653 B/op 1 allocs/op
```
Fix#5343
- Update the `evictionQueue` to log when it drops a value
- Update the `evictionQueue` to be declared over an `[T any]` parameter
so it knows what to log when it is dropping a value and to reduce the
`interface{}` allocation
- Add a `clone` method to replace the now unneeded
`interfaceArrayTo*Array` functions.
- Update the `recordingSpan` to log once that is dropped an attribute
when limits are reached.
From
https://github.com/open-telemetry/opentelemetry-go-contrib/pull/5654#discussion_r1617971674
Constructing a view requires an `Instrument` to be constructed. Given
`NewView` will not return an error directly when an empty instrument is
passed, it may be ideal for users to check this prior to making the
call. Instead of having all use-cases copy this code, export it so they
can just call the method.
Fix#5342
Run of `go test -v -timeout 10s -short -count=10000 ./...
-run='TestBatchProcessor/ForceFlush/ErrorPartialFlush'`
**Before**:
Failed with `panic: test timed out after 10s`
**After**:
Passed
Problem was with `bufferExporter.input` chan.
In test expected:
> 1 export being performed, 1 export in buffer chan, >1 batch
But buffer chan wasn't checked. Now we ensure, that record is in buffer
chan
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Fix#5384
Run of `go test -count=1000000 -run="TestBatchProcessor/DroppedLogs"`
**Before**:
Failed with either `Condition never satisfied` or panic
**After**:
Passed
First, bytes.Buffer is not thread-safe, so writing log and reading
(`bytes.String()`) caused panic. Added `concurrentBuffer`
Second, fixed flaky test with 4 records:
1. Record goes to `testExporter.Export` function and blocks in this
function because of `ExportTrigger`
(19ee6d4775/sdk/log/exporter_test.go (L87))
2. Record goes to `bufferExporter.input`
(7c5e64cccc/sdk/log/exporter.go (L129))
3. Record goes to `BatchProcessor.q` queue and it could not be enqueued
to export, because `bufferExporter.input` is full
4. Record goes to `BatchProcessor.q` and because of overfill, drops
third record
---------
Co-authored-by: Sam Xie <sam@samxie.me>
Fix#5317
According to the
[specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/sdk.md#logrecord-limits),
there should be a message printed in the SDK's log to indicate to the
user that an attribute was discarded due to such a limit. To prevent
excessive logging, the message must be printed at most once per
`LogRecord` (i.e., not per discarded attribute).
This change centralizes the `Record` dropped field writes and calls a
global logging function. This will at most log once per any `Record`
dropping attributes, meeting the specification requirement.
This does not log once per `Record` when an attribute is dropped. To do
that we would need to maintain state within the `Record` (i.e.
`sync.Mutex` or `sync.Once`). These types cannot be copied, meaning the
`Record` would take on this "no copy" requirement. This seems too
restrictive and with the permissive specification allowing a single log
line, that is the solution added.
---------
Co-authored-by: Robert Pająk <pellared@hotmail.com>
Leftover after
https://github.com/open-telemetry/opentelemetry-go/pull/5230
We want to have the benchmarks working with 5+ attributes as this is
when allocations kick in.
Before changes:
```
BenchmarkLoggerNewRecord/5_attributes-16 4016042 309.0 ns/op 0 B/op 0 allocs/op
BenchmarkLoggerNewRecord/10_attributes-16 2150197 543.4 ns/op 0 B/op 0 allocs/op
```
After changes:
```
BenchmarkLoggerNewRecord/5_attributes-16 3779966 311.1 ns/op 0 B/op 0 allocs/op
BenchmarkLoggerNewRecord/10_attributes-16 1000000 1314 ns/op 610 B/op 4 allocs/op
```
Fix#5384
On single-threaded, or in general slow, systems where the log message
may not be emitted, use assert.Everything to allow multiple lookups for
the expected log message.
Co-authored-by: Sam Xie <sam@samxie.me>
This release includes the first beta release of the OpenTelemetry Logs
Bridge API and SDK for Go.
### Added
- Add example for `go.opentelemetry.io/otel/exporters/stdout/stdoutlog`.
(#5242)
- Add `RecordFactory` in `go.opentelemetry.io/otel/sdk/log/logtest` to
facilitate testing exporter and processor implementations. (#5258)
- Add `RecordFactory` in `go.opentelemetry.io/otel/log/logtest` to
facilitate testing bridge implementations. (#5263)
- The count of dropped records from the `BatchProcessor` in
`go.opentelemetry.io/otel/sdk/log` is logged. (#5276)
- Add metrics in the `otel-collector` example. (#5283)
- Add the synchronous gauge instrument to
`go.opentelemetry.io/otel/metric`. (#5304)
- An `int64` or `float64` synchronous gauge instrument can now be
created from a `Meter`.
- All implementations of the API
(`go.opentelemetry.io/otel/metric/noop`,
`go.opentelemetry.io/otel/sdk/metric`) are updated to support this
instrument.
- Add logs to `go.opentelemetry.io/otel/example/dice`. (#5349)
### Changed
- The `Shutdown` method of `Exporter` in
`go.opentelemetry.io/otel/exporters/stdout/stdouttrace` ignores the
context cancellation and always returns `nil`. (#5189)
- The `ForceFlush` and `Shutdown` methods of the exporter returned by
`New` in `go.opentelemetry.io/otel/exporters/stdout/stdoutmetric` ignore
the context cancellation and always return `nil`. (#5189)
- Apply the value length limits to `Record` attributes in
`go.opentelemetry.io/otel/sdk/log`. (#5230)
- De-duplicate map attributes added to a `Record` in
`go.opentelemetry.io/otel/sdk/log`. (#5230)
- `go.opentelemetry.io/otel/exporters/stdout/stdoutlog` won't print
timestamps when `WithoutTimestamps` option is set. (#5241)
- The `go.opentelemetry.io/otel/exporters/stdout/stdoutlog` exporter
won't print `AttributeValueLengthLimit` and `AttributeCountLimit` fields
now, instead it prints the `DroppedAttributes` field. (#5272)
- Improved performance in the `Stringer` implementation of
`go.opentelemetry.io/otel/baggage.Member` by reducing the number of
allocations. (#5286)
- Set the start time for last-value aggregates in
`go.opentelemetry.io/otel/sdk/metric`. (#5305)
- The `Span` in `go.opentelemetry.io/otel/sdk/trace` will record links
without span context if either non-empty `TraceState` or attributes are
provided. (#5315)
- Upgrade all dependencies of `go.opentelemetry.io/otel/semconv/v1.24.0`
to `go.opentelemetry.io/otel/semconv/v1.25.0`. (#5374)
### Fixed
- Comparison of unordered maps for
`go.opentelemetry.io/otel/log.KeyValue` and
`go.opentelemetry.io/otel/log.Value`. (#5306)
- Fix the empty output of `go.opentelemetry.io/otel/log.Value` in
`go.opentelemetry.io/otel/exporters/stdout/stdoutlog`. (#5311)
- Split the behavior of `Recorder` in
`go.opentelemetry.io/otel/log/logtest` so it behaves as a
`LoggerProvider` only. (#5365)
- Fix wrong package name of the error message when parsing endpoint URL
in `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp`.
(#5371)
- Identify the `Logger` returned from the global `LoggerProvider` in
`go.opentelemetry.io/otel/log/global` with its schema URL. (#5375)
#5304 introduced the following incompatible changes:
- `InstrumentKindObservableCounter`: value changed from 4 to 5
- `InstrumentKindObservableGauge`: value changed from 6 to 7
- `InstrumentKindObservableUpDownCounter`: value changed from 5 to 6
This reverts that change, making `InstrumentKindGauge` explicitly `7`.
Additionally, this removes the use of `iota` to prevent this kind of
breaking change from being accidentally introduced in the future.
* record links with empty span context
* add global trace state
* fix test comments and changelog
---------
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
* Refactor exemplars to not use generic argument
* Update internal/aggregate
* Update metric SDK
* Test exemplar value type
* Add TestCollectExemplars
* Fix lint
---------
Co-authored-by: Sam Xie <sam@samxie.me>
* emit slices as their json representation
* add changelog
* fix resource tests
* indicate invalid slice if we couldn't turn them into json
* move changelog entry to the unreleased section
---------
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
build(deps): bump google.golang.org/protobuf from 1.33.0 to 1.34.0 in /exporters/otlp/otlptrace/otlptracehttp
build(deps): bump codecov/codecov-action from 4.3.0 to 4.3.1
build(deps): bump google.golang.org/protobuf from 1.33.0 to 1.34.0 in /exporters/otlp/otlptrace
build(deps): bump google.golang.org/protobuf from 1.33.0 to 1.34.0 in /exporters/otlp/otlptrace/otlptracegrpc
build(deps): bump google.golang.org/protobuf from 1.33.0 to 1.34.0 in /exporters/prometheus
build(deps): bump golang.org/x/sys from 0.19.0 to 0.20.0 in /sdk
build(deps): bump github.com/golangci/golangci-lint from 1.57.2 to 1.58.0 in /internal/tools
build(deps): bump google.golang.org/protobuf from 1.33.0 to 1.34.0 in /exporters/otlp/otlpmetric/otlpmetrichttp
build(deps): bump google.golang.org/protobuf from 1.33.0 to 1.34.0 in /exporters/otlp/otlplog/otlploghttp
build(deps): bump github.com/openzipkin/zipkin-go from 0.4.2 to 0.4.3 in /exporters/zipkin
build(deps): bump google.golang.org/protobuf from 1.33.0 to 1.34.0 in /exporters/otlp/otlpmetric/otlpmetricgrpc
* Bump versions in versions.yaml
* Prepare stable-v1 for version v1.26.0
* Prepare experimental-metrics for version v0.48.0
* Prepare experimental-logs for version v0.2.0-alpha
* Prepare experimental-schema for version v0.0.9
* Update CHANGELOG
* Unbump experimental-schema
* Update CHANGELOG.md
Co-authored-by: Robert Pająk <pellared@hotmail.com>
---------
Co-authored-by: Robert Pająk <pellared@hotmail.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
* [WIP] Implement the BatchingProcessor
* Add TestExportSync
* Add TestChunker
* Test export error default to ErrorHandler
* Fix lint
* Fix chunk smaller than size error
* Add batch tests
* Fix lint
* Update OnEmit test
Check the len of records in eventually assertion given that is what we
are going to measure.
* Revert unneeded change to BatchingProcessor doc
* Add batch type
* Refactor testing of batching config
The BatchingProcessor is not expected to ultimately contain
configuration fields for queue size or export parameters (see #5093).
This will break TestNewBatchingProcessorConfiguration which tests the
configuration by evaluating the BatchingProcessor directly.
Instead, test the batchingConfig and rename the test to
TestNewBatchingConfig to match what is being tested.
* Implement the BatchingProcessor without polling
* Add TestBatchingProcessor
* Add ConcurrentSafe test
* Expand Shutdown tests
* Test context canceled for ForceFlush
* Refactor batch to queue
* Use exportSync
* Update docs and naming
* Split buffered export to its own type
* Update comments and naming
* Fix lint
* Remove redundant triggered type
* Add interval polling
* Refactor test structure
* Add custom ring implimementation
* Add BenchmarkBatchingProcessor
* Fix merge
* Remove custom ring impl
* Remove BenchmarkBatchingProcessor
* Update dev docs
* Test nil exporter
* Update OnEmit test
Ensure the poll goroutine will completely flush the queue of batches.
* Test RetriggerFlushNonBlocking
* Update ascii diagram
* Fix flaky OnEmit
* Revert unnecessary change to test pkg name
* Use batching term in docs
* Document EnqueueExport
* Return from EnqueueExport if blocked
Do not wait for the enqueue to succeed.
* Do not drop failed flush log records
* Use cancelable ctx in concurrency test
* Fix comments
* Apply feedback
Do not spawn a goroutine for the flush operation.
* Return true from EnqueueExport when stopped
* Update sdk/log/batch.go
Co-authored-by: Robert Pająk <pellared@hotmail.com>
* Remove TODO
* Comment re-trigger in poll
---------
Co-authored-by: Robert Pająk <pellared@hotmail.com>
* Replace Record lim methods with DroppedAttributes
* Add changelog entry
* Add TestRecordDroppedAttributes
* Add TestRecordCompactAttr
* Add an indexPool
* Fix gramatical error
* Apply feedback
Reduce indentation level.
* Apply feedback
Comment compactAttr and deduplicate.
* Deduplicate all attributes when added
* Comment why head is not used
* Clarify comments
* Move TestAllocationLimits to new file
Do not run this test when the race detector is on.
* Comment follow-up task
build(deps): bump golang.org/x/tools from 0.19.0 to 0.20.0 in /internal/tools
build(deps): bump go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp from 0.49.0 to 0.50.0 in /example/dice
build(deps): bump golang.org/x/sys from 0.18.0 to 0.19.0 in /sdk
* Bump versions in versions.yaml
* Prepare stable-v1 for version v1.25.0
* Prepare experimental-metrics for version v0.47.0
* Prepare experimental-logs for version v0.1.0-alpha
* Prepare experimental-schema for version v0.0.8
* Update changelog
* Run go mod tidy
* Update CHANGELOG.md
---------
Co-authored-by: Damien Mathieu <damien.mathieu@elastic.co>
Co-authored-by: Robert Pająk <pellared@hotmail.com>