Skip to content

Honor WithContext during otelconf/x resource detection #9158

@MrAlias

Description

@MrAlias

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.

Metadata

Metadata

Assignees

Labels

area: file-configRelated to file-based configurationenhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions