Skip to content

feat(sdk)!: support resource detectors - #555

Open
hectorhdzg wants to merge 7 commits into
open-telemetry:mainfrom
hectorhdzg:hectorhdzg-sdk-resource-detectors
Open

hectorhdzg wants to merge 7 commits into
open-telemetry:mainfrom
hectorhdzg:hectorhdzg-sdk-resource-detectors

Conversation

@hectorhdzg

Copy link
Copy Markdown
Member

Follow-up to the discussion in #460. Resource detection should be opt-in, but easy to turn on: you pass detectors in the SDK config and the SDK runs them, instead of calling detectResources yourself and copying attributes over by hand. Logs and traces also need to share one resource instead of each building their own.

Fixes #460

@hectorhdzg
hectorhdzg requested a review from a team as a code owner November 6, 2026 22:05
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on maintainers · refreshed 2026-11-25 23:28 UTC

Merge when ready.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with the author? Comment /dashboard route:author to route it back.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

@adityareddy-dev adityareddy-dev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

passing resource together with resourceDetectors or resourceAttributes just drops the extra config without saying anything, could we diag.warn there? easy to set both and not notice detection never ran

Comment thread packages/sdk/src/core/types.ts Resolved
Comment thread packages/sdk/src/core/resource.ts Resolved
@trentm

trentm commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Or perhaps consider (and document) startTracesSdk() and startLogsSdk() as lower-level APIs with stricter config requirements. Then:

  • require a resource option is passed in
  • drop the resourceAttributes option to these functions (but keep it on startBrowserSdk())
  • export a createResource() function (for users that will be calling startTracesSdk() and/or startLogsSdk() directly -- though I'd clean up the options signature on createResource() a bit

FWIW, from the Node.js side, I redesign the options to startNodeSdk() recently (https://github.com/open-telemetry/opentelemetry-js/blob/c6affabfca28258cddacf40bb7c5cc05761184ab/experimental/packages/opentelemetry-sdk-node/src/types.ts#L49-L200). Notably:

  • resourceAttributes and resourceDetectors are the common options to configure the resource, as you have here
  • a baseResource option was added for the expected to be rare use case of a user wanting to disable the spec-described default resource (e.g. telemetry.sdk.* attributes). I don't think you really need that unless someone asks.
  • I dropped serviceName (and serviceVersion) as a separate convenience. Users can set resourceAttributes: {'service.name': 'foo'}. Having serviceName just added another confusion on the priority order for setting service.name -- especially in Node.js-land where service.name can also come from OTEL_SERVICE_NAME, OTEL_RESOURCE_ATTRIBUTES, a declarative config file, a resource detector, the fallback default of unknown_service:node.

Comment on lines +55 to +61
const sdkAttributes = resourceFromAttributes({
[ATTR_TELEMETRY_SDK_LANGUAGE]:
defaults.attributes[ATTR_TELEMETRY_SDK_LANGUAGE],
[ATTR_TELEMETRY_SDK_NAME]: defaults.attributes[ATTR_TELEMETRY_SDK_NAME],
[ATTR_TELEMETRY_SDK_VERSION]:
defaults.attributes[ATTR_TELEMETRY_SDK_VERSION],
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to specifically guard against resource detectors or the resourceAtrtibutes option overriding telemetry.sdk.* values? FWIW sdk-node doesn't bother guarding this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's there so detectors and resourceAttributes can't override telemetry.sdk.* and telemetry.distro.*, since only the SDK or distro knows those values. This was discussed in #460 (#460 (comment)).

@opentelemetry-pr-dashboard

This comment has been minimized.

@hectorhdzg

Copy link
Copy Markdown
Member Author

@trentm thanks. The latest commit removes resource from startBrowserSdk, and on startTracesSdk and startLogsSdk passing resource together with serviceName, serviceVersion or resourceAttributes is now a type error, so those confusing combinations can't happen anymore. Dropping serviceName and serviceVersion like startNodeSdk is a bigger breaking change, so I'd rather track it in a separate issue than grow this PR.

Comment thread packages/sdk/src/core/resource.ts Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support resource detectors in the browser SDK

4 participants