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

Control which framework/technology transactions are created from #3756

Open
thorhj opened this issue Nov 27, 2023 · 3 comments
Open

Control which framework/technology transactions are created from #3756

thorhj opened this issue Nov 27, 2023 · 3 comments
Labels
agent-nodejs Make available for APM Agents project planning. community enhancement

Comments

@thorhj
Copy link

thorhj commented Nov 27, 2023

The problem
I am hosting fastify APIs in AWS Lambda functions, using API Gateway as a proxy to route requests to the lambda. I am using fastify/aws-lambda-fastify to do this.

In a non-Lambda context, when I start the APM agent, it will hook in to the fastify context and create transactions based on routes that are hit. For instance, if a user navigate to

GET /users/3ffb7b9c-655e-4a87-b094-8eea9c725d0d/profile
GET /users/3ffb7b9c-655e-4a87-b094-8eea9c725d0d/roles
DELETE /users/3ffb7b9c-655e-4a87-b094-8eea9c725d0d

then the resulting transactions would be based on the registered route configuration to group related requests, so it would end up in APM something like this:

GET /users/:userId/profile
GET /users/:userId/roles
DELETE /users/:userId

The problem is when I use the Elastic APM agent on fastify APIs hosted in Lambda functions as described, the transaction is based on the API Gateway context. Given that I am proxying all traffic from API Gateway the examples above will show up as:

GET /users/{proxy+}
GET /users/{proxy+}
DELETE /users/{proxy+}

Of course this grouping is not desirable, as it only really separates routes by HTTP method and not by the URL.

Suggested solution
I would like some setting to control which technology/framework to base transactions on. As far as I can tell I have no way to do this now. In my case I would want APM to use fastify instead of AWS Lambda/API Gateway. It could possibly look something like this:

// On the agent:
apm.usePreferredFramework("fastify") // "awslambda" | "fastify" | "nextjs" | "azurefunction" | ...

// Or as an environment variable:
ELASTIC_APM_USE_PREFERRED_FRAMEWORK=fastify

Alternatives
I have looked into usePathAsTransactionName, but that setting eliminates all grouping so this is not desirable either. Having looked through the documentation I have not been able to find a suitable workaround.

@github-actions github-actions bot added agent-nodejs Make available for APM Agents project planning. community triage labels Nov 27, 2023
@trentm
Copy link
Member

trentm commented Nov 27, 2023

@thorhj Thank you for the issue and the suggestion. I think you are correct that the agent currently doesn't support this, so we'd need to add support for it. We'll discuss this internally soon.

One thing that would very much help when we come around to implementing this would be a small repro case. Looking at https://github.com/fastify/aws-lambda-fastify#example it should be very straightforward for me to whip up an example for testing. However, in case you have a small example lambda handler file (and app.js if separate) that you could post here, that would be great.

@thorhj
Copy link
Author

thorhj commented Nov 28, 2023

Thanks @trentm. I think I can manage to create a repository with a fastify API within a few days 👍

@trentm trentm removed the triage label Dec 4, 2023
@thorhj
Copy link
Author

thorhj commented Dec 8, 2023

Hi @trentm.

I have created a repository to illustrate this issue: thorhj/fastify-lambda-apm-test.

The built lambda function code can be found in lambda/index.js. This can be used directly. I have made a step-by-step guide in README.md for how I set up the Lambda function and API Gateway proxy through AWS Console.

The API has two endpoints:

  • /api-test/ok which returns 200 OK { "foo": "bar }
  • /api-test/error which returns 500 InternalServerError.

Let me know if anything is unclear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-nodejs Make available for APM Agents project planning. community enhancement
Projects
None yet
Development

No branches or pull requests

2 participants