aws / aws-xray-sdk-go

AWS X-Ray SDK for the Go programming language.
Apache License 2.0
276 stars 117 forks source link

X-Ray for a lambda function #410

Closed jledesma-opsguru closed 11 months ago

jledesma-opsguru commented 1 year ago

Hi there,

I have some lambda functions written in Go 1.20 and aws-sdk-go-v2 to interact with services like Cognito, SQS, StepFunctions, among others. I am using SAM to deploy the functions, so I activate the tracing and with it, I can see API Gateway and Lambda in the X-Ray service map and also the transactions, but I cannot see the other AWS services. I've been researching and trying to add X-Ray to AWS service clients, but haven't succeeded yet.

Should I use the xray module in aws-sdk-go-v2 or should I use github.com/aws/aws-xray-sdk-go?

The following is an example of what I am trying to do:

import (
        "context"
        cognito "github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider"
       "github.com/aws/aws-xray-sdk-go/xray"
    )

    func GetClient() {
    ...
    cfg, errCfg := config.LoadDefaultConfig(context.TODO())
    client := cognito.NewFromConfig(cfg)

    // the next line is not valid, because the function receives a *client.Client as a parameter
    // and my current client is of type *cognito.Client
    // the error is: cannot use client (variable of type *cognitoidentityprovider.Client) as *"github.com/aws/aws-sdk-go/aws/client".Client value in argument to xray.AWS
    xray.AWS(client)
    ...
    }

I really appreciate your support on this.

narqo commented 11 months ago

There is an example of instrumenting AWS SDK V2 (seems to be your case) in the README. Have you tried it?

cfg, _ := config.LoadDefaultConfig(ctx)

// instrument AWS SDK v2
awsv2.AWSV2Instrumentor(&cfg.APIOptions)

// use instumented Config to setup other AWS SDK v2 clients
...