Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 of 2 tasks
sgohlke opened this issue Apr 16, 2024 · 7 comments · Fixed by #4687
Closed
1 of 2 tasks
Labels

Comments

@sgohlke
Copy link

sgohlke commented Apr 16, 2024

  • 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.

@tmokmss
Copy link

tmokmss commented Apr 23, 2024

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

packages versions are same as the OP.

@timosaikkonen
Copy link

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),
  ],
})

@Billmike
Copy link

@timosaikkonen Your solution was really helpful!

@Aaqib041
Copy link

Aaqib041 commented Jul 31, 2024

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

Copy link

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 github-actions bot added the stale label Sep 30, 2024
@renatomjr
Copy link

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

@aabmass
Copy link
Member

aabmass commented Sep 30, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants