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

feat: add global error handler #1514

Merged
merged 18 commits into from
Oct 7, 2020
Merged

Conversation

mwear
Copy link
Member

@mwear mwear commented Sep 10, 2020

Which problem is this PR solving?

Short description of the changes

  • This PR adds a global error handler and updates SDK components to use it. The default global error handler is configured with a ConsoleLogger at LogLevel.ERROR. This might be a questionable default and we can discuss alternatives.
  • CollectorExporterError was changed from an interface to a subclass. Other string based log messages were converted to error objects as well. This change means these errors will get a stack that is logged by the default handler.

@codecov
Copy link

codecov bot commented Sep 10, 2020

Codecov Report

Merging #1514 into master will increase coverage by 0.25%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1514      +/-   ##
==========================================
+ Coverage   92.93%   93.19%   +0.25%     
==========================================
  Files         156       82      -74     
  Lines        4871     2161    -2710     
  Branches      988      428     -560     
==========================================
- Hits         4527     2014    -2513     
+ Misses        344      147     -197     
Impacted Files Coverage Δ
packages/opentelemetry-core/src/common/types.ts 100.00% <ø> (ø)
...ntelemetry-core/src/common/global-error-handler.ts 100.00% <100.00%> (ø)
...telemetry-core/src/common/logging-error-handler.ts 100.00% <100.00%> (ø)
...ry-exporter-collector/src/CollectorExporterBase.ts 91.83% <100.00%> (-0.17%) ⬇️
...ages/opentelemetry-exporter-collector/src/types.ts 100.00% <100.00%> (ø)
...ckages/opentelemetry-exporter-zipkin/src/zipkin.ts 82.22% <0.00%> (-17.78%) ⬇️
...ges/opentelemetry-exporter-jaeger/src/transform.ts
packages/opentelemetry-sdk-node/src/sdk.ts
...-plugin-grpc-js/src/server/clientStreamAndUnary.ts
...plugin-grpc-js/src/client/loadPackageDefinition.ts
... and 69 more

Copy link
Member

@obecny obecny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the global error handler should be a part of api, otherwise we will always depend on sdk which I think is not desired. We should decouple sdk from api as much as possible.
@dyladan what do you think about moving this to api ?

@mwear
Copy link
Member Author

mwear commented Sep 16, 2020

I think the global error handler should be a part of api, otherwise we will always depend on sdk which I think is not desired. We should decouple sdk from api as much as possible.

I'm fine with wherever we decide to put this, but the global error handler is meant to log errors that come from the SDK. Quoting from #1415:

This error handler is for when the SDK itself errors, not when a monitored entity throws an error.

@dyladan
Copy link
Member

dyladan commented Sep 21, 2020

I think the global error handler should be a part of api, otherwise we will always depend on sdk which I think is not desired. We should decouple sdk from api as much as possible.

I'm fine with wherever we decide to put this, but the global error handler is meant to log errors that come from the SDK. Quoting from #1415:

This error handler is for when the SDK itself errors, not when a monitored entity throws an error.

I see this one both ways. Where have other SIGs implemented it?

@mwear
Copy link
Member Author

mwear commented Sep 21, 2020

Surveying Python and Go and it's a 50/50 split. Python has it as part of the SDK: open-telemetry/opentelemetry-python#1080. Go has it as part of the API: https://github.com/open-telemetry/opentelemetry-go/blob/master/api/global/handler.go.

@dyladan
Copy link
Member

dyladan commented Sep 21, 2020

Surveying Python and Go and it's a 50/50 split. Python has it has part of the SDK: open-telemetry/opentelemetry-python#1080. Go has it as part of the API: https://github.com/open-telemetry/opentelemetry-go/blob/master/api/global/handler.go.

Asked in gitter https://gitter.im/open-telemetry/maintainers?at=5f68edb9ce5bbc7ffddc7b9c

@dyladan
Copy link
Member

dyladan commented Sep 21, 2020

As mentioned by @mwear in gitter, the discussion in open-telemetry/opentelemetry-specification#696 seems to point to including this in the SDK.

edit: I also agree with this as I see this as more of an SDK configuration topic than a tracing API

@dyladan dyladan added the enhancement New feature or request label Sep 23, 2020
@dyladan dyladan added this to In progress PRs in GA Burndown via automation Sep 23, 2020
message: error.message,
});
globalErrorHandler(error);
onError(error);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well i believe it's the case here too, globalErrorHandler should only be called inside the CollectorExporterBase i think

Copy link
Member Author

@mwear mwear Sep 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, thanks again! I made another pass through and cleaned up redundant calls to the globalErrorHandler.

Copy link
Member

@vmarchaud vmarchaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually forgotten about those path (see #1561):

return new Promise((resolve, reject) => {
this._exporter.export(
this._meter.getBatcher().checkPointSet(),
result => {
if (result === ExportResult.SUCCESS) {
resolve();
} else {
// @todo log error
reject();
}
}
);
});

https://github.com/open-telemetry/opentelemetry-js/blob/master/packages/opentelemetry-tracing/src/MultiSpanProcessor.ts#L36

@mwear
Copy link
Member Author

mwear commented Oct 7, 2020

@vmarchaud I made the changes you requested. Let me know if that's what you had in mind. Codecov is coming in slim after the latest round of changes though.

@dyladan
Copy link
Member

dyladan commented Oct 7, 2020

Codecov is having a service outage but the error handler itself is tested so I think this is fine. If you fix the conflicts this can be merged.

@dyladan dyladan merged commit 240f852 into open-telemetry:master Oct 7, 2020
GA Burndown automation moved this from Approved to Done Oct 7, 2020
@mwear
Copy link
Member Author

mwear commented Oct 7, 2020

FWIW, I increased the test coverage before rebasing.

dyladan pushed a commit to dyladan/opentelemetry-js that referenced this pull request Sep 9, 2022
dyladan pushed a commit to dyladan/opentelemetry-js that referenced this pull request Sep 9, 2022
pichlermarc pushed a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
GA Burndown
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants