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

1124 Commits

Author SHA1 Message Date
Peter Nguyen 015ed1a7a4 sdk/metric: Support specifying cardinality limits per instrument kinds (#7855)
Previously, we only had `WithCardinalityLimit()`, which adds a global
cardinality limit.

This PR adds a new API on the reader `WithCardinalityLimitSelector` that
can be used to specify limits per instrument kinds.


[spec](https://github.com/open-telemetry/opentelemetry-specification/blob/49845849d2d8df07059f82033f39e96c561927cf/specification/metrics/sdk.md?plain=1#L1282)


[schema](https://github.com/open-telemetry/opentelemetry-configuration/blob/3dbebe292912f0c0c96ce5dcfefc45dfe5e20f39/snippets/CardinalityLimits_kitchen_sink.yaml#L11-L18)

closes #7786

---------

Co-authored-by: David Ashpole <dashpole@google.com>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
2026-03-20 11:24:19 +01:00
yoshimura 528ebabbf0 sdk/trace/internal/observ: guard SpanStarted and spanLive with Enabled (#8067)
Guards SpanStarted and spanLive with Enabled(ctx) to avoid building
metric
options/attributes when instruments are disabled.

```
BenchmarkTracer (noop MeterProvider):

  SpanStarted: ~1.77 ns/op -> ~0.48 ns/op (~3.7x)
  SpanLive:    ~2.05 ns/op -> ~0.52 ns/op (~3.9x)
  SpanEnded:   ~2.05 ns/op -> ~0.52 ns/op (~3.9x)
```

No behavior change when enabled; existing tests cover enabled path.
~~No CHANGELOG entry, following #7848.~~

Issue: #7800

---------

Co-authored-by: Damien Mathieu <42@dmathieu.com>
2026-03-18 16:11:37 +01:00
David Ashpole 025b01be59 Add support for the development per-series starttime feature (#8060)
Add a feature to use per-series start times to match the spec:
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#start-timestamps

This is a prerequisite to [finishing /
closing](https://github.com/open-telemetry/opentelemetry-specification/pull/4702).

Previous prototype:
https://github.com/open-telemetry/opentelemetry-go/pull/7719

---------

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: Robert Pająk <pellared@hotmail.com>
2026-03-18 09:46:12 -04:00
Ijas d5f403cab5 sdk/resource: add WithContext variants for Default and Environment (#7808) (#8051)
## Description
Address issue #7808 by plumbing `context.Context` through
`resource.Environment` and `resource.Default`.

Currently, these functions hardcode `context.Background()`, which
prevents detectors (especially those that might perform network lookups
or OS calls) from respecting timeouts or cancellations provided by the
caller.

## Changes

- Adds `EnvironmentWithContext(ctx context.Context)` as a new public
function.
- Adds `DefaultWithContext(ctx context.Context)` as a new public
function.
- Maintains backward compatibility by making `Environment()` and
`Default()` thin wrappers around the new WithContext variants.

## Testing

- Added unit tests in `sdk/resource/resource_test.go` to verify the new
functions.
- Verified that all `sdk/resource` tests pass.
- Verified that make `golangci-lint` passes repository-wide.

Fixes #7808

---------

Co-authored-by: Damien Mathieu <42@dmathieu.com>
2026-03-17 09:35:03 +01:00
David Ashpole 206ac291d0 Fix race in the lastvalue aggregation where 0 could be observed (#8056)
This initializes the value of the gauge with the correct value before it
is stored in the map. We end up storing the same thing twice on the
first call, but that isn't a big deal performance-wise.

Discovered during
https://github.com/open-telemetry/opentelemetry-go/pull/8021
2026-03-16 09:30:51 -04:00
Yuanyuan Zhao 2ffde5a428 trace: add Random Trace ID Flag (#8012)
## Summary

Adds API support for the W3C tracecontext random flag on `TraceFlags`
and `SpanContext` in `go.opentelemetry.io/otel/trace`:

- **`TraceFlags.IsRandom()`** — reports whether the random bit is set
- **`TraceFlags.WithRandom(bool)`** — sets or clears the random bit in a
copy of the flags
- **`SpanContext.IsRandom()`** — reports whether the random bit is set
in the span context's trace flags

These mirror the existing `IsSampled` / `WithSampled` pattern.

## Motivation

The W3C Trace Context spec defines a random bit in trace flags to
indicate probabilistic sampling. This is required for [TraceIdRatioBased
sampler](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#traceidratiobased)
support, where the random bit is set when a trace is probabilistically
sampled and is used for extrapolated span metrics.

## Related

Part of #7928 (Support TraceIdRatioBased Sampler). This PR adds the
trace API needed for that work; sampler implementation and tracestate
`th` handling will follow in separate PRs.

## Co-Author
Joshua MacDonald <jmacd@users.noreply.github.com>

---------

Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com>
Co-authored-by: Robert Pająk <pellared@hotmail.com>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
2026-03-13 09:22:56 +01:00
Tyler Yahn 9587c57d48 Optimize attribute slice conversion (#8039)
This PR refactors the internal slice conversion helpers in
`attribute/internal` to use generics and adds explicit short-length fast
paths for slice-backed attribute values.

The main changes are:

- replace the old type-specific internal helpers with generic
`SliceValue[T]` and `AsSlice[T]`
- preserve the comparable-array storage model used by `Value` and
`KeyValue`
- add fixed-size fast paths for lengths `0..3`
- add a matching short-length fast path in `IntSliceValue` before
falling back to `[]int64` conversion
- keep reflection as the fallback for larger slice lengths
- keep the existing `Value.As*Slice()` methods in `attribute` as thin
wrappers over the generic internal helpers
- add type-mismatch coverage for `AsSlice[T]`
- expand the benchmark suite so it measures both:
  - short slices that hit the new fixed-size path
  - longer slices that still use the reflective fallback

## Rationale

The package still needs reflection for arbitrary runtime lengths because
slice values are stored as comparable arrays behind `any`, and Go cannot
construct a runtime-sized array type without `reflect.ArrayOf`.

The fast path is intentionally small. The cutoff of `0..3` is based on a
combination of:

- benchmark gains for short slices
- semantic convention examples where `1..3` values are common
- downstream source analysis, which found that most external call sites
pass variables rather than inline literals, so static source scanning
does not justify a larger cutoff

## External Usage Validation

Downstream scan:

- sampled repos cloned and scanned: `285`
- most external call sites pass dynamic slice variables, not inline
literals
- final literal counts recovered statically:
- `StringSlice`: total `131`, dynamic `121`, literal len `0`: `1`, len
`1`: `8`, len `2`: `1`
  - `IntSlice`: total `5`, all dynamic
  - `Int64Slice`: total `6`, all dynamic
  - `BoolSlice`: total `3`, all dynamic
  - `Float64Slice`: total `3`, all dynamic

Semantic conventions reviewed locally in `semantic-conventions` include
several slice-valued attributes where short lists are normal, for
example:

- `browser.brands`
- `gen_ai.request.stop_sequences`
- `gen_ai.request.encoding_formats`
- `gen_ai.response.finish_reasons`
- `user.roles`
- `file.attributes`

There are also clearly unbounded cases like headers, metadata, command
args, and some cloud/provider arrays. That combination supports a small
fast path, but not an assumption that all real-world slices are tiny.

## Benchmarks

Changes to the benchmarks:

- internal microbenchmarks now run both `Len2` and `Len8`
- public `attribute` benchmarks now run both `Len2` and `Len8`
- repeated benchmark runs were compared with `benchstat`

`Len2` exercises the new fixed-size path. `Len8` exercises the
reflective fallback path.

Headline result:

- short slices improve substantially
- large slices stay close to baseline because they still use reflection
- `IntSlice` now gets the same short-slice win as the other slice types,
but larger `[]int` values still pay the `[]int` to `[]int64` conversion
cost

### Internal Helpers

```text
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/attribute/internal
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
                         │ /tmp/bench-internal-base-v2.txt │  /tmp/bench-internal-current-v2.txt  │
                         │             sec/op              │    sec/op     vs base                │
BoolSliceValue/Len2-8                        124.00n ±  4%   19.36n ± 12%  -84.39% (p=0.000 n=12)
BoolSliceValue/Len8-8                         129.9n ±  2%   136.8n ±  3%   +5.31% (p=0.000 n=12)
Int64SliceValue/Len2-8                       146.00n ± 26%   26.13n ±  3%  -82.10% (p=0.000 n=12)
Int64SliceValue/Len8-8                        172.1n ±  4%   174.9n ±  5%        ~ (p=0.443 n=12)
Float64SliceValue/Len2-8                     151.70n ±  2%   26.25n ±  2%  -82.70% (p=0.000 n=12)
Float64SliceValue/Len8-8                      173.6n ±  2%   169.7n ±  4%        ~ (p=0.155 n=12)
StringSliceValue/Len2-8                      177.15n ±  2%   42.03n ±  3%  -76.27% (p=0.000 n=12)
StringSliceValue/Len8-8                       217.2n ±  6%   219.1n ±  6%        ~ (p=0.504 n=12)
AsFloat64Slice/Len2-8                         96.77n ±  3%   63.05n ± 27%  -34.84% (p=0.000 n=12)
AsFloat64Slice/Len8-8                         123.8n ± 18%   117.1n ±  4%        ~ (p=1.000 n=12)
geomean                                       147.6n         71.85n        -51.33%

                         │ /tmp/bench-internal-base-v2.txt │  /tmp/bench-internal-current-v2.txt  │
                         │              B/op               │    B/op     vs base                  │
BoolSliceValue/Len2-8                           4.000 ± 0%   2.000 ± 0%  -50.00% (p=0.000 n=12)
BoolSliceValue/Len8-8                           16.00 ± 0%   16.00 ± 0%        ~ (p=1.000 n=12) ¹
Int64SliceValue/Len2-8                          32.00 ± 0%   16.00 ± 0%  -50.00% (p=0.000 n=12)
Int64SliceValue/Len8-8                          128.0 ± 0%   128.0 ± 0%        ~ (p=1.000 n=12) ¹
Float64SliceValue/Len2-8                        32.00 ± 0%   16.00 ± 0%  -50.00% (p=0.000 n=12)
Float64SliceValue/Len8-8                        128.0 ± 0%   128.0 ± 0%        ~ (p=1.000 n=12) ¹
StringSliceValue/Len2-8                         64.00 ± 0%   32.00 ± 0%  -50.00% (p=0.000 n=12)
StringSliceValue/Len8-8                         256.0 ± 0%   256.0 ± 0%        ~ (p=1.000 n=12) ¹
AsFloat64Slice/Len2-8                           40.00 ± 0%   40.00 ± 0%        ~ (p=1.000 n=12) ¹
AsFloat64Slice/Len8-8                           88.00 ± 0%   88.00 ± 0%        ~ (p=1.000 n=12) ¹
geomean                                         47.77        36.21       -24.21%
¹ all samples are equal

                         │ /tmp/bench-internal-base-v2.txt │  /tmp/bench-internal-current-v2.txt  │
                         │            allocs/op            │ allocs/op   vs base                  │
BoolSliceValue/Len2-8                           2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=12)
BoolSliceValue/Len8-8                           2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=12) ¹
Int64SliceValue/Len2-8                          2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=12)
Int64SliceValue/Len8-8                          2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=12) ¹
Float64SliceValue/Len2-8                        2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=12)
Float64SliceValue/Len8-8                        2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=12) ¹
StringSliceValue/Len2-8                         2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=12)
StringSliceValue/Len8-8                         2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=12) ¹
AsFloat64Slice/Len2-8                           2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=12) ¹
AsFloat64Slice/Len8-8                           2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=12) ¹
geomean                                         2.000        1.516       -24.21%
¹ all samples are equal
```

### Public `attribute` API

```text
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/attribute
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
                                   │ /tmp/bench-attr-base-v2.txt │    /tmp/bench-attr-current-v3.txt    │
                                   │           sec/op            │    sec/op     vs base                │
BoolSlice/Len2/Value-8                             130.65n ±  3%   16.90n ±  3%  -87.06% (p=0.000 n=12)
BoolSlice/Len2/KeyValue-8                          135.85n ± 14%   23.49n ±  2%  -82.71% (p=0.000 n=12)
BoolSlice/Len2/AsBoolSlice-8                        50.22n ±  1%   19.12n ± 15%  -61.92% (p=0.000 n=12)
BoolSlice/Len2/Emit-8                               343.9n ±  1%   293.4n ±  1%  -14.68% (p=0.000 n=12)
BoolSlice/Len8/Value-8                              134.7n ±  2%   136.4n ±  2%   +1.22% (p=0.011 n=12)
BoolSlice/Len8/KeyValue-8                           137.7n ±  2%   140.6n ±  2%   +2.11% (p=0.046 n=12)
BoolSlice/Len8/AsBoolSlice-8                        53.59n ± 22%   61.15n ± 22%  +14.11% (p=0.020 n=12)
BoolSlice/Len8/Emit-8                               773.5n ±  1%   788.5n ±  2%   +1.93% (p=0.028 n=12)
IntSlice/Len2/Value-8                              140.85n ±  2%   36.20n ±  3%  -74.30% (p=0.000 n=12)
IntSlice/Len2/KeyValue-8                           149.65n ±  2%   42.84n ±  3%  -71.37% (p=0.000 n=12)
IntSlice/Len2/Emit-8                                318.2n ±  3%   279.6n ± 15%  -12.15% (p=0.012 n=12)
IntSlice/Len8/Value-8                               217.9n ±  1%   228.8n ±  2%   +5.00% (p=0.001 n=12)
IntSlice/Len8/KeyValue-8                            225.6n ± 29%   232.3n ±  3%        ~ (p=0.767 n=12)
IntSlice/Len8/Emit-8                                480.0n ±  1%   478.6n ±  2%        ~ (p=0.899 n=12)
Int64Slice/Len2/Value-8                            150.90n ±  1%   27.43n ±  3%  -81.82% (p=0.000 n=12)
Int64Slice/Len2/KeyValue-8                         152.05n ±  1%   34.34n ±  3%  -77.42% (p=0.000 n=12)
Int64Slice/Len2/AsInt64Slice-8                      58.69n ±  4%   28.58n ±  3%  -51.30% (p=0.000 n=12)
Int64Slice/Len2/Emit-8                              318.4n ±  3%   273.9n ±  1%  -13.99% (p=0.000 n=12)
Int64Slice/Len8/Value-8                             173.0n ±  8%   177.8n ±  2%        ~ (p=0.173 n=12)
Int64Slice/Len8/KeyValue-8                          184.0n ± 24%   184.3n ±  2%        ~ (p=0.701 n=12)
Int64Slice/Len8/AsInt64Slice-8                      72.04n ±  2%   83.05n ±  2%  +15.30% (p=0.000 n=12)
Int64Slice/Len8/Emit-8                              474.9n ± 19%   501.9n ± 18%   +5.67% (p=0.020 n=12)
Float64Slice/Len2/Value-8                          150.95n ±  3%   26.92n ±  3%  -82.17% (p=0.000 n=12)
Float64Slice/Len2/KeyValue-8                       153.95n ±  3%   33.08n ±  2%  -78.52% (p=0.000 n=12)
Float64Slice/Len2/AsFloat64Slice-8                  60.31n ± 24%   27.02n ±  1%  -55.19% (p=0.000 n=12)
Float64Slice/Len2/Emit-8                            434.2n ±  2%   380.4n ±  1%  -12.40% (p=0.000 n=12)
Float64Slice/Len8/Value-8                           173.7n ±  2%   175.2n ± 25%        ~ (p=0.248 n=12)
Float64Slice/Len8/KeyValue-8                        174.0n ±  4%   175.2n ±  2%        ~ (p=0.702 n=12)
Float64Slice/Len8/AsFloat64Slice-8                  71.17n ±  8%   78.00n ±  4%   +9.58% (p=0.007 n=12)
Float64Slice/Len8/Emit-8                            920.6n ± 20%   909.9n ±  8%        ~ (p=0.378 n=12)
StringSlice/Len2/Value-8                           174.00n ±  5%   41.97n ± 20%  -75.88% (p=0.000 n=12)
StringSlice/Len2/KeyValue-8                        179.85n ±  2%   46.76n ±  2%  -74.00% (p=0.000 n=12)
StringSlice/Len2/AsStringSlice-8                    76.03n ±  5%   39.83n ±  3%  -47.61% (p=0.000 n=12)
StringSlice/Len2/Emit-8                             386.0n ±  2%   332.3n ±  3%  -13.91% (p=0.000 n=12)
StringSlice/Len8/Value-8                            225.4n ±  4%   226.2n ±  4%        ~ (p=0.311 n=12)
StringSlice/Len8/KeyValue-8                         228.1n ±  7%   234.2n ±  4%        ~ (p=0.386 n=12)
StringSlice/Len8/AsStringSlice-8                    110.8n ± 25%   117.8n ±  4%        ~ (p=0.173 n=12)
StringSlice/Len8/Emit-8                             658.7n ±  3%   647.9n ±  5%        ~ (p=0.319 n=12)
geomean                                             181.7n         110.7n        -39.08%

                                   │ /tmp/bench-attr-base-v2.txt │    /tmp/bench-attr-current-v3.txt    │
                                   │            B/op             │    B/op     vs base                  │
BoolSlice/Len2/Value-8                                4.000 ± 0%   2.000 ± 0%  -50.00% (p=0.000 n=12)
BoolSlice/Len2/KeyValue-8                             4.000 ± 0%   2.000 ± 0%  -50.00% (p=0.000 n=12)
BoolSlice/Len2/AsBoolSlice-8                          2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=12) ¹
BoolSlice/Len2/Emit-8                                 40.00 ± 0%   40.00 ± 0%        ~ (p=1.000 n=12) ¹
BoolSlice/Len8/Value-8                                16.00 ± 0%   16.00 ± 0%        ~ (p=1.000 n=12) ¹
BoolSlice/Len8/KeyValue-8                             16.00 ± 0%   16.00 ± 0%        ~ (p=1.000 n=12) ¹
BoolSlice/Len8/AsBoolSlice-8                          8.000 ± 0%   8.000 ± 0%        ~ (p=1.000 n=12) ¹
BoolSlice/Len8/Emit-8                                 88.00 ± 0%   88.00 ± 0%        ~ (p=1.000 n=12) ¹
IntSlice/Len2/Value-8                                 32.00 ± 0%   16.00 ± 0%  -50.00% (p=0.000 n=12)
IntSlice/Len2/KeyValue-8                              32.00 ± 0%   16.00 ± 0%  -50.00% (p=0.000 n=12)
IntSlice/Len2/Emit-8                                  56.00 ± 0%   56.00 ± 0%        ~ (p=1.000 n=12) ¹
IntSlice/Len8/Value-8                                 128.0 ± 0%   192.0 ± 0%  +50.00% (p=0.000 n=12)
IntSlice/Len8/KeyValue-8                              128.0 ± 0%   192.0 ± 0%  +50.00% (p=0.000 n=12)
IntSlice/Len8/Emit-8                                  136.0 ± 0%   136.0 ± 0%        ~ (p=1.000 n=12) ¹
Int64Slice/Len2/Value-8                               32.00 ± 0%   16.00 ± 0%  -50.00% (p=0.000 n=12)
Int64Slice/Len2/KeyValue-8                            32.00 ± 0%   16.00 ± 0%  -50.00% (p=0.000 n=12)
Int64Slice/Len2/AsInt64Slice-8                        16.00 ± 0%   16.00 ± 0%        ~ (p=1.000 n=12) ¹
Int64Slice/Len2/Emit-8                                56.00 ± 0%   56.00 ± 0%        ~ (p=1.000 n=12) ¹
Int64Slice/Len8/Value-8                               128.0 ± 0%   128.0 ± 0%        ~ (p=1.000 n=12) ¹
Int64Slice/Len8/KeyValue-8                            128.0 ± 0%   128.0 ± 0%        ~ (p=1.000 n=12) ¹
Int64Slice/Len8/AsInt64Slice-8                        64.00 ± 0%   64.00 ± 0%        ~ (p=1.000 n=12) ¹
Int64Slice/Len8/Emit-8                                136.0 ± 0%   136.0 ± 0%        ~ (p=1.000 n=12) ¹
Float64Slice/Len2/Value-8                             32.00 ± 0%   16.00 ± 0%  -50.00% (p=0.000 n=12)
Float64Slice/Len2/KeyValue-8                          32.00 ± 0%   16.00 ± 0%  -50.00% (p=0.000 n=12)
Float64Slice/Len2/AsFloat64Slice-8                    16.00 ± 0%   16.00 ± 0%        ~ (p=1.000 n=12) ¹
Float64Slice/Len2/Emit-8                              56.00 ± 0%   56.00 ± 0%        ~ (p=1.000 n=12) ¹
Float64Slice/Len8/Value-8                             128.0 ± 0%   128.0 ± 0%        ~ (p=1.000 n=12) ¹
Float64Slice/Len8/KeyValue-8                          128.0 ± 0%   128.0 ± 0%        ~ (p=1.000 n=12) ¹
Float64Slice/Len8/AsFloat64Slice-8                    64.00 ± 0%   64.00 ± 0%        ~ (p=1.000 n=12) ¹
Float64Slice/Len8/Emit-8                              136.0 ± 0%   136.0 ± 0%        ~ (p=1.000 n=12) ¹
StringSlice/Len2/Value-8                              64.00 ± 0%   32.00 ± 0%  -50.00% (p=0.000 n=12)
StringSlice/Len2/KeyValue-8                           64.00 ± 0%   32.00 ± 0%  -50.00% (p=0.000 n=12)
StringSlice/Len2/AsStringSlice-8                      32.00 ± 0%   32.00 ± 0%        ~ (p=1.000 n=12) ¹
StringSlice/Len2/Emit-8                               120.0 ± 0%   120.0 ± 0%        ~ (p=1.000 n=12) ¹
StringSlice/Len8/Value-8                              256.0 ± 0%   256.0 ± 0%        ~ (p=1.000 n=12) ¹
StringSlice/Len8/KeyValue-8                           256.0 ± 0%   256.0 ± 0%        ~ (p=1.000 n=12) ¹
StringSlice/Len8/AsStringSlice-8                      128.0 ± 0%   128.0 ± 0%        ~ (p=1.000 n=12) ¹
StringSlice/Len8/Emit-8                               344.0 ± 0%   344.0 ± 0%        ~ (p=1.000 n=12) ¹
geomean                                               49.39        42.05       -14.88%
¹ all samples are equal

                                   │ /tmp/bench-attr-base-v2.txt │    /tmp/bench-attr-current-v3.txt    │
                                   │          allocs/op          │ allocs/op   vs base                  │
BoolSlice/Len2/Value-8                                2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=12)
BoolSlice/Len2/KeyValue-8                             2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=12)
BoolSlice/Len2/AsBoolSlice-8                          1.000 ± 0%   1.000 ± 0%        ~ (p=1.000 n=12) ¹
BoolSlice/Len2/Emit-8                                 5.000 ± 0%   5.000 ± 0%        ~ (p=1.000 n=12) ¹
BoolSlice/Len8/Value-8                                2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=12) ¹
BoolSlice/Len8/KeyValue-8                             2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=12) ¹
BoolSlice/Len8/AsBoolSlice-8                          1.000 ± 0%   1.000 ± 0%        ~ (p=1.000 n=12) ¹
BoolSlice/Len8/Emit-8                                 11.00 ± 0%   11.00 ± 0%        ~ (p=1.000 n=12) ¹
IntSlice/Len2/Value-8                                 2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=12)
IntSlice/Len2/KeyValue-8                              2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=12)
IntSlice/Len2/Emit-8                                  4.000 ± 0%   4.000 ± 0%        ~ (p=1.000 n=12) ¹
IntSlice/Len8/Value-8                                 2.000 ± 0%   3.000 ± 0%  +50.00% (p=0.000 n=12)
IntSlice/Len8/KeyValue-8                              2.000 ± 0%   3.000 ± 0%  +50.00% (p=0.000 n=12)
IntSlice/Len8/Emit-8                                  4.000 ± 0%   4.000 ± 0%        ~ (p=1.000 n=12) ¹
Int64Slice/Len2/Value-8                               2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=12)
Int64Slice/Len2/KeyValue-8                            2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=12)
Int64Slice/Len2/AsInt64Slice-8                        1.000 ± 0%   1.000 ± 0%        ~ (p=1.000 n=12) ¹
Int64Slice/Len2/Emit-8                                4.000 ± 0%   4.000 ± 0%        ~ (p=1.000 n=12) ¹
Int64Slice/Len8/Value-8                               2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=12) ¹
Int64Slice/Len8/KeyValue-8                            2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=12) ¹
Int64Slice/Len8/AsInt64Slice-8                        1.000 ± 0%   1.000 ± 0%        ~ (p=1.000 n=12) ¹
Int64Slice/Len8/Emit-8                                4.000 ± 0%   4.000 ± 0%        ~ (p=1.000 n=12) ¹
Float64Slice/Len2/Value-8                             2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=12)
Float64Slice/Len2/KeyValue-8                          2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=12)
Float64Slice/Len2/AsFloat64Slice-8                    1.000 ± 0%   1.000 ± 0%        ~ (p=1.000 n=12) ¹
Float64Slice/Len2/Emit-8                              4.000 ± 0%   4.000 ± 0%        ~ (p=1.000 n=12) ¹
Float64Slice/Len8/Value-8                             2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=12) ¹
Float64Slice/Len8/KeyValue-8                          2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=12) ¹
Float64Slice/Len8/AsFloat64Slice-8                    1.000 ± 0%   1.000 ± 0%        ~ (p=1.000 n=12) ¹
Float64Slice/Len8/Emit-8                              4.000 ± 0%   4.000 ± 0%        ~ (p=1.000 n=12) ¹
StringSlice/Len2/Value-8                              2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=12)
StringSlice/Len2/KeyValue-8                           2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=12)
StringSlice/Len2/AsStringSlice-8                      1.000 ± 0%   1.000 ± 0%        ~ (p=1.000 n=12) ¹
StringSlice/Len2/Emit-8                               4.000 ± 0%   4.000 ± 0%        ~ (p=1.000 n=12) ¹
StringSlice/Len8/Value-8                              2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=12) ¹
StringSlice/Len8/KeyValue-8                           2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=12) ¹
StringSlice/Len8/AsStringSlice-8                      1.000 ± 0%   1.000 ± 0%        ~ (p=1.000 n=12) ¹
StringSlice/Len8/Emit-8                               4.000 ± 0%   4.000 ± 0%        ~ (p=1.000 n=12) ¹
geomean                                               2.143        1.824       -14.88%
¹ all samples are equal
```

## Notes

- `Len2` is where the wins show up because those calls avoid
`reflect.ArrayOf` and one allocation.
- `Len8` stays much closer to baseline because it still uses the
reflective path.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: David Ashpole <dashpole@google.com>
2026-03-12 09:33:23 -07:00
Mikhail Mazurskiy ddd2b0e398 fix(sdk/trace): return spec-compliant TraceIdRatioBased description (#8027)
Optimize performance when sampling is disabled - no need to calculate
fraction based on trace id (in `traceIDRatioSampler`) if fraction is
zero.

---------

Co-authored-by: David Ashpole <dashpole@google.com>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
2026-03-12 10:11:33 +01:00
Robert Pająk f4da59e651 attribute: change INVALID Type to EMPTY and mark INVALID as deprecated (#8038)
Fixes https://github.com/open-telemetry/opentelemetry-go/issues/7932

Noticeable comment from previous PR:
https://github.com/open-telemetry/opentelemetry-go/pull/7942#discussion_r2913179215

Print the empty value as empty string per
https://opentelemetry.io/docs/specs/otel/common/#empty-values
2026-03-12 09:43:04 +01:00
Alex Boten fabe66658f resource: add WithService detector option (#7642)
I was looking at implementing resource detection in otelconf and was
finding that all the detectors were implemented in a similar way except
for the service detector. Added the resource options in this PR for
feedback. Will add tests if the go approvers/maintainers support this
approach.

---------

Signed-off-by: alex boten <223565+codeboten@users.noreply.github.com>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
2026-03-10 10:22:06 +01:00
Robert Pająk a3941ff595 Release v1.42.0/v0.64.0/v0.18.0/v0.0.16 (#8006)
### Added

- Add `go.opentelemetry.io/otel/semconv/v1.40.0` package.
The package contains semantic conventions from the `v1.40.0` version of
the OpenTelemetry Semantic Conventions.
See the [migration documentation](./semconv/v1.40.0/MIGRATION.md) for
information on how to upgrade from
`go.opentelemetry.io/otel/semconv/v1.39.0`. (#7985)
- Add `Err` and `SetErr` on `Record` in `go.opentelemetry.io/otel/log`
to attach an error and set record exception attributes in
`go.opentelemetry.io/otel/log/sdk`. (#7924)

### Changed

- `TracerProvider.ForceFlush` in `go.opentelemetry.io/otel/sdk/trace`
joins errors together and continues iteration through SpanProcessors as
opposed to returning the first encountered error without attempting
exports on subsequent SpanProcessors. (#7856)

### Fixed

- Fix missing `request.GetBody` in
`go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp` to
correctly handle HTTP2 GOAWAY frame. (#7931)
- Fix semconv v1.39.0 generated metric helpers skipping required
attributes when extra attributes were empty. (#7964)
- Preserve W3C TraceFlags bitmask (including the random Trace ID flag)
during trace context extraction and injection in
`go.opentelemetry.io/otel/propagation`. (#7834)

### Removed

- Drop support for [Go 1.24]. (#7984)
2026-03-06 20:13:23 +01:00
Israel Blancas c9d20155fc log: add error field to Record and make SDK to emit exception attributes (#7924)
Fixes #7923


```sh
$ go test -run=^$ -bench=BenchmarkLoggerEmitExceptionAttributes -benchmem -count=5 -benchtime=500ms -cpu=1
goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/otel/sdk/log
cpu: Apple M4 Pro
BenchmarkLoggerSetErrAndEmit                 	  628162	      1023 ns/op	    5371 B/op	       1 allocs/op
BenchmarkLoggerSetErrAndEmit                 	  663955	       863.3 ns/op	    5105 B/op	       1 allocs/op
BenchmarkLoggerSetErrAndEmit                 	  653888	      1067 ns/op	    5177 B/op	       1 allocs/op
BenchmarkLoggerSetErrAndEmit                 	  716438	       824.8 ns/op	    4764 B/op	       1 allocs/op
BenchmarkLoggerSetErrAndEmit                 	  746902	       999.2 ns/op	    5630 B/op	       1 allocs/op
BenchmarkLoggerSetExceptionAttributesAndEmit 	  650696	      1042 ns/op	    5200 B/op	       1 allocs/op
BenchmarkLoggerSetExceptionAttributesAndEmit 	  574962	       980.7 ns/op	    4743 B/op	       1 allocs/op
BenchmarkLoggerSetExceptionAttributesAndEmit 	  536736	       989.2 ns/op	    5049 B/op	       1 allocs/op
BenchmarkLoggerSetExceptionAttributesAndEmit 	  558511	      1190 ns/op	    4870 B/op	       1 allocs/op
BenchmarkLoggerSetExceptionAttributesAndEmit 	  669452	       978.8 ns/op	    5067 B/op	       1 allocs/op
PASS
ok  	go.opentelemetry.io/otel/sdk/log	6.994s
```

TODO after merged:
-
https://github.com/open-telemetry/opentelemetry-go/pull/7924#discussion_r2832906451

---------

Signed-off-by: Israel Blancas <iblancasa@gmail.com>
Co-authored-by: Robert Pająk <pellared@hotmail.com>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
2026-03-05 10:24:05 +01:00
sawamurataxman fdd1320c39 TracerProvider ForceFlush() Error Fix (#7856)
Previously upon a SpanProcessor's ForceFlush returning an error, it
would return that error and not attempt to flush subsequent
SpanProcessors. Now when an error is encountered, it will Join the new
error with the existing errors and continue iterating through the
SpanProcessors and return the consolidated error at the end of
iteration. This is in line with the workflow found in LoggerProvider's
ForceFlush.

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
2026-03-05 08:36:30 +01:00
Nikhil Mantri 8c91c83fb6 Feat: Have SpanContext support the new W3C random flag. (#7834)
Problem
- The Go SDK masks trace flags to the sampled bit and rejects version 00
flags > 0x02.
- This drops the W3C Trace Context Level 2 random Trace ID flag (0x02)
and any forward-compatible bits.

Approach
- Treat trace flags as an 8-bit bitmask across extract, storage, and
inject.
- Accept any flags for traceparent version 00 and preserve them
unchanged.
- Interpret only known bits for behavior (sampling uses 0x01); do not
change sampling logic.

Implementation details
- propagation/trace_context.go
  - Inject: emit sc.TraceFlags() without masking.
- Extract: remove opts[0] > 2 rejection; store full flags byte in
SpanContextConfig.TraceFlags.
- propagation/trace_context_test.go
  - Add extract cases for 0x02 and 0x03; ensure 0x09 is preserved.
  - Remove "unused bits set" from invalid cases.
  - Inject cases preserve 0xff, 0x02, and 0x03.
  - Future-version flag tests now expect full byte, not masked.
  
Closes #7635

---------

Co-authored-by: Damien Mathieu <42@dmathieu.com>
2026-03-04 14:28:59 +01:00
Victor edba765831 fix: generated semconv helpers skipping attributes (#7964)
This is related to issue #7938.

### The Bug

Semconv code generator Jinja2 template (instrument.j2) had an early
return optimization that skipped required attributes when no extra
optional attributes were passed.

The root cause seemed to be two macros in
semconv/templates/registry/go/instrument.j2:
  - add_method_with_optional (for counters/updowncounters)
  - record_method_with_optional (for histograms/gauges)

Both had `if len(attrs) == 0 { m.Inst.Add(ctx, incr); return }`, which
bypassed required attributes entirely.

### The Fix
I added a conditional check to verify when required attributes exist
`(req_attr | length > 0)`, the early return now passes them via
metric.WithAttributes(...). When there are no required attributes, the
original fast path is preserved.

I also regenerated the semconv `v1.39.0`, but if thats not desired due
to existing clients, let me know. It is my first time contributing here
and any feedback is appreciated!

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
2026-03-04 14:20:36 +01:00
Mariana Farias a8665644e1 support stdlib request.GetBody on metrics (#7931)
Based on https://github.com/open-telemetry/opentelemetry-go/pull/7794

This solves the exact same problem but on metrics. 

> traces export: Post "https://***/v1/metrics": 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-03-03 10:23:05 +01:00
Tyler Yahn 5dee2eb2dc Revert "Revert "Generate semconv/v1.40.0"" (#7985)
Reverts open-telemetry/opentelemetry-go#7978
2026-03-03 07:32:17 +01:00
Tyler Yahn d5febb955e Drop support for Go 1.24 (#7984) 2026-03-02 22:25:05 +01:00
Robert Pająk f1f16bcb62 fix changelog protection marker (#7986) 2026-03-02 21:28:37 +01:00
Robert Pająk 4575a9774d Release 1.41.0/0.63.0/0.17.0/0.0.15 (#7977)
This release is the last to support [Go 1.24].
The next release will require at least [Go 1.25].

### Added

- Support testing of [Go 1.26]. (#7902)

### Fixed

- Update `Baggage` in `go.opentelemetry.io/otel/propagation` and `Parse`
and `New` in `go.opentelemetry.io/otel/baggage` to comply with W3C
Baggage specification limits.
`New` and `Parse` now return partial baggage along with an error when
limits are exceeded.
Errors from baggage extraction are reported to the global error handler.
(#7880)

[Go 1.26]: https://go.dev/doc/go1.26
[Go 1.25]: https://go.dev/doc/go1.25
[Go 1.24]: https://go.dev/doc/go1.24
2026-03-02 19:39:57 +01:00
Sandy Chen 66fc10d9df fix: add error handling for insecure HTTP endpoints with TLS client configuration (#7914)
## Summary

This PR moves the `insecure + TLS config` validation into the core OTLP
HTTP exporters in `opentelemetry-go` (trace, metric, and log), instead
of relying on validation in external/config-wrapper code.

This aligns with feedback from `open-telemetry/opentelemetry-go-contrib`
PR https://github.com/open-telemetry/opentelemetry-go-contrib/pull/8560:
these packages are maintained/released together, so the check should be
enforced in this repo as well.

## What changed

- Added exporter-level validation error:
  - `"insecure HTTP endpoint cannot use TLS client configuration"`
- Enforced in:
  - `otlpmetrichttp` client construction
  - `otlploghttp` client construction
- `otlptracehttp` client startup (`Start`, since `NewClient` does not
return an error)
- Added tests in all three exporters to cover:
- Error when `WithInsecure()` and `WithTLSClientConfig(...)` are both
set
- No error when a custom `WithHTTPClient(...)` is provided (preserves
existing precedence semantics)

## Behavior

- Invalid config (`insecure` + TLS config) now fails fast directly in
exporters.
- Existing `WithHTTPClient` override behavior remains unchanged.

## Testing

Ran:

- `go test ./...` in `exporters/otlp/otlpmetric/otlpmetrichttp`
- `go test ./...` in `exporters/otlp/otlplog/otlploghttp`
- `go test ./...` in `exporters/otlp/otlptrace/otlptracehttp`

## Related

- `open-telemetry/opentelemetry-go-contrib` PR
(https://github.com/open-telemetry/opentelemetry-go-contrib/pull/8560)

---------

Co-authored-by: Damien Mathieu <42@dmathieu.com>
2026-03-02 15:46:50 +01:00
Damien Mathieu 0d50f9008c Revert "Generate semconv/v1.40.0" (#7978)
Reverts open-telemetry/opentelemetry-go#7929
2026-03-02 11:06:31 +01:00
Christos Markou c38a4a57c3 Generate semconv/v1.40.0 (#7929)
Similar to https://github.com/open-telemetry/opentelemetry-go/pull/7783
for semconv/v1.40.0:
https://github.com/open-telemetry/semantic-conventions/releases/tag/v1.40.0

---------

Signed-off-by: ChrsMark <chrismarkou92@gmail.com>
2026-03-02 10:54:57 +01:00
Sam Xie aa1894e09e Comply with W3C Baggage specification limits (#7880)
Updates the baggage implementation to comply with
https://www.w3.org/TR/baggage/#limits:

- Changed maxMembers from 180 to 64 (the W3C compliance requirement)

  > The resulting baggage-string contains 64 list-members or less.

- Removed maxBytesPerMembers (4096) - this per-member limit was not part
of the W3C spec
- Added limit checking in extractMultiBaggage for multiple baggage
headers:
  - Checks combined byte size across all headers (max 8192 bytes)
  - Checks combined member count across all headers (max 64 members)

This uses non-deterministic truncation when handling baggage limits.
2026-02-28 20:15:17 +01:00
Damien Mathieu ee3d4bd796 Support Go 1.26 (#7902) 2026-02-13 09:27:30 +01:00
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