### Added
- The `IsEmpty` method is added to the `Instrument` type in
`go.opentelemetry.io/otel/sdk/metric`.
This method is used to check if an `Instrument` instance is a
zero-value. (#5431)
- Store and provide the emitted `context.Context` in `ScopeRecords` of
`go.opentelemetry.io/otel/sdk/log/logtest`. (#5468)
- The `go.opentelemetry.io/otel/semconv/v1.26.0` package.
The package contains semantic conventions from the `v1.26.0` version of
the OpenTelemetry Semantic Conventions. (#5476)
- The `AssertRecordEqual` method to
`go.opentelemetry.io/otel/log/logtest` to allow comparison of two log
records in tests. (#5499)
- The `WithHeaders` option to
`go.opentelemetry.io/otel/exporters/zipkin` to allow configuring custom
http headers while exporting spans. (#5530)
### Changed
- `Tracer.Start` in `go.opentelemetry.io/otel/trace/noop` no longer
allocates a span for empty span context. (#5457)
- Upgrade `go.opentelemetry.io/otel/semconv/v1.25.0` to
`go.opentelemetry.io/otel/semconv/v1.26.0` in
`go.opentelemetry.io/otel/example/otel-collector`. (#5490)
- Upgrade `go.opentelemetry.io/otel/semconv/v1.25.0` to
`go.opentelemetry.io/otel/semconv/v1.26.0` in
`go.opentelemetry.io/otel/example/zipkin`. (#5490)
- Upgrade `go.opentelemetry.io/otel/semconv/v1.25.0` to
`go.opentelemetry.io/otel/semconv/v1.26.0` in
`go.opentelemetry.io/otel/exporters/zipkin`. (#5490)
- The exporter no longer exports the deprecated "otel.library.name" or
"otel.library.version" attributes.
- Upgrade `go.opentelemetry.io/otel/semconv/v1.25.0` to
`go.opentelemetry.io/otel/semconv/v1.26.0` in
`go.opentelemetry.io/otel/sdk/resource`. (#5490)
- Upgrade `go.opentelemetry.io/otel/semconv/v1.25.0` to
`go.opentelemetry.io/otel/semconv/v1.26.0` in
`go.opentelemetry.io/otel/sdk/trace`. (#5490)
- `SimpleProcessor.OnEmit` in `go.opentelemetry.io/otel/sdk/log` no
longer allocates a slice which makes it possible to have a
zero-allocation log processing using `SimpleProcessor`. (#5493)
- Use non-generic functions in the `Start` method of
`"go.opentelemetry.io/otel/sdk/trace".Trace` to reduce memory
allocation. (#5497)
- `service.instance.id` is populated for a `Resource` created with
`"go.opentelemetry.io/otel/sdk/resource".Default` with a default value
when `OTEL_GO_X_RESOURCE` is set. (#5520)
- Improve performance of metric instruments in
`go.opentelemetry.io/otel/sdk/metric` by removing unnecessary calls to
`time.Now`. (#5545)
### Fixed
- Log a warning to the OpenTelemetry internal logger when a `Record` in
`go.opentelemetry.io/otel/sdk/log` drops an attribute due to a limit
being reached. (#5376)
- Identify the `Tracer` returned from the global `TracerProvider` in
`go.opentelemetry.io/otel/global` with its schema URL. (#5426)
- Identify the `Meter` returned from the global `MeterProvider` in
`go.opentelemetry.io/otel/global` with its schema URL. (#5426)
- Log a warning to the OpenTelemetry internal logger when a `Span` in
`go.opentelemetry.io/otel/sdk/trace` drops an attribute, event, or link
due to a limit being reached. (#5434)
- Document instrument name requirements in
`go.opentelemetry.io/otel/metric`. (#5435)
- Prevent random number generation data-race for experimental rand
exemplars in `go.opentelemetry.io/otel/sdk/metric`. (#5456)
- Fix counting number of dropped attributes of `Record` in
`go.opentelemetry.io/otel/sdk/log`. (#5464)
- Fix panic in baggage creation when a member contains `0x80` char in
key or value. (#5494)
- Correct comments for the priority of the `WithEndpoint` and
`WithEndpointURL` options and their corresponding environment variables
in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc`.
(#5508)
- Retry trace and span ID generation if it generated an invalid one in
`go.opentelemetry.io/otel/sdk/trace`. (#5514)
- Fix stale timestamps reported by the last-value aggregation. (#5517)
- Indicate the `Exporter` in
`go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp` must be
created by the `New` method. (#5521)
- Improved performance in all `{Bool,Int64,Float64,String}SliceValue`
functions of `go.opentelemetry.io/attributes` by reducing the number of
allocations. (#5549)
Towards https://github.com/open-telemetry/opentelemetry-go/issues/5065
Follow our own docs. From `Processor.Enabled` docs:
> Before modifying a Record, the implementation must use Record.Clone to
create a copy that shares no state with the original.
I was looking at the trace benchmarks, and noticed this one, which says
it tests "span start", but ending the span is included within the data.
So this change removes ending the span from the computation, and adds a
new benchmark which only computes span end.
benchstat for span start:
```
pkg: go.opentelemetry.io/otel/sdk/trace
│ bench-main │ bench-branch │
│ sec/op │ sec/op vs base │
TraceStart-10 725.6n ± 3% 667.2n ± 2% -8.04% (p=0.000 n=10)
│ bench-main │ bench-branch │
│ B/op │ B/op vs base │
TraceStart-10 704.0 ± 0% 704.0 ± 0% ~ (p=1.000 n=10) ¹
¹ all samples are equal
│ bench-main │ bench-branch │
│ allocs/op │ allocs/op vs base │
TraceStart-10 14.00 ± 0% 14.00 ± 0% ~ (p=1.000 n=10) ¹
¹ all samples are equal
```
Benchmark for span end:
```
BenchmarkSpanEnd-10 16486819 147.7 ns/op 0 B/op 0 allocs/op
```
This adds a benchmark to create a logger from a logger provider.
Related: #5054.
```
BenchmarkLoggerProviderLogger-10 3145390 548.8 ns/op 330 B/op 1 allocs/op
```
This benchmark currently tests two rather different methods within the
same loop, which makes it hard to see what could be causing a
performance degradation.
Related: #5054.
```
BenchmarkSetAddAttributes/SetAttributes-10 14066331 82.80 ns/op 48 B/op 1 allocs/op
BenchmarkSetAddAttributes/AddAttributes-10 19333711 114.7 ns/op 0 B/op 0 allocs/op
```
As discussed in a previous SIG meeting, this PR adds support for setting
a default value for
[`service.instance.id`](https://github.com/open-telemetry/semantic-conventions/tree/main/docs/resource#service-experimental)
according to semantic conventions:
> Implementations, such as SDKs, are recommended to generate a random
Version 1 or Version 4 [RFC 4122](https://www.ietf.org/rfc/rfc4122.txt)
UUID, but are free to use an inherent unique ID as the source of this
value if stability is desirable. In that case, the ID SHOULD be used as
source of a UUID Version 5 and SHOULD use the following UUID as the
namespace: `4d63009a-8d0f-11ee-aad7-4c796ed8e320`.
This PR follows the recommendation and populates `service.instance.id`
with a random Version 4 UUID. The functionality is guarded by the
`OTEL_GO_X_RESOURCE` feature flag environment variable.
There are plans to declare `service.instance.id` stable and also make it
a required attribute (similar to `service.name`). Once this happens, the
functionality can be made available regardless of whether
`OTEL_GO_X_RESOURCE` is set.
Closes
https://github.com/open-telemetry/opentelemetry-go-contrib/issues/5423
---------
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: Tyler Yahn <codingalias@gmail.com>
This adds the [unparam](https://github.com/mvdan/unparam) linter.
Co-authored-by: Sam Xie <sam@samxie.me>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This adds the unconvert linter, and fixes every new issue related to it.
Co-authored-by: Sam Xie <sam@samxie.me>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
# Description
Fix#5462
## Type of change
add a loop to generate the spanID and traceID.
the loop will not stop until it generate a valid ID
- [x] Bug fix (non-breaking change which fixes an issue)
---------
Co-authored-by: Damien Mathieu <42@dmathieu.com>
Co-authored-by: Robert Pająk <pellared@hotmail.com>
The reason for this improvement (apart that, in general, it is good to
have better performance) is there may be good use case to use a
`SimpleProcessor` to emit logs efficiently to standard output. It could
be one of the most efficient solutions (from application performance
perspective) and thanks to such configuration the user would not lose
any logs if the application suddenly crashes. For instance, a useful
configuration could be a simple processor with an OTLP file exporter
(https://github.com/open-telemetry/opentelemetry-go/issues/5408).
I think we might consider changing the following portion of
`SimpleProcessor` documentation (but I would prefer to do it as separate
PR):
> // This Processor is not recommended for production use. The
synchronous
// nature of this Processor make it good for testing, debugging, or
// showing examples of other features, but it can be slow and have a
high
// computation resource usage overhead. [NewBatchProcessor] is
recommended
// for production use instead.
```
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/log
cpu: Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz
│ old.txt │ new.txt │
│ sec/op │ sec/op vs base │
Processor/Simple-16 449.4n ± 7% 156.2n ± 5% -65.25% (p=0.000 n=10)
Processor/ModifyTimestampSimple-16 468.0n ± 6% 171.3n ± 15% -63.40% (p=0.000 n=10)
Processor/ModifyAttributesSimple-16 515.8n ± 3% 233.2n ± 8% -54.77% (p=0.000 n=10)
geomean 476.9n 184.1n -61.40%
│ old.txt │ new.txt │
│ B/op │ B/op vs base │
Processor/Simple-16 417.0 ± 0% 0.0 ± 0% -100.00% (p=0.000 n=10)
Processor/ModifyTimestampSimple-16 417.0 ± 0% 0.0 ± 0% -100.00% (p=0.000 n=10)
Processor/ModifyAttributesSimple-16 465.00 ± 0% 48.00 ± 0% -89.68% (p=0.000 n=10)
geomean 432.4 ? ¹ ²
¹ summaries must be >0 to compute geomean
² ratios must be >0 to compute geomean
│ old.txt │ new.txt │
│ allocs/op │ allocs/op vs base │
Processor/Simple-16 1.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10)
Processor/ModifyTimestampSimple-16 1.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10)
Processor/ModifyAttributesSimple-16 2.000 ± 0% 1.000 ± 0% -50.00% (p=0.000 n=10)
geomean 1.260 ? ¹ ²
¹ summaries must be >0 to compute geomean
² ratios must be >0 to compute geomean
```
---------
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Add the `x` package to handle experimental feature flagging within the
go.opentelemetry.io/otel/sdk module. Currently this only supports
enabling experimental resource semantic conventions.
Resolve#5436
cc @pyohannes
---------
Co-authored-by: Sam Xie <sam@samxie.me>
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>