abp icon indicating copy to clipboard operation
abp copied to clipboard

How I access correlationId within BackgroundJob?

Open CaglarMacha opened this issue 1 year ago • 5 comments

Documentation

Please check the official documentation before asking questions: https://docs.abp.io

GitHub Issues

GitHub issues are for bug reports, feature requests, and other discussions about the framework.

If you're creating a bug/problem report, please include the followings:

  • Your ABP Framework version.
  • Your User Interface type (Angular/MVC/React... etc.) if the issue is related to a specific UI
  • Your database provider(EF Core/MongoDB)
  • Exception message and stack trace if available (check the logs).
  • Steps needed to reproduce the problem.

Please write in English.

Stack Overflow

Please use Stack Overflow for your questions about using the framework, templates, and samples:

https://stackoverflow.com/questions/tagged/abp

Use abp tag in your questions.

ABP Framework version = 5.3.3 Db Provider = EF Core

We use background jobs within some of our AppService or manager class. However, we want to access the correlationId information from Audit logs within these jobs. How can I access correlationId within jobs?. We don't want to pass the correlationId information as a parameter.

CaglarMacha avatar May 06 '24 13:05 CaglarMacha

hi

We don't want to pass the correlationId information as a parameter.

It seems this is the only way to get correlationid in BackgroundJob.

maliming avatar May 07 '24 01:05 maliming

hi

We don't want to pass the correlationId information as a parameter.

It seems this is the only way to get correlationid in BackgroundJob.

Thank you so much your answer. Maybe I can create an interface or class to access the correlationId information, and then have my job classes derive from this interface so that they can automatically set the correlationId information. I thought this could be one way, do you have any other recommendations? What's the best practice according to you?

CaglarMacha avatar May 07 '24 05:05 CaglarMacha

hi

The correlationId is related to HttpContext, so it can't be used in a BackgroundJob.

https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs#L24-L44

maliming avatar May 07 '24 05:05 maliming

hi

The is related to , so it can't be used in a .correlationId``HttpContext``BackgroundJob

https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Tracing/AbpCorrelationIdMiddleware.cs#L24-L44

I see that after 7.4.0, the DistributedEventHandler can pass the CorrelationId, but the BackgroundJob is still not supported, is there any concern that can not achieve it? BackgroundJob mission, will be affected by the AbpCorrelationIdMiddleware?

zhangzw218 avatar Aug 09 '24 14:08 zhangzw218

I pass the CorrelationId to RabbitMQ when performing background jobs. It's like DistributedEventBus.

But saw your this reply, don't know what will there be an unknown problem, can tell me about your last reply, AbpCorrelationIdMiddleware leads to any questions? @maliming

abp version 8.2.1

zhangzw218 avatar Aug 13 '24 06:08 zhangzw218

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 26 '25 05:04 stale[bot]