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

No 'ICorrelationIdProvider' has been registered but I use CorrelationIdGenerator #99

Open
arphox opened this issue Jan 5, 2021 · 0 comments

Comments

@arphox
Copy link

arphox commented Jan 5, 2021

Hi!

While setting up the usage of the nuget package (version 3.0.0), I encountered the following problem on application startup:

{
  "exception": {
    "ClassName": "System.InvalidOperationException",
    "Message": "No 'ICorrelationIdProvider' has been registered. You must either add the correlation ID services using the 'AddDefaultCorrelationId' extension method or you must register a suitable provider using the 'ICorrelationIdBuilder'.",
    "Data": null,
    "InnerException": null,
    "HelpURL": null,
    "StackTraceString": "   at CorrelationId.CorrelationIdMiddleware.Invoke(HttpContext context, ICorrelationContextFactory correlationContextFactory)\r\n   at HIDDEN"
  (...)
}

Which is unexpected as I don't want to use an ICorrelationIdProvider. I expect my setup to work, this is it:

Inside ConfigureServices

services.AddCorrelationId(options =>
{
    options.CorrelationIdGenerator = () => Guid.NewGuid().ToString("N");
    options.RequestHeader = LoggingConstants.CorrelationHeaderName;
    options.ResponseHeader = LoggingConstants.CorrelationHeaderName;
    options.AddToLoggingScope = true;
    options.LoggingScopeKey = LoggingConstants.SerilogCorrelationIdPropertyName;
});

Inside Configure:

app.UseCorrelationId();

According to the documentation of options.CorrelationIdGenerator, "When set, this function will be used instead of the registered ICorrelationIdProvider" which makes sense and I like it, but then do not require an ICorrelationIdProvider to be registered since it will never be used.

I understand that instead of AddCorrelationId I could use AddDefaultCorrelationId which would probably solve the problem since it registers a default Guid correlation id provider, but why would I register a default that should never be used and is forbidden to use?

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

No branches or pull requests

2 participants