aws-xray-sdk-node: captureAWSv3Client does not support SQS or SSM clients

The captureAWSv3Client documentation states:

/**
 * Instruments AWS SDK V3 clients with X-Ray via middleware.
 *
 * @param client - AWS SDK V3 client to instrument
 * @param manualSegment - Parent segment or subsegment that is passed in for manual mode users
 * @returns - the client with the X-Ray instrumentation middleware added to its middleware stack
 */

However if you try and use SSMClient or SQSClient in a TypeScript context you will get an error:

Argument of type 'SSMClient' is not assignable to parameter of type 'Client<any, any, any>'.
  The types of 'middlewareStack.concat' are incompatible between these types.
     ... and many other lines...

Presumably this applies to any AWS v3 Client which extends Client<HandlerOptions, ClientInput extends object, ClientOutput extends MetadataBearer, ResolvedClientConfiguration extends SmithyResolvedConfiguration<HandlerOptions>> (in @aws-sdk/smithy-client/dist/types/client.d.ts).

import { SSMClient } from '@aws-sdk/client-ssm';
import { captureAWSv3Client } from 'aws-xray-sdk';
let ssm: SSMClient = new SSMClient({});
ssm = captureAWSv3Client(ssm);
Argument of type 'SSMClient' is not assignable to parameter of type 'Client<any, any, any>'.
  The types of 'middlewareStack.concat' are incompatible between these types.
    Type '<InputType extends ServiceInputTypes, OutputType extends ServiceOutputTypes>(from: MiddlewareStack<InputType, OutputType>) => MiddlewareStack<InputType, OutputType>' is not assignable to type '<InputType extends any, OutputType extends any>(from: MiddlewareStack<InputType, OutputType>) => MiddlewareStack<InputType, OutputType>'.
      Types of parameters 'from' and 'from' are incompatible.
        Type 'MiddlewareStack<InputType, OutputType>' is not assignable to type 'MiddlewareStack<InputType, ServiceOutputTypes>'.
          Types of property 'addRelativeTo' are incompatible.
            Type '(middleware: MiddlewareType<InputType, OutputType>, options: RelativeMiddlewareOptions) => void' is not assignable to type '(middleware: MiddlewareType<InputType, ServiceOutputTypes>, options: RelativeMiddlewareOptions) => void'.
              Types of parameters 'middleware' and 'middleware' are incompatible.
                Type 'MiddlewareType<InputType, ServiceOutputTypes>' is not assignable to type 'MiddlewareType<InputType, OutputType>'.
                  Type 'InitializeMiddleware<InputType, ServiceOutputTypes>' is not assignable to type 'MiddlewareType<InputType, OutputType>'.
                    Type 'InitializeMiddleware<InputType, ServiceOutputTypes>' is not assignable to type 'InitializeMiddleware<InputType, OutputType>'.
                      Call signature return types 'InitializeHandler<InputType, ServiceOutputTypes>' and 'InitializeHandler<InputType, OutputType>' are incompatible.
                        Type 'Promise<InitializeHandlerOutput<ServiceOutputTypes>>' is not assignable to type 'Promise<InitializeHandlerOutput<OutputType>>'.
                          Type 'InitializeHandlerOutput<ServiceOutputTypes>' is not assignable to type 'InitializeHandlerOutput<OutputType>'.
                            Types of property 'output' are incompatible.
                              Type 'ServiceOutputTypes' is not assignable to type 'OutputType'.
                                'ServiceOutputTypes' is assignable to the constraint of type 'OutputType', but 'OutputType' could be instantiated with a different subtype of constraint 'any'.
                                  Type 'AddTagsToResourceCommandOutput' is not assignable to type 'OutputType'.
                                    'AddTagsToResourceCommandOutput' is assignable to the constraint of type 'OutputType', but 'OutputType' could be instantiated with a different subtype of constraint 'any'.ts(2345)

If captureAWSClient should be used for these type of clients, then the documentation is very confusing since client-ssm and client-sqs are explicitly v3 clients and captureAWSv3Client does not define any specific subset of v3 clients that it supports, nor does it indicate the user should fallback to captureAWSClient (I’m not sure if that’s actually what should be done, just saying it doesn’t state to do so therefore the assumption for a reader of the documentation should be that you cannot fallback due to the explicit documentation on captureAWSv3Client that it is for v3 clients).

(I’m not sure if this a code bug, a documentation bug, or if someone is going to reply “you didn’t read…”)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 18 (6 by maintainers)

Most upvoted comments

Any plans to fix this issue soon?

Hi @mward-LT, the TS error reported in this issue was fixed in #575! I’ll close out this issue since the fix has been released