Component
Config
Problem Statement
otelconf/x.NewSDK accepts WithContext(ctx) and stores it in the internal configuration options. Most SDK construction paths use that context when creating exporters, processors, and metric readers.
Resource construction is an exception. otelconf/x/resource.go calls resource.New(context.Background(), ...), including when resource.detection/development enables SDK resource detectors. This means resource detection ignores the context supplied with NewSDK(WithContext(...)).
The current built-in detectors mostly do local work and may not make this very visible today, but resource.New accepts a context for detector execution and the rest of otelconf/x already treats WithContext as the SDK construction context. Resource detection should follow the same behavior.
Expected Behavior
When callers configure otelconf/x.NewSDK(WithContext(ctx), ...), resource construction and resource detector execution should use that context.
Actual Behavior
otelconf/x uses context.Background() while creating the resource, so caller cancellation/deadline is not propagated to resource detection.
Proposed Solution
Thread the SDK construction context into resource creation:
- Change
newResource in otelconf/x to accept a context.Context.
- Call it from
NewSDK with o.ctx.
- Ensure any helper that builds detected resources also uses that context when calling
resource.New.
It may also be worth updating stable otelconf/resource.go to accept the SDK construction context for consistency, although stable otelconf does not currently expose resource.detection/development.
Additional Context
This came up while reviewing #9131. That PR makes resource detection handling more visible, but the context behavior predates that change and is separate from attribute filtering.
Component
Config
Problem Statement
otelconf/x.NewSDKacceptsWithContext(ctx)and stores it in the internal configuration options. Most SDK construction paths use that context when creating exporters, processors, and metric readers.Resource construction is an exception.
otelconf/x/resource.gocallsresource.New(context.Background(), ...), including whenresource.detection/developmentenables SDK resource detectors. This means resource detection ignores the context supplied withNewSDK(WithContext(...)).The current built-in detectors mostly do local work and may not make this very visible today, but
resource.Newaccepts a context for detector execution and the rest ofotelconf/xalready treatsWithContextas the SDK construction context. Resource detection should follow the same behavior.Expected Behavior
When callers configure
otelconf/x.NewSDK(WithContext(ctx), ...), resource construction and resource detector execution should use that context.Actual Behavior
otelconf/xusescontext.Background()while creating the resource, so caller cancellation/deadline is not propagated to resource detection.Proposed Solution
Thread the SDK construction context into resource creation:
newResourceinotelconf/xto accept acontext.Context.NewSDKwitho.ctx.resource.New.It may also be worth updating stable
otelconf/resource.goto accept the SDK construction context for consistency, although stableotelconfdoes not currently exposeresource.detection/development.Additional Context
This came up while reviewing #9131. That PR makes resource detection handling more visible, but the context behavior predates that change and is separate from attribute filtering.