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

TypeError: timer.unref is not a function #4535

Closed
iemjitendra opened this issue Mar 8, 2024 · 7 comments
Closed

TypeError: timer.unref is not a function #4535

iemjitendra opened this issue Mar 8, 2024 · 7 comments
Labels
bug Something isn't working priority:p1 Bugs which cause problems in end-user applications such as crashes, data inconsistencies, etc

Comments

@iemjitendra
Copy link

What happened?

Steps to Reproduce

As per latest open telemetry metrics version, they mentioned to access addMetricReader through constructor. i tried to did the same with below example.

private metricsCollectorOptions = {
url: xx,
headers: {},
};

private metricExporter = new OTLPMetricExporter(this.metricsCollectorOptions);
private providerConfig = {
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: xx,
[SemanticResourceAttributes.SERVICE_NAMESPACE]: xx,
[SemanticResourceAttributes.SERVICE_INSTANCE_ID]: xx,
[SemanticResourceAttributes.SERVICE_VERSION]: xx,
[SemanticResourceAttributes.DEVICE_MODEL_IDENTIFIER]:xx,
}),
readers: [
new PeriodicExportingMetricReader({exporter: this.metricExporter}),
],
};
private meterProvider = new MeterProvider(this.providerConfig);

BUT i am facing error while running existing specific test file by writing yarn test xx.test.js even though i did not write any specific test cases for metrics. the error is appeared as below

TypeError: timer.unref is not a function >>> this error is referring to above line new MeterProvider(this.providerConfig)

i am using below versions
"@opentelemetry/exporter-metrics-otlp-http": "^0.49.1",
"@opentelemetry/sdk-metrics": "^1.22.0"

Please let me know how can i fix it.
PS: the implementation of metric feature is working as expected with latest changes. but the yarn test is blocker for me.

Expected Result

The existing test cases should continue to pass as i still didn't mention or write new test cases for metrics.

Actual Result

i am getting TypeError: timer.unref is not a function for new MeterProvider() when i am using readers config with in it.

Additional Details

OpenTelemetry Setup Code

private metricsCollectorOptions = {
    url: xx,
    headers: {},
  };

private metricExporter = new OTLPMetricExporter(this.metricsCollectorOptions);
private providerConfig = {
    resource: new Resource({
      [SemanticResourceAttributes.SERVICE_NAME]: xx,
      [SemanticResourceAttributes.SERVICE_NAMESPACE]: xx,
      [SemanticResourceAttributes.SERVICE_INSTANCE_ID]: xx,
      [SemanticResourceAttributes.SERVICE_VERSION]: xx,
      [SemanticResourceAttributes.DEVICE_MODEL_IDENTIFIER]:xx,
    }),
    readers: [
      new PeriodicExportingMetricReader({exporter: this.metricExporter}),
    ],
  };
private meterProvider = new MeterProvider(this.providerConfig);

Below how the error looks like from terminal.

TypeError: timer.unref is not a function

       97 |
       98 |   private provider = new WebTracerProvider(this.providerConfig);
    >  99 |   private meterProvider = new MeterProvider(this.providerConfig);

package.json

"@opentelemetry/exporter-metrics-otlp-http": "^0.49.1",
  "@opentelemetry/sdk-metrics": "^1.22.0"

Relevant log output

TypeError: timer.unref is not a function

       97 |
       98 |   private provider = new WebTracerProvider(this.providerConfig);
    >  99 |   private meterProvider = new MeterProvider(this.providerConfig);
@iemjitendra iemjitendra added bug Something isn't working triage labels Mar 8, 2024
@pichlermarc
Copy link
Member

Do you call MeterProvider.shutdown() when the tests are done?
Which platform are you running on?

@iemjitendra
Copy link
Author

@pichlermarc Do you call MeterProvider.shutdown() when the tests are done? >>> NO
Which platform are you running on? >>> i am running on my localhost(macbook). i run yarn test on my project after integrating metrics sdk. As i still did not write any test cases for metrics then why my project existing test suite is braking by just integrating metrics api.
I tried this as well, did not work for me -> #3723 (comment)

@iemjitendra
Copy link
Author

iemjitendra commented Mar 13, 2024

@pichlermarc can you please help in identify this issue. As i could not make out if this issue coming from metrics library or is there something wrong i am doing it.

@pichlermarc
Copy link
Member

pichlermarc commented Mar 18, 2024

The reason is that we currently don't set the browser overrides in a way that jest can deal with them, it only works for webpack and some other bundlers.

See

So it's not something you're doing wrong, but testing in jest like this is a case we currently don't support. That being said #4543 is now up-for-grabs in case someone has cycles to work on it.

@pichlermarc pichlermarc added priority:p1 Bugs which cause problems in end-user applications such as crashes, data inconsistencies, etc and removed triage labels Mar 20, 2024
@iemjitendra
Copy link
Author

iemjitendra commented Mar 22, 2024

thank you so much for help @pichlermarc
this issue is resolved by mocking metircs library in jest setupTest file, which is root file of jest
jest.mock('@opentelemetry/sdk-metrics');

BTW in the future upcoming versions, can this error go away without mocking metrics library.

@dyladan
Copy link
Member

dyladan commented Apr 3, 2024

I believe this can be closed in favor of #4543

@pichlermarc
Copy link
Member

BTW in the future upcoming versions, can this error go away without mocking metrics library.

@iemjitendra, yes we hope to address this with #4543, which should take care of that. I'll close this issue as duplicate for now as the other one is more explicit about what we need to do.

@pichlermarc pichlermarc closed this as not planned Won't fix, can't repro, duplicate, stale Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority:p1 Bugs which cause problems in end-user applications such as crashes, data inconsistencies, etc
Projects
None yet
Development

No branches or pull requests

3 participants