1

Per https://aws.amazon.com/xray/faqs/:

Q: My application components run in their own AWS accounts. Can I use X-Ray to collect data across AWS accounts?
Yes, the X-Ray agent can assume a role to publish data into an account different from the one in which it is running. This enables you publish data from various components of your application into a central account.

I know that I can assume a role like so:

    st := sts.NewFromConfig(awsConf)
    creds := stscreds.NewAssumeRoleProvider(st, "myRoleArn")
    awsConf.Credentials = aws.NewCredentialsCache(creds)

I know that I can create an xray service using those creds:

    import xrayv2 "github.com/aws/aws-sdk-go-v2/service/xray" 
    xrayService := xrayv2.NewFromConfig(awsConf)

The problem is that the xray service is made for interacting directly with the xray API, it doesn't have any of the wonderful magic that the xray client provides. The xray client I know is configured this way:

    import "github.com/aws/aws-xray-sdk-go/xray"
    xray.Configure(xray.Config{
        DaemonAddr:                  "",
        ServiceVersion:              "",
        Emitter:                     nil,
        SamplingStrategy:            nil,
        StreamingStrategy:           nil,
        ExceptionFormattingStrategy: nil,
        ContextMissingStrategy:      nil,
        LogLevel:                    "",
        LogFormat:                   "",
    })

Regardless of if I was using the aws or aws-v2 library, I don't see a place where I can provide the xray client any sort of aws conf / credential provider. I can create a custom emitter, but I was hoping to avoid that.

Any ideas on how I might provide a credentials cache to github.com/aws/aws-xray-sdk-go/xray?

TopherGopher
  • 655
  • 11
  • 21

1 Answers1

1

This other S.O. question helped me misunderstand my misconception. The AWS X-Ray client library just publishes information to a local running daemon. So the code isn't responsible for shipping traces off to x-ray.

By following the steps here - https://aws.amazon.com/blogs/compute/application-tracing-on-kubernetes-with-aws-x-ray/

And setting this variable _ = os.Setenv("AWS_XRAY_DAEMON_ADDRESS", "xray-service.kube-system:2000"), we were able to point the library to the local daemon.

Then it's the daemon that is responsible for forwarding, so we override the role that the daemon is running as by overriding the RoleArn in the xray ConfigMap.

TopherGopher
  • 655
  • 11
  • 21