Ephemeral Jobs

Hi I'm just curious if the APM libraries can be used for short lived jobs (ie. a cron job that processes some entries in a queue and puts them in a database and exits). I haven't seen any special configuration for this. Do the APM libs flush before exit automatically or are they more suited for long-running daemons?

Thanks in advance.

Hey @jasonmoo-we

Excellent question! It depends a bit on which agent/language you use. Some agents, e.g. for Java and Python, will automatically flush the queue before the process exits (assuming a clean shutdown of the process). For other agents, like .net and Go, you will have to use the available APIs to manually flush the queue at the end of your program.

Hope this helps :slight_smile:

1 Like

Hey thanks for the response. Can you point me to any documentation where the manual flush is described, and which languages require it? Based on what you're saying it sounds like even the daemon processes should flush prior to shutdown.

@beniwohli is there anything you can share that references these ideas?

Hi @jasonmoo-we,

So, for Go, here is the Flush function with some documentation.

Also, here you can read a little bit more about this topic.

For .NET we don’t really have a public API yet to flush data manually, so the use case is not really supported at the moment in .NET. In .NET we have some settings that can help in this case, but those don’t really solve the problem.

Is there any specific language where we should follow up with more details?

1 Like

Hey thanks @GregKalapos. I'm doing a survey for a deployment involving several languages so I'm trying to see how much difference there is between agents. Currently researching go and ruby.

From what I can see with the ruby agent, the worker (short lived jobs) does a flush before shutdown, but the rails server does not?
And the go agent lib requires an explicit flush before exit in both worker and server applications.

If you could provide the flush behavior across all supported languages that would be ideal.

Node.js tries to flush on process exit, but the process could be in an unknown or unexpected state at that point so there's no guarantees it would actually succeed.

1 Like

Hi @jasonmoo-we!

The Ruby agent should empty its queue before exiting but there are no guarantees. The agent behaves the same with Rails request events as with events from background jobs. The Worker in the agent codebase is only related to the inner workings of the agent and doesn't relate directly to the concept of your app's worker processes.

What background job library are you using?

1 Like

Cool. I'm looking at supporting arbitrary ruby applications that are able to instrument using the agent supplied.

We don't have a manual flush API for the Java agent but we register a shutdown hook to flush on JVM shutdown.

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.