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

Hangfire with Aspire integration #2408

Open
meghuizen opened this issue May 24, 2024 · 6 comments
Open

Hangfire with Aspire integration #2408

meghuizen opened this issue May 24, 2024 · 6 comments

Comments

@meghuizen
Copy link

What I think would be a killer combo is having Hangfire integration in Aspire.
The scenario I would like to see is that you have Aspire running with multiple Hangfire workers on different projects running in Aspire.
The Hangfire dashboard as plugin part of the Aspire dashboard, which will give an overview on all the Hangfire jobs on all the Hangfire workers running in Aspire.
Also the telemetry and logging being visible from Aspire.

@odinserj
Copy link
Member

Looks indeed interesting, but need to understand its component model first. It seems to me that it's possible to integrate Hangfire with its current capabilities, since Aspire is likely using ASP.NET Core infrastructure, so it is likely to see the logs in Aspire dashboard anyway. But more detailed integration would be useful to have.

@adanbrownpaca
Copy link

adanbrownpaca commented May 26, 2024

We should make this simpler - we should add the ability for Hangfire to simply use a DB on the container provide by aspire. Do do this it needs to be able to install the DB seamlessly:

Hangfire Project:
builder.AddSqlServerClient("BackgroundJobsDb");

Aspire:
var sqldbserver = builder.AddSqlServer("DbServer");
var backgroundjobsdb = sqldbserver.AddDatabase("BackgroundJobsDb");
builder.AddProject<Projects.BackgroundJobs>("backgroundjobs")
.WithReference(backgroundjobsdb);

This way the Db gets installed on the local development container and initialized with the schema. Then, this simplifies deployment to Azure.

@arielmoraes
Copy link

Let's not forget Aspire provides packages for the client too. So all the goodies like OpenTelemetry, Health Checks, and more are expected to be provided out-of-box.

@sagarok
Copy link

sagarok commented Sep 10, 2024

We should make this simpler - we should add the ability for Hangfire to simply use a DB on the container provide by aspire. Do do this it needs to be able to install the DB seamlessly:

Hangfire Project: builder.AddSqlServerClient("BackgroundJobsDb");

Aspire: var sqldbserver = builder.AddSqlServer("DbServer"); var backgroundjobsdb = sqldbserver.AddDatabase("BackgroundJobsDb"); builder.AddProject<Projects.BackgroundJobs>("backgroundjobs") .WithReference(backgroundjobsdb);

This way the Db gets installed on the local development container and initialized with the schema. Then, this simplifies deployment to Azure.

Would be very useful. Any chance on that?

@sgryphon
Copy link

sgryphon commented Oct 25, 2024

At a minimum, I am looking at adding Activity (trace/span) support, for Producer/Consumer, similar to MassTransit. (Because Hangfire doesn't integrate with activity, so has no trace ID).

Once tracing is working, logs should be automatically correlated (if they go through normal .NET ILogger).

Metrics can be added later.

sgryphon added a commit to sgryphon/Hangfire that referenced this issue Oct 27, 2024
Addresses tracing aspects of HangfireIO#2408 for integration with Aspire,
as well as all other OpenTelemetery based diagnostics.

Start producer activities (spans) when jobs created, and consumer
activities when jobs executed. Pass the creation context through
as TraceParent and TraceState, so that distributed tracing works
across job scheduling.

Note that activity supports is only from netstandard2.0 onwards,
and only creates activities if there is a configured listener.
@sgryphon
Copy link

I've put up a PR for the observability aspects, to start new activities for job producer and consumer. #2460

This follows .NET standards (based on OpenTelemetry), so observability can easily be added (just add the named source to OTel so it creates a listener and activates the integration). This will cover the trace and logging aspects.

(Metrics will need to be done separately).

sgryphon added a commit to sgryphon/Hangfire that referenced this issue Oct 27, 2024
Addresses tracing aspects of HangfireIO#2408 for integration with Aspire,
as well as all other OpenTelemetery based diagnostics.

Start producer activities (spans) when jobs created, and consumer
activities when jobs executed. Pass the creation context through
as TraceParent and TraceState, so that distributed tracing works
across job scheduling.

Note that activity supports is only from netstandard2.0 onwards,
and only creates activities if there is a configured listener.
sgryphon added a commit to sgryphon/Hangfire that referenced this issue Nov 12, 2024
Addresses tracing aspects of HangfireIO#2408 for integration with Aspire,
as well as all other OpenTelemetery based diagnostics.

Start producer activities (spans) when jobs created, and consumer
activities when jobs executed. Pass the creation context through
as TraceParent and TraceState, so that distributed tracing works
across job scheduling.

Note that activity supports is only from netstandard2.0 onwards,
and only creates activities if there is a configured listener.
sgryphon added a commit to sgryphon/Hangfire that referenced this issue Nov 15, 2024
Addresses tracing aspects of HangfireIO#2408 for integration with Aspire,
as well as all other OpenTelemetery based diagnostics.

Start producer activities (spans) when jobs created, and consumer
activities when jobs executed. Pass the creation context through
as TraceParent and TraceState, so that distributed tracing works
across job scheduling.

Note that activity supports is only from netstandard2.0 onwards,
and only creates activities if there is a configured listener.
sgryphon added a commit to sgryphon/Hangfire that referenced this issue Nov 17, 2024
Addresses tracing aspects of HangfireIO#2408 for integration with Aspire, as well as all other OpenTelemetery based diagnostics,  and addresses HangfireIO#2017.

Add a default filter to start producer activities (spans) when jobs created, and consumer
activities when jobs performed. Pass the creation context through as TraceParent and TraceState job parameters, so that distributed tracing works across job scheduling.

Note that activity supports is only from netstandard2.0 onwards, and only creates activities if there is a configured listener.
sgryphon added a commit to sgryphon/Hangfire that referenced this issue Nov 23, 2024
Addresses tracing aspects of HangfireIO#2408 for integration with Aspire, as well as all other OpenTelemetery based diagnostics,  and addresses HangfireIO#2017.

Add a default filter to start producer activities (spans) when jobs created, and consumer
activities when jobs performed. Pass the creation context through as TraceParent and TraceState job parameters, so that distributed tracing works across job scheduling.

Note that activity supports is only from netstandard2.0 onwards, and only creates activities if there is a configured listener.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

6 participants