1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-28 21:09:17 +02:00
Commit Graph

961 Commits

Author SHA1 Message Date
renovate[bot]
4875735fd8
fix(deps): update module github.com/golangci/golangci-lint to v1.60.2 (#5711)
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[github.com/golangci/golangci-lint](https://togithub.com/golangci/golangci-lint)
| `v1.60.1` -> `v1.60.2` |
[![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fgolangci%2fgolangci-lint/v1.60.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2fgolangci%2fgolangci-lint/v1.60.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2fgolangci%2fgolangci-lint/v1.60.1/v1.60.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fgolangci%2fgolangci-lint/v1.60.1/v1.60.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>golangci/golangci-lint
(github.com/golangci/golangci-lint)</summary>

###
[`v1.60.2`](https://togithub.com/golangci/golangci-lint/compare/v1.60.1...v1.60.2)

[Compare
Source](https://togithub.com/golangci/golangci-lint/compare/v1.60.1...v1.60.2)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View the
[repository job
log](https://developer.mend.io/github/open-telemetry/opentelemetry-go).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4yNi4xIiwidXBkYXRlZEluVmVyIjoiMzguMjYuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiU2tpcCBDaGFuZ2Vsb2ciLCJkZXBlbmRlbmNpZXMiXX0=-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Tyler Yahn <codingalias@gmail.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
2024-08-23 08:07:25 -07:00
Tyler Yahn
002c0a4c03
Move log.Processor.Enabled to independent FilterProcessor interfaced type (#5692)
Closes #5425 

Our current log `Processor` interface contains more functionality than
the [OTel
spec](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/sdk.md#logrecordprocessor-operations).
The additional functionality allows processors to report back to the API
if a Record should be constructed and emitted or not, which is quite
helpful[^1][^2][^3][^4][^5].

This removes the `Enabled` method from the `Processor` type. It adds
this functionality a new optional and experimental `FilterProcessor`
interface type. The logger and provider are updated to check for this
optional interface to be implemented with the configured processors and
uses them to back the `Logger.Enabled` method, preserving existing
functionality.

By making this change:

- The `Processor` interface is now compliant with the OTel spec and does
not contain any additional unspecified behavior.
- All `Processor` implementations are no longer required to implement an
`Enabled` method. The default, when they do not implement this method,
is to assume they are enabled.

### Benchmark

```terminal
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/log
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
                │   old.txt    │              new7.txt               │
                │    sec/op    │   sec/op     vs base                │
LoggerEnabled-8   133.30n ± 3%   32.36n ± 3%  -75.72% (p=0.000 n=10)

                │  old.txt   │            new7.txt            │
                │    B/op    │    B/op     vs base            │
LoggerEnabled-8   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal

                │  old.txt   │            new7.txt            │
                │ allocs/op  │ allocs/op   vs base            │
LoggerEnabled-8   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal
```

This is a significant performance improvement due to the `Record` no
longer being converted from the API version to the SDK version.

[^1]: https://pkg.go.dev/go.opentelemetry.io/contrib/processors/minsev
[^2]:
https://pkg.go.dev/go.opentelemetry.io/otel/sdk/log#BatchProcessor.Enabled
[^3]:
https://pkg.go.dev/go.opentelemetry.io/otel/sdk/log#SimpleProcessor.Enabled
[^4]:
af75717ac4/bridges/otelslog/handler.go (L206-L211)
[^5]:
d0309ddd8c/bridges/otelzap/core.go (L142-L146)

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
Co-authored-by: Sam Xie <sam@samxie.me>
2024-08-22 09:12:23 -07:00
Damien Mathieu
083d03e605
Add support for go 1.23 (#5720)
Go 1.23 was released a few days ago.
https://go.dev/blog/go1.23

This also upgrades golangci-lint (and fixes new issues), since it
appears 1.59 doesn't work nicely with Go 1.23.

---------

Co-authored-by: Sam Xie <sam@samxie.me>
2024-08-21 09:37:56 +02:00
Tyler Yahn
c4ebcaa08d
Ensure exported struct in sdk/log are not comparable (#5693)
Ensure the `Record` and `Provider` continue to be non-comparable.

Restrict `BatchProcessor` and `SimpleProcessor` to be non-comparable.

There is no obvious reason an end-user will need to compare these types,
and we want to keep the possibility of changing the internals without
changing this behavior.

if comparability is required by end-users in the future we can add
`Equal(other T)` methods in the future.
2024-08-09 07:31:42 -07:00
Robert Pająk
69e235829e
sdk/log: SimpleProcessor synchronizes OnEmit calls (#5666)
From
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/sdk.md#export:

> `Export` will never be called concurrently for the same exporter
instance.

From our SDK perspective this change will make
https://pkg.go.dev/go.opentelemetry.io/otel/exporters/stdout/stdoutlog
concurrent-safe when used with the simple processor. Before the change,
there can be multiple goroutines calling `Write` in parallel (via
`json.Encoder.Encode`).

### Remarks

[Maybe we should simply state that "whole" exporter implementation does
not need to be
concurrent-safe?](https://github.com/open-telemetry/opentelemetry-specification/pull/4173#discussion_r1699958752)
However:
1. we would need to make complex changes in `BatchExporter` to
synchronize the `Export`, `Shutdown`, `ForceFlush` calls
2. we would need to update all exporters (remove synchronization) and
simple exporter (add locks to `Shutdown`, `ForceFlush`)
3. I am 100% not sure if this would be compliant with the specification
- I think it would be complaint because we would simply give stronger
safety-measures


We should probably discuss it separately, but I wanted to highlight my
though process.
Even if we decide that simple and batch processors to synchronize all
calls then I would prefer to address it in a separate PR.

Related spec clarification PR:
-
https://github.com/open-telemetry/opentelemetry-specification/pull/4173
2024-08-09 08:40:39 +02:00
renovate[bot]
a5d1ec0edf
chore(deps): update module golang.org/x/sys to v0.24.0 (#5700)
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| golang.org/x/sys | `v0.23.0` -> `v0.24.0` |
[![age](https://developer.mend.io/api/mc/badges/age/go/golang.org%2fx%2fsys/v0.24.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/go/golang.org%2fx%2fsys/v0.24.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/go/golang.org%2fx%2fsys/v0.23.0/v0.24.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/go/golang.org%2fx%2fsys/v0.23.0/v0.24.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these
updates again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View the
[repository job
log](https://developer.mend.io/github/open-telemetry/opentelemetry-go).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4yMC4xIiwidXBkYXRlZEluVmVyIjoiMzguMjAuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiU2tpcCBDaGFuZ2Vsb2ciLCJkZXBlbmRlbmNpZXMiXX0=-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-08-08 19:01:15 -07:00
Robert Pająk
5edfc73c67
Fix interfaces doc formatting (#5658)
The methods should be separated by lines if there are GoDoc comments.
2024-08-05 21:14:00 +02:00
renovate[bot]
ef08fb9c65
chore(deps): update module golang.org/x/sys to v0.23.0 (#5669)
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| golang.org/x/sys | `v0.22.0` -> `v0.23.0` |
[![age](https://developer.mend.io/api/mc/badges/age/go/golang.org%2fx%2fsys/v0.23.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/go/golang.org%2fx%2fsys/v0.23.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/go/golang.org%2fx%2fsys/v0.22.0/v0.23.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/go/golang.org%2fx%2fsys/v0.22.0/v0.23.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these
updates again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View the
[repository job
log](https://developer.mend.io/github/open-telemetry/opentelemetry-go).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJTa2lwIENoYW5nZWxvZyIsImRlcGVuZGVuY2llcyJdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-08-05 07:12:28 -07:00
Robert Pająk
f079b03364
sdk/log: SimpleProcessor to not panic for zero value (#5665) 2024-08-04 12:35:58 +02:00
Robert Pająk
8e8ad092cc
sdk/log: Processor.OnEmit accetps a Record pointer (#5636)
## What

Change `Processor.OnEmit` methods to accept a record pointer.

## Why

Fixes https://github.com/open-telemetry/opentelemetry-go/issues/5219

This would be specification compliant according to discussions around
https://github.com/open-telemetry/opentelemetry-specification/pull/4067

This is inline of how processors Go span processors works and how log
processors work in other languages.

If the performance (an additional heap allocation during log processing)
would occur to be a significant problem for some users, we have at few
possible solutions:

1. Utilize PGO which may also lead to decreasing heap allocations
(sources:
https://landontclipp.github.io/blog/2023/08/25/profile-guided-optimizations-in-go/#devirtualization,
https://andrewwphillips.github.io/blog/pgo.html). Currently it does not
but I expect it may change in future.
2. Improve the Go compilers escape analysis (related to previous point)
3. introduce new "chaining processor" which can be also desirable in
other languages

## Benchstat

`old` is from `main`.
`new` is from current branch.

`new-pgo` is from current branch with PGO optimization. I first run
benchmarks to generate a CPU profile using `go test -run=^$ -bench=.
-count=10 -cpuprofile default.pgo` and then I rerun the tests with PGO.
Currently, the number of heap allocations is the same.

```
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                │              new-pgo.txt              │
                                  │    sec/op     │    sec/op     vs base                 │    sec/op     vs base                 │
BatchProcessorOnEmit-16              402.7n ± 18%   382.0n ±  7%         ~ (p=0.247 n=10)   376.7n ± 14%         ~ (p=0.210 n=10)
Processor/Simple-16                  350.9n ±  9%   782.5n ±  6%  +123.00% (p=0.000 n=10)   755.1n ±  5%  +115.19% (p=0.000 n=10)
Processor/Batch-16                   1.333µ ± 15%   1.497µ ± 11%   +12.27% (p=0.000 n=10)   1.528µ ±  8%   +14.63% (p=0.000 n=10)
Processor/SetTimestampSimple-16      329.5n ± 15%   711.6n ±  4%  +115.93% (p=0.000 n=10)   721.9n ±  5%  +119.04% (p=0.000 n=10)
Processor/SetTimestampBatch-16       1.163µ ±  2%   1.524µ ±  3%   +31.03% (p=0.000 n=10)   1.461µ ±  5%   +25.57% (p=0.000 n=10)
Processor/AddAttributesSimple-16     408.7n ±  3%   810.1n ±  4%   +98.21% (p=0.000 n=10)   830.1n ±  4%  +103.11% (p=0.000 n=10)
Processor/AddAttributesBatch-16      1.270µ ±  2%   1.623µ ±  4%   +27.71% (p=0.000 n=10)   1.597µ ±  7%   +25.66% (p=0.000 n=10)
Processor/SetAttributesSimple-16     436.2n ± 10%   796.1n ±  3%   +82.50% (p=0.000 n=10)   817.6n ±  4%   +87.43% (p=0.000 n=10)
Processor/SetAttributesBatch-16      1.202µ ±  2%   1.552µ ±  2%   +29.06% (p=0.000 n=10)   1.659µ ± 11%   +37.96% (p=0.000 n=10)
LoggerNewRecord/5_attributes-16      366.6n ±  3%   363.7n ±  7%         ~ (p=0.952 n=10)   426.2n ±  7%   +16.27% (p=0.000 n=10)
LoggerNewRecord/10_attributes-16     1.711µ ±  2%   1.909µ ± 18%   +11.57% (p=0.000 n=10)   2.077µ ± 10%   +21.39% (p=0.000 n=10)
LoggerProviderLogger-16              650.1n ±  4%   690.1n ±  8%    +6.15% (p=0.019 n=10)   737.6n ± 13%   +13.47% (p=0.004 n=10)
WalkAttributes/1_attributes-16       5.264n ± 12%   5.510n ±  8%         ~ (p=0.812 n=10)   5.865n ±  5%   +11.41% (p=0.011 n=10)
WalkAttributes/10_attributes-16      5.440n ±  8%   5.881n ±  7%    +8.12% (p=0.004 n=10)   6.104n ±  7%   +12.21% (p=0.005 n=10)
WalkAttributes/100_attributes-16     5.403n ±  9%   5.894n ±  9%    +9.10% (p=0.029 n=10)   5.783n ±  6%         ~ (p=0.052 n=10)
WalkAttributes/1000_attributes-16    5.196n ±  4%   5.860n ±  8%   +12.79% (p=0.000 n=10)   5.981n ± 13%   +15.13% (p=0.002 n=10)
SetAddAttributes/SetAttributes-16    181.2n ± 14%   208.1n ± 12%   +14.85% (p=0.005 n=10)   209.9n ± 11%   +15.87% (p=0.007 n=10)
SetAddAttributes/AddAttributes-16    156.7n ± 14%   161.1n ± 16%         ~ (p=0.190 n=10)   165.5n ± 15%         ~ (p=0.315 n=10)
SimpleProcessorOnEmit-16            11.775n ± 10%   9.027n ± 17%   -23.33% (p=0.000 n=10)   9.389n ± 18%   -20.26% (p=0.002 n=10)
geomean                              169.1n         209.6n         +23.98%                  215.5n         +27.48%

                        │     old.txt     │               new.txt                │              new-pgo.txt              │
                        │       B/s       │     B/s       vs base                │      B/s       vs base                │
BatchProcessorOnEmit-16   1004.39Mi ± 15%   79.88Mi ± 7%  -92.05% (p=0.000 n=10)   81.06Mi ± 12%  -91.93% (p=0.000 n=10)

                                  │   old.txt    │                new.txt                 │               new-pgo.txt               │
                                  │     B/op     │    B/op      vs base                   │     B/op      vs base                   │
BatchProcessorOnEmit-16             0.000 ± 0%      0.000 ± 0%         ~ (p=1.000 n=10) ¹    0.000 ±  0%         ~ (p=1.000 n=10) ¹
Processor/Simple-16                   0.0 ± 0%      417.0 ± 0%         ? (p=0.000 n=10)      417.0 ±  0%         ? (p=0.000 n=10)
Processor/Batch-16                  621.5 ± 2%     1057.5 ± 1%   +70.15% (p=0.000 n=10)     1064.5 ±  1%   +71.28% (p=0.000 n=10)
Processor/SetTimestampSimple-16       0.0 ± 0%      417.0 ± 0%         ? (p=0.000 n=10)      418.0 ±  0%         ? (p=0.000 n=10)
Processor/SetTimestampBatch-16      626.5 ± 3%     1049.5 ± 1%   +67.52% (p=0.000 n=10)     1057.5 ±  2%   +68.79% (p=0.000 n=10)
Processor/AddAttributesSimple-16      0.0 ± 0%      417.0 ± 0%         ? (p=0.000 n=10)      417.0 ±  0%         ? (p=0.000 n=10)
Processor/AddAttributesBatch-16     616.5 ± 3%     1053.0 ± 2%   +70.80% (p=0.000 n=10)     1048.5 ±  2%   +70.07% (p=0.000 n=10)
Processor/SetAttributesSimple-16    48.00 ± 0%     466.00 ± 0%  +870.83% (p=0.000 n=10)     466.00 ±  0%  +870.83% (p=0.000 n=10)
Processor/SetAttributesBatch-16     648.0 ± 3%     1089.5 ± 1%   +68.13% (p=0.000 n=10)     1087.5 ±  4%   +67.82% (p=0.000 n=10)
LoggerNewRecord/5_attributes-16     0.000 ± 0%      0.000 ± 0%         ~ (p=1.000 n=10) ¹    0.000 ±  0%         ~ (p=1.000 n=10) ¹
LoggerNewRecord/10_attributes-16    610.0 ± 0%      610.0 ± 0%         ~ (p=1.000 n=10) ¹    610.0 ±  0%         ~ (p=1.000 n=10) ¹
LoggerProviderLogger-16             354.5 ± 6%      368.0 ± 7%         ~ (p=0.288 n=10)      391.0 ± 29%         ~ (p=0.239 n=10)
WalkAttributes/1_attributes-16      0.000 ± 0%      0.000 ± 0%         ~ (p=1.000 n=10) ¹    0.000 ±  0%         ~ (p=1.000 n=10) ¹
WalkAttributes/10_attributes-16     0.000 ± 0%      0.000 ± 0%         ~ (p=1.000 n=10) ¹    0.000 ±  0%         ~ (p=1.000 n=10) ¹
WalkAttributes/100_attributes-16    0.000 ± 0%      0.000 ± 0%         ~ (p=1.000 n=10) ¹    0.000 ±  0%         ~ (p=1.000 n=10) ¹
WalkAttributes/1000_attributes-16   0.000 ± 0%      0.000 ± 0%         ~ (p=1.000 n=10) ¹    0.000 ±  0%         ~ (p=1.000 n=10) ¹
SetAddAttributes/SetAttributes-16   48.00 ± 0%      48.00 ± 0%         ~ (p=1.000 n=10) ¹    48.00 ±  0%         ~ (p=1.000 n=10) ¹
SetAddAttributes/AddAttributes-16   0.000 ± 0%      0.000 ± 0%         ~ (p=1.000 n=10) ¹    0.000 ±  0%         ~ (p=1.000 n=10) ¹
SimpleProcessorOnEmit-16            0.000 ± 0%      0.000 ± 0%         ~ (p=1.000 n=10) ¹    0.000 ±  0%         ~ (p=1.000 n=10) ¹
geomean                                        ²                ?                       ²                 ?                       ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                                  │   old.txt    │                new.txt                │              new-pgo.txt              │
                                  │  allocs/op   │ allocs/op   vs base                   │ allocs/op   vs base                   │
BatchProcessorOnEmit-16             0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=10) ¹   0.000 ± 0%         ~ (p=1.000 n=10) ¹
Processor/Simple-16                 0.000 ± 0%     1.000 ± 0%         ? (p=0.000 n=10)     1.000 ± 0%         ? (p=0.000 n=10)
Processor/Batch-16                  0.000 ± 0%     1.000 ± 0%         ? (p=0.000 n=10)     1.000 ± 0%         ? (p=0.000 n=10)
Processor/SetTimestampSimple-16     0.000 ± 0%     1.000 ± 0%         ? (p=0.000 n=10)     1.000 ± 0%         ? (p=0.000 n=10)
Processor/SetTimestampBatch-16      0.000 ± 0%     1.000 ± 0%         ? (p=0.000 n=10)     1.000 ± 0%         ? (p=0.000 n=10)
Processor/AddAttributesSimple-16    0.000 ± 0%     1.000 ± 0%         ? (p=0.000 n=10)     1.000 ± 0%         ? (p=0.000 n=10)
Processor/AddAttributesBatch-16     0.000 ± 0%     1.000 ± 0%         ? (p=0.000 n=10)     1.000 ± 0%         ? (p=0.000 n=10)
Processor/SetAttributesSimple-16    1.000 ± 0%     2.000 ± 0%  +100.00% (p=0.000 n=10)     2.000 ± 0%  +100.00% (p=0.000 n=10)
Processor/SetAttributesBatch-16     1.000 ± 0%     2.000 ± 0%  +100.00% (p=0.000 n=10)     2.000 ± 0%  +100.00% (p=0.000 n=10)
LoggerNewRecord/5_attributes-16     0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=10) ¹   0.000 ± 0%         ~ (p=1.000 n=10) ¹
LoggerNewRecord/10_attributes-16    4.000 ± 0%     4.000 ± 0%         ~ (p=1.000 n=10) ¹   4.000 ± 0%         ~ (p=1.000 n=10) ¹
LoggerProviderLogger-16             1.000 ± 0%     1.000 ± 0%         ~ (p=1.000 n=10) ¹   1.000 ± 0%         ~ (p=1.000 n=10) ¹
WalkAttributes/1_attributes-16      0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=10) ¹   0.000 ± 0%         ~ (p=1.000 n=10) ¹
WalkAttributes/10_attributes-16     0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=10) ¹   0.000 ± 0%         ~ (p=1.000 n=10) ¹
WalkAttributes/100_attributes-16    0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=10) ¹   0.000 ± 0%         ~ (p=1.000 n=10) ¹
WalkAttributes/1000_attributes-16   0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=10) ¹   0.000 ± 0%         ~ (p=1.000 n=10) ¹
SetAddAttributes/SetAttributes-16   1.000 ± 0%     1.000 ± 0%         ~ (p=1.000 n=10) ¹   1.000 ± 0%         ~ (p=1.000 n=10) ¹
SetAddAttributes/AddAttributes-16   0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=10) ¹   0.000 ± 0%         ~ (p=1.000 n=10) ¹
SimpleProcessorOnEmit-16            0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=10) ¹   0.000 ± 0%         ~ (p=1.000 n=10) ¹
geomean                                        ²               ?                       ²               ?                       ²
¹ all samples are equal
² summaries must be >0 to compute geomean
```
2024-08-01 10:13:43 +02:00
Robert Pająk
e2b0751cd1
[chore] Add asasalint linter (#5653)
Add https://golangci-lint.run/usage/linters/#asasalint linter.

Fix the bugs detected by the linter.

PR in Contrib:
https://github.com/open-telemetry/opentelemetry-go-contrib/pull/5957
2024-07-31 08:41:11 +02:00
Tanaka Naoto
16a4e33276
typo: fix docs (#5649)
Fixed the typo `PeroidicExporter` in reader.go

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
2024-07-26 09:41:00 -07:00
Damien Mathieu
3e17ef99d6
Allow relying on InstrumentationScope in SpanStub and fix remaining deprecation issues (#5627)
Rather than the deprecated InstrumentationLibrary

This is a replacement for
https://github.com/open-telemetry/opentelemetry-go/pull/3104, as after
this, there is no usage of `instrumentation.Library` within the SDK
anymore.

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
Co-authored-by: Sam Xie <sam@samxie.me>
2024-07-24 09:33:07 +02:00
Damien Mathieu
ae6d29f4b1
Refactor Batch Processor benchmark to really test OnEnd (#5600)
This benchmark was not only testing the batch processor, since it was
starting a span, and ending it.
So the entire process of recording span was being accounted.

This changes the benchmark to only account for the batch processor being
tested, not the entire stack.

Before:
```
pkg: go.opentelemetry.io/otel/sdk/trace
BenchmarkSpanProcessor-10                         137320              8696 ns/op           11184 B/op        155 allocs/op
BenchmarkSpanProcessorVerboseLogging-10           135483              8881 ns/op           11184 B/op        155 allocs/op
PASS
ok      go.opentelemetry.io/otel/sdk/trace      3.984s
```

After:
```
pkg: go.opentelemetry.io/otel/sdk/trace
BenchmarkSpanProcessorOnEnd/batch:_10,_spans:_10-10              6055572               173.2 ns/op             0 B/op          0 allocs/op
BenchmarkSpanProcessorOnEnd/batch:_10,_spans:_100-10              684236              1733 ns/op               0 B/op          0 allocs/op
BenchmarkSpanProcessorOnEnd/batch:_100,_spans:_10-10             6930391               173.8 ns/op             0 B/op          0 allocs/op
BenchmarkSpanProcessorOnEnd/batch:_100,_spans:_100-10             677128              1731 ns/op               0 B/op          0 allocs/op
BenchmarkSpanProcessorVerboseLogging-10                           128823              9318 ns/op           11184 B/op        155 allocs/op
PASS
ok      go.opentelemetry.io/otel/sdk/trace      6.763s
```

I haven't touched the verbose logging benchmark, as I suppose a
benchmark with verbose logging could actually benefit from the entire
stack.
I also feel one benchmark testing the entire stack up to there could be
nice.
2024-07-16 09:22:04 +02:00
David Ashpole
9535f08920
Add comment to other observable instruments about repeated creation with callbacks (#5606)
In https://github.com/open-telemetry/opentelemetry-go/pull/4820, I only
added a comment describing the behavior to `Int64ObservableCounter`, but
forgot other instruments. This adds the comment to all observable
instruments.

Fixes https://github.com/open-telemetry/opentelemetry-go/issues/5561

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
2024-07-12 11:45:51 -07:00
Robert Pająk
5881fe708b
sdk/log: Package documentation (#5609)
Fixes https://github.com/open-telemetry/opentelemetry-go/issues/5065

Based on https://pkg.go.dev/go.opentelemetry.io/otel/sdk/metric

---------

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
2024-07-12 17:58:54 +02:00
Robert Pająk
d595dab76f
sdk/log: Simple processor may be useful for production (#5578)
Update the design doc:
- describe that minimizing the amount of the heap allocation is one of
the design goals
- provide more usage examples

Moreover update the docs to not discourage using a simple processor from
production. It would be good if the user would use it e.g. with an
[user_events](https://docs.kernel.org/trace/user_events.html),
[LLTng](https://lttng.org/docs/v2.13/#doc-tracing-your-own-user-application)
or
[ETW](https://learn.microsoft.com/en-us/windows/win32/etw/about-event-tracing)
exporter. However, we recommend using a batch processor when using OTLP
over HTTP or gRPC exporters.
2024-07-11 20:06:19 +02:00
Robert Pająk
d6aa213a7e
sdk/log: Refine BenchmarkProcessor (#5607)
Add a benchmark that shows that a processor that adds an attribute may
not introduce a heap allocation (as long as the log record still has <=
5 attributes).
2024-07-11 19:51:25 +02:00
Robert Pająk
d5c3319720
sdk/log: Add package example (#5579)
Towards https://github.com/open-telemetry/opentelemetry-go/issues/5065

Co-authored-by: Sam Xie <sam@samxie.me>
2024-07-06 13:07:29 +02:00
renovate[bot]
5e3499c1f3
chore(deps): update module golang.org/x/sys to v0.22.0 (#5576) 2024-07-05 09:28:05 +02:00
Tyler Yahn
81216fb002
Releases v1.28.0/v0.50.0/v0.4.0 (#5569)
### 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)
2024-07-02 13:29:45 -07:00
David Ashpole
0485de287e
Move time.Now call into exemplar reservoir to improve performance (#5545)
Part of addressing
https://github.com/open-telemetry/opentelemetry-go/issues/5542.

### Motivation

This removes the `time.Now()` call from filtered-out Exemplars by only
invoking `time.Now()` after the filtering decision is made. This
improvement is especially noticeable for measurements without any
attributes.

```
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/metric
cpu: AMD EPYC 7B12
                                                                 │   old.txt    │                new.txt                │
                                                                 │    sec/op    │   sec/op     vs base                  │
SyncMeasure/NoView/Int64Counter/Attributes/0-24                    158.20n ± 4%   99.83n ± 1%  -36.90% (p=0.000 n=10)
SyncMeasure/NoView/Int64Counter/Attributes/1-24                     333.3n ± 4%   274.8n ± 1%  -17.55% (p=0.000 n=10)
SyncMeasure/NoView/Int64Counter/Attributes/10-24                    1.640µ ± 1%   1.600µ ± 1%   -2.41% (p=0.000 n=10)
SyncMeasure/NoView/Float64Counter/Attributes/0-24                   159.0n ± 3%   101.3n ± 0%  -36.27% (p=0.000 n=10)
SyncMeasure/NoView/Float64Counter/Attributes/1-24                   340.0n ± 2%   272.0n ± 1%  -20.00% (p=0.000 n=10)
SyncMeasure/NoView/Float64Counter/Attributes/10-24                  1.661µ ± 1%   1.597µ ± 0%   -3.85% (p=0.000 n=10)
SyncMeasure/NoView/Int64UpDownCounter/Attributes/0-24               159.8n ± 1%   103.1n ± 0%  -35.50% (p=0.000 n=10)
SyncMeasure/NoView/Int64UpDownCounter/Attributes/1-24               339.5n ± 1%   273.1n ± 0%  -19.57% (p=0.000 n=10)
SyncMeasure/NoView/Int64UpDownCounter/Attributes/10-24              1.656µ ± 0%   1.589µ ± 0%   -4.05% (p=0.000 n=10)
SyncMeasure/NoView/Float64UpDownCounter/Attributes/0-24             159.3n ± 2%   100.8n ± 0%  -36.74% (p=0.000 n=10)
SyncMeasure/NoView/Float64UpDownCounter/Attributes/1-24             337.9n ± 2%   271.8n ± 1%  -19.55% (p=0.000 n=10)
SyncMeasure/NoView/Float64UpDownCounter/Attributes/10-24            1.657µ ± 0%   1.593µ ± 1%   -3.83% (p=0.000 n=10)
SyncMeasure/NoView/Int64Histogram/Attributes/0-24                  144.65n ± 4%   89.38n ± 0%  -38.21% (p=0.000 n=10)
SyncMeasure/NoView/Int64Histogram/Attributes/1-24                   235.7n ± 2%   183.5n ± 0%  -22.15% (p=0.000 n=10)
SyncMeasure/NoView/Int64Histogram/Attributes/10-24                  900.8n ± 1%   836.8n ± 0%   -7.10% (p=0.000 n=10)
SyncMeasure/NoView/Float64Histogram/Attributes/0-24                145.60n ± 5%   93.48n ± 1%  -35.80% (p=0.000 n=10)
SyncMeasure/NoView/Float64Histogram/Attributes/1-24                 240.9n ± 1%   183.0n ± 0%  -24.06% (p=0.000 n=10)
SyncMeasure/NoView/Float64Histogram/Attributes/10-24                905.6n ± 1%   826.3n ± 0%   -8.76% (p=0.000 n=10)
SyncMeasure/DropView/Int64Counter/Attributes/0-24                   20.33n ± 0%   20.35n ± 0%        ~ (p=0.302 n=10)
SyncMeasure/DropView/Int64Counter/Attributes/1-24                   26.46n ± 0%   26.45n ± 1%        ~ (p=0.868 n=10)
SyncMeasure/DropView/Int64Counter/Attributes/10-24                  26.50n ± 0%   26.47n ± 0%        ~ (p=0.208 n=10)
SyncMeasure/DropView/Float64Counter/Attributes/0-24                 20.34n ± 1%   20.27n ± 0%   -0.34% (p=0.009 n=10)
SyncMeasure/DropView/Float64Counter/Attributes/1-24                 26.55n ± 0%   26.60n ± 1%        ~ (p=0.109 n=10)
SyncMeasure/DropView/Float64Counter/Attributes/10-24                26.59n ± 1%   26.57n ± 1%        ~ (p=0.926 n=10)
SyncMeasure/DropView/Int64UpDownCounter/Attributes/0-24             20.38n ± 1%   20.38n ± 0%        ~ (p=0.725 n=10)
SyncMeasure/DropView/Int64UpDownCounter/Attributes/1-24             26.39n ± 0%   26.44n ± 0%        ~ (p=0.238 n=10)
SyncMeasure/DropView/Int64UpDownCounter/Attributes/10-24            26.52n ± 0%   26.42n ± 0%   -0.36% (p=0.049 n=10)
SyncMeasure/DropView/Float64UpDownCounter/Attributes/0-24           20.30n ± 0%   20.25n ± 0%        ~ (p=0.196 n=10)
SyncMeasure/DropView/Float64UpDownCounter/Attributes/1-24           26.57n ± 0%   26.54n ± 1%        ~ (p=0.540 n=10)
SyncMeasure/DropView/Float64UpDownCounter/Attributes/10-24          26.57n ± 0%   26.51n ± 1%        ~ (p=0.643 n=10)
SyncMeasure/DropView/Int64Histogram/Attributes/0-24                 20.37n ± 0%   20.36n ± 1%        ~ (p=1.000 n=10)
SyncMeasure/DropView/Int64Histogram/Attributes/1-24                 26.41n ± 0%   26.50n ± 0%   +0.32% (p=0.007 n=10)
SyncMeasure/DropView/Int64Histogram/Attributes/10-24                26.44n ± 0%   26.55n ± 1%   +0.42% (p=0.012 n=10)
SyncMeasure/DropView/Float64Histogram/Attributes/0-24               20.30n ± 0%   20.45n ± 0%   +0.74% (p=0.000 n=10)
SyncMeasure/DropView/Float64Histogram/Attributes/1-24               26.52n ± 0%   26.48n ± 0%        ~ (p=0.127 n=10)
SyncMeasure/DropView/Float64Histogram/Attributes/10-24              26.55n ± 0%   26.48n ± 0%   -0.26% (p=0.002 n=10)
SyncMeasure/AttrFilterView/Int64Counter/Attributes/0-24             170.5n ± 2%   110.8n ± 0%  -35.03% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Int64Counter/Attributes/1-24             402.5n ± 1%   331.5n ± 1%  -17.64% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Int64Counter/Attributes/10-24            1.363µ ± 1%   1.281µ ± 1%   -6.02% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Float64Counter/Attributes/0-24           170.6n ± 1%   111.5n ± 1%  -34.64% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Float64Counter/Attributes/1-24           397.1n ± 1%   335.9n ± 0%  -15.41% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Float64Counter/Attributes/10-24          1.371µ ± 1%   1.279µ ± 1%   -6.71% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Int64UpDownCounter/Attributes/0-24       170.1n ± 1%   112.2n ± 0%  -34.09% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Int64UpDownCounter/Attributes/1-24       397.5n ± 1%   330.2n ± 0%  -16.93% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Int64UpDownCounter/Attributes/10-24      1.371µ ± 1%   1.289µ ± 1%   -5.95% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Float64UpDownCounter/Attributes/0-24     171.4n ± 2%   112.9n ± 0%  -34.13% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Float64UpDownCounter/Attributes/1-24     397.0n ± 3%   336.4n ± 0%  -15.24% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Float64UpDownCounter/Attributes/10-24    1.383µ ± 1%   1.305µ ± 1%   -5.61% (p=0.000 n=10)
SyncMeasure/AttrFilterView/Int64Histogram/Attributes/0-24          157.30n ± 2%   98.58n ± 1%  -37.33% (p=0.000 n=6+10)
```

### Changes

* Introduce `exemplar.Filter`, which is a filter function based on the
context. It will not be user-facing, so we can always add other
parameters later if needed.
* Introduce `exemplar.FilteredReservoir`, which is similar to a
reservoir, except it does not receive a timestamp. It gets the current
time after the filter decision has been made. It uses generics to avoid
the call to exemplar.NewValue(), since it is internal-only.
* The `exemplar.Reservoir` is left as-is, so that it can be made public
when exemplars are stable. It still includes a timestamp argument.
* Unit tests are updated to expect a much lower number of calls to
time.Now
* `exemplar.Drop` is now an `exemplar.FilteredReservoir` instead of a
`Reservoir`, since we don't need a Reservoir to store things in if the
measurement is always dropped.

Co-authored-by: Sam Xie <sam@samxie.me>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
2024-07-01 09:36:11 -07:00
Robert Pająk
b477e34939
sdk/log: Add filtering Processor example (#5543)
Towards https://github.com/open-telemetry/opentelemetry-go/issues/5065
2024-07-01 15:49:12 +02:00
Robert Pająk
d7e5001b4d
sdk/log: Fix ExampleProcessor_redact to clone the record (#5559)
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.
2024-07-01 15:01:22 +02:00
Damien Mathieu
4987a1dd4b
Split the span start/end benchmarks and test start with links and attributes (#5554)
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
```
2024-06-28 11:51:09 +02:00
Damien Mathieu
acb2471488
Add benchmark retrieving a new logger (#5548)
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
```
2024-06-27 13:39:58 +02:00
Damien Mathieu
12f0db5215
Add walk attributes benchmark (#5547)
This adds a benchmark for `record.WalkAttributes`.

Part of #5054.

```
BenchmarkWalkAttributes/1_attributes-10                 346989372                3.449 ns/op           0 B/op          0 allocs/op
BenchmarkWalkAttributes/10_attributes-10                345712522                3.459 ns/op           0 B/op          0 allocs/op
BenchmarkWalkAttributes/100_attributes-10               349380534                3.455 ns/op           0 B/op          0 allocs/op
BenchmarkWalkAttributes/1000_attributes-10              342041373                3.484 ns/op           0 B/op          0 allocs/op
```
2024-06-27 13:29:38 +02:00
Damien Mathieu
649484ef38
Split the set and add attributes benchmarks (#5546)
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
```
2024-06-27 13:17:09 +02:00
Robert Pająk
cda5094cdd
sdk/log: Add altering Processor example (#5550)
Towards https://github.com/open-telemetry/opentelemetry-go/issues/5065

---------

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
2024-06-27 11:55:29 +02:00
Damien Mathieu
6d45f283c7
Add errorlint linter (#5535)
This is the last PR adding missing linters, adding
[errorlint](https://github.com/polyfloyd/go-errorlint).

Co-authored-by: Sam Xie <sam@samxie.me>
2024-06-25 10:55:00 -07:00
Johannes Tax
4e94f405ab
Populate service.instance.id with a default value when OTEL_GO_X_RESOURCE is set (#5520)
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>
2024-06-24 08:25:49 -07:00
Damien Mathieu
f6a5aa2c3f
Add unparam linter (#5531)
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>
2024-06-21 16:02:07 -07:00
Damien Mathieu
3e91436a3b
Add unconvert linter (#5529)
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>
2024-06-21 15:00:26 -07:00
David Ashpole
773aec217d
Fix timestamp handling for the lastvalue aggregation (#5517)
Fixes https://github.com/open-telemetry/opentelemetry-go/issues/5510

From https://opentelemetry.io/docs/specs/otel/metrics/sdk/#metricreader:

> The ending timestamp (i.e. TimeUnixNano) MUST always be equal to time
the metric data point took effect, which is equal to when
[MetricReader.Collect](https://opentelemetry.io/docs/specs/otel/metrics/sdk/#collect)
was invoked. These rules apply to all metrics, not just those whose
[point
kinds](https://opentelemetry.io/docs/specs/otel/metrics/data-model/#point-kinds)
includes an aggregation temporality field.

Before https://github.com/open-telemetry/opentelemetry-go/pull/5305, we
used the measurement time as the timestamp, but it didn't matter because
the collection time is always the same as the measurement time for
asynchronous instruments. We didn't catch the issue when we implemented
synchronous instruments.

This PR changes the (end) timestamp handling for the Last Value
aggregation to match the (end) timestamp handling for sum and histogram
aggregations. As described in the spec above, we take the timestamp when
computing the aggregation during Collect.
2024-06-19 12:13:04 +02:00
Fools
ffe855df33
Fix IDGenerator may generate zero TraceId / SpanId (#5514)
# 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>
2024-06-18 15:57:45 -07:00
ttoad
30e82e01b6
trace: Use non-generic to replace newEvictedQueue in trace.start to reduce memory usage. (#5497)
benchstat:
```
goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/otel/sdk/trace
              │     old     │                 new                 │
              │   sec/op    │   sec/op     vs base                │
TraceStart-10   950.6n ± 1%   641.0n ± 0%  -32.57% (p=0.000 n=10)

              │     old     │                new                 │
              │    B/op     │    B/op     vs base                │
TraceStart-10   1040.0 ± 0%   704.0 ± 0%  -32.31% (p=0.000 n=10)

              │    old     │                new                 │
              │ allocs/op  │ allocs/op   vs base                │
TraceStart-10   20.00 ± 0%   14.00 ± 0%  -30.00% (p=0.000 n=10)
```

---------

Co-authored-by: Damien Mathieu <damien.mathieu@elastic.co>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
2024-06-17 07:39:03 -07:00
Julius Volz
2841e39661
Add missing word in WithView() doc string (#5506)
Signed-off-by: Julius Volz <julius.volz@gmail.com>
Co-authored-by: Sam Xie <sam@samxie.me>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
2024-06-14 09:43:17 -07:00
Robert Pająk
6082e830c2
sdk/log: Remove slice allocation from SimpleProcessor.OnEmit (#5493)
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>
2024-06-11 07:28:56 -07:00
Tyler Yahn
6a0fa3c911
Upgrade semconv use to v1.26.0 (#5490)
Follow up to #5476
2024-06-06 09:36:59 -07:00
Tyler Yahn
c015059314
Add the sdk/internal/x package (#5444)
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>
2024-06-05 09:00:57 -07:00
renovate[bot]
3c32df8c7d
chore(deps): update module golang.org/x/sys to v0.21.0 (#5481)
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| golang.org/x/sys | `v0.20.0` -> `v0.21.0` |
[![age](https://developer.mend.io/api/mc/badges/age/go/golang.org%2fx%2fsys/v0.21.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/go/golang.org%2fx%2fsys/v0.21.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/go/golang.org%2fx%2fsys/v0.20.0/v0.21.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/go/golang.org%2fx%2fsys/v0.20.0/v0.21.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these
updates again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/open-telemetry/opentelemetry-go).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zODguMSIsInVwZGF0ZWRJblZlciI6IjM3LjM4OC4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJTa2lwIENoYW5nZWxvZyIsImRlcGVuZGVuY2llcyJdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-06-04 11:59:31 -07:00
Anton Manakin
4fc7162e89
sdk/log: Fix counting number of dropped attributes of log.Record (#5464)
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
```
2024-06-04 09:18:14 +02:00
Tyler Yahn
047df28b88
Guard rng in exemplar rand computation (#5456)
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`.
2024-06-03 11:11:20 +02:00
Robert Pająk
f80064a978
sdk/log: Add processor benchmarks (#5448)
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
```
2024-06-03 07:14:52 +02:00
Tyler Yahn
1bcb778c28
Move MonotonicEndTime to only use (#5443)
Have the code definition live next to its usage.

Co-authored-by: Sam Xie <sam@samxie.me>
2024-05-31 12:37:38 +02:00
Tyler Yahn
5bfa9c55be
Log warning when a trace attribute/event/link is discarded due to limits (#5434)
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.
2024-05-30 11:40:08 -07:00
Tyler Yahn
fad23ee62c
Remove zeroInstrumentKind (#5433)
It is a duplicate of `instrumentKindUndefined`. Use
`instrumentKindUndefined` instead.
2024-05-30 11:27:07 -07:00
Tyler Yahn
c3569d85d9
Export the Instrument IsEmpty method (#5431)
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.
2024-05-30 07:50:34 -07:00
Anton Manakin
8d4d3c875c
sdk/log: Fix TestBatchProcessor/ForceFlush/ErrorPartialFlush flaky test (#5416)
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>
2024-05-30 07:40:19 -07:00
Anton Manakin
982e96dd9b
sdk/log: Fix TestBatchProcessor/DroppedLogs flaky test (#5421)
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>
2024-05-29 11:19:57 -07:00