@@ -10,7 +10,13 @@ import {
1010 ConsoleMetricExporter ,
1111 PeriodicExportingMetricReader ,
1212} from "@opentelemetry/sdk-metrics" ;
13- import { resourceFromAttributes } from "@opentelemetry/resources" ;
13+ import {
14+ envDetector ,
15+ processDetector ,
16+ resourceFromAttributes ,
17+ hostDetector ,
18+ ResourceDetectionConfig ,
19+ } from "@opentelemetry/resources" ;
1420import { NodeSDK } from "@opentelemetry/sdk-node" ;
1521import {
1622 AlwaysOnSampler ,
@@ -62,6 +68,15 @@ export async function nodeSDKBuilder() {
6268
6369 const sentryClient = Sentry . getClient ( ) ;
6470
71+ // All required resources are injected through env vars
72+ // in cloud deployment, but locally we can use detectors
73+ // The host detector has a known issue with async attributes
74+ // and isn't super important
75+ // https://github.com/open-telemetry/opentelemetry-js/issues/4638
76+ const resourceDetectors = isLocalCollector
77+ ? [ processDetector , envDetector ]
78+ : undefined ;
79+
6580 if ( sentryClient ) {
6681 // https://github.com/getsentry/sentry-javascript/tree/develop/packages/opentelemetry
6782 setupEventContextTrace ( sentryClient ) ;
@@ -118,6 +133,10 @@ export async function nodeSDKBuilder() {
118133 // Ensure the correct subset of traces is sent to Sentry
119134 // This also ensures trace propagation works as expected
120135 sampler,
136+ // Kuberenetes infrastructure automatically injects
137+ // required resources through environment variables
138+ autoDetectResources : isLocalCollector ? true : false ,
139+ resourceDetectors,
121140 instrumentations : [
122141 getNodeAutoInstrumentations ( {
123142 "@opentelemetry/instrumentation-fs" : {
0 commit comments