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

1140 Commits

Author SHA1 Message Date
Robert Pająk 866dd2504c attribute: deprecate Value.Emit (#8176)
Fixes https://github.com/open-telemetry/opentelemetry-go/issues/8145
2026-04-13 08:24:39 +02:00
David Ashpole d96b420138 Add support for the development attributes advisory parameter (#8135)
From [the
spec](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#instrument-advisory-parameter-attributes):

> ##### Instrument advisory parameter: `Attributes`

> **Status**: [Development](../document-status.md)

> Applies to all instrument types.

> `Attributes` (a list of [attribute
keys](../common/README.md#attribute)) is
the recommended set of attribute keys to be used for the resulting
metrics.

We already have `WithAttributes` options, so i've opted to name this
`WithDefaultAttributes` to avoid naming collisions. We could also
consider `WithAttributeKeys`, or `WithDefaultAttributeKeys`

Follows the pattern for experimental options introduced in
https://github.com/open-telemetry/opentelemetry-go/pull/8111

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
2026-04-10 14:38:44 -04:00
Robert Pająk 73876cb450 prometheus: use Value.String instead of Value.Emit (#8170)
Fixes https://github.com/open-telemetry/opentelemetry-go/issues/8144

From
https://opentelemetry.io/docs/specs/otel/compatibility/prometheus_and_openmetrics/#metric-attributes:

> non-string Attribute values MUST be converted to string attributes
following the [attribute
specification](https://opentelemetry.io/docs/specs/otel/common/#attribute).
2026-04-10 15:18:46 +02:00
Robert Pająk 1519eb8c33 attribute: Set.MarshalLog to use Value.String instead of Value.Emit (#8169)
Towards https://github.com/open-telemetry/opentelemetry-go/issues/8145
2026-04-10 15:11:31 +02:00
Tyler Yahn b1284dbfaa Support BYTESLICE attributes across trace and exporter paths (#8153)
Fixes https://github.com/open-telemetry/opentelemetry-go/issues/8164

Supersedes #8042 which does not address the `trace` or `zipkin`
packages, and has unrelated support changes.

Add end-to-end handling for `attribute.BYTESLICE` in the remaining trace
and exporter paths that still dropped, invalidated, or stringified byte
slice attributes.

This change:

- preserves byte slice attributes in `trace/auto`
- encodes byte slice attributes as OTLP `AnyValue_BytesValue` in trace,
log, and metric transforms
- serializes Zipkin byte slice attributes as JSON arrays of byte values
- adds regression tests for each updated path

## Problem

`attribute.BYTESLICE` is public, but several downstream conversions
still did not handle it correctly:

- `trace/auto` dropped byte slice attributes during conversion
- OTLP trace, log, and metric transforms fell through to their invalid
default handling
- Zipkin fell back to `Value.Emit()`, which produced a base64 string
rather than an explicit byte-array representation

That made `BYTESLICE` unusable or inconsistent depending on the export
path.

## Changes

### Trace

- Handle `attribute.BYTESLICE` in `trace/auto` by converting it to an
internal telemetry bytes value.
- Add a regression test covering byte slice conversion.

### OTLP

- Handle `attribute.BYTESLICE` in:
  - trace attribute transform
  - log gRPC attribute transform
  - log HTTP attribute transform
  - metric HTTP attribute transform
  - metric gRPC attribute transform
- Update the shared log and metric transform templates so generated
outputs stay aligned.
- Add regression tests for the trace transform, both log transform
outputs, and both metric transform outputs.

### Zipkin

- Handle `attribute.BYTESLICE` explicitly in Zipkin tag serialization.
- Serialize byte slices as JSON arrays of byte values instead of base64
text.
- Add a regression test for Zipkin byte slice serialization.

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
2026-04-09 14:04:03 -07:00
David Ashpole 0c09e08e7f Add experimental support for batching in periodic reader (#8071)
Adds experimental support for maxExportBatchSize using the
`OTEL_GO_X_METRIC_EXPORT_BATCH_SIZE=<size>` environment variable.

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

This preserves existing behavior for timeouts when batching is not used,
but individually applies the timeout to export calls when batching is
used.
2026-04-09 09:31:05 -04:00
Tyler Yahn 552d7ac071 fix(otlploghttp): replay gzipped bodies on redirect (#8152)
When gzip compression is enabled, the OTLP log HTTP client compressed
the request body for the initial send but left GetBody wired to the
original uncompressed protobuf payload.

Any redirect or retry path that rebuilt the request from GetBody could
then resend an uncompressed body while still advertising
Content-Encoding: gzip.

Update GetBody to return the gzipped buffer and add a redirect
regression test that verifies the replayed body matches the original
compressed request and can be decompressed successfully.
2026-04-08 11:48:23 -07:00
Robert Pająk 876f7c51e4 attribute: add String method for Value type (#8142)
Towards https://github.com/open-telemetry/opentelemetry-go/issues/7810

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

String representation follows:
https://opentelemetry.io/docs/specs/otel/common/#anyvalue-representation-for-non-otlp-protocols

This uses optimizations like
https://github.com/open-telemetry/opentelemetry-go/pull/8039 and we
inline the JSON-array/string encoding logic so we avoid the extra
allocations and reflection overhead of marshaling through encoding/json
(the code is inlined here not to reimplement JSON broadly, but to
provide a spec-specific, allocation-conscious formatter for a
constrained data model).

Benchmarks of both `String` and `Emit` (that is going to be deprecated)
showcase that `String` is even more efficient.

```
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/attribute
cpu: 13th Gen Intel(R) Core(TM) i7-13800H
BenchmarkBool/String-20                 100000000               10.20 ns/op            0 B/op          0 allocs/op
BenchmarkBool/Emit-20                   100000000               10.33 ns/op            0 B/op          0 allocs/op
BenchmarkBoolSlice/Len2/String-20               28427863                36.15 ns/op           16 B/op          1 allocs/op
BenchmarkBoolSlice/Len2/Emit-20                  5433291               201.8 ns/op            40 B/op          5 allocs/op
BenchmarkBoolSlice/Len8/String-20               12453201                99.46 ns/op           48 B/op          1 allocs/op
BenchmarkBoolSlice/Len8/Emit-20                  2185160               546.0 ns/op            88 B/op         11 allocs/op
BenchmarkInt/String-20                          100000000               10.73 ns/op            0 B/op          0 allocs/op
BenchmarkInt/Emit-20                            100000000               11.03 ns/op            0 B/op          0 allocs/op
BenchmarkIntSlice/Len2/String-20                17855926                61.57 ns/op           48 B/op          1 allocs/op
BenchmarkIntSlice/Len2/Emit-20                   6237072               184.9 ns/op            56 B/op          4 allocs/op
BenchmarkIntSlice/Len8/String-20                 6573506               192.1 ns/op           176 B/op          1 allocs/op
BenchmarkIntSlice/Len8/Emit-20                   3620901               332.8 ns/op           136 B/op          4 allocs/op
BenchmarkInt64/String-20                        100000000               10.90 ns/op            0 B/op          0 allocs/op
BenchmarkInt64/Emit-20                          100000000               10.91 ns/op            0 B/op          0 allocs/op
BenchmarkInt64Slice/Len2/String-20              20924970                59.59 ns/op           48 B/op          1 allocs/op
BenchmarkInt64Slice/Len2/Emit-20                 6755516               184.2 ns/op            56 B/op          4 allocs/op
BenchmarkInt64Slice/Len8/String-20               6033630               207.9 ns/op           176 B/op          1 allocs/op
BenchmarkInt64Slice/Len8/Emit-20                 3491808               327.2 ns/op           136 B/op          4 allocs/op
BenchmarkFloat64/String-20                      23607802                52.21 ns/op            2 B/op          1 allocs/op
BenchmarkFloat64/Emit-20                        13578472                93.34 ns/op           16 B/op          2 allocs/op
BenchmarkFloat64Slice/Len2/String-20                    12066591               111.0 ns/op            64 B/op          1 allocs/op
BenchmarkFloat64Slice/Len2/Emit-20                       5177293               234.3 ns/op            56 B/op          4 allocs/op
BenchmarkFloat64Slice/Len8/String-20                     3041408               381.9 ns/op           208 B/op          1 allocs/op
BenchmarkFloat64Slice/Len8/Emit-20                       2369974               548.3 ns/op           136 B/op          4 allocs/op
BenchmarkString/String-20                               137506468                8.578 ns/op           0 B/op          0 allocs/op
BenchmarkString/Emit-20                                 139229646                8.542 ns/op           0 B/op          0 allocs/op
BenchmarkStringSlice/Len2/Emit-20                        5809321               228.9 ns/op           120 B/op          4 allocs/op
BenchmarkStringSlice/Len8/String-20                      5089977               240.0 ns/op            96 B/op          1 allocs/op
BenchmarkStringSlice/Len8/Emit-20                        2569848               480.0 ns/op           344 B/op          4 allocs/op
BenchmarkByteSlice/String-20                            32244670                34.31 ns/op           16 B/op          1 allocs/op
BenchmarkByteSlice/Emit-20                              36643321                34.63 ns/op           16 B/op          1 allocs/op
```
2026-04-08 09:50:54 +02:00
Robert Pająk 99b2206d11 log/logtest: add Error field to Record type (#8148)
Fixes https://github.com/open-telemetry/opentelemetry-go/issues/8147
2026-04-08 09:41:26 +02:00
Robert Pająk 3b18b21580 unwrap error chains created with fmt.Errorf (#8133)
Fixes https://github.com/open-telemetry/opentelemetry-go/issues/7975

Per
https://github.com/open-telemetry/opentelemetry-go/issues/7975#issuecomment-4183251694

Per https://github.com/open-telemetry/semantic-conventions/issues/3588

Credits:
- Balaji01-4D for
https://github.com/open-telemetry/opentelemetry-go/pull/8018
- seh for providing valuable feedback
2026-04-07 20:03:30 +02:00
Nesterov Yehor 5e9a80b3ce attribute: add BYTESLICE type support (#7948)
Fixes #7933 

Add BYTES type to https://pkg.go.dev/go.opentelemetry.io/otel/attribute

- Introduces BYTES type and byte 
- Adds Bytes / BytesValue constructors
- Implements hashing support
- Adds base64 representation in Emit()
- Adds test coverage for constructors, hashing, and set equality

```
$ go test -run=^$ -bench=BenchmarkByteSlice
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/attribute
cpu: 13th Gen Intel(R) Core(TM) i7-13800H
BenchmarkByteSlice/Value-20             149529567                7.993 ns/op           0 B/op          0 allocs/op
BenchmarkByteSlice/KeyValue-20          136973736                8.768 ns/op           0 B/op          0 allocs/op
BenchmarkByteSlice/AsByteSlice-20       562915658                2.120 ns/op           0 B/op          0 allocs/op
BenchmarkByteSlice/Emit-20              29149410                40.26 ns/op           16 B/op          1 allocs/op
PASS
```

---------

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: Robert Pająk <pellared@hotmail.com>
2026-04-07 09:39:32 +02:00
Damien Mathieu 9276201a64 Release v1.43.0 / v0.65.0 / v0.19.0 (#8128)
Release issue:
https://github.com/open-telemetry/opentelemetry-go/issues/8127

## Added

- Add `IsRandom` and `WithRandom` on `TraceFlags`, and `IsRandom` on
`SpanContext` in `go.opentelemetry.io/otel/trace`
for [W3C Trace Context Level 2 Random Trace ID
Flag](https://www.w3.org/TR/trace-context-2/#random-trace-id-flag)
support. (#8012)
- Add service detection with `WithService` in
`go.opentelemetry.io/otel/sdk/resource`. (#7642)
- Add `DefaultWithContext` and `EnvironmentWithContext` in
`go.opentelemetry.io/otel/sdk/resource` to support plumbing
`context.Context` through default and environment detectors. (#8051)
- Support attributes with empty value (`attribute.EMPTY`) in
`go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc`.
(#8038)
- Support attributes with empty value (`attribute.EMPTY`) in
`go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc`.
(#8038)
- Support attributes with empty value (`attribute.EMPTY`) in
`go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc`. (#8038)
- Support attributes with empty value (`attribute.EMPTY`) in
`go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`.
(#8038)
- Support attributes with empty value (`attribute.EMPTY`) in
`go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`.
(#8038)
- Support attributes with empty value (`attribute.EMPTY`) in
`go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp`. (#8038)
- Support attributes with empty value (`attribute.EMPTY`) in
`go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest`. (#8038)
- Add support for per-series start time tracking for cumulative metrics
in `go.opentelemetry.io/otel/sdk/metric`.
  Set `OTEL_GO_X_PER_SERIES_START_TIMESTAMPS=true` to enable. (#8060)
- Add `WithCardinalityLimitSelector` for metric reader for configuring
cardinality limits specific to the instrument kind. (#7855)

## Changed

- Introduce the `EMPTY` Type in `go.opentelemetry.io/otel/attribute` to
reflect that an empty value is now a valid value, with `INVALID`
remaining as a deprecated alias of `EMPTY`. (#8038)
- Refactor slice handling in `go.opentelemetry.io/otel/attribute` to
optimize short slice values with fixed-size fast paths. (#8039)
- Improve performance of span metric recording in
`go.opentelemetry.io/otel/sdk/trace` by returning early if
self-observability is not enabled. (#8067)
- Improve formatting of metric data diffs in
`go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest`. (#8073)

## Deprecated

- Deprecate `INVALID` in `go.opentelemetry.io/otel/attribute`. Use
`EMPTY` instead. (#8038)

## Fixed

- Return spec-compliant `TraceIdRatioBased` description. This is a
breaking behavioral change, but it is necessary to
make the implementation
[spec-compliant](https://opentelemetry.io/docs/specs/otel/trace/sdk/#traceidratiobased).
(#8027)
- Fix a race condition in `go.opentelemetry.io/otel/sdk/metric` where
the lastvalue aggregation could collect the value 0 even when no
zero-value measurements were recorded. (#8056)
- Limit HTTP response body to 4 MiB in
`go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp` to
mitigate excessive memory usage caused by a misconfigured or malicious
server.
Responses exceeding the limit are treated as non-retryable errors.
(#8108)
- Limit HTTP response body to 4 MiB in
`go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp` to
mitigate excessive memory usage caused by a misconfigured or malicious
server.
Responses exceeding the limit are treated as non-retryable errors.
(#8108)
- Limit HTTP response body to 4 MiB in
`go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp` to
mitigate excessive memory usage caused by a misconfigured or malicious
server.
Responses exceeding the limit are treated as non-retryable errors.
(#8108)
- `WithHostID` detector in `go.opentelemetry.io/otel/sdk/resource` to
use full path for `kenv` command on BSD. (#8113)
- Fix missing `request.GetBody` in
`go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp` to
correctly handle HTTP2 GOAWAY frame. (#8096)

---------

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
2026-04-03 10:30:03 +02:00
Robert Pająk 5e363de517 limit response body size for OTLP HTTP exporters (#8108)
Per https://github.com/open-telemetry/opentelemetry-proto/pull/781
2026-04-01 11:48:05 +02:00
Damien Mathieu 35214b6013 Use an absolute path when calling bsd kenv (#8113)
Co-authored-by: Robert Pająk <pellared@hotmail.com>
2026-04-01 11:05:13 +02:00
Toma Puljak e70658e098 fix: support getBody in otelploghttp (#8096)
Based on #7931

Adding another `getBody` PR to the chain 😄.

This one is harder to catch if it's a problem since logs aren't being
sent in case of error.

---------

Signed-off-by: Toma Puljak <toma.puljak@hotmail.com>
Co-authored-by: Robert Pająk <pellared@hotmail.com>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
2026-04-01 09:48:12 +02:00
David Ashpole ab27913693 metricdatatest: Improve printing of diffs (#8073)
I've been getting tired of trying to parse blobs of OTLP-like text when
debugging metrics SDK test failures. This PR updating the printing of
diffs between metrics.

### Changes

This combines the `compareDiff`, and `diffSlices` functions into a
single `diffSlices` function. The `compare` parameter now returns a
`[]string` instead of a bool, to allow us to get a list of specific
differences between elements. `diffSlices` now also accepts a
`formatContext` parameter that provides the context (e.g. which scope,
which metric, etc) to print before printing the difference itself.

I've chosen to use the scope name, metric name, and attributes as the
context for scope, metric, and datapoint respectively. We could print
out more (as those are not the only identifying fields), but that is
usually enough to point to the problem.

### Example

I "broke" one of the OpenCensus tests by changing the expected SpanID
from 2 -> 1. You can see the resulting error message before and after
below:

Before:
```
--- FAIL: TestConvertMetrics (0.00s)
    --- FAIL: TestConvertMetrics/normal_Histogram,_summary,_gauges,_and_sums (0.00s)
        metric_test.go:940: [ScopeMetrics Metrics not equal:
            missing expected values:
            metricdata.Metrics{Name:"foo.com/histogram-a", Description:"a testing histogram", Unit:"1", 
Data:metricdata.Histogram[float64]{DataPoints:[]metricdata.HistogramDataPoint[float64]
{metricdata.HistogramDataPoint[float64]{Attributes:attribute.Set{hash:0x83dbf482c8017da3, data:
[2]attribute.KeyValue{attribute.KeyValue{Key:"a", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"hello", 
slice:interface {}(nil)}}, attribute.KeyValue{Key:"b", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"world", 
slice:interface {}(nil)}}}}, StartTime:time.Date(2026, time.March, 18, 15, 46, 53, 76753334, time.Local), 
Time:time.Date(2026, time.March, 18, 15, 47, 53, 77753334, time.Local), Count:0x8, Bounds:[]float64{1, 2, 3}, 
BucketCounts:[]uint64{0x1, 0x2, 0x5}, Min:metricdata.Extrema[float64]{value:0, valid:false}, 
Max:metricdata.Extrema[float64]{value:0, valid:false}, Sum:100, Exemplars:[]metricdata.Exemplar[float64]
{metricdata.Exemplar[float64]{FilteredAttributes:[]attribute.KeyValue{attribute.KeyValue{Key:"bool", 
Value:attribute.Value{vtype:1, numeric:0x1, stringly:"", slice:interface {}(nil)}}}, Time:time.Date(2026, time.March, 18, 15, 
47, 43, 77753334, time.Local), Value:0.8, SpanID:[]uint8{0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, TraceID:[]uint8{0x1, 0x0, 
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}, metricdata.Exemplar[float64]{FilteredAttributes:
[]attribute.KeyValue(nil), Time:time.Date(2026, time.March, 18, 15, 47, 43, 77753334, time.Local), Value:1.5, SpanID:
[]uint8{0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, TraceID:[]uint8{0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
0x0, 0x0, 0x0, 0x0}}, metricdata.Exemplar[float64]{FilteredAttributes:[]attribute.KeyValue(nil), Time:time.Date(2026, 
time.March, 18, 15, 47, 43, 77753334, time.Local), Value:2.6, SpanID:[]uint8{0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, 
TraceID:[]uint8{0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}}}, 
metricdata.HistogramDataPoint[float64]{Attributes:attribute.Set{hash:0x83dbf482c8017da3, data:
[2]attribute.KeyValue{attribute.KeyValue{Key:"a", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"hello", 
slice:interface {}(nil)}}, attribute.KeyValue{Key:"b", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"world", 
slice:interface {}(nil)}}}}, StartTime:time.Date(2026, time.March, 18, 15, 46, 53, 76753334, time.Local), 
Time:time.Date(2026, time.March, 18, 15, 47, 53, 76753334, time.Local), Count:0xa, Bounds:[]float64{1, 2, 3}, 
BucketCounts:[]uint64{0x1, 0x4, 0x5}, Min:metricdata.Extrema[float64]{value:0, valid:false}, 
Max:metricdata.Extrema[float64]{value:0, valid:false}, Sum:110, Exemplars:[]metricdata.Exemplar[float64]
{metricdata.Exemplar[float64]{FilteredAttributes:[]attribute.KeyValue(nil), Time:time.Date(2026, time.March, 18, 15, 47, 
43, 77753334, time.Local), Value:0.9, SpanID:[]uint8{0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, TraceID:[]uint8{0x7, 0x0, 
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}, metricdata.Exemplar[float64]{FilteredAttributes:
[]attribute.KeyValue(nil), Time:time.Date(2026, time.March, 18, 15, 47, 43, 77753334, time.Local), Value:1.1, SpanID:
[]uint8{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, TraceID:[]uint8{0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
0x0, 0x0, 0x0, 0x0}}, metricdata.Exemplar[float64]{FilteredAttributes:[]attribute.KeyValue(nil), Time:time.Date(2026, 
time.March, 18, 15, 47, 43, 77753334, time.Local), Value:2.7, SpanID:[]uint8{0xc, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, 
TraceID:[]uint8{0xb, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}}}}, Temporality:0x1}}
            unexpected additional values:
            metricdata.Metrics{Name:"foo.com/histogram-a", Description:"a testing histogram", Unit:"1", 
Data:metricdata.Histogram[float64]{DataPoints:[]metricdata.HistogramDataPoint[float64]
{metricdata.HistogramDataPoint[float64]{Attributes:attribute.Set{hash:0x83dbf482c8017da3, data:
[2]attribute.KeyValue{attribute.KeyValue{Key:"a", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"hello", 
slice:interface {}(nil)}}, attribute.KeyValue{Key:"b", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"world", 
slice:interface {}(nil)}}}}, StartTime:time.Date(2026, time.March, 18, 15, 46, 53, 76753334, time.Local), 
Time:time.Date(2026, time.March, 18, 15, 47, 53, 77753334, time.Local), Count:0x8, Bounds:[]float64{1, 2, 3}, 
BucketCounts:[]uint64{0x1, 0x2, 0x5}, Min:metricdata.Extrema[float64]{value:0, valid:false}, 
Max:metricdata.Extrema[float64]{value:0, valid:false}, Sum:100, Exemplars:[]metricdata.Exemplar[float64]
{metricdata.Exemplar[float64]{FilteredAttributes:[]attribute.KeyValue{attribute.KeyValue{Key:"bool", 
Value:attribute.Value{vtype:1, numeric:0x1, stringly:"", slice:interface {}(nil)}}}, Time:time.Date(2026, time.March, 18, 15, 
47, 43, 77753334, time.Local), Value:0.8, SpanID:[]uint8{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, TraceID:[]uint8{0x1, 0x0, 
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}, metricdata.Exemplar[float64]{FilteredAttributes:
[]attribute.KeyValue(nil), Time:time.Date(2026, time.March, 18, 15, 47, 43, 77753334, time.Local), Value:1.5, SpanID:
[]uint8{0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, TraceID:[]uint8{0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
0x0, 0x0, 0x0, 0x0}}, metricdata.Exemplar[float64]{FilteredAttributes:[]attribute.KeyValue(nil), Time:time.Date(2026, 
time.March, 18, 15, 47, 43, 77753334, time.Local), Value:2.6, SpanID:[]uint8{0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, 
TraceID:[]uint8{0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}}}, 
metricdata.HistogramDataPoint[float64]{Attributes:attribute.Set{hash:0x83dbf482c8017da3, data:
[2]attribute.KeyValue{attribute.KeyValue{Key:"a", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"hello", 
slice:interface {}(nil)}}, attribute.KeyValue{Key:"b", Value:attribute.Value{vtype:4, numeric:0x0, stringly:"world", 
slice:interface {}(nil)}}}}, StartTime:time.Date(2026, time.March, 18, 15, 46, 53, 76753334, time.Local), 
Time:time.Date(2026, time.March, 18, 15, 47, 53, 76753334, time.Local), Count:0xa, Bounds:[]float64{1, 2, 3}, 
BucketCounts:[]uint64{0x1, 0x4, 0x5}, Min:metricdata.Extrema[float64]{value:0, valid:false}, 
Max:metricdata.Extrema[float64]{value:0, valid:false}, Sum:110, Exemplars:[]metricdata.Exemplar[float64]
{metricdata.Exemplar[float64]{FilteredAttributes:[]attribute.KeyValue(nil), Time:time.Date(2026, time.March, 18, 15, 47, 
43, 77753334, time.Local), Value:0.9, SpanID:[]uint8{0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, TraceID:[]uint8{0x7, 0x0, 
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}, metricdata.Exemplar[float64]{FilteredAttributes:
[]attribute.KeyValue(nil), Time:time.Date(2026, time.March, 18, 15, 47, 43, 77753334, time.Local), Value:1.1, SpanID:
[]uint8{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, TraceID:[]uint8{0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
0x0, 0x0, 0x0, 0x0}}, metricdata.Exemplar[float64]{FilteredAttributes:[]attribute.KeyValue(nil), Time:time.Date(2026, 
time.March, 18, 15, 47, 43, 77753334, time.Local), Value:2.7, SpanID:[]uint8{0xc, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, 
TraceID:[]uint8{0xb, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}}}}, Temporality:0x1}}
            ]
FAIL
FAIL    go.opentelemetry.io/otel/bridge/opencensus/internal/ocmetric    0.037s
```

After:

```
--- FAIL: TestConvertMetrics (0.00s)
    --- FAIL: TestConvertMetrics/normal_Histogram,_summary,_gauges,_and_sums (0.00s)
        metric_test.go:940: [ScopeMetrics Metrics not equal:
            Metric "foo.com/histogram-a":
                Metrics Data not equal:
                Histogram not equal:
                Histogram DataPoints not equal:
                HistogramDataPoint [a=hello,b=world]:
                        Exemplars not equal:
                        Exemplar:
                                SpanID not equal:
                                expected: [2 0 0 0 0 0 0 0]
                                actual: [1 0 0 0 0 0 0 0]
            ]
FAIL
FAIL    go.opentelemetry.io/otel/bridge/opencensus/internal/ocmetric    0.036s
```
2026-03-30 15:51:15 -04:00
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