APM on Azure Functions

Hello,

On the recent update, v1.20.0, it was added support for the Azure Functions though the new nuget package, but I'm having some doubts, and I don't know if it's not supported or if I'm doing something wrong.

I saw that the request is captured and the headers are being correctly capture, but I add the "ELASTIC_APM_CAPTURE_BODY": "all" and the body is not being captured. Is this supported or something else needs to be done?

Does the ApmMiddleware capture the external http calls, like we used to have with the HttpDiagnosticsSubscriber? I have an external call and it's not being captured, I even added Agent.Subscribe(new HtppDiagnosticsSubscriber()) to no avail. Any suggestions?

Thanks,
Pedro

Hi @PedroBrasilBorges

thanks for your input - for the outgoing HTTP calls, I think I can offer a workaround, for the request bodies, we'll need to do some work on the agent side.

In general what you describe seems valid for me.

Unfortunately we don't capture HTTP request bodies in Azure functions, and the listener for outgoing HTTP calls is not turned on.

I opened an issue for these issues: Azure functions - next iteration · Issue #2035 · elastic/apm-agent-dotnet · GitHub

Now... you should be able to turn on the HtppDiagnosticsSubscriber, so turning it on manually should work. One important note here is that you'll need to call Agent.Subscribe(new HtppDiagnosticsSubscriber()) AFTER the agent is initialized. Right now, the agent is initialized when the first run happens in Azure functions, so you need to make sure that happens before you call Agent.Subscribe(...).

We also offer an API to query if the agent is already initialized: Agent.IsConfigured - make sure you call Agent.Subscribe(...) once this returns true.

I understand this is far from ideal, so we plan to make this in Azure functions - next iteration · Issue #2035 · elastic/apm-agent-dotnet · GitHub better.

Hope this helps.

Hello @GregKalapos,

I've tried with the Agent.IsConfigured and the external calls are being capture. Just one thing that I think it's missing is the response http properties. In a normal application the response status codes, headers, etc, are captured, but from what I've seen on the azure function it doesn't. Again something I need to do, or it's from the behaviour and might be added in the future?

Thanks a lot,
Pedro

Hi @PedroBrasilBorges,

In a normal application the response status codes, headers, etc, are captured, but from what I've seen on the azure function it doesn't.

Which http request do you mean here? 1) The outgoing one from the Azure function to another service which you (I guess) create by the HttpClient class or 2) the one representing the incoming HTTP call into the Azure function?

If it's the 1. one, then it should with with HtppDiagnosticsSubscriber - if it does not, let me know, because in that case I'll need to look into that. If it's the 2. one, then it's expected - that will be covered by Azure functions - next iteration · Issue #2035 · elastic/apm-agent-dotnet · GitHub and unfortunately there isn't really a nice workaround.

One thing you can always do is to add things manually to the transaction, like this (add null checks accordingly):

Agent.Tracer.CurrentTransaction.Context.Request = //.. fill request properties
Agent.Tracer.CurrentTransaction.Context.Response = //.. fill response properties

But other than that once we get to Azure functions - next iteration · Issue #2035 · elastic/apm-agent-dotnet · GitHub, it should happen automatically.

Hello @GregKalapos ,

I meant the number 2, meaning it's the actual azure function endpoint response that doesn't get captured. The calls to external services that the Azure function is doing are being captured correctly. Then I'll try to add manually in a middleware the response. I'll keep an eye on the issue!

Thanks a lot,
Keep the great work,
Pedro

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