Skip to content

Commit 1c7d05f

Browse files
committed
fix(otel): fix async attributes access warning
1 parent 383d377 commit 1c7d05f

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

.env.local.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,5 @@ PUBSUB_EMULATOR_HOST=localhost:8085
6969
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
7070
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
7171
OTEL_SERVICE_NAME=monitor
72-
OTEL_NODE_ENABLED_INSTRUMENTATIONS="http,knex,fs,grpc,aws-sdk,http,ioredis,knex,winston,undici,runtime-node,redis"
72+
OTEL_NODE_ENABLED_INSTRUMENTATIONS="http,knex,fs,grpc,aws-sdk,ioredis,winston,undici,runtime-node,redis"
7373
OTEL_RESOURCE_ATTRIBUTES="service.namespace=monitor-local,service.version=0.0.1"

src/instrumentation.node.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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";
1420
import { NodeSDK } from "@opentelemetry/sdk-node";
1521
import {
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

Comments
 (0)