SIGN IN SIGN UP

opentelemetry-sdk: remove unnecessary dict in set_attribute method (#5274)

* opentelemetry-sdk: remove unnecessary dict in method

set_attribute was unnecessarily creating a dict to set the attribute via set_attributes. removed that call and instead put the code from set_attributes directly into set_attribute. there is a small amount of time saved from doing this, the memory footprint is essentially the same:

Ran:

```
pytest opentelemetry-sdk/benchmarks/trace/test_benchmark_trace.py::test_set_attribute \
  --memray --trace-python-allocators \
  --benchmark-min-rounds=10 --benchmark-columns=mean,median,ops
```

And got the following results:

| attrs | Before mean (µs) | After mean (µs) | Time saved | Before mem (KiB) | After mem (KiB) | Mem saved |
|------|-----------------|----------------|-----------|-----------------|----------------|----------|
|     1 |            22.7  |            21.6 |        5%  |            176.8 |           174.6 |      1.2  |
|    10 |            39.9  |            34.4 |       14%  |            356.0 |           408.9 |     -52.9 |
|    50 |           117.6  |            90.4 |       23%  |            190.9 |           240.1 |     -49.2 |
|   128 |           266.3  |           199.3 |       25%  |            115.3 |           139.9 |     -24.6 |

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>

* changelog

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>

---------

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
A
Alex Boten committed
60b6749af8055e1ba20f309222c3a65896ec490c
Parent: 419c463
Committed by GitHub <noreply@github.com> on 6/8/2026, 4:59:27 PM