1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00
Commit Graph

1099 Commits

Author SHA1 Message Date
Tyler Yahn a3a5317c5c Release v1.40.0 (#7859)
### Added

- Add `Enabled` method to all synchronous instrument interfaces
(`Float64Counter`, `Float64UpDownCounter`, `Float64Histogram`,
`Float64Gauge`, `Int64Counter`, `Int64UpDownCounter`, `Int64Histogram`,
`Int64Gauge`,) in `go.opentelemetry.io/otel/metric`. This stabilizes the
synchronous instrument enabled feature, allowing users to check if an
instrument will process measurements before performing computationally
expensive operations. (#7763)
- Add `AlwaysRecord` sampler in `go.opentelemetry.io/otel/sdk/trace`.
(#7724)
- Add `go.opentelemetry.io/otel/semconv/v1.39.0` package. The package
contains semantic conventions from the `v1.39.0` version of the
OpenTelemetry Semantic Conventions. See the [migration
documentation](https://github.com/open-telemetry/opentelemetry-go/blob/298cbedf256b7a9ab3c21e41fc5e3e6d6e4e94aa/semconv/v1.39.0/MIGRATION.md)
for information on how to upgrade from
`go.opentelemetry.io/otel/semconv/v1.38.0.` (#7783, #7789)

### Changed

- `Exporter` in `go.opentelemetry.io/otel/exporter/prometheus` ignores
metrics with the scope `go.opentelemetry.io/contrib/bridges/prometheus`.
This prevents scrape failures when the Prometheus exporter is
misconfigured to get data from the Prometheus bridge. (#7688)
- Improve performance of concurrent histogram measurements in
`go.opentelemetry.io/otel/sdk/metric`. (#7474)
- Add experimental observability metrics in
`go.opentelemetry.io/otel/exporters/stdout/stdoutmetric`. (#7492)
- Improve the concurrent performance of `HistogramReservoir` in
`go.opentelemetry.io/otel/sdk/metric/exemplar` by 4x. (#7443)
- Improve performance of concurrent synchronous gauge measurements in
`go.opentelemetry.io/otel/sdk/metric`. (#7478)
- Improve performance of concurrent exponential histogram measurements
in `go.opentelemetry.io/otel/sdk/metric`. (#7702)
- Improve the concurrent performance of `FixedSizeReservoir` in
`go.opentelemetry.io/otel/sdk/metric/exemplar`. (#7447)
- The `rpc.grpc.status_code` attribute in the experimental metrics
emitted from
`go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc` is
replaced with the `rpc.response.status_code` attribute to align with the
semantic conventions. (#7854)
- The `rpc.grpc.status_code` attribute in the experimental metrics
emitted from
`go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc` is
replaced with the `rpc.response.status_code` attribute to align with the
semantic conventions. (#7854)

### Fixed

- Fix bad log message when key-value pairs are dropped because of key
duplication in `go.opentelemetry.io/otel/sdk/log`. (#7662)
- Fix `DroppedAttributes` on `Record` in
`go.opentelemetry.io/otel/sdk/log` to not count the non-attribute
key-value pairs dropped because of key duplication. (#7662)
- Fix `SetAttributes` on `Record` in `go.opentelemetry.io/otel/sdk/log`
to not log that attributes are dropped when they are actually not
dropped. (#7662)
- `WithHostID` detector in `go.opentelemetry.io/otel/sdk/resource` to
use full path for `ioreg` command on Darwin (macOS). (#7818)
- Fix missing `request.GetBody` in
`go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp` to
correctly handle HTTP2 GOAWAY frame. (#7794)

### Deprecated

- Deprecate `go.opentelemetry.io/otel/exporters/zipkin`. For more
information, see the [OTel blog post deprecating the Zipkin
exporter](https://opentelemetry.io/blog/2025/deprecating-zipkin-exporters/).
(#7670)

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-02-02 09:46:33 -08:00
Tyler Yahn 298cbedf25 Upgrade semconv use to v1.39.0 (#7854)
Resolve #7806 

- Replace use of `rpc.grpc.status_code` with `rpc.response.status_code`
(https://github.com/open-telemetry/semantic-conventions/issues/1504)
- Pin zipkin semconv to use 1.38.0 for deprecated `PeerServiceKey`
(https://github.com/open-telemetry/opentelemetry-specification/blob/343c2abbcb86a94292bd7cd55e96edcea5a96113/specification/trace/sdk_exporters/zipkin.md#otlp---zipkin)

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-02-02 08:23:37 -08:00
Damien Mathieu 34c8fa5592 Deprecate the zipkin exporter (#7670)
We're entitled to keep providing security and bug fixes until december
2026, but letting users now as soon as possible makes migrations easier.

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
2026-01-28 09:56:38 +01:00
David Ashpole 714ca7c32e Optimize fixedsize reservoir (#7447)
~Depends on #7441, #7443~

This improves the concurrent performance of the fixed size reservoir's
Offer function by 4x (i.e. 75% reduction). This improves the performance
of Measure() for fixed-size reservoirs by 60% overall.

Accomplish this by:

* using a single atomic for count and next. This assumes that both can
fit in a uint32.
* only use a lock to guard changing `w` and `next` together.

Offer benchmarks:
```
                           │   main.txt   │           fixedsize.txt            │
                           │    sec/op    │   sec/op     vs base               │
FixedSizeReservoirOffer-24   185.25n ± 4%   45.58n ± 1%  -75.40% (p=0.002 n=6)
```

Measure benchmarks:
```
                                                                          │   main.txt   │            fixedsize.txt            │
                                                                          │    sec/op    │    sec/op     vs base               │
SyncMeasure/NoView/ExemplarsEnabled/Int64Counter/Attributes/0-24            175.45n ± 6%   67.01n ±  9%  -61.81% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64Counter/Attributes/1-24            170.25n ± 1%   69.82n ±  6%  -58.99% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64Counter/Attributes/10-24           167.40n ± 2%   64.52n ± 10%  -61.46% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Counter/Attributes/0-24          173.55n ± 0%   69.17n ± 12%  -60.14% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Counter/Attributes/1-24          169.50n ± 1%   68.55n ±  5%  -59.56% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Counter/Attributes/10-24         166.95n ± 1%   65.82n ±  6%  -60.58% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64UpDownCounter/Attributes/0-24      168.85n ± 1%   67.99n ± 11%  -59.73% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64UpDownCounter/Attributes/1-24      173.50n ± 1%   66.69n ±  2%  -61.56% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64UpDownCounter/Attributes/10-24     171.30n ± 5%   67.73n ±  8%  -60.46% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64UpDownCounter/Attributes/0-24    168.90n ± 2%   67.69n ±  9%  -59.92% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64UpDownCounter/Attributes/1-24    173.35n ± 2%   68.25n ±  9%  -60.63% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64UpDownCounter/Attributes/10-24   172.95n ± 2%   70.90n ±  7%  -59.01% (p=0.002 n=6)
geomean                                                                      171.0n        67.83n        -60.33%
```

---------

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: Robert Pająk <pellared@hotmail.com>
2026-01-23 09:27:43 -05:00
Robert Pająk d45961bcda resource: specify full path for ioreg command in Darwin host ID reader (#7818)
Use full path when calling `ioreg` to mitigate potential malicious code
execution in case of [Path
Interception](https://attack.mitre.org/techniques/T1574/007/).

Note that path interception typically requires the attacker to influence
the environment or place a malicious executable earlier in $PATH, which,
in this context, generally implies the script itself would need to be
introduced/uploaded (or otherwise placed/executed) in the target
environment for the attacker’s substitute `ioreg` to be reached during
execution.

Reference:
- https://cwe.mitre.org/data/definitions/426.html
2026-01-21 18:33:00 +01:00
Grzegorz Wyszyński 37aa18dd0e support stdlib request.GetBody (#7794)
This is a fix for HTTP2 GOAWAY errors.
It's hard to test GOAWAY directly, but the same mechanism is used on
redirects, so the test aims to verify if the mechanism work for
redirects.

Example log error:
```
traces export: Post "https://***/v1/traces": http2: Transport: cannot retry err [http2: Transport received Server's graceful shutdown GOAWAY] after Request.Body was written; define Request.GetBody to avoid this error
```

---------

Co-authored-by: Damien Mathieu <42@dmathieu.com>
2026-01-21 11:01:44 +01:00
Saharsh Tibrewala 61f0e4855c Bump semconv from v1.37.0 to v1.39.0 (#7789)
Fixes #7788

---------

Co-authored-by: Damien Mathieu <42@dmathieu.com>
2026-01-21 10:42:41 +01:00
Christos Markou f809f7d71e Generate semconv/v1.39.0 (#7783)
Towards https://github.com/open-telemetry/opentelemetry-go/issues/7784

Similar to https://github.com/open-telemetry/opentelemetry-go/pull/7648
for semconv/v1.39.0:
https://github.com/open-telemetry/semantic-conventions/releases/tag/v1.39.0

---------

Signed-off-by: ChrsMark <chrismarkou92@gmail.com>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
2026-01-15 14:43:11 +01:00
Rodrigo Mecheri f98af48bcc sdk/log: fix "limit reached" logging and Record.DroppedAttributes (#7662)
Fixes: #6983

Enhance logging and error reporting in the log record
attribute handling code, specifically around dropped attributes and
duplicate key-value pairs. The main focus is to provide clearer warnings
when key-value pairs are dropped due to duplication, and to ensure
warnings are only logged when actual drops occur.

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
2026-01-13 14:43:36 +01:00
Robert Pająk 7706e21e4a metric: add Enabled method to synchronous instruments (#7763)
Fixes https://github.com/open-telemetry/opentelemetry-go/issues/7681
2026-01-12 16:21:49 +01:00
Vitor Vasconcellos 7e1ff96f6c sdk/trace: Add AlwaysRecord sampler (#7724)
### Description

- Add `AlwaysRecord` sampler to `sdk/trace`.
 
### Related issue

Closes #7714.

---------

Signed-off-by: Vitor Vasconcellos <vitor.vasconcellos@mercadolivre.com>
Co-authored-by: Flc゛ <i@flc.io>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
2026-01-12 14:57:31 +01:00
David Ashpole 279f1453fe Exponential histogram: defer computing count until collect (#7702)
Tiny part of
https://github.com/open-telemetry/opentelemetry-go/pull/7535

It doesn't make much of a difference now, since we are bound by lock
contention, but it matters once we move to atomics.

```
                                                                                  │  main.txt   │           defercount.txt           │
                                                                                  │   sec/op    │    sec/op     vs base              │
SyncMeasure/NoView/ExemplarsDisabled/ExponentialInt64Histogram/Attributes/0-24      300.9n ± 7%   282.8n ± 10%       ~ (p=0.394 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialInt64Histogram/Attributes/1-24      300.0n ± 8%   307.5n ±  3%       ~ (p=0.394 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialInt64Histogram/Attributes/10-24     301.4n ± 5%   300.7n ±  5%       ~ (p=0.485 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialFloat64Histogram/Attributes/0-24    286.4n ± 4%   284.8n ±  3%       ~ (p=0.420 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialFloat64Histogram/Attributes/1-24    303.8n ± 3%   294.3n ±  2%  -3.11% (p=0.006 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialFloat64Histogram/Attributes/10-24   297.9n ± 4%   291.6n ±  3%  -2.10% (p=0.024 n=6)
geomean                                                                             298.3n        293.5n        -1.62%
```
2025-12-16 11:03:52 -05:00
David Ashpole 68d2f72614 Use sync.Map and atomics for lastvalue aggregations (#7478)
Depends on https://github.com/open-telemetry/opentelemetry-go/pull/7474

This applies similar optimizations as
https://github.com/open-telemetry/opentelemetry-go/pull/7427 to the last
value aggregation.

Changes for last value are contained in
https://github.com/open-telemetry/opentelemetry-go/pull/7478/commits/27e14829716bfa5b6cfcdf4841c45c93bf5f0a91.


Parallel benchmarks:
```
                                                                   │   main.txt   │               lv.txt               │
                                                                   │    sec/op    │   sec/op     vs base               │
SyncMeasure/NoView/ExemplarsDisabled/Int64Gauge/Attributes/10-24     264.60n ± 3%   66.46n ± 1%  -74.88% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64Gauge/Attributes/10-24   270.25n ± 4%   69.69n ± 1%  -74.21% (p=0.002 n=6)
geomean                                                               267.4n        68.05n       -74.55%
```

Co-authored-by: Damien Mathieu <42@dmathieu.com>
2025-12-16 09:23:13 +01:00
David Ashpole e8542ae7f3 Optimize histogram reservoir (#7443)
This improves the concurrent performance of the histogram reservoir's
Offer function by 4x (i.e. 75% reduction).

Accomplish this by locking each measurement, rather than locking around
the entire storage. Also, defer extracting the trace context from
context.Context until collection time. This improves the performance of
Offer, which is on the measure hot path. Exemplars are often
overwritten, so deferring the operation until Collect reduces the
overall work.

```
                           │   main.txt   │              hist.txt              │
                           │    sec/op    │   sec/op     vs base               │
FixedSizeReservoirOffer-24    211.4n ± 3%   177.5n ± 3%  -16.04% (p=0.002 n=6)
HistogramReservoirOffer-24   200.85n ± 2%   47.41n ± 2%  -76.40% (p=0.002 n=6)
geomean                       206.1n        91.73n       -55.48%
```

Benchmarks for Measure:
```
                                                                                 │  main.txt   │             histres.txt             │
                                                                                 │   sec/op    │    sec/op     vs base               │
SyncMeasure/NoView/ExemplarsEnabled/Int64Histogram/Attributes/0-24                 436.7n ± 4%   114.8n ±  5%  -73.72% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64Histogram/Attributes/10-24                472.2n ± 2%   169.7n ±  8%  -64.08% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Histogram/Attributes/0-24               431.0n ± 2%   116.3n ±  2%  -73.01% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Histogram/Attributes/10-24              470.9n ± 1%   171.0n ±  5%  -63.70% (p=0.002 n=6)
```

I explored using a []atomic.Pointer[measurement], but this had similar
performance while being much more complex (needing a sync.Pool to
eliminate allocations). The single-threaded performance was also much
worse for that solution. See
https://github.com/open-telemetry/opentelemetry-go/compare/main...dashpole:optimize_histogram_reservoir_old.

---------

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
2025-12-15 09:59:34 -05:00
Mahendra Bishnoi c15644d64e stdoutmetric exporter observability (#7492)
Fixes https://github.com/open-telemetry/opentelemetry-go/issues/7014

This PR adds support for below self observability metrics for
stdoutmetric exporter

- otel.sdk.exporter.metric_data_point.inflight
- otel.sdk.exporter.metric_data_point.exported
- otel.sdk.exporter.operation.duration

These metrics are experimental and hence behind a feature flag
OTEL_GO_X_OBSERVABILITY.
Definition of above metrics is available at
https://github.com/open-telemetry/semantic-conventions/blob/v1.36.0/docs/otel/sdk-metrics.md

<details>
<summary>Observability Implementation Checklist</summary>

## Observability Implementation Checklist
Based on the [project Observability
guidelines](https://github.com/open-telemetry/opentelemetry-go/blob/e4ab3141123d0811125a69823dbbe4d9ec5a9b8f/CONTRIBUTING.md#observability),
ensure the following are completed:

### Environment Variable Activation
* [x] Observability features are disabled by default
* [x] Features are activated through the `OTEL_GO_X_OBSERVABILITY`
environment variable
* [x] Use consistent pattern with `x.Observability.Enabled()` check [^1]
* [x] Follow established experimental feature pattern [^2][^3]

[^1]:
https://github.com/open-telemetry/opentelemetry-go/blob/e4ab3141123d0811125a69823dbbe4d9ec5a9b8f/exporters/stdout/stdouttrace/internal/observ/instrumentation.go#L101-L103
[^2]:
https://github.com/open-telemetry/opentelemetry-go/blob/e4ab3141123d0811125a69823dbbe4d9ec5a9b8f/exporters/stdout/stdouttrace/internal/x/x.go
[^3]:
https://github.com/open-telemetry/opentelemetry-go/blob/e4ab3141123d0811125a69823dbbe4d9ec5a9b8f/sdk/internal/x/x.go

### Encapsulation
* [x] Instrumentation is encapsulated within a dedicated `struct` (e.g.,
[`Instrumentation`](https://github.com/open-telemetry/opentelemetry-go/blob/e4ab3141123d0811125a69823dbbe4d9ec5a9b8f/exporters/stdout/stdouttrace/internal/observ/instrumentation.go#L86-L94))
* [x] Instrumentation is not mixed into the instrumented component
* [x] Instrumentation code is in its own file or package if
complex/reused
* [x] Instrumentation setup doesn't bloat the main component code

### Initialization
* [x] Initialization is only done when observability is enabled
* [x] Setup is explicit and side-effect free
* [x] Return errors from initialization when appropriate
* [x] Use the global Meter provider (e.g., `otel.GetMeterProvider()`)
* [x] Include proper meter configuration with:
  * [x] Instrumentation package name is used for the Meter
* [x] Instrumentation version (e.g.
[`Version`](https://github.com/open-telemetry/opentelemetry-go/blob/e4ab3141123d0811125a69823dbbe4d9ec5a9b8f/exporters/stdout/stdouttrace/internal/observ/instrumentation.go#L40-L43))
* [x] Schema URL (e.g.
[`SchemaURL`](https://github.com/open-telemetry/opentelemetry-go/blob/e4ab3141123d0811125a69823dbbe4d9ec5a9b8f/exporters/stdout/stdouttrace/internal/observ/instrumentation.go#L36-L38))

### Performance
* [x] Little to no overhead when observability is disabled
* [x] Expensive operations are only executed when observability is
enabled
* [x] When enabled, instrumentation code paths are optimized to reduce
allocation/computation overhead

#### Attribute and Option Allocation Management
* [x] Use `sync.Pool` for attribute slices and options with dynamic
attributes
* [x] Pool objects are properly reset before returning to pool
* [x] Pools are scoped for maximum efficiency while ensuring correctness

#### Caching
* [x] Static attribute sets known at compile time are pre-computed and
cached
* [x] Common attribute combinations use lookup tables/maps

#### Benchmarking
* [x] Benchmarks provided for all instrumentation code
* [ ] Benchmark scenarios include both enabled and disabled
observability
* [x] Benchmark results show impact on allocs/op, B/op, and ns/op (use
`b.ReportAllocs()` in benchmarks)

### Error Handling and Robustness
* [x] Errors are reported back to caller when possible
* [x] Partial failures are handled gracefully
* [x] Use partially initialized components when available
* [x] Return errors to caller instead of only using `otel.Handle()`
* [x] Use `otel.Handle()` only when component cannot report error to
user

### Context Propagation
* [x] Observability measurements receive the context from the function
being measured (don't break context propagation by using
`context.Background()`)

### Semantic Conventions Compliance
* [x] All metrics follow [OpenTelemetry Semantic
Conventions](https://github.com/open-telemetry/semantic-conventions/blob/5ee549b1ce30fe11fcb9b7e3bd35ebfb363f467f/docs/otel/sdk-metrics.md)
* [x] Use the
[`otelconv`](https://pkg.go.dev/go.opentelemetry.io/otel@v1.38.0/semconv/v1.37.0/otelconv)
convenience package for metric semantic conventions
* [x] Component names follow semantic conventions
* [x] Use package path scope type as stable identifier for non-standard
components
* [x] Component names are stable unique identifiers
* [x] Use global counter for uniqueness if necessary
* [x] Component ID counter is resettable for deterministic testing

### Testing
* [x] Use deterministic testing with isolated state
* [x] Restore previous state after tests (`t.Cleanup()`)
* [x] Isolate meter provider for testing
* [x] Use `t.Setenv()` for environment variable testing
* [x] Reset component ID counter for deterministic component names
* [x] Test order doesn't affect results
</details>

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
2025-12-15 11:45:10 +01:00
David Ashpole f57bf14de2 Use sync.Map and atomics for fixed bucket histograms (#7474)
Implement a lockless histogram using atomics, and use a sync.Map for
attribute access. This improves performance by ~2x.

The design is very similar to
https://github.com/open-telemetry/opentelemetry-go/pull/7427, but with
one additional change to make the histogram data point itself atomic:

* For cumulative histograms, which do not use a hot/cold limitedSyncMap,
we use a hot/cold data point. This way, we maintain the keys in the sync
map, but still ensure that collection gets a consistent view of
measure() calls.

Parallel benchmarks:
```
                                                                       │  main.txt   │              hist.txt              │
                                                                       │   sec/op    │   sec/op     vs base               │
SyncMeasure/NoView/ExemplarsDisabled/Int64Histogram/Attributes/10-24     274.5n ± 2%   125.2n ± 5%  -54.42% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64Histogram/Attributes/10-24   274.1n ± 2%   132.5n ± 2%  -51.65% (p=0.002 n=6)
geomean                                                                  274.3n        128.8n       -53.05%
```

zero memory allocations before and after this change for Measure().
Omitted for brevity

Benchmarks for collect:
```
                                                    │   main.txt    │               hist.txt               │
                                                    │    sec/op     │    sec/op     vs base                │
Collect/NoView/Int64Histogram/1/Attributes/0-24       1.799µ ±  60%    1.702µ ± 6%         ~ (p=1.000 n=6)
Collect/NoView/Int64Histogram/1/Attributes/1-24       973.7n ±  28%   1720.0n ± 5%   +76.65% (p=0.002 n=6)
Collect/NoView/Int64Histogram/1/Attributes/10-24      881.0n ±  17%   1710.0n ± 5%   +94.09% (p=0.002 n=6)
Collect/NoView/Int64Histogram/10/Attributes/0-24      996.1n ±  14%   1781.5n ± 4%   +78.85% (p=0.002 n=6)
Collect/NoView/Int64Histogram/10/Attributes/1-24      1.029µ ±  67%    1.733µ ± 3%   +68.42% (p=0.009 n=6)
Collect/NoView/Int64Histogram/10/Attributes/10-24     1.533µ ±  18%    1.708µ ± 4%         ~ (p=0.240 n=6)
Collect/NoView/Float64Histogram/1/Attributes/0-24     1.222µ ± 120%    1.733µ ± 4%         ~ (p=0.065 n=6)
Collect/NoView/Float64Histogram/1/Attributes/1-24     893.3n ±   8%   1733.0n ± 4%   +94.00% (p=0.002 n=6)
Collect/NoView/Float64Histogram/1/Attributes/10-24    860.7n ±   2%   1732.0n ± 5%  +101.23% (p=0.002 n=6)
Collect/NoView/Float64Histogram/10/Attributes/0-24    852.5n ±   4%   1758.0n ± 3%  +106.22% (p=0.002 n=6)
Collect/NoView/Float64Histogram/10/Attributes/1-24    853.8n ±   3%   1725.0n ± 3%  +102.04% (p=0.002 n=6)
Collect/NoView/Float64Histogram/10/Attributes/10-24   843.4n ±   2%   1755.0n ± 4%  +108.10% (p=0.002 n=6)
geomean                                               1.028µ           1.732µ        +68.46%

                                                    │  main.txt  │               hist.txt               │
                                                    │    B/op    │     B/op      vs base                │
Collect/NoView/Int64Histogram/1/Attributes/0-24       336.0 ± 0%    2131.0 ± 0%  +534.23% (p=0.002 n=6)
Collect/NoView/Int64Histogram/1/Attributes/1-24       336.0 ± 0%    2131.0 ± 0%  +534.23% (p=0.002 n=6)
Collect/NoView/Int64Histogram/1/Attributes/10-24      336.0 ± 0%    2131.0 ± 0%  +534.23% (p=0.002 n=6)
Collect/NoView/Int64Histogram/10/Attributes/0-24      336.0 ± 0%    2131.0 ± 0%  +534.23% (p=0.002 n=6)
Collect/NoView/Int64Histogram/10/Attributes/1-24      336.0 ± 0%    2131.0 ± 0%  +534.23% (p=0.002 n=6)
Collect/NoView/Int64Histogram/10/Attributes/10-24     336.0 ± 0%    2131.0 ± 0%  +534.23% (p=0.002 n=6)
Collect/NoView/Float64Histogram/1/Attributes/0-24     336.0 ± 0%    2131.0 ± 0%  +534.23% (p=0.002 n=6)
Collect/NoView/Float64Histogram/1/Attributes/1-24     336.0 ± 0%    2130.5 ± 0%  +534.08% (p=0.002 n=6)
Collect/NoView/Float64Histogram/1/Attributes/10-24    336.0 ± 0%    2131.0 ± 0%  +534.23% (p=0.002 n=6)
Collect/NoView/Float64Histogram/10/Attributes/0-24    336.0 ± 0%    2131.0 ± 0%  +534.23% (p=0.002 n=6)
Collect/NoView/Float64Histogram/10/Attributes/1-24    336.0 ± 0%    2131.0 ± 0%  +534.23% (p=0.002 n=6)
Collect/NoView/Float64Histogram/10/Attributes/10-24   336.0 ± 0%    2131.0 ± 0%  +534.23% (p=0.002 n=6)
geomean                                               336.0        2.081Ki       +534.21%

                                                    │  main.txt  │             hist.txt              │
                                                    │ allocs/op  │ allocs/op   vs base               │
Collect/NoView/Int64Histogram/1/Attributes/0-24       5.000 ± 0%   6.000 ± 0%  +20.00% (p=0.002 n=6)
Collect/NoView/Int64Histogram/1/Attributes/1-24       5.000 ± 0%   6.000 ± 0%  +20.00% (p=0.002 n=6)
Collect/NoView/Int64Histogram/1/Attributes/10-24      5.000 ± 0%   6.000 ± 0%  +20.00% (p=0.002 n=6)
Collect/NoView/Int64Histogram/10/Attributes/0-24      5.000 ± 0%   6.000 ± 0%  +20.00% (p=0.002 n=6)
Collect/NoView/Int64Histogram/10/Attributes/1-24      5.000 ± 0%   6.000 ± 0%  +20.00% (p=0.002 n=6)
Collect/NoView/Int64Histogram/10/Attributes/10-24     5.000 ± 0%   6.000 ± 0%  +20.00% (p=0.002 n=6)
Collect/NoView/Float64Histogram/1/Attributes/0-24     5.000 ± 0%   6.000 ± 0%  +20.00% (p=0.002 n=6)
Collect/NoView/Float64Histogram/1/Attributes/1-24     5.000 ± 0%   6.000 ± 0%  +20.00% (p=0.002 n=6)
Collect/NoView/Float64Histogram/1/Attributes/10-24    5.000 ± 0%   6.000 ± 0%  +20.00% (p=0.002 n=6)
Collect/NoView/Float64Histogram/10/Attributes/0-24    5.000 ± 0%   6.000 ± 0%  +20.00% (p=0.002 n=6)
Collect/NoView/Float64Histogram/10/Attributes/1-24    5.000 ± 0%   6.000 ± 0%  +20.00% (p=0.002 n=6)
Collect/NoView/Float64Histogram/10/Attributes/10-24   5.000 ± 0%   6.000 ± 0%  +20.00% (p=0.002 n=6)
geomean                                               5.000        6.000       +20.00%
```

Collect does get substantially worse, but Measure is expected to be
called significantly more often than collect.

---------

Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
2025-12-11 11:56:03 -05:00
David Ashpole bfbfdf9d53 prometheus exporter ignores metrics from the Prometheus bridge (#7688)
Related to
https://github.com/open-telemetry/opentelemetry-go/issues/7686.

This makes the Prometheus exporter ignore all metrics from the
Prometheus bridge. This is almost certainly a misconfiguration, but may
happen when using autoexport or other packages that automatically
install the bridge.
2025-12-09 13:50:55 -05:00
Tyler Yahn 6ce14298b9 Release v1.39.0 (#7676)
## Overview

### Added

- Greatly reduce the cost of recording metrics in
`go.opentelemetry.io/otel/sdk/metric` using hashing for map keys.
(#7175)
- Add `WithInstrumentationAttributeSet` option to
`go.opentelemetry.io/otel/log`, `go.opentelemetry.io/otel/metric`, and
`go.opentelemetry.io/otel/trace` packages. This provides a
concurrent-safe and performant alternative to
`WithInstrumentationAttributes` by accepting a pre-constructed
`attribute.Set`. (#7287)
- Add experimental observability for the Prometheus exporter in
`go.opentelemetry.io/otel/exporters/prometheus`. Check the
`go.opentelemetry.io/otel/exporters/prometheus/internal/x` package
documentation for more information. (#7345)
- Add experimental observability metrics in
`go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc`. (#7353)
- Add temporality selector functions `DeltaTemporalitySelector`,
`CumulativeTemporalitySelector`, `LowMemoryTemporalitySelector` to
`go.opentelemetry.io/otel/sdk/metric`. (#7434)
- Add experimental observability metrics for simple log processor in
`go.opentelemetry.io/otel/sdk/log`. (#7548)
- Add experimental observability metrics in
`go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc`.
(#7459)
- Add experimental observability metrics in
`go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`.
(#7486)
- Add experimental observability metrics for simple span processor in
`go.opentelemetry.io/otel/sdk/trace`. (#7374)
- Add experimental observability metrics in
`go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp`. (#7512)
- Add experimental observability metrics for manual reader in
`go.opentelemetry.io/otel/sdk/metric`. (#7524)
- Add experimental observability metrics for periodic reader in
`go.opentelemetry.io/otel/sdk/metric`. (#7571)
- Support `OTEL_EXPORTER_OTLP_LOGS_INSECURE` and
`OTEL_EXPORTER_OTLP_INSECURE` environmental variables in
`go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp`. (#7608)
- Add `Enabled` method to the `Processor` interface in
`go.opentelemetry.io/otel/sdk/log`. All `Processor` implementations now
include an `Enabled` method. (#7639)
- The `go.opentelemetry.io/otel/semconv/v1.38.0` package. The package
contains semantic conventions from the `v1.38.0` version of the
OpenTelemetry Semantic Conventions. See the [migration
documentation](./semconv/v1.38.0/MIGRATION.md) for information on how to
upgrade from `go.opentelemetry.io/otel/semconv/v1.37.0.`(#7648)

### Changed

- `Distinct` in `go.opentelemetry.io/otel/attribute` is no longer
guaranteed to uniquely identify an attribute set. Collisions between
`Distinct` values for different Sets are possible with extremely high
cardinality (billions of series per instrument), but are highly
unlikely. (#7175)
- `WithInstrumentationAttributes` in `go.opentelemetry.io/otel/trace`
synchronously de-duplicates the passed attributes instead of delegating
it to the returned `TracerOption`. (#7266)
- `WithInstrumentationAttributes` in `go.opentelemetry.io/otel/meter`
synchronously de-duplicates the passed attributes instead of delegating
it to the returned `MeterOption`. (#7266)
- `WithInstrumentationAttributes` in `go.opentelemetry.io/otel/log`
synchronously de-duplicates the passed attributes instead of delegating
it to the returned `LoggerOption`. (#7266)
- Rename the `OTEL_GO_X_SELF_OBSERVABILITY` environment variable to
`OTEL_GO_X_OBSERVABILITY` in `go.opentelemetry.io/otel/sdk/trace`,
`go.opentelemetry.io/otel/sdk/log`, and
`go.opentelemetry.io/otel/exporters/stdout/stdouttrace`. (#7302)
- Improve performance of histogram `Record` in
`go.opentelemetry.io/otel/sdk/metric` when min and max are disabled
using `NoMinMax`. (#7306)
- Improve error handling for dropped data during translation by using
`prometheus.NewInvalidMetric` in
`go.opentelemetry.io/otel/exporters/prometheus`. ⚠️ **Breaking Change:**
Previously, these cases were only logged and scrapes succeeded. Now,
when translation would drop data (e.g., invalid label/value), the
exporter emits a `NewInvalidMetric`, and Prometheus scrapes **fail with
HTTP 500** by default. To preserve the prior behavior (scrapes succeed
while errors are logged), configure your Prometheus HTTP handler with:
`promhttp.HandlerOpts{ ErrorHandling: promhttp.ContinueOnError }`.
(#7363)
- Replace fnv hash with xxhash in `go.opentelemetry.io/otel/attribute`
for better performance. (#7371)
- The default `TranslationStrategy` in
`go.opentelemetry.io/exporters/prometheus` is changed from
`otlptranslator.NoUTF8EscapingWithSuffixes` to
`otlptranslator.UnderscoreEscapingWithSuffixes`. (#7421)
- Improve performance of concurrent measurements in
`go.opentelemetry.io/otel/sdk/metric`. (#7427)
- Include W3C TraceFlags (bits 0–7) in the OTLP `Span.Flags` field in
`go.opentelemetry.io/exporters/otlp/otlptrace/otlptracehttp` and
`go.opentelemetry.io/exporters/otlp/otlptrace/otlptracegrpc`. (#7438)
- The `ErrorType` function in `go.opentelemetry.io/otel/semconv/v1.37.0`
now handles custom error types.
If an error implements an `ErrorType() string` method, the return value
of that method will be used as the error type. (#7442)

### Fixed

- Fix `WithInstrumentationAttributes` options in
`go.opentelemetry.io/otel/trace`, `go.opentelemetry.io/otel/metric`, and
`go.opentelemetry.io/otel/log` to properly merge attributes when passed
multiple times instead of replacing them. Attributes with duplicate keys
will use the last value passed. (#7300)
- The equality of `attribute.Set` when using the `Equal` method is not
affected by the user overriding the empty set pointed to by
`attribute.EmptySet` in `go.opentelemetry.io/otel/attribute`. (#7357)
- Return partial OTLP export errors to the caller in
`go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc`. (#7372)
- Return partial OTLP export errors to the caller in
`go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp`. (#7372)
- Return partial OTLP export errors to the caller in
`go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc`.
(#7372)
- Return partial OTLP export errors to the caller in
`go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`.
(#7372)
- Return partial OTLP export errors to the caller in
`go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc`.
(#7372)
- Return partial OTLP export errors to the caller in
`go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`.
(#7372)
- Fix `AddAttributes`, `SetAttributes`, `SetBody` on `Record` in
`go.opentelemetry.io/otel/sdk/log` to not mutate input. (#7403)
- Do not double record measurements of `RecordSet` methods in
`go.opentelemetry.io/otel/semconv/v1.37.0`. (#7655)
- Do not double record measurements of `RecordSet` methods in
`go.opentelemetry.io/otel/semconv/v1.36.0`. (#7656)

### Removed

- Drop support for [Go 1.23]. (#7274)
- Remove the `FilterProcessor` interface in
`go.opentelemetry.io/otel/sdk/log`. The `Enabled` method has been added
to the `Processor` interface instead. All `Processor` implementations
must now implement the `Enabled` method. Custom processors that do not
filter records can implement `Enabled` to return `true`. (#7639)
2025-12-08 08:30:47 -08:00
Robert Pająk 12e421a706 sdk/log: move Enabled method from FilterProcessor to Processor (#7639)
Fixes #7617

Simplify the Logs SDK by unifying processor capabilities into a single
interface.

- Add `Enabled(ctx context.Context, p EnabledParameters) bool` to
`sdk/log.Processor`.
- Remove `sdk/log.FilterProcessor` interface.

`Processor` implementations must now implement the `Enabled` method.
Custom processors that do not filter records can implement `Enabled` to
return `true`.
2025-12-08 15:26:05 +01:00
Tyler Yahn a64b9ec518 Fix package documentation name and return error in semconv/v1.36.0 (#7656)
Identified in the review of #7648
2025-12-05 08:18:09 -08:00
Tyler Yahn e69beb88b5 Fix package documentation name and return err in semconv/v1.37.0 (#7655)
Identified in the review of #7648
2025-12-05 07:38:48 -08:00
ian ca53078985 Instrument the SimpleLogProcessor from sdk/log (#7548)
ref #7016


```txt
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/log
cpu: Intel(R) Core(TM) i7-14700
                                                │ before.txt  │  .\after_res.txt   │
                                                │   sec/op    │   sec/op     vs base   │
SimpleProcessorObservability/NoObservability-28   27.68n ± 4%
SimpleProcessorObservability/Observability-28                   27.39n ± 5%
geomean                                           27.68n        27.38n       ? ¹ ²
¹ benchmark set differs from baseline; geomeans may not be comparable
² ratios must be >0 to compute geomean

                                                │  before.txt  │   .\after_res.txt   │
                                                │     B/op     │    B/op     vs base │
SimpleProcessorObservability/NoObservability-28   0.000 ± 0%
SimpleProcessorObservability/Observability-28                    0.000 ± 0%
geomean                                                      ¹               ? ² ¹ ³
¹ summaries must be >0 to compute geomean
² benchmark set differs from baseline; geomeans may not be comparable
³ ratios must be >0 to compute geomean

                                                │  before.txt  │   .\after_res.txt   │
                                                │  allocs/op   │ allocs/op   vs base │
SimpleProcessorObservability/NoObservability-28   0.000 ± 0%
SimpleProcessorObservability/Observability-28                    0.000 ± 0%
geomean                                                      ¹               ? ² ¹ ³
¹ summaries must be >0 to compute geomean
² benchmark set differs from baseline; geomeans may not be comparable
³ ratios must be >0 to compute geomean
```

---------

Co-authored-by: Flc゛ <i@flc.io>
Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
Co-authored-by: Robert Pająk <pellared@hotmail.com>
Co-authored-by: dmathieu <42@dmathieu.com>
2025-12-04 13:28:07 +01:00
Tyler Yahn 6af2f2ff67 Generate semconv/v1.38.0 (#7648)
Resolve #7647
2025-12-03 19:55:44 -08:00
Simon Menke da01323ac8 otlploghttp: support OTEL_EXPORTER_OTLP_LOGS_INSECURE and OTEL_EXPORTER_OTLP_INSECURE env vars (#7608) 2025-11-21 09:17:38 +01:00
Preeti Dewani 49292857b7 Replace fnv with xxhash (#7497)
**Objective**:
- Performance comparison between fnv and xxhash in terms of ops/sec,
allocations and collisions
- Implement xxhash according to first objective

**Changes**:
- fnv is replaced by xxhash. 
  Perform stats:
  - **Collision**: No collision upto 100M
  - **Allocations**: Same in both cases
- **Ops/sec**: xxhash performed better in cases with medium to large
strings
 
 **Benchmarks**:
 ```
 benchstat old.txt new.txt
goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/otel/attribute
cpu: Apple M2
│ old.txt │ new.txt │
│ sec/op │ sec/op vs base │
NewSet-8 205.5n ± 1% 229.4n ± 1% +11.61% (p=0.002 n=6)
NewSetSmallStrings-8 160.5n ± 1% 169.0n ± 5% +5.26% (p=0.002 n=6)
NewSetMediumStrings-8 263.8n ± 6% 185.0n ± 1% -29.89% (p=0.002 n=6)
NewSetLargeStrings-8 426.4n ± 9% 210.2n ± 1% -50.72% (p=0.002 n=6)
NewSetVeryLargeStrings-8 1012.5n ± 7% 238.7n ± 2% -76.43% (p=0.002 n=6)
NewSetHugeStrings-8 3622.0n ± 8% 397.1n ± 1% -89.04% (p=0.002 n=6)
geomean                     488.6n        228.6n       -53.21%

│ old.txt │ new.txt │
│ B/op │ B/op vs base │
NewSet-8 448.0 ± 0% 448.0 ± 0% ~ (p=1.000 n=6) ¹
NewSetSmallStrings-8 320.0 ± 0% 320.0 ± 0% ~ (p=1.000 n=6) ¹
NewSetMediumStrings-8 320.0 ± 0% 320.0 ± 0% ~ (p=1.000 n=6) ¹
NewSetLargeStrings-8 320.0 ± 0% 320.0 ± 0% ~ (p=1.000 n=6) ¹
NewSetVeryLargeStrings-8 320.0 ± 0% 320.0 ± 0% ~ (p=1.000 n=6) ¹
NewSetHugeStrings-8 320.0 ± 0% 320.0 ± 0% ~ (p=1.000 n=6) ¹
geomean                    338.5        338.5       +0.00%
¹ all samples are equal

│ old.txt │ new.txt │
│ allocs/op │ allocs/op vs base │
NewSet-8 1.000 ± 0% 1.000 ± 0% ~ (p=1.000 n=6) ¹
NewSetSmallStrings-8 1.000 ± 0% 1.000 ± 0% ~ (p=1.000 n=6) ¹
NewSetMediumStrings-8 1.000 ± 0% 1.000 ± 0% ~ (p=1.000 n=6) ¹
NewSetLargeStrings-8 1.000 ± 0% 1.000 ± 0% ~ (p=1.000 n=6) ¹
NewSetVeryLargeStrings-8 1.000 ± 0% 1.000 ± 0% ~ (p=1.000 n=6) ¹
NewSetHugeStrings-8 1.000 ± 0% 1.000 ± 0% ~ (p=1.000 n=6) ¹
geomean                    1.000        1.000       +0.00%
¹ all samples are equal
```

Previous implementation for reference: 
https://github.com/open-telemetry/opentelemetry-go/blame/d0483a7c89d936dcced557fb523465daeac16967/CHANGELOG.md#L16

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
2025-11-19 11:06:20 +01:00
Robert Wu a80ee2de89 feat: instrument periodic reader from sdk/metric (#7571)
Resolve: #7010 

### Benchmarks

```
➜ benchstat /tmp/bench_disabled.txt /tmp/bench_enabled.txt
goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/otel/sdk/metric
cpu: Apple M1 Max
                                                 │ /tmp/bench_disabled.txt │       /tmp/bench_enabled.txt       │
                                                 │         sec/op          │   sec/op     vs base               │
PeriodicReaderInstrumentation/NoObservability-10               17.00µ ± 0%   17.02µ ± 0%       ~ (p=0.400 n=50)
PeriodicReaderInstrumentation/Observability-10                 17.48µ ± 0%   17.47µ ± 0%       ~ (p=0.361 n=50)
geomean                                                        17.24µ        17.24µ       +0.04%

                                                 │ /tmp/bench_disabled.txt │       /tmp/bench_enabled.txt        │
                                                 │          B/op           │     B/op      vs base               │
PeriodicReaderInstrumentation/NoObservability-10              47.63Ki ± 0%   47.63Ki ± 0%       ~ (p=0.159 n=50)
PeriodicReaderInstrumentation/Observability-10                47.65Ki ± 0%   47.65Ki ± 0%       ~ (p=0.780 n=50)
geomean                                                       47.64Ki        47.64Ki       +0.00%

                                                 │ /tmp/bench_disabled.txt │       /tmp/bench_enabled.txt        │
                                                 │        allocs/op        │ allocs/op   vs base                 │
PeriodicReaderInstrumentation/NoObservability-10                376.0 ± 0%   376.0 ± 0%       ~ (p=1.000 n=50) ¹
PeriodicReaderInstrumentation/Observability-10                  376.0 ± 0%   376.0 ± 0%       ~ (p=1.000 n=50) ¹
geomean                                                         376.0        376.0       +0.00%
¹ all samples are equal
```

---------

Co-authored-by: Damien Mathieu <42@dmathieu.com>
2025-11-05 10:19:20 +01:00
Robert Wu 68190cc102 Instrument manual reader from sdk/metric (#7524)
Resolve: #7009 

### Benchmarks

```
➜ benchstat /tmp/manual_bench_disabled.txt /tmp/manual_bench_enabled.txt
goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/otel/sdk/metric
cpu: Apple M1 Max
                                               │ /tmp/manual_bench_disabled.txt │    /tmp/manual_bench_enabled.txt    │
                                               │             sec/op             │    sec/op     vs base               │
ManualReaderInstrumentation/NoObservability-10                     35.98µ ± 14%   36.29µ ± 11%       ~ (p=0.665 n=40)
ManualReaderInstrumentation/Observability-10                       26.98µ ±  9%   28.23µ ±  3%       ~ (p=0.207 n=40)
geomean                                                            31.16µ         32.01µ        +2.73%

                                               │ /tmp/manual_bench_disabled.txt │    /tmp/manual_bench_enabled.txt    │
                                               │              B/op              │     B/op      vs base               │
ManualReaderInstrumentation/NoObservability-10                     49.24Ki ± 1%   49.24Ki ± 1%       ~ (p=1.000 n=40)
ManualReaderInstrumentation/Observability-10                       51.78Ki ± 0%   51.78Ki ± 0%       ~ (p=0.485 n=40)
geomean                                                            50.50Ki        50.50Ki       +0.00%

                                               │ /tmp/manual_bench_disabled.txt │   /tmp/manual_bench_enabled.txt   │
                                               │           allocs/op            │ allocs/op   vs base               │
ManualReaderInstrumentation/NoObservability-10                       381.0 ± 1%   381.0 ± 1%       ~ (p=1.000 n=40)
ManualReaderInstrumentation/Observability-10                         387.0 ± 0%   387.0 ± 1%       ~ (p=0.485 n=40)
geomean                                                              384.0        384.0       +0.00%
```

---------

Co-authored-by: Damien Mathieu <42@dmathieu.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
2025-11-03 14:55:09 -08:00
ian eadb423cf5 Instrument the otlploghttp exporter (#7512)
- Part of https://github.com/open-telemetry/opentelemetry-go/issues/7018

```
goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp
cpu: Apple M3
                                     │ result.txt  │
                                     │   sec/op    │
ExporterExportLogs/Observability-8     70.72µ ± 3%
ExporterExportLogs/NoObservability-8   68.63µ ± 3%
geomean                                69.66µ

                                     │  result.txt  │
                                     │     B/op     │
ExporterExportLogs/Observability-8     42.90Ki ± 0%
ExporterExportLogs/NoObservability-8   42.89Ki ± 0%
geomean                                42.89Ki

                                     │ result.txt │
                                     │ allocs/op  │
ExporterExportLogs/Observability-8     557.0 ± 0%
ExporterExportLogs/NoObservability-8   557.0 ± 0%
geomean                                557.0
```


```shell
goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp
cpu: Apple M3
                                   │ before.txt  │           after.txt           │
                                   │   sec/op    │   sec/op     vs base          │
ExporterExportLogs/Observability-8   67.46µ ± 3%   68.61µ ± 3%  ~ (p=0.105 n=10)

                                   │  before.txt  │              after.txt              │
                                   │     B/op     │     B/op      vs base               │
ExporterExportLogs/Observability-8   42.88Ki ± 0%   42.90Ki ± 0%  +0.04% (p=0.033 n=10)

                                   │ before.txt │           after.txt            │
                                   │ allocs/op  │ allocs/op   vs base            │
ExporterExportLogs/Observability-8   557.0 ± 0%   557.0 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal
```
2025-10-21 09:00:11 -07:00
Mahendra Bishnoi f7d2882606 feat: sdk/trace: span processed metric for simple span processor (#7374)
Fixes #7004 

This PR adds support for experimental otel.sdk.processor.span.processed
metric in simple span processor.
Definition of metric at:
https://github.com/open-telemetry/semantic-conventions/blob/v1.36.0/docs/otel/sdk-metrics.md

Experimental metrics are behind a feature flag:
`OTEL_GO_X_OBSERVABILITY`

<details>
<summary>Observability Implementation Checklist</summary>

## Observability Implementation Checklist
Based on the [project Observability
guidelines](https://github.com/open-telemetry/opentelemetry-go/blob/e4ab3141123d0811125a69823dbbe4d9ec5a9b8f/CONTRIBUTING.md#observability),
ensure the following are completed:

### Environment Variable Activation
* [x] Observability features are disabled by default
* [x] Features are activated through the `OTEL_GO_X_OBSERVABILITY`
environment variable
* [x] Use consistent pattern with `x.Observability.Enabled()` check [^1]
* [x] Follow established experimental feature pattern [^2][^3]

[^1]:
https://github.com/open-telemetry/opentelemetry-go/blob/e4ab3141123d0811125a69823dbbe4d9ec5a9b8f/exporters/stdout/stdouttrace/internal/observ/instrumentation.go#L101-L103
[^2]:
https://github.com/open-telemetry/opentelemetry-go/blob/e4ab3141123d0811125a69823dbbe4d9ec5a9b8f/exporters/stdout/stdouttrace/internal/x/x.go
[^3]:
https://github.com/open-telemetry/opentelemetry-go/blob/e4ab3141123d0811125a69823dbbe4d9ec5a9b8f/sdk/internal/x/x.go

### Encapsulation
* [x] Instrumentation is encapsulated within a dedicated `struct` (e.g.,
[`Instrumentation`](https://github.com/open-telemetry/opentelemetry-go/blob/e4ab3141123d0811125a69823dbbe4d9ec5a9b8f/exporters/stdout/stdouttrace/internal/observ/instrumentation.go#L86-L94))
* [x] Instrumentation is not mixed into the instrumented component
* [x] Instrumentation code is in its own file or package if
complex/reused
* [x] Instrumentation setup doesn't bloat the main component code

### Initialization
* [x] Initialization is only done when observability is enabled
* [x] Setup is explicit and side-effect free
* [x] Return errors from initialization when appropriate
* [x] Use the global Meter provider (e.g., `otel.GetMeterProvider()`)
* [x] Include proper meter configuration with:
  * [x] Instrumentation package name is used for the Meter
* [x] Instrumentation version (e.g.
[`Version`](https://github.com/open-telemetry/opentelemetry-go/blob/e4ab3141123d0811125a69823dbbe4d9ec5a9b8f/exporters/stdout/stdouttrace/internal/observ/instrumentation.go#L40-L43))
* [x] Schema URL (e.g.
[`SchemaURL`](https://github.com/open-telemetry/opentelemetry-go/blob/e4ab3141123d0811125a69823dbbe4d9ec5a9b8f/exporters/stdout/stdouttrace/internal/observ/instrumentation.go#L36-L38))

### Performance
* [x] Little to no overhead when observability is disabled
* [x] Expensive operations are only executed when observability is
enabled
* [x] When enabled, instrumentation code paths are optimized to reduce
allocation/computation overhead

#### Attribute and Option Allocation Management
* [x] Use `sync.Pool` for attribute slices and options with dynamic
attributes
* [x] Pool objects are properly reset before returning to pool
* [x] Pools are scoped for maximum efficiency while ensuring correctness

#### Caching
* [x] Static attribute sets known at compile time are pre-computed and
cached
* [x] Common attribute combinations use lookup tables/maps

#### Benchmarking
* [x] Benchmarks provided for all instrumentation code
* [ ] Benchmark scenarios include both enabled and disabled
observability
* [x] Benchmark results show impact on allocs/op, B/op, and ns/op (use
`b.ReportAllocs()` in benchmarks)

### Error Handling and Robustness
* [x] Errors are reported back to caller when possible
* [x] Partial failures are handled gracefully
* [x] Use partially initialized components when available
* [x] Return errors to caller instead of only using `otel.Handle()`
* [x] Use `otel.Handle()` only when component cannot report error to
user

### Context Propagation
* [x] Observability measurements receive the context from the function
being measured (don't break context propagation by using
`context.Background()`)

### Semantic Conventions Compliance
* [x] All metrics follow [OpenTelemetry Semantic
Conventions](https://github.com/open-telemetry/semantic-conventions/blob/5ee549b1ce30fe11fcb9b7e3bd35ebfb363f467f/docs/otel/sdk-metrics.md)
* [x] Use the
[`otelconv`](https://pkg.go.dev/go.opentelemetry.io/otel@v1.38.0/semconv/v1.37.0/otelconv)
convenience package for metric semantic conventions
* [x] Component names follow semantic conventions
* [x] Use package path scope type as stable identifier for non-standard
components
* [x] Component names are stable unique identifiers
* [x] Use global counter for uniqueness if necessary
* [x] Component ID counter is resettable for deterministic testing

### Testing
* [x] Use deterministic testing with isolated state
* [x] Restore previous state after tests (`t.Cleanup()`)
* [x] Isolate meter provider for testing
* [x] Use `t.Setenv()` for environment variable testing
* [x] Reset component ID counter for deterministic component names
* [x] Test order doesn't affect results
</details>

### Benchmarks

```console
> benchstat bmark.result
goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/otel/sdk/trace/internal/observ
cpu: Apple M1 Pro
                             │ bmark.result │
                             │    sec/op    │
SSP/SpanProcessed-8            146.7n ± 15%
SSP/SpanProcessedWithError-8   205.1n ±  3%
geomean                        173.5n

                             │ bmark.result │
                             │     B/op     │
SSP/SpanProcessed-8              280.0 ± 0%
SSP/SpanProcessedWithError-8     408.0 ± 0%
geomean                          338.0

                             │ bmark.result │
                             │  allocs/op   │
SSP/SpanProcessed-8              3.000 ± 0%
SSP/SpanProcessedWithError-8     3.000 ± 0%
geomean                          3.000
```

---------

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
2025-10-17 15:57:35 -07:00
Robert Pająk b5b6989c7a sdk/log: Fix AddAttributes, SetAttributes, SetBody on Record to not mutate input (#7403)
Fixes #7364

The allocations happen only when necessary.
This is when deduplication happens or data is truncated because of the
limits.

```
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/log
cpu: 13th Gen Intel(R) Core(TM) i7-13800H
                                              │    old.txt    │                new.txt                 │
                                              │    sec/op     │    sec/op      vs base                 │
AddAttributes/Single/NoLimits-20                 57.91n ± 19%    29.12n ±  5%   -49.71% (p=0.000 n=10)
AddAttributes/Single/AllowDuplicates-20          24.21n ±  2%    24.46n ± 17%    +1.05% (p=0.011 n=10)
AddAttributes/Unique/NoLimits-20                 174.6n ±  8%    184.2n ±  7%    +5.47% (p=0.027 n=10)
AddAttributes/Unique/AllowDuplicates-20          69.79n ± 22%    67.83n ±  9%    -2.81% (p=0.019 n=10)
AddAttributes/Deduplication/Enabled-20           144.5n ±  4%    165.8n ±  4%   +14.71% (p=0.000 n=10)
AddAttributes/NestedDeduplication/Enabled-20     439.2n ±  2%    792.4n ± 11%   +80.41% (p=0.000 n=10)
AddAttributes/NestedDeduplication/Disabled-20   162.60n ±  1%    86.84n ±  5%   -46.59% (p=0.000 n=10)
AddAttributes/Deduplication/Disabled-20          68.15n ±  8%    67.59n ±  8%         ~ (p=0.190 n=10)
AddAttributes/CountLimit/Hit-20                  629.1n ±  4%    621.0n ±  7%         ~ (p=0.325 n=10)
AddAttributes/CountLimit/NotHit-20               914.6n ±  7%    944.2n ± 13%         ~ (p=0.393 n=10)
AddAttributes/ValueLimit/Hit-20                  133.5n ±  2%    162.1n ±  2%   +21.43% (p=0.000 n=10)
AddAttributes/ValueLimit/NotHit-20               115.8n ±  9%    131.2n ±  8%   +13.26% (p=0.000 n=10)
SetAttributes/Single/NoLimits-20                 59.38n ±  2%    28.89n ± 22%   -51.36% (p=0.000 n=10)
SetAttributes/Single/AllowDuplicates-20          24.19n ±  1%    24.30n ±  2%         ~ (p=0.867 n=10)
SetAttributes/Unique/NoLimits-20                 179.8n ±  2%    200.7n ±  6%   +11.66% (p=0.000 n=10)
SetAttributes/Unique/AllowDuplicates-20          72.65n ±  6%    71.91n ±  6%         ~ (p=0.218 n=10)
SetAttributes/Deduplication/Enabled-20           143.9n ±  6%    188.5n ± 12%   +30.96% (p=0.000 n=10)
SetAttributes/Deduplication/Disabled-20          77.68n ± 12%    69.20n ±  8%   -10.92% (p=0.008 n=10)
SetAttributes/NestedDeduplication/Enabled-20     443.7n ± 11%    770.8n ±  7%   +73.75% (p=0.000 n=10)
SetAttributes/NestedDeduplication/Disabled-20   172.60n ±  4%    91.73n ± 11%   -46.85% (p=0.000 n=10)
SetAttributes/CountLimit/Hit-20                  629.1n ±  2%    631.3n ±  7%         ~ (p=0.971 n=10)
SetAttributes/CountLimit/NotHit-20               909.2n ±  8%    866.4n ±  7%         ~ (p=0.143 n=10)
SetAttributes/ValueLimit/Hit-20                  135.5n ±  2%    150.2n ±  5%   +10.85% (p=0.000 n=10)
SetAttributes/ValueLimit/NotHit-20               121.7n ±  7%    137.2n ±  6%   +12.65% (p=0.001 n=10)
SetAttributes/Overwrite/Existing-20              176.0n ±  5%    184.1n ±  2%    +4.60% (p=0.005 n=10)
SetBody/Simple/NoLimits-20                       13.54n ±  1%    13.34n ±  2%    -1.48% (p=0.027 n=10)
SetBody/Simple/WithLimits-20                     13.46n ± 11%    13.91n ±  9%         ~ (p=0.541 n=10)
SetBody/UniqueMap/NoLimits-20                    216.2n ±  8%    183.8n ±  3%   -14.94% (p=0.000 n=10)
SetBody/UniqueMap/AllowDuplicates-20             12.89n ±  1%    12.75n ±  1%    -1.05% (p=0.001 n=10)
SetBody/Deduplication/Enabled-20                 113.5n ±  2%    164.4n ±  4%   +44.85% (p=0.000 n=10)
SetBody/Deduplication/Disabled-20                12.93n ± 41%    12.74n ±  1%    -1.51% (p=0.000 n=10)
SetBody/NestedDeduplication/Enabled-20           206.4n ±  2%    493.4n ±  2%  +139.05% (p=0.000 n=10)
SetBody/NestedDeduplication/Disabled-20          12.93n ±  1%    12.98n ± 11%         ~ (p=0.515 n=10)
SetBody/ValueLimit/Hit-20                        86.22n ±  1%   110.25n ±  3%   +27.87% (p=0.000 n=10)
SetBody/ValueLimit/NoHit-20                      85.52n ±  8%   104.25n ±  1%   +21.91% (p=0.000 n=10)
geomean                                          104.2n          107.1n          +2.84%

                                              │   old.txt    │            new.txt             │
                                              │     B/op     │    B/op     vs base            │
AddAttributes/Single/NoLimits-20                0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
AddAttributes/Single/AllowDuplicates-20         0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
AddAttributes/Unique/NoLimits-20                0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
AddAttributes/Unique/AllowDuplicates-20         0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
AddAttributes/Deduplication/Enabled-20            0.0 ± 0%     128.0 ± 0%  ? (p=0.000 n=10)
AddAttributes/NestedDeduplication/Enabled-20      0.0 ± 0%     312.0 ± 0%  ? (p=0.000 n=10)
AddAttributes/NestedDeduplication/Disabled-20   0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
AddAttributes/Deduplication/Disabled-20         0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
AddAttributes/CountLimit/Hit-20                 208.0 ± 0%     208.0 ± 0%  ~ (p=1.000 n=10) ¹
AddAttributes/CountLimit/NotHit-20              640.0 ± 0%     640.0 ± 0%  ~ (p=1.000 n=10) ¹
AddAttributes/ValueLimit/Hit-20                 0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
AddAttributes/ValueLimit/NotHit-20              0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/Single/NoLimits-20                0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/Single/AllowDuplicates-20         0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/Unique/NoLimits-20                0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/Unique/AllowDuplicates-20         0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/Deduplication/Enabled-20            0.0 ± 0%     128.0 ± 0%  ? (p=0.000 n=10)
SetAttributes/Deduplication/Disabled-20         0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/NestedDeduplication/Enabled-20      0.0 ± 0%     312.0 ± 0%  ? (p=0.000 n=10)
SetAttributes/NestedDeduplication/Disabled-20   0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/CountLimit/Hit-20                 208.0 ± 0%     208.0 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/CountLimit/NotHit-20              640.0 ± 0%     640.0 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/ValueLimit/Hit-20                 0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/ValueLimit/NotHit-20              0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/Overwrite/Existing-20             0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetBody/Simple/NoLimits-20                      0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetBody/Simple/WithLimits-20                    0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetBody/UniqueMap/NoLimits-20                   0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetBody/UniqueMap/AllowDuplicates-20            0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetBody/Deduplication/Enabled-20                  0.0 ± 0%     128.0 ± 0%  ? (p=0.000 n=10)
SetBody/Deduplication/Disabled-20               0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetBody/NestedDeduplication/Enabled-20            0.0 ± 0%     280.0 ± 0%  ? (p=0.000 n=10)
SetBody/NestedDeduplication/Disabled-20         0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetBody/ValueLimit/Hit-20                       0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetBody/ValueLimit/NoHit-20                     0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
geomean                                                    ²               ?                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                                              │   old.txt    │            new.txt             │
                                              │  allocs/op   │ allocs/op   vs base            │
AddAttributes/Single/NoLimits-20                0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
AddAttributes/Single/AllowDuplicates-20         0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
AddAttributes/Unique/NoLimits-20                0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
AddAttributes/Unique/AllowDuplicates-20         0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
AddAttributes/Deduplication/Enabled-20          0.000 ± 0%     1.000 ± 0%  ? (p=0.000 n=10)
AddAttributes/NestedDeduplication/Enabled-20    0.000 ± 0%     5.000 ± 0%  ? (p=0.000 n=10)
AddAttributes/NestedDeduplication/Disabled-20   0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
AddAttributes/Deduplication/Disabled-20         0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
AddAttributes/CountLimit/Hit-20                 1.000 ± 0%     1.000 ± 0%  ~ (p=1.000 n=10) ¹
AddAttributes/CountLimit/NotHit-20              1.000 ± 0%     1.000 ± 0%  ~ (p=1.000 n=10) ¹
AddAttributes/ValueLimit/Hit-20                 0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
AddAttributes/ValueLimit/NotHit-20              0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/Single/NoLimits-20                0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/Single/AllowDuplicates-20         0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/Unique/NoLimits-20                0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/Unique/AllowDuplicates-20         0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/Deduplication/Enabled-20          0.000 ± 0%     1.000 ± 0%  ? (p=0.000 n=10)
SetAttributes/Deduplication/Disabled-20         0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/NestedDeduplication/Enabled-20    0.000 ± 0%     5.000 ± 0%  ? (p=0.000 n=10)
SetAttributes/NestedDeduplication/Disabled-20   0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/CountLimit/Hit-20                 1.000 ± 0%     1.000 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/CountLimit/NotHit-20              1.000 ± 0%     1.000 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/ValueLimit/Hit-20                 0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/ValueLimit/NotHit-20              0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetAttributes/Overwrite/Existing-20             0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetBody/Simple/NoLimits-20                      0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetBody/Simple/WithLimits-20                    0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetBody/UniqueMap/NoLimits-20                   0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetBody/UniqueMap/AllowDuplicates-20            0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetBody/Deduplication/Enabled-20                0.000 ± 0%     1.000 ± 0%  ? (p=0.000 n=10)
SetBody/Deduplication/Disabled-20               0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetBody/NestedDeduplication/Enabled-20          0.000 ± 0%     4.000 ± 0%  ? (p=0.000 n=10)
SetBody/NestedDeduplication/Disabled-20         0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetBody/ValueLimit/Hit-20                       0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
SetBody/ValueLimit/NoHit-20                     0.000 ± 0%     0.000 ± 0%  ~ (p=1.000 n=10) ¹
geomean                                                    ²               ?                ²
¹ all samples are equal
² summaries must be >0 to compute geomean
```
2025-10-16 21:07:08 +02:00
Nikhil Mantri fa8e48ba88 OTLP trace exporter include W3C trace flags (bits 0–7) in Span.Flags (#7438)
Closes #7436 

Span.Flags should include:
Bits 0–7: span’s W3C TraceFlags (e.g., sampled)
Bits 8–9: “has parent isRemote” and “parent isRemote” per OTLP spec

Update the trace exporter to include the span’s W3C trace flags in the
lower 8 bits and keep the existing 8–9 isRemote logic.
Conceptually:
For spans: flags := uint32(sd.SpanContext().TraceFlags() & 0xff)
Always set SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK
If sd.Parent().IsRemote(), also set SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK
Assign s.Flags = flags
Apply the same for links using the link’s SpanContext.TraceFlags() for
bits 0–7 and the link’s SpanContext.IsRemote() for bits 8–9.

---------

Co-authored-by: Damien Mathieu <42@dmathieu.com>
2025-10-13 09:52:27 +02:00
Tyler Yahn f58f79bacb Instrument the otlptracehttp exporter (#7486)
Resolve #7006

### Benchmarks

```console
> benchstat bmark.results
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
                                      │ bmark.results │
                                      │    sec/op     │
ExporterExportSpans/Observability-8      111.6µ ± 12%
ExporterExportSpans/NoObservability-8    108.5µ ±  7%
geomean                                  110.0µ

                                      │ bmark.results │
                                      │     B/op      │
ExporterExportSpans/Observability-8      20.69Ki ± 0%
ExporterExportSpans/NoObservability-8    19.93Ki ± 0%
geomean                                  20.30Ki

                                      │ bmark.results │
                                      │   allocs/op   │
ExporterExportSpans/Observability-8        251.0 ± 0%
ExporterExportSpans/NoObservability-8      247.0 ± 0%
geomean                                    249.0
```
2025-10-10 15:24:13 -07:00
Robert Wu 874c4c3edf feat: Improve error handling in prometheus exporter (#7363)
fix #7066

---------

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
2025-10-09 14:02:15 -07:00
Tyler Yahn c692bc4b87 Instrument the otlptracegrpc exporter (#7459)
Resolve #7007 

### Benchmarks

```console
> benchstat inst-otlptracegrpc.bmark.result
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
                                      │ inst-otlptracegrpc.bmark.result │
                                      │             sec/op              │
ExporterExportSpans/Observability-8                         144.3µ ± 4%
ExporterExportSpans/NoObservability-8                       147.3µ ± 4%
geomean                                                     145.8µ

                                      │ inst-otlptracegrpc.bmark.result │
                                      │              B/op               │
ExporterExportSpans/Observability-8                        23.07Ki ± 0%
ExporterExportSpans/NoObservability-8                      22.34Ki ± 0%
geomean                                                    22.70Ki

                                      │ inst-otlptracegrpc.bmark.result │
                                      │            allocs/op            │
ExporterExportSpans/Observability-8                          335.0 ± 0%
ExporterExportSpans/NoObservability-8                        331.0 ± 0%
geomean                                                      333.0
```
2025-10-07 14:16:39 -07:00
David Ashpole c8e3897521 Use sync.Map and atomics to improve sum performance (#7427)
Alternative to
https://github.com/open-telemetry/opentelemetry-go/pull/7380

This uses a sync.Map and atomics for the sum's counter value. This
intentionally introduces a new race condition that didn't previously
exist:
* It is possible for the exemplar to be recorded in the batch of metrics
after the add() for cumulative sum aggregations. For cumulative, this
isn't a huge issue since exemplars are expected to persist across
collection cycles. This is difficult to fix because we can't manage the
internal storage of an exemplar.Reservoir (to atomically swap between
hot and cold storage). If we are able to make assumptions about how
exemplar reservoirs are managed (i.e. that the number of and order of
exemplars returned is always the same), then we could possibly fix this
by merging at export time.

### Alternatives Considered

#### RWLock for the map instead of sync.Map

This is significantly less performant.

#### Single sync.Map without hotColdWaitGroup

Deleting keys from the sync.Map concurrently with measurements (during
Clear() of the sync.Map) can cause measurements to be made to a counter
that has already been read, exported and deleted. This can produce
incorrect sums when delta is used. Instead, atomically switching writes
to a completely empty sync.Map and waiting for writes to the previous
sync.Map complete eliminates this issue.

#### Use two sync.Map for cumulative sums

One idea I explored was doing a hot-cold swap for cumulative sums just
like we do for delta sums. We would swap the hot and cold sync.Maps,
wait for writes to the cold sync.Map to complete while new writes go to
the hot map. Then, once we are done reading the cold map, we could merge
the contents of the cold map back into the new hot map.

This approach has two issues:

* It isn't possible to "merge" one exemplar reservoir into another. This
is an issue for persistent exemplars that aren't overwritten in a
collection interval.
* We can't keep a consistent set of keys in overflow scenarios.
Measurements that are made to the hot map before the merge of the cold
into hot that should have been overflows will be added as new attribute
sets. That, in turn, means we will need to change previously-exported
attribute sets to the overflow set, which will cause issues for users.

### Benchmarks

Parallel:
```
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/metric
cpu: AMD EPYC 7B12
                                                                                  │  main24.txt   │            new24_new.txt            │
                                                                                  │    sec/op     │    sec/op     vs base               │
SyncMeasure/NoView/ExemplarsDisabled/Int64Counter/Attributes/0-24                   255.65n ± 13%   68.06n ±  3%  -73.38% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64Counter/Attributes/1-24                   286.70n ±  8%   67.66n ±  4%  -76.40% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64Counter/Attributes/10-24                  287.15n ± 14%   69.90n ±  3%  -75.66% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64Counter/Attributes/0-24                 244.75n ±  9%   68.83n ±  4%  -71.88% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64Counter/Attributes/1-24                 267.20n ± 14%   65.86n ±  3%  -75.35% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64Counter/Attributes/10-24                291.50n ± 13%   66.59n ± 11%  -77.15% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64UpDownCounter/Attributes/0-24             247.85n ±  7%   66.06n ±  3%  -73.34% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64UpDownCounter/Attributes/1-24             286.75n ± 10%   68.52n ±  2%  -76.10% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64UpDownCounter/Attributes/10-24            289.50n ± 20%   67.45n ±  4%  -76.70% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64UpDownCounter/Attributes/0-24           246.25n ± 14%   66.69n ±  2%  -72.92% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64UpDownCounter/Attributes/1-24           289.55n ±  9%   65.54n ±  5%  -77.36% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64UpDownCounter/Attributes/10-24          286.05n ± 14%   67.55n ±  2%  -76.39% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64Gauge/Attributes/0-24                      254.8n ± 23%   225.9n ± 17%  -11.32% (p=0.026 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64Gauge/Attributes/1-24                      304.4n ± 13%   234.4n ± 19%  -23.01% (p=0.004 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64Gauge/Attributes/10-24                     308.9n ± 20%   217.6n ± 10%  -29.56% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64Gauge/Attributes/0-24                    267.8n ± 14%   220.1n ± 19%  -17.80% (p=0.004 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64Gauge/Attributes/1-24                    274.1n ± 21%   226.5n ±  5%  -17.38% (p=0.024 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64Gauge/Attributes/10-24                   239.0n ± 14%   236.1n ± 18%        ~ (p=0.589 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64Histogram/Attributes/0-24                  223.7n ± 11%   234.8n ±  7%        ~ (p=0.240 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64Histogram/Attributes/1-24                  253.9n ± 10%   244.8n ± 11%        ~ (p=0.240 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64Histogram/Attributes/10-24                 272.6n ±  7%   250.0n ± 12%   -8.33% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64Histogram/Attributes/0-24                232.6n ±  4%   232.2n ±  8%        ~ (p=0.937 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64Histogram/Attributes/1-24                276.7n ± 20%   249.2n ± 11%        ~ (p=0.485 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64Histogram/Attributes/10-24               265.9n ± 18%   246.4n ±  9%        ~ (p=0.240 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialInt64Histogram/Attributes/0-24       294.0n ± 11%   269.0n ±  5%   -8.47% (p=0.015 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialInt64Histogram/Attributes/1-24       314.6n ± 10%   268.8n ±  6%  -14.54% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialInt64Histogram/Attributes/10-24      303.9n ± 11%   285.4n ±  4%        ~ (p=0.180 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialFloat64Histogram/Attributes/0-24     274.7n ± 13%   262.9n ±  7%        ~ (p=0.145 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialFloat64Histogram/Attributes/1-24     296.1n ±  6%   288.9n ±  9%        ~ (p=0.180 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialFloat64Histogram/Attributes/10-24    276.0n ± 14%   299.4n ± 12%        ~ (p=0.240 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64Counter/Attributes/0-24                     191.4n ±  4%   176.0n ±  3%   -8.05% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64Counter/Attributes/1-24                     223.2n ±  8%   172.8n ±  3%  -22.54% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64Counter/Attributes/10-24                    265.7n ± 19%   172.2n ±  2%  -35.21% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Counter/Attributes/0-24                   179.4n ± 18%   171.0n ±  3%   -4.74% (p=0.009 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Counter/Attributes/1-24                   209.1n ± 16%   175.4n ±  5%  -16.07% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Counter/Attributes/10-24                  222.5n ± 17%   175.6n ±  4%  -21.08% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64UpDownCounter/Attributes/0-24               194.4n ± 11%   176.9n ±  5%   -9.03% (p=0.004 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64UpDownCounter/Attributes/1-24               207.5n ± 13%   175.1n ±  2%  -15.66% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64UpDownCounter/Attributes/10-24              243.7n ± 13%   172.6n ±  3%  -29.15% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64UpDownCounter/Attributes/0-24             218.3n ± 10%   177.6n ±  2%  -18.67% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64UpDownCounter/Attributes/1-24             193.5n ± 10%   176.1n ±  2%   -8.99% (p=0.004 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64UpDownCounter/Attributes/10-24            192.8n ± 11%   173.7n ±  2%   -9.91% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64Gauge/Attributes/0-24                       185.1n ±  9%   204.8n ±  9%  +10.61% (p=0.004 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64Gauge/Attributes/1-24                       218.8n ± 14%   229.7n ± 16%        ~ (p=0.310 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64Gauge/Attributes/10-24                      242.7n ±  8%   209.1n ± 18%  -13.84% (p=0.041 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Gauge/Attributes/0-24                     182.8n ± 42%   255.2n ±  8%  +39.67% (p=0.015 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Gauge/Attributes/1-24                     198.0n ±  7%   280.6n ± 22%  +41.72% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Gauge/Attributes/10-24                    236.3n ± 18%   261.7n ±  8%        ~ (p=0.065 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64Histogram/Attributes/0-24                   223.2n ±  9%   226.9n ±  4%        ~ (p=0.965 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64Histogram/Attributes/1-24                   270.1n ± 10%   280.2n ±  6%        ~ (p=0.143 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64Histogram/Attributes/10-24                  257.2n ±  7%   252.0n ±  7%        ~ (p=0.485 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Histogram/Attributes/0-24                 277.0n ±  5%   310.4n ± 12%        ~ (p=0.065 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Histogram/Attributes/1-24                 287.3n ±  9%   271.2n ± 12%        ~ (p=0.699 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Histogram/Attributes/10-24                281.8n ±  9%   316.5n ± 22%  +12.29% (p=0.041 n=6)
SyncMeasure/NoView/ExemplarsEnabled/ExponentialInt64Histogram/Attributes/0-24        289.1n ±  9%   297.1n ± 12%        ~ (p=0.310 n=6)
SyncMeasure/NoView/ExemplarsEnabled/ExponentialInt64Histogram/Attributes/1-24        277.8n ±  6%   353.1n ± 11%  +27.11% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/ExponentialInt64Histogram/Attributes/10-24       281.8n ± 11%   352.2n ± 16%  +24.94% (p=0.009 n=6)
SyncMeasure/NoView/ExemplarsEnabled/ExponentialFloat64Histogram/Attributes/0-24      294.1n ±  7%   317.5n ±  9%        ~ (p=0.065 n=6)
SyncMeasure/NoView/ExemplarsEnabled/ExponentialFloat64Histogram/Attributes/1-24      281.7n ± 10%   332.1n ±  8%  +17.89% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/ExponentialFloat64Histogram/Attributes/10-24     238.9n ± 12%   318.1n ±  9%  +33.13% (p=0.002 n=6)
geomean                                                                              251.9n         184.4n        -26.77%
```


Single-threaded:
```
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/metric
cpu: Intel(R) Xeon(R) CPU @ 2.20GHz
                                                                               │  main1.txt   │              sync1.txt              │
                                                                               │    sec/op    │    sec/op     vs base               │
SyncMeasure/NoView/ExemplarsDisabled/Int64Counter/Attributes/0                   109.8n ±  7%   113.4n ± 23%        ~ (p=1.000 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64Counter/Attributes/1                   115.0n ±  4%   113.3n ± 20%        ~ (p=0.729 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64Counter/Attributes/10                  177.1n ± 34%   110.2n ± 16%  -37.78% (p=0.009 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64Counter/Attributes/0                 110.5n ± 42%   109.2n ± 19%        ~ (p=0.457 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64Counter/Attributes/1                 118.8n ±  2%   118.4n ±  5%        ~ (p=0.619 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64Counter/Attributes/10                119.0n ±  2%   116.8n ± 42%        ~ (p=0.699 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64UpDownCounter/Attributes/0             106.9n ±  1%   102.5n ±  5%   -4.16% (p=0.030 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64UpDownCounter/Attributes/1             117.2n ±  2%   116.9n ±  7%        ~ (p=1.000 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64UpDownCounter/Attributes/10            115.4n ±  1%   115.1n ±  5%        ~ (p=0.937 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64UpDownCounter/Attributes/0           109.5n ±  5%   104.2n ±  8%   -4.84% (p=0.041 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64UpDownCounter/Attributes/1           118.7n ± 14%   113.8n ± 35%        ~ (p=0.240 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64UpDownCounter/Attributes/10          116.6n ±  1%   116.8n ±  8%        ~ (p=0.968 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64Gauge/Attributes/0                     106.6n ±  4%   109.4n ±  5%        ~ (p=0.093 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64Gauge/Attributes/1                     114.7n ±  4%   117.9n ±  4%        ~ (p=0.240 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64Gauge/Attributes/10                    115.2n ±  4%   114.5n ±  1%        ~ (p=0.162 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64Gauge/Attributes/0                   109.4n ±  5%   107.5n ±  3%        ~ (p=0.132 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64Gauge/Attributes/1                   118.3n ±  2%   117.9n ±  3%        ~ (p=0.589 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64Gauge/Attributes/10                  117.7n ±  2%   120.8n ± 14%        ~ (p=0.093 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64Histogram/Attributes/0                 96.78n ±  1%   99.37n ±  3%        ~ (p=0.065 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64Histogram/Attributes/1                 103.0n ±  3%   116.5n ± 26%  +13.16% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Int64Histogram/Attributes/10                102.8n ±  1%   107.6n ± 22%   +4.67% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64Histogram/Attributes/0               93.95n ± 22%   99.88n ± 18%   +6.32% (p=0.041 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64Histogram/Attributes/1               102.7n ±  5%   106.2n ±  6%        ~ (p=0.089 n=6)
SyncMeasure/NoView/ExemplarsDisabled/Float64Histogram/Attributes/10              104.1n ±  4%   108.3n ± 27%   +4.03% (p=0.026 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialInt64Histogram/Attributes/0      146.3n ±  1%   154.0n ± 24%   +5.23% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialInt64Histogram/Attributes/1      154.8n ±  3%   161.2n ±  2%   +4.20% (p=0.004 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialInt64Histogram/Attributes/10     155.5n ±  1%   164.0n ±  4%   +5.43% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialFloat64Histogram/Attributes/0    145.9n ±  2%   159.7n ± 12%   +9.42% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialFloat64Histogram/Attributes/1    155.2n ±  0%   164.0n ±  6%   +5.70% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialFloat64Histogram/Attributes/10   219.3n ± 29%   159.5n ±  3%        ~ (p=0.065 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64Counter/Attributes/0                    263.6n ± 36%   177.2n ±  1%        ~ (p=0.065 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64Counter/Attributes/1                    189.1n ±  8%   190.4n ± 12%        ~ (p=0.589 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64Counter/Attributes/10                   184.3n ±  3%   189.4n ±  6%        ~ (p=0.065 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Counter/Attributes/0                  180.7n ±  1%   182.7n ±  2%        ~ (p=0.457 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Counter/Attributes/1                  192.8n ±  9%   192.0n ±  1%        ~ (p=1.000 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Counter/Attributes/10                 192.3n ±  4%   190.2n ±  4%        ~ (p=0.093 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64UpDownCounter/Attributes/0              176.5n ±  2%   181.7n ±  4%   +2.95% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64UpDownCounter/Attributes/1              184.0n ±  4%   192.0n ±  1%   +4.32% (p=0.015 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64UpDownCounter/Attributes/10             184.4n ±  1%   195.2n ±  3%   +5.83% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64UpDownCounter/Attributes/0            183.0n ±  3%   177.4n ±  5%   -3.06% (p=0.048 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64UpDownCounter/Attributes/1            194.4n ±  4%   188.1n ±  5%        ~ (p=0.084 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64UpDownCounter/Attributes/10           193.0n ±  5%   194.1n ±  5%        ~ (p=0.699 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64Gauge/Attributes/0                      178.4n ± 14%   185.6n ± 29%        ~ (p=0.240 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64Gauge/Attributes/1                      189.0n ±  8%   193.2n ±  2%        ~ (p=0.132 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64Gauge/Attributes/10                     197.7n ±  5%   198.8n ±  2%        ~ (p=0.619 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Gauge/Attributes/0                    185.5n ±  3%   188.8n ±  4%        ~ (p=0.310 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Gauge/Attributes/1                    191.2n ±  3%   190.2n ±  7%        ~ (p=0.732 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Gauge/Attributes/10                   186.8n ±  2%   197.1n ±  6%   +5.54% (p=0.004 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64Histogram/Attributes/0                  224.2n ±  4%   227.3n ±  2%        ~ (p=0.394 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64Histogram/Attributes/1                  232.5n ±  3%   242.5n ±  5%        ~ (p=0.132 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Int64Histogram/Attributes/10                 232.5n ±  3%   237.1n ±  5%   +2.00% (p=0.045 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Histogram/Attributes/0                227.5n ±  2%   238.5n ±  5%   +4.81% (p=0.017 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Histogram/Attributes/1                239.4n ±  8%   250.1n ±  6%        ~ (p=0.240 n=6)
SyncMeasure/NoView/ExemplarsEnabled/Float64Histogram/Attributes/10               241.5n ±  4%   254.0n ±  2%   +5.18% (p=0.004 n=6)
SyncMeasure/NoView/ExemplarsEnabled/ExponentialInt64Histogram/Attributes/0       231.1n ±  5%   239.2n ±  3%        ~ (p=0.084 n=6)
SyncMeasure/NoView/ExemplarsEnabled/ExponentialInt64Histogram/Attributes/1       260.2n ± 16%   253.8n ±  4%        ~ (p=0.190 n=6)
SyncMeasure/NoView/ExemplarsEnabled/ExponentialInt64Histogram/Attributes/10      234.3n ±  1%   246.8n ±  2%   +5.29% (p=0.002 n=6)
SyncMeasure/NoView/ExemplarsEnabled/ExponentialFloat64Histogram/Attributes/0     221.8n ±  6%   232.0n ±  4%   +4.58% (p=0.037 n=6)
SyncMeasure/NoView/ExemplarsEnabled/ExponentialFloat64Histogram/Attributes/1     228.2n ±  7%   240.6n ±  1%   +5.41% (p=0.041 n=6)
SyncMeasure/NoView/ExemplarsEnabled/ExponentialFloat64Histogram/Attributes/10    228.6n ±  7%   244.7n ±  1%   +7.04% (p=0.015 n=6)
geomean                                                                          158.1n         158.1n         +0.00%
```

---------

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
2025-10-07 09:40:23 -04:00
Tyler Yahn c4bdd87543 Support custom error type semantics (#7442)
Allow instrumentation to provide domain-specific error type values (i.e.
HTTP or gRPC status codes) for the "error.type" semantic attribute. This
is accomplished by passing an error value that implements the
`interface{ ErrorType string }` interface.

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
2025-10-03 15:39:35 -07:00
ian 5dd35ce873 feat: logs SDK observability - otlploggrpc exporter metrics (#7353)
This PR adds support for experimental metrics in `otlploggrpc`

- `otel.sdk.exporter.log.inflight`
- `otel.sdk.exporter.log.exported`
- `otel.sdk.exporter.operation.duration`

References:

-  #7084 
-  https://github.com/open-telemetry/opentelemetry-go/issues/7019
- [Follow
guidelines](https://github.com/open-telemetry/opentelemetry-go/blob/a5dcd68ebb2f3669f7685ac7b0f3f1624251a381/CONTRIBUTING.md#encapsulation).

-----
```txt
goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc
cpu: Apple M3
                                   │ disabled.txt │          enabled.txt          │
                                   │    sec/op    │   sec/op     vs base          │
ExporterExportLogs/Observability-8    681.5µ ± 3%   684.3µ ± 6%  ~ (p=0.315 n=10)

                                   │ disabled.txt │          enabled.txt           │
                                   │     B/op     │     B/op      vs base          │
ExporterExportLogs/Observability-8   672.8Ki ± 0%   673.6Ki ± 1%  ~ (p=0.247 n=10)

                                   │ disabled.txt │            enabled.txt             │
                                   │  allocs/op   │  allocs/op   vs base               │
ExporterExportLogs/Observability-8    9.224k ± 0%   9.232k ± 0%  +0.09% (p=0.000 n=10)
```

-----
```txt
goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc/internal/observ
cpu: Apple M3
                                         │  bench.txt  │
                                         │   sec/op    │
InstrumentationExportLogs/NoError-8        162.6n ± 3%
InstrumentationExportLogs/PartialError-8   705.5n ± 5%
InstrumentationExportLogs/FullError-8      592.1n ± 1%
geomean                                    408.0n

                                         │ bench.txt  │
                                         │    B/op    │
InstrumentationExportLogs/NoError-8        152.0 ± 0%
InstrumentationExportLogs/PartialError-8   697.0 ± 0%
InstrumentationExportLogs/FullError-8      616.0 ± 0%
geomean                                    402.6

                                         │ bench.txt  │
                                         │ allocs/op  │
InstrumentationExportLogs/NoError-8        3.000 ± 0%
InstrumentationExportLogs/PartialError-8   10.00 ± 0%
InstrumentationExportLogs/FullError-8      8.000 ± 0%
geomean                                    6.214
```

-----
```txt
pkg: go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc/internal/observ
cpu: Apple M3
                                 │ parse_target.txt │
                                 │      sec/op      │
ParseTarget/HostName-8                 38.00n ± ∞ ¹
ParseTarget/HostPort-8                 51.33n ± ∞ ¹
ParseTarget/IPv4WithoutPort-8          44.74n ± ∞ ¹
ParseTarget/IPv4WithPort-8             62.56n ± ∞ ¹
ParseTarget/IPv6Bare-8                 94.89n ± ∞ ¹
ParseTarget/IPv6Bracket-8              93.78n ± ∞ ¹
ParseTarget/IPv6WithPort-8             57.57n ± ∞ ¹
ParseTarget/UnixSocket-8               8.329n ± ∞ ¹
ParseTarget/UnixAbstractSocket-8       9.082n ± ∞ ¹
ParseTarget/Passthrough-8              58.06n ± ∞ ¹
geomean                                40.64n
¹ need >= 6 samples for confidence interval at level 0.95

                                 │ parse_target.txt │
                                 │       B/op       │
ParseTarget/HostName-8                  48.00 ± ∞ ¹
ParseTarget/HostPort-8                  48.00 ± ∞ ¹
ParseTarget/IPv4WithoutPort-8           16.00 ± ∞ ¹
ParseTarget/IPv4WithPort-8              48.00 ± ∞ ¹
ParseTarget/IPv6Bare-8                  16.00 ± ∞ ¹
ParseTarget/IPv6Bracket-8               16.00 ± ∞ ¹
ParseTarget/IPv6WithPort-8              48.00 ± ∞ ¹
ParseTarget/UnixSocket-8                0.000 ± ∞ ¹
ParseTarget/UnixAbstractSocket-8        0.000 ± ∞ ¹
ParseTarget/Passthrough-8               48.00 ± ∞ ¹
geomean                                           ²
¹ need >= 6 samples for confidence interval at level 0.95
² summaries must be >0 to compute geomean

                                 │ parse_target.txt │
                                 │    allocs/op     │
ParseTarget/HostName-8                  1.000 ± ∞ ¹
ParseTarget/HostPort-8                  1.000 ± ∞ ¹
ParseTarget/IPv4WithoutPort-8           1.000 ± ∞ ¹
ParseTarget/IPv4WithPort-8              1.000 ± ∞ ¹
ParseTarget/IPv6Bare-8                  1.000 ± ∞ ¹
ParseTarget/IPv6Bracket-8               1.000 ± ∞ ¹
ParseTarget/IPv6WithPort-8              1.000 ± ∞ ¹
ParseTarget/UnixSocket-8                0.000 ± ∞ ¹
ParseTarget/UnixAbstractSocket-8        0.000 ± ∞ ¹
ParseTarget/Passthrough-8               1.000 ± ∞ ¹
geomean                                           ²
¹ need >= 6 samples for confidence interval at level 0.95
² summaries must be >0 to compute geomean
```

---------

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
2025-10-02 10:15:41 -07:00
Dave Protasowski dee11e6ae3 Add temporality selector functions (#7434)
From: https://github.com/open-telemetry/opentelemetry-go/pull/7346

This PR exposes the default TemporalitySelector funcs that are used by
the OTel env var processing.

The reason to expose these funcs is because there is some discrepancy in
various vendor documentation on how to enable these settings using go
option args WithTemporalitySelector

https://cloud-native.slack.com/archives/C01NPAXACKT/p1757443233624599

---------

Co-authored-by: Damien Mathieu <42@dmathieu.com>
Co-authored-by: David Ashpole <dashpole@google.com>
2025-10-02 16:13:59 +02:00
David Ashpole 59ac46c03a Prometheus exporter: change default translation strategy (#7421)
Part of https://github.com/open-telemetry/opentelemetry-go/issues/7083

cc @ywwg @ArthurSens

---------

Co-authored-by: Flc゛ <four_leaf_clover@foxmail.com>
2025-09-29 11:19:09 -04:00
Tyler Yahn 6180f833bc Return partial OTLP export errors to the caller (#7372)
Fix #7370 

Do not pass relevant errors for the operation of the export to the
`otel.ErrorHandler`. Instead, include them in the error returned to the
caller.
2025-09-18 13:08:25 -07:00
Robert Wu 60f9f39d78 feat(prometheus): Add observability for prometheus exporter (#7345)
fix #7013 

References: 

- [Follow
guidelines](https://github.com/open-telemetry/opentelemetry-go/blob/a5dcd68ebb2f3669f7685ac7b0f3f1624251a381/CONTRIBUTING.md#encapsulation).
- PR: #7307 

Implement following self-observability metrics from
https://github.com/open-telemetry/semantic-conventions/blob/v1.36.0/docs/otel/sdk-metrics.md
for https://pkg.go.dev/go.opentelemetry.io/otel/exporters/prometheus:

- otel.sdk.exporter.metric_data_point.inflight
- otel.sdk.exporter.metric_data_point.exported
- otel.sdk.exporter.operation.duration
- otel.sdk.metric_reader.collection.duration

### Benchmarks

```console
➜ benchstat /tmp/bench_disabled.txt /tmp/bench_enabled.txt
goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/otel/exporters/prometheus/internal/observ
cpu: Apple M1 Max
                                           │ /tmp/bench_disabled.txt │       /tmp/bench_enabled.txt       │
                                           │         sec/op          │   sec/op     vs base               │
InstrumentationExportMetrics-10                          177.5n ± 0%   177.8n ± 0%  +0.14% (p=0.039 n=20)
InstrumentationRecordOperationDuration-10                246.6n ± 0%   246.7n ± 0%       ~ (p=0.606 n=20)
InstrumentationRecordCollectionDuration-10               246.8n ± 1%   247.2n ± 0%       ~ (p=0.456 n=20)
geomean                                                  221.1n        221.3n       +0.09%

                                           │ /tmp/bench_disabled.txt │       /tmp/bench_enabled.txt        │
                                           │          B/op           │    B/op     vs base                 │
InstrumentationExportMetrics-10                           256.0 ± 0%   256.0 ± 0%       ~ (p=1.000 n=20) ¹
InstrumentationRecordOperationDuration-10                 272.0 ± 0%   272.0 ± 0%       ~ (p=1.000 n=20) ¹
InstrumentationRecordCollectionDuration-10                272.0 ± 0%   272.0 ± 0%       ~ (p=1.000 n=20) ¹
geomean                                                   266.6        266.6       +0.00%
¹ all samples are equal

                                           │ /tmp/bench_disabled.txt │       /tmp/bench_enabled.txt        │
                                           │        allocs/op        │ allocs/op   vs base                 │
InstrumentationExportMetrics-10                           3.000 ± 0%   3.000 ± 0%       ~ (p=1.000 n=20) ¹
InstrumentationRecordOperationDuration-10                 3.000 ± 0%   3.000 ± 0%       ~ (p=1.000 n=20) ¹
InstrumentationRecordCollectionDuration-10                3.000 ± 0%   3.000 ± 0%       ~ (p=1.000 n=20) ¹
geomean                                                   3.000        3.000       +0.00%
¹ all samples are equal
```

---------

Co-authored-by: Flc゛ <four_leaf_clover@foxmail.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
2025-09-18 07:52:54 -07:00
David Ashpole 9d52bde6d6 Use Set hash in Distinct (2nd attempt) (#7175)
Re-opening https://github.com/open-telemetry/opentelemetry-go/pull/5028
with new benchmarks. For cases with 10 attributes, this reduces the
overhead of metric measurements by ~80-90% (depending on lock
contention). It introduces a small probability of collision for
attribute sets in the metrics SDK. For an instrument with 1 million
different attribute sets, the probability of a collision is
approximately 2 * 10^-8. For a more "normal" cardinality of 1000 on an
instrument, it is approximately 2 * 10^-17.

```
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/attribute
cpu: Intel(R) Xeon(R) CPU @ 2.20GHz
                                            │   main.txt    │              hash.txt               │
                                            │    sec/op     │    sec/op     vs base               │
EquivalentMapAccess/Empty-24                    32.01n ± 2%   10.12n ±  4%  -68.37% (p=0.002 n=6)
EquivalentMapAccess/1_string_attribute-24      106.25n ± 2%   10.01n ±  5%  -90.58% (p=0.002 n=6)
EquivalentMapAccess/10_string_attributes-24   826.250n ± 1%   9.982n ± 11%  -98.79% (p=0.002 n=6)
EquivalentMapAccess/1_int_attribute-24         106.65n ± 2%   10.13n ±  3%  -90.50% (p=0.002 n=6)
EquivalentMapAccess/10_int_attributes-24       833.25n ± 2%   10.04n ±  5%  -98.80% (p=0.002 n=6)
geomean                                         190.3n        10.06n        -94.72%
```

Parallel benchmarks:

```
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/metric
cpu: Intel(R) Xeon(R) CPU @ 2.20GHz
                                                         │  main24.txt   │              new24.txt              │
                                                         │    sec/op     │    sec/op     vs base               │
SyncMeasure/NoView/Int64Counter/Attributes/0-24             288.4n ± 13%   267.0n ± 16%        ~ (p=0.180 n=6)
SyncMeasure/NoView/Int64Counter/Attributes/1-24             372.7n ± 24%   303.3n ±  6%  -18.61% (p=0.002 n=6)
SyncMeasure/NoView/Int64Counter/Attributes/10-24           1862.5n ± 11%   302.2n ±  6%  -83.77% (p=0.002 n=6)
SyncMeasure/NoView/Float64Counter/Attributes/0-24           288.2n ±  5%   291.8n ± 14%        ~ (p=0.589 n=6)
SyncMeasure/NoView/Float64Counter/Attributes/1-24           374.8n ± 22%   326.2n ± 15%  -12.98% (p=0.002 n=6)
SyncMeasure/NoView/Float64Counter/Attributes/10-24         1984.0n ± 10%   277.9n ± 15%  -85.99% (p=0.002 n=6)
SyncMeasure/NoView/Int64UpDownCounter/Attributes/0-24       286.8n ± 13%   279.4n ± 14%        ~ (p=0.818 n=6)
SyncMeasure/NoView/Int64UpDownCounter/Attributes/1-24       415.4n ± 14%   309.5n ± 11%  -25.47% (p=0.002 n=6)
SyncMeasure/NoView/Int64UpDownCounter/Attributes/10-24     1923.0n ± 19%   294.1n ± 17%  -84.71% (p=0.002 n=6)
SyncMeasure/NoView/Float64UpDownCounter/Attributes/0-24     284.9n ±  5%   271.6n ± 11%        ~ (p=0.240 n=6)
SyncMeasure/NoView/Float64UpDownCounter/Attributes/1-24     382.9n ± 23%   295.7n ± 13%  -22.78% (p=0.002 n=6)
SyncMeasure/NoView/Float64UpDownCounter/Attributes/10-24   1787.0n ± 28%   289.2n ± 12%  -83.81% (p=0.002 n=6)
SyncMeasure/NoView/Int64Histogram/Attributes/0-24           283.4n ±  8%   269.9n ±  9%        ~ (p=0.589 n=6)
SyncMeasure/NoView/Int64Histogram/Attributes/1-24           300.7n ±  8%   270.1n ± 15%  -10.16% (p=0.026 n=6)
SyncMeasure/NoView/Int64Histogram/Attributes/10-24         1046.8n ± 24%   299.2n ± 16%  -71.42% (p=0.002 n=6)
SyncMeasure/NoView/Float64Histogram/Attributes/0-24         264.3n ± 12%   295.9n ±  5%  +11.93% (p=0.026 n=6)
SyncMeasure/NoView/Float64Histogram/Attributes/1-24         321.0n ±  8%   269.4n ± 11%  -16.09% (p=0.002 n=6)
SyncMeasure/NoView/Float64Histogram/Attributes/10-24       1052.2n ± 10%   274.6n ±  5%  -73.90% (p=0.002 n=6)
geomean                                                     540.0n         287.7n        -46.72%
```

Single-threaded benchmarks:

```
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/metric
cpu: Intel(R) Xeon(R) CPU @ 2.20GHz
                                                      │   main1.txt   │              new1.txt               │
                                                      │    sec/op     │    sec/op     vs base               │
SyncMeasure/NoView/Int64Counter/Attributes/0            130.95n ±  1%   97.99n ± 21%  -25.17% (p=0.002 n=6)
SyncMeasure/NoView/Int64Counter/Attributes/1             300.8n ±  7%   104.6n ±  3%  -65.21% (p=0.002 n=6)
SyncMeasure/NoView/Int64Counter/Attributes/10           1646.0n ±  2%   105.8n ±  2%  -93.58% (p=0.002 n=6)
SyncMeasure/NoView/Float64Counter/Attributes/0          132.65n ±  1%   99.28n ±  4%  -25.16% (p=0.002 n=6)
SyncMeasure/NoView/Float64Counter/Attributes/1           295.4n ±  3%   107.7n ±  3%  -63.54% (p=0.002 n=6)
SyncMeasure/NoView/Float64Counter/Attributes/10         1620.0n ±  1%   109.6n ±  4%  -93.23% (p=0.002 n=6)
SyncMeasure/NoView/Int64UpDownCounter/Attributes/0      132.85n ± 80%   99.34n ±  1%  -25.22% (p=0.002 n=6)
SyncMeasure/NoView/Int64UpDownCounter/Attributes/1       300.4n ±  1%   106.0n ±  1%  -64.71% (p=0.002 n=6)
SyncMeasure/NoView/Int64UpDownCounter/Attributes/10     1622.0n ±  1%   105.8n ±  1%  -93.48% (p=0.002 n=6)
SyncMeasure/NoView/Float64UpDownCounter/Attributes/0    134.90n ± 51%   99.16n ±  4%  -26.49% (p=0.002 n=6)
SyncMeasure/NoView/Float64UpDownCounter/Attributes/1     312.4n ± 34%   107.8n ±  2%  -65.51% (p=0.002 n=6)
SyncMeasure/NoView/Float64UpDownCounter/Attributes/10   1613.0n ± 23%   106.1n ±  1%  -93.43% (p=0.002 n=6)
SyncMeasure/NoView/Int64Histogram/Attributes/0          103.50n ± 17%   88.53n ±  1%  -14.46% (p=0.002 n=6)
SyncMeasure/NoView/Int64Histogram/Attributes/1          199.50n ± 16%   95.44n ±  2%  -52.16% (p=0.002 n=6)
SyncMeasure/NoView/Int64Histogram/Attributes/10         878.70n ±  2%   95.78n ±  2%  -89.10% (p=0.002 n=6)
SyncMeasure/NoView/Float64Histogram/Attributes/0        108.55n ± 54%   88.45n ±  1%  -18.51% (p=0.002 n=6)
SyncMeasure/NoView/Float64Histogram/Attributes/1        257.30n ± 14%   95.05n ±  2%  -63.06% (p=0.002 n=6)
SyncMeasure/NoView/Float64Histogram/Attributes/10       882.70n ± 18%   96.28n ±  1%  -89.09% (p=0.002 n=6)
geomean                                                  355.2n         100.3n        -71.77%
```

---------

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: Robert Pająk <pellared@hotmail.com>
2025-09-16 16:04:50 -04:00
Tyler Yahn 59563f7ae4 Do not use the user-defined empty set when comparing sets. (#7357)
Fix #7356
2025-09-15 09:28:12 -07:00
Andrew Wilkins e2da30d7d0 trace,metric,log: change WithInstrumentationAttributes to not de-depuplicate the passed attributes in a closure (#7266)
WithInstrumentationAttributes is creating a closure with a reference to
a slice which is later passed to attribute.NewSet.

attribute.NewSet may mutate the slice, so this will lead to a data race
when the option is applied concurrently. We can fix this by moving the
call to attribute.NewSet outside the closure.

Fixes #7217

<details>
<summary>benchstat for New*Config</summary>

```
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/log
cpu: Intel(R) Core(TM) Ultra 7 155U
                                                      │ /tmp/old.txt │            /tmp/new.txt            │
                                                      │    sec/op    │   sec/op     vs base               │
NewLoggerConfig/with_no_options-14                       2.961n ± 6%   3.091n ± 6%        ~ (p=0.132 n=6)
NewLoggerConfig/with_an_instrumentation_version-14       24.75n ± 4%   25.04n ± 5%        ~ (p=0.126 n=6)
NewLoggerConfig/with_a_schema_url-14                     24.97n ± 6%   24.79n ± 4%        ~ (p=0.974 n=6)
NewLoggerConfig/with_instrumentation_attribute-14        55.32n ± 4%   25.32n ± 4%  -54.23% (p=0.002 n=6)
NewLoggerConfig/with_instrumentation_attribute_set-14    24.77n ± 3%   24.96n ± 4%        ~ (p=0.394 n=6)
geomean                                                  19.05n        16.47n       -13.52%

                                                      │ /tmp/old.txt │              /tmp/new.txt              │
                                                      │     B/op     │    B/op     vs base                    │
NewLoggerConfig/with_no_options-14                      0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewLoggerConfig/with_an_instrumentation_version-14      0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewLoggerConfig/with_a_schema_url-14                    0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewLoggerConfig/with_instrumentation_attribute-14       64.00 ± 0%      0.00 ± 0%  -100.00% (p=0.002 n=6)
NewLoggerConfig/with_instrumentation_attribute_set-14   0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
geomean                                                            ²               ?                      ² ³
¹ all samples are equal
² summaries must be >0 to compute geomean
³ ratios must be >0 to compute geomean

                                                      │ /tmp/old.txt │              /tmp/new.txt              │
                                                      │  allocs/op   │ allocs/op   vs base                    │
NewLoggerConfig/with_no_options-14                      0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewLoggerConfig/with_an_instrumentation_version-14      0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewLoggerConfig/with_a_schema_url-14                    0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewLoggerConfig/with_instrumentation_attribute-14       1.000 ± 0%     0.000 ± 0%  -100.00% (p=0.002 n=6)
NewLoggerConfig/with_instrumentation_attribute_set-14   0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
geomean                                                            ²               ?                      ² ³
¹ all samples are equal
² summaries must be >0 to compute geomean
³ ratios must be >0 to compute geomean

pkg: go.opentelemetry.io/otel/metric
                                                     │ /tmp/old.txt │            /tmp/new.txt            │
                                                     │    sec/op    │   sec/op     vs base               │
NewMeterConfig/with_no_options-14                       3.255n ± 2%   3.045n ± 4%   -6.42% (p=0.002 n=6)
NewMeterConfig/with_an_instrumentation_version-14       22.84n ± 6%   23.14n ± 3%        ~ (p=0.818 n=6)
NewMeterConfig/with_a_schema_url-14                     24.71n ± 5%   25.29n ± 4%        ~ (p=0.132 n=6)
NewMeterConfig/with_instrumentation_attribute-14        61.30n ± 5%   25.36n ± 7%  -58.63% (p=0.002 n=6)
NewMeterConfig/with_instrumentation_attribute_set-14    25.93n ± 5%   26.24n ± 4%        ~ (p=0.485 n=6)
geomean                                                 19.64n        16.40n       -16.49%

                                                     │ /tmp/old.txt │              /tmp/new.txt              │
                                                     │     B/op     │    B/op     vs base                    │
NewMeterConfig/with_no_options-14                      0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewMeterConfig/with_an_instrumentation_version-14      0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewMeterConfig/with_a_schema_url-14                    0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewMeterConfig/with_instrumentation_attribute-14       64.00 ± 0%      0.00 ± 0%  -100.00% (p=0.002 n=6)
NewMeterConfig/with_instrumentation_attribute_set-14   0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
geomean                                                           ²               ?                      ² ³
¹ all samples are equal
² summaries must be >0 to compute geomean
³ ratios must be >0 to compute geomean

                                                     │ /tmp/old.txt │              /tmp/new.txt              │
                                                     │  allocs/op   │ allocs/op   vs base                    │
NewMeterConfig/with_no_options-14                      0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewMeterConfig/with_an_instrumentation_version-14      0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewMeterConfig/with_a_schema_url-14                    0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewMeterConfig/with_instrumentation_attribute-14       1.000 ± 0%     0.000 ± 0%  -100.00% (p=0.002 n=6)
NewMeterConfig/with_instrumentation_attribute_set-14   0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
geomean                                                           ²               ?                      ² ³
¹ all samples are equal
² summaries must be >0 to compute geomean
³ ratios must be >0 to compute geomean

pkg: go.opentelemetry.io/otel/trace
                                                         │ /tmp/old.txt  │            /tmp/new.txt             │
                                                         │    sec/op     │    sec/op     vs base               │
NewTracerConfig/with_no_options-14                          2.980n ±  5%   2.948n ±  3%        ~ (p=0.240 n=6)
NewTracerConfig/with_an_instrumentation_version-14          24.44n ±  4%   23.54n ±  1%   -3.70% (p=0.002 n=6)
NewTracerConfig/with_a_schema_url-14                        24.47n ±  5%   23.95n ±  7%        ~ (p=0.180 n=6)
NewTracerConfig/with_instrumentation_attribute-14           58.39n ±  7%   25.54n ±  6%  -56.25% (p=0.002 n=6)
NewTracerConfig/with_instrumentation_attribute_set-14       25.70n ±  3%   26.55n ±  6%        ~ (p=0.310 n=6)
NewSpanStartConfig/with_no_options-14                       2.670n ±  7%   2.838n ±  6%        ~ (p=0.093 n=6)
NewSpanStartConfig/with_attributes-14                       60.65n ± 20%   51.84n ±  8%        ~ (p=0.240 n=6)
NewSpanStartConfig/with_attributes_set_multiple_times-14    115.4n ± 10%   110.0n ±  7%   -4.68% (p=0.004 n=6)
NewSpanStartConfig/with_a_timestamp-14                      18.03n ±  3%   17.77n ±  4%        ~ (p=0.937 n=6)
NewSpanStartConfig/with_links-14                            66.63n ±  8%   75.60n ±  8%  +13.47% (p=0.009 n=6)
NewSpanStartConfig/with_links_set_multiple_times-14         155.2n ±  4%   162.8n ± 18%        ~ (p=0.485 n=6)
NewSpanStartConfig/with_new_root-14                         26.59n ± 19%   23.04n ±  4%  -13.32% (p=0.004 n=6)
NewSpanStartConfig/with_span_kind-14                        24.02n ±  4%   23.72n ±  9%        ~ (p=0.589 n=6)
NewSpanEndConfig/with_no_options-14                         2.673n ± 10%   2.765n ±  7%        ~ (p=0.485 n=6)
NewSpanEndConfig/with_a_timestamp-14                        17.37n ±  9%   18.04n ±  4%        ~ (p=0.093 n=6)
NewSpanEndConfig/with_stack_trace-14                        16.70n ±  3%   16.59n ±  4%        ~ (p=0.937 n=6)
NewEventConfig/with_no_options-14                           37.14n ±  6%   36.63n ±  3%        ~ (p=0.818 n=6)
NewEventConfig/with_attributes-14                          117.15n ±  9%   98.92n ± 14%  -15.56% (p=0.009 n=6)
NewEventConfig/with_attributes_set_multiple_times-14        172.6n ±  5%   168.1n ±  9%        ~ (p=0.333 n=6)
NewEventConfig/with_a_timestamp-14                          25.41n ±  3%   26.66n ±  3%   +4.92% (p=0.002 n=6)
NewEventConfig/with_a_stacktrace-14                         51.01n ± 15%   52.45n ±  2%        ~ (p=0.093 n=6)
geomean                                                     28.82n         27.38n         -4.98%

                                                         │ /tmp/old.txt │              /tmp/new.txt              │
                                                         │     B/op     │    B/op     vs base                    │
NewTracerConfig/with_no_options-14                         0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewTracerConfig/with_an_instrumentation_version-14         0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewTracerConfig/with_a_schema_url-14                       0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewTracerConfig/with_instrumentation_attribute-14          64.00 ± 0%      0.00 ± 0%  -100.00% (p=0.002 n=6)
NewTracerConfig/with_instrumentation_attribute_set-14      0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanStartConfig/with_no_options-14                      0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanStartConfig/with_attributes-14                      64.00 ± 0%     64.00 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanStartConfig/with_attributes_set_multiple_times-14   192.0 ± 0%     192.0 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanStartConfig/with_a_timestamp-14                     0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanStartConfig/with_links-14                           96.00 ± 0%     96.00 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanStartConfig/with_links_set_multiple_times-14        272.0 ± 0%     272.0 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanStartConfig/with_new_root-14                        0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanStartConfig/with_span_kind-14                       0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanEndConfig/with_no_options-14                        0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanEndConfig/with_a_timestamp-14                       0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanEndConfig/with_stack_trace-14                       0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewEventConfig/with_no_options-14                          0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewEventConfig/with_attributes-14                          64.00 ± 0%     64.00 ± 0%         ~ (p=1.000 n=6) ¹
NewEventConfig/with_attributes_set_multiple_times-14       192.0 ± 0%     192.0 ± 0%         ~ (p=1.000 n=6) ¹
NewEventConfig/with_a_timestamp-14                         0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewEventConfig/with_a_stacktrace-14                        0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
geomean                                                               ²               ?                      ² ³
¹ all samples are equal
² summaries must be >0 to compute geomean
³ ratios must be >0 to compute geomean

                                                         │ /tmp/old.txt │              /tmp/new.txt              │
                                                         │  allocs/op   │ allocs/op   vs base                    │
NewTracerConfig/with_no_options-14                         0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewTracerConfig/with_an_instrumentation_version-14         0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewTracerConfig/with_a_schema_url-14                       0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewTracerConfig/with_instrumentation_attribute-14          1.000 ± 0%     0.000 ± 0%  -100.00% (p=0.002 n=6)
NewTracerConfig/with_instrumentation_attribute_set-14      0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanStartConfig/with_no_options-14                      0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanStartConfig/with_attributes-14                      1.000 ± 0%     1.000 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanStartConfig/with_attributes_set_multiple_times-14   2.000 ± 0%     2.000 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanStartConfig/with_a_timestamp-14                     0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanStartConfig/with_links-14                           1.000 ± 0%     1.000 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanStartConfig/with_links_set_multiple_times-14        2.000 ± 0%     2.000 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanStartConfig/with_new_root-14                        0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanStartConfig/with_span_kind-14                       0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanEndConfig/with_no_options-14                        0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanEndConfig/with_a_timestamp-14                       0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewSpanEndConfig/with_stack_trace-14                       0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewEventConfig/with_no_options-14                          0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewEventConfig/with_attributes-14                          1.000 ± 0%     1.000 ± 0%         ~ (p=1.000 n=6) ¹
NewEventConfig/with_attributes_set_multiple_times-14       2.000 ± 0%     2.000 ± 0%         ~ (p=1.000 n=6) ¹
NewEventConfig/with_a_timestamp-14                         0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
NewEventConfig/with_a_stacktrace-14                        0.000 ± 0%     0.000 ± 0%         ~ (p=1.000 n=6) ¹
geomean                                                               ²               ?                      ² ³
¹ all samples are equal
² summaries must be >0 to compute geomean
³ ratios must be >0 to compute geomean
```
</details>

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
Co-authored-by: Flc゛ <four_leaf_clover@foxmail.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
2025-09-11 08:47:22 -07:00
Tyler Yahn 7fdebbe3ed Rename Self-Observability as just Observability (#7302)
Self-Observability is a redundant term, the self being instrumented is
always the self that observability is being provided for. Remove this
redundancy.

Continue to provide backwards compatibility for any users already using
`OTEL_GO_X_SELF_OBSERVABILITY` to enable the feature.

---------

Co-authored-by: Damien Mathieu <42@dmathieu.com>
2025-09-11 10:01:19 +02:00
Robert Pająk 07a91dd2b0 trace,metric,log: add WithInstrumentationAttributeSet option (#7287)
Per
https://github.com/open-telemetry/opentelemetry-go/pull/7266#issuecomment-3237027300

Related to
https://github.com/open-telemetry/opentelemetry-go/issues/7217

## What

This PR adds `WithInstrumentationAttributeSet` option functions to the
`log`, `metric`, and `trace` packages as suggested in
https://github.com/open-telemetry/opentelemetry-go/pull/7266#issuecomment-3237027300.
These new functions provide a more concurrent-safe alternative to the
existing `WithInstrumentationAttributes` functions by accepting a
pre-constructed `attribute.Set` instead of variadic `attribute.KeyValue`
parameters.

## Why

As discussed in #7266, the existing `WithInstrumentationAttributes`
functions can lead to data races when used concurrently because
`attribute.NewSet()` may mutate the passed slice in-place. While the
issue was partially addressed by moving the `attribute.NewSet()` call
outside the closure, the best long-term solution is to provide an
alternative that accepts an immutable `attribute.Set`.

**Benefits:**

1. **Concurrent Safety**: Since `attribute.Set` is immutable, these
functions are inherently safe for concurrent use
2. **Performance**: Avoids repeated calls to `attribute.NewSet()` when
the same attributes are used multiple times
3. **Consistency**: Matches the existing pattern used in
`metric.WithAttributeSet()`
4. **Flexibility**: Allows users to pre-compute attribute sets and reuse
them

Deprecating `WithInstrumentationAttributes` is out of scope. See
https://github.com/open-telemetry/opentelemetry-go/pull/7287#issuecomment-3245820459.

## Benchmarks

```
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/trace
cpu: 13th Gen Intel(R) Core(TM) i7-13800H
BenchmarkNewTracerConfig/with_no_options-20         	280298306	         4.268 ns/op	       0 B/op	       0 allocs/op
BenchmarkNewTracerConfig/with_an_instrumentation_version-20         	33389427	        30.84 ns/op	       0 B/op	       0 allocs/op
BenchmarkNewTracerConfig/with_a_schema_url-20                       	35441077	        30.46 ns/op	       0 B/op	       0 allocs/op
BenchmarkNewTracerConfig/with_instrumentation_attribute-20          	17607649	        88.23 ns/op	      64 B/op	       1 allocs/op
BenchmarkNewTracerConfig/with_instrumentation_attribute_set-20      	38336211	        31.30 ns/op	       0 B/op	       0 allocs/op
```

```
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/metric
cpu: 13th Gen Intel(R) Core(TM) i7-13800H
BenchmarkNewMeterConfig/with_no_options-20         	262998199	         4.525 ns/op	       0 B/op	       0 allocs/op
BenchmarkNewMeterConfig/with_an_instrumentation_version-20         	40483780	        29.31 ns/op	       0 B/op	       0 allocs/op
BenchmarkNewMeterConfig/with_a_schema_url-20                       	39162420	        30.58 ns/op	       0 B/op	       0 allocs/op
BenchmarkNewMeterConfig/with_instrumentation_attribute-20          	19900275	        77.50 ns/op	      64 B/op	       1 allocs/op
BenchmarkNewMeterConfig/with_instrumentation_attribute_set-20      	37519020	        31.93 ns/op	       0 B/op	       0 allocs/op
```

```
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/log
cpu: 13th Gen Intel(R) Core(TM) i7-13800H
BenchmarkNewLoggerConfig/with_no_options-20         	271100760	         4.322 ns/op	       0 B/op	       0 allocs/op
BenchmarkNewLoggerConfig/with_an_instrumentation_version-20         	38392390	        30.77 ns/op	       0 B/op	       0 allocs/op
BenchmarkNewLoggerConfig/with_a_schema_url-20                       	39615074	        30.25 ns/op	       0 B/op	       0 allocs/op
BenchmarkNewLoggerConfig/with_instrumentation_attribute-20          	17108463	        82.51 ns/op	      64 B/op	       1 allocs/op
BenchmarkNewLoggerConfig/with_instrumentation_attribute_set-20      	37746534	        31.70 ns/op	       0 B/op	       0 allocs/op
```
2025-09-08 17:21:37 +02:00
Robert Pająk dcf14aa937 trace,metric,log: WithInstrumentationAttributes options to merge attributes (#7300)
## What

Fix `WithInstrumentationAttributes` options in
`go.opentelemetry.io/otel/trace`, `go.opentelemetry.io/otel/metric`, and
`go.opentelemetry.io/otel/log` to properly merge attributes when passed
multiple times instead of replacing them. Attributes with duplicate keys
will use the last value passed.

## Why

Per
https://github.com/open-telemetry/opentelemetry-go/pull/7287#pullrequestreview-3181379062
and
https://github.com/open-telemetry/opentelemetry-go/pull/7287#issuecomment-3250085450

Not that this does not address
https://github.com/open-telemetry/opentelemetry-go/issues/7217. This is
left to a seperate PR to not scope creep this one. CC @axw

---------

Co-authored-by: Damien Mathieu <42@dmathieu.com>
2025-09-08 10:46:08 +02:00
David Ashpole b218e4bb5a Don't track min and max when disabled (#7306)
Minor optimization for histogram `measure()`. When min/max are disabled
for histograms, don't track it during measure().

the `bin` function is split into `bin` and `minMax` to facilitate this.

---------

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
2025-09-06 08:46:00 -07:00
Tyler Yahn 774c740caa Fix missing link in changelog (#7273)
Co-authored-by: Damien Mathieu <42@dmathieu.com>
2025-09-01 11:43:25 +02:00
Tyler Yahn 8ab8e421a5 Drop support for Go 1.23 (#7274) 2025-08-31 07:52:30 -07:00