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

ReferenceError: Cannot access 'FALLBACK_OTEL_TRACES_SAMPLER' before initialization #2170

Closed
weyert opened this issue Apr 30, 2021 · 7 comments · Fixed by #2171
Closed

ReferenceError: Cannot access 'FALLBACK_OTEL_TRACES_SAMPLER' before initialization #2170

weyert opened this issue Apr 30, 2021 · 7 comments · Fixed by #2171
Assignees
Labels
bug Something isn't working

Comments

@weyert
Copy link
Contributor

weyert commented Apr 30, 2021

Please answer these questions before submitting a bug report.

What version of OpenTelemetry are you using?

0.19

What version of Node are you using?

14.5.0

Please provide the code you used to setup the OpenTelemetry SDK

N/A

What did you do?

I am trying to run some unit tests in CI and Jest was throwing this error:

[test]     ReferenceError: Cannot access 'FALLBACK_OTEL_TRACES_SAMPLER' before initialization
[test] 
[test]       at buildSamplerFromEnv (node_modules/@opentelemetry/tracing/src/config.ts:75:89)
[test]       at Object.<anonymous> (node_modules/@opentelemetry/tracing/src/config.ts:37:12)
[test]       at Object.<anonymous> (node_modules/@opentelemetry/tracing/src/utility.ts:17:1)

If possible, provide a recipe for reproducing the error.

What did you expect to see?

I would expect this error is not happening :)

What did you see instead?

An runtime error is thrown

Additional context

Mostly a ticket to remind myself to look into this issue. Probably need to move the declaring of FALLBACK_OTEL_TRACES_SAMPLER above the function buildSamplerFromEnv

@weyert weyert added the bug Something isn't working label Apr 30, 2021
@dyladan
Copy link
Member

dyladan commented Apr 30, 2021

FALLBACK_OTEL_TRACES_SAMPLER is already declared above buildSamplerFromEnv...

From the code I'm looking at this should definitely not be happening. I wonder if either tsc or webpack is doing some mangling? What tests were causing this? I haven't seen this failure in our CI yet.

@weyert
Copy link
Contributor Author

weyert commented Apr 30, 2021

Oh these our my project's tests :)

@dyladan
Copy link
Member

dyladan commented Apr 30, 2021

I think this might be a bug with your program, not with our library. Can you provide a repro?

edit: we should do our best not to crash even with incorrect usage so this is definitely something we want to look into even if it isn't a "bug"

@weyert
Copy link
Contributor Author

weyert commented Apr 30, 2021

I was thinking this call is problematic:

sampler: buildSamplerFromEnv(env),

As it calls buildSamplerFromEnv which uses FALLBACK_OTEL_TRACES_SAMPLER but FALLBACK_OTEL_TRACES_SAMPLER is not defined above DEFAULT_CONFIG.

But yeah, I agree it should not crash and probably I am doing something silly like using OTEL env variables :)
I will do some digging next week

@dyladan
Copy link
Member

dyladan commented Apr 30, 2021

image

you're right. easy to fix though

@dyladan
Copy link
Member

dyladan commented Apr 30, 2021

#2171

@dyladan dyladan self-assigned this Apr 30, 2021
@dyladan
Copy link
Member

dyladan commented Apr 30, 2021

JS function hoisting hoists the function getConst but does not hoist the const being returned. Even though it appears in the code that the const is declared before the function, during runtime it is actually not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants