1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00
Files
opentelemetry-go/sdk
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
..
2026-03-09 09:48:14 +01:00
2026-03-09 09:48:14 +01:00