newrelic-dotnet-agent icon indicating copy to clipboard operation
newrelic-dotnet-agent copied to clipboard

Custom Runtime w/ .NET Core 3.1 in dotnet lambdas support for tracing

Open wr-cdargis opened this issue 3 years ago • 7 comments

Is your feature request related to a problem? Please describe.

I am using dotnetcore3.1 examples as a reference for hopefully getting dotnetcore3.1 to work with custom runtime. Traces show up in Span table but they do not show up in the tracing UI

Feature Description

I am asking for custom runtime support in dotnet lambdas. dotnetcore3.1 is listed here as supported. It would be awesome if dotnetcore3.1 was also fully supported in the custom runtime.

Additional context

I do have some Span data coming in from AWS but it doesn't show up the same way as the regular flavor of the dotnet lambdas. We seem to be missing AWS. ARN and AWS. METRIC STREAM attributes (but AWS.LAMBDA.ARN) is present.

Here is what my code would look like in an HttpApi (I have tried similar with SQS lambdas, etc):

public class CustomEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayHttpApiV2ProxyFunction
{
    public override async Task<APIGatewayHttpApiV2ProxyResponse> FunctionHandlerAsync(APIGatewayHttpApiV2ProxyRequest request, ILambdaContext lambdaContext)
    {
        // Wrap execution in trace
        return await new TracingRequestHandler().LambdaWrapper(base.FunctionHandlerAsync, request, lambdaContext).ConfigureAwait(false);
    }
}

public class Program
{
    public static void Main(string[] args)
    {
        // Register global tracer
        GlobalTracer.Register(LambdaTracer.Instance);

        CustomEntryPoint lambdaEntry = new CustomEntryPoint();
        var functionHandler = (Func<APIGatewayHttpApiV2ProxyRequest, ILambdaContext, Task<APIGatewayHttpApiV2ProxyResponse>>)(lambdaEntry.FunctionHandlerAsync);
        using (var handlerWrapper = HandlerWrapper.GetHandlerWrapper(functionHandler, new JsonSerializer()))
        using (var bootstrap = new LambdaBootstrap(handlerWrapper))
        {
            bootstrap.RunAsync().Wait();
        }
    }
}

Priority

Must Have

Happy to clarify anything or add additional context. My goal is for this to correctly show in the tracing UI. If there is some workaround for this that would be great to know.

wr-cdargis avatar Aug 24 '21 19:08 wr-cdargis

Hi @wr-cdargis We haven't looked into or tested using custom runtimes with AWS Lambda. I took a quick look at the article you linked (thank you!) and it is definitely intriguing, though a bit different than our normal Lambda setup.

It looks similar to our inheriting setup.

I think the hard part is figuring out where to call our TracingRequestHandler().LambdaWrapper since this is not identical to the inheriting setup. I definitely think we need to look into it!

Can you provide more details on what metrics are missing? It would help us figure out a good spot to do the wrapper work.

jaffinito avatar Aug 25 '21 20:08 jaffinito

Hey @jaffinito ! :)

I think the hard part is figuring out where to call our TracingRequestHandler().LambdaWrapper since this is not identical to the inheriting setup. I definitely think we need to look into it!

Happy to hear ya'll want to take a look! I don't know how many options there are for the location of the LambdaWrapper() call - the spot that I wired it into this APIGatewayHttpApiV2ProxyFunction is one of the few spots I have scope on the ILambdaContext. Check it. Maybe protected ProcessRequest(ILambdaContext lambdaContext, ...) is an option too. This obviously changes for something like an SQS triggered lambda.

Maybe this link is helpful as well. Everything in the .NET custom runtime works off of LambdaBootstrap from the Amazon.Lambda.Runtime.Support lib

Can you provide more details on what metrics are missing? It would help us figure out a good spot to do the wrapper work.

Here is what the Explorer is telling me when I query the Span table.

Missing from custom runtime but present in regular dotnet lambda flavor: AWS. ARN, AWS. METRIC STREAM ARN, AWS. NAMESPACE ARN, AWS.ACCOUNT ID, AWS.REGION, DISPLAY NAME, ENTITY.GUID, ENTITY.NAME, ENTITY GUID, ENTITY NAME, NEW RELIC.INGEST POINT, NEWRELIC.CLOUD INTEGRATIONS.PROVIDER ACCOUNT NAME, NEWRELIC.CLOUD INTEGRATIONS.PROVIDER EXTERNAL ID, SERVICE.NAME.

The AWS. ARN is weird, the row for the custom runtime lambda does have AWS.ARN (note no space in that attribute). The regular dotnet flavor lambda has both AWS. ARN and AWS.ARN. Also if it is helpful New Relic is able to grab stuff for the custom runtime lambda like INVOCATION ID, AWS.LAMBDA.ARN, AWS.REQUEST ID.

wr-cdargis avatar Aug 25 '21 22:08 wr-cdargis

@elucus @jaffinito @angelatan2 I see it added to the backlog. I know that this is every developers' favorite question but do you know when work will be started on it?

wr-cdargis avatar Sep 02 '21 20:09 wr-cdargis

Hi @wr-cdargis, sorry to say, but as you probably guessed by the delayed response, it's not on our short-term roadmap. I'll flag this for consideration in an upcoming quarterly feature pack.

elucus avatar Nov 05 '21 18:11 elucus

@elucus I closed on accident. I don't know if that messed with the labels/backlog/lanes.

wr-cdargis avatar Nov 05 '21 21:11 wr-cdargis

https://issues.newrelic.com/browse/NEWRELIC-3654

Commented by svengala: All lambda features will be looked into later as a strategic plan is being discussed for serverless. Once finalized we will revisit.

This issue won't be actioned.