powertools-lambda-typescript icon indicating copy to clipboard operation
powertools-lambda-typescript copied to clipboard

Feature request: Add support for captureMySQL

Open cortexcompiler opened this issue 3 years ago • 3 comments

Description of the feature request

Add captureMySQL support to the Tracer or add it to the ProviderServiceInterface

Problem statement

As a user I would like to trace MySQL queries leveraging the powertools Tracer.

Summary of the feature

I appreciate the encapsulation of X-Ray that is enabled through Tracer and would like to use it more fully. Rather than using captureMySQL from aws-xray-sdk-mysql, I would prefer to do one of the following (in order of preference):

  1. Automatically Trace MySQL calls, either by default or enabled with a setting, similar to tracing-http-requests
  2. Manually trace MySQL calls by wrapping the library with a tracer.captureMySQL(mysqlLib) similar to patching-aws-sdk-clients
  3. Leverage the escape hatch mechanism to access the tracer.provider.captureMySQL() as is eluded to in the escape-hatch-mechanism that refers to SQL queries tracing

Code examples Current approach

// current approach 1
const AWSXRay = require('aws-xray-sdk');
const mysql = AWSXRay.captureMySQL(require('mysql'));

// current approach 2
const captureMySQL = require('aws-xray-sdk-mysql');
captureMySQL(require('mysql2'));

Options

import { Tracer } from '@aws-lambda-powertools/tracer';
const tracer = new Tracer({ serviceName: 'myService' });

// Option 1 - automatic
const mysql = require('mysql');

// Option 2 - similar to patching AWS SDK
const mysql2 = tracer.captureMySQL(require('mysql'));

// Option 3 - escape hatch
const mysql3 = tracer.provider.captureMySQL(require('mysql'));

Benefits for you and the wider AWS community Uniformly using the powertools Tracer abstraction rather than directly using X-Ray. This would allow users to benefit from the continued improvements added to the powertools without the need to modify tracing code.

Describe alternatives you've considered Continue to use the x-ray sdk directly.

Additional context

Related issues, RFCs

cortexcompiler avatar Apr 08 '22 20:04 cortexcompiler

Hi @cortexcompiler, thank you for the feature request.

At the moment Tracer depends only on aws-xray-sdk-core, this choice was made to keep dependencies and deployment size low.

The X-Ray SDK also vends separately aws-xray-sdk-postgres and aws-xray-sdk-mysql, with the latter being the one needed to unlock the use case you suggest.

Since not every customer will be querying Mysql nor Postgres with their functions I would like to explore the possibility of Tracer supporting these features without having to include these dependencies in the library. Ideally this would mean that customers interested in tracing these types of operations would be able to add the extra dependency and pass either their own provider (option 1 that you suggest) or the captureMySQL function only when instantiating the Tracer.

This type of mechanism requires a bit of thought so we'll need a bit of time to investigate options and consider the feature request.

We are currently focused on bringing the current feature set to general availability and production ready worthiness. After this is done we'll re evaluate this (and other feature requests) to decide our next steps based on demand.

dreamorosi avatar Apr 11 '22 11:04 dreamorosi

Hi we are also interested in this feature - https://github.com/aws-powertools/powertools-lambda-typescript/discussions/2027

kaykhan avatar Feb 07 '24 08:02 kaykhan