opentelemetry-js icon indicating copy to clipboard operation
opentelemetry-js copied to clipboard

How to handle "Accessing resource attributes before async attributes settled" errors

Open sgohlke opened this issue 1 year ago • 4 comments

  • [x] This only affects the JavaScript OpenTelemetry library
  • [ ] This may affect other libraries, but I would like to get opinions here first

In the logs of one of our applications I see the following error from time to time: Accessing resource attributes before async attributes settled I took a look into https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-resources/src/Resource.ts#L98 which I assume is the code line that writes this error.

I'm not sure what to do with this error. Is is necessary to take an action or can this error be ignored? There isn't really much information about the origin of this error so I'm not sure how to find the root problem/how to debug this.

We are using the following packages:

  • "@opentelemetry/api": "1.8.0",
  • "@opentelemetry/exporter-trace-otlp-http": "0.50.0",
  • "@opentelemetry/instrumentation-http": "0.50.0",
  • "@opentelemetry/resources": "1.23.0",
  • "@opentelemetry/sdk-node": "0.50.0",
  • "@opentelemetry/semantic-conventions": "1.23.0",

In our instrumentation create a new SDK using the following resource:

resource: Resource.default().merge(
                new Resource({
                    [SEMRESATTRS_SERVICE_NAME]: 'our-service',
                })
            )

Maybe someone has an idea how to handle this.

sgohlke avatar Apr 16 '24 09:04 sgohlke

I'm also seeing this message. My otel config is here: https://gist.github.com/tmokmss/b6b0d639658161cd28519a65992866f9

packages versions are same as the OP.

tmokmss avatar Apr 23 '24 10:04 tmokmss

Encountered the same issue and wrote a simple workaround while awaiting the actual fix to land:

import {
  Detector,
  DetectorSync,
  IResource,
  ResourceDetectionConfig,
  envDetectorSync,
  hostDetectorSync,
  processDetectorSync,
} from "@opentelemetry/resources"

function awaitAttributes(detector: DetectorSync): Detector {
  return {
    async detect(config?: ResourceDetectionConfig): Promise<IResource> {
      const resource = detector.detect(config)
      await resource.waitForAsyncAttributes?.()

      return resource
    },
  }
}

const sdk = new opentelemetry.NodeSDK({
  // ...
  resourceDetectors: [
    awaitAttributes(envDetectorSync),
    awaitAttributes(processDetectorSync),
    awaitAttributes(hostDetectorSync),
  ],
})

timosaikkonen avatar May 22 '24 07:05 timosaikkonen

@timosaikkonen Your solution was really helpful!

Billmike avatar May 24 '24 07:05 Billmike

I too faced same issue in my application , when I removed the below environment definition , the error is NO more appears . My application is built in nodejs

        - name: OTEL_LOG_LEVEL
          value: info

Anyone know the significance of this parameter and why error appear when I enable this on deployment ?

Thanks

Aaqib041 avatar Jul 31 '24 08:07 Aaqib041

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] avatar Sep 30 '24 06:09 github-actions[bot]

Not stale. Since the Detector type is deprecated in favor of DetectorSync, the current workaround may break in future releases.

renatomjr avatar Sep 30 '24 09:09 renatomjr

It would be helpful if someone can share a stack trace of what is triggering the log message.

OTel SDK components should already be awaiting waitForAsyncAttributes() before accessing the resource attributes (examples), which should avoid the log message. If that's not the case, stack trace would be helpful as it may be a bug. Otherwise, it may be log spam.

If this is happening in your own code, just await waitForAsyncAttributes() before accessing the resource attributes.

aabmass avatar Sep 30 '24 19:09 aabmass