aws / aws-xray-sdk-go

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

How do I add a custom detector to allow seamless snowflake integration? #453

Open amanangira opened 4 months ago

amanangira commented 4 months ago

Hello, below are the details of what I am trying to do

import (
    _ "github.com/snowflakedb/gosnowflake" // Snowflake
    "github.com/aws/aws-xray-sdk-go/xray"
    "github.com/jmoiron/sqlx"
)

func main() {
    dsn := ""
    sqlDB, err := xray.SQLContext("snowflake", dsn)
    if err != nil {
        panic(err)
    }
    sqlxDB := sqlx.NewDb(sqlDB, "snowflake")
    rows, rowErr := sqlxDB.QueryContext(context.Background(), "SELECT 1")
    if rowErr != nil {
    panic(rowErr)
    }
}

During debugging the QueryContext context statement I found the below call stack. Screenshot 2024-02-22 at 4 04 12 PM

Now the problem as per my understanding is that the [newDBAttribute](https://github.com/aws/aws-xray-sdk-go/blob/e9627da6f47902f96f26c577cbe6f9244987a4fb/xray/sql_context.go#L370) call under sql_context.go only seems to be supporting postgres, mysql, and oracle driver types because of which the meta query being fired in case of snowflake is SELECT version(), current_user, current_database() and the Snowflake version() equivalent is [current_version()](https://docs.snowflake.com/en/sql-reference/functions/current_version) which results in some error logs.

Version I am using go 1.21.0 aws-xray-sdk-go v1.8.3 snowflakedb/gosnowflake v1.8.0

wangzlei commented 4 months ago

@amanangira Please help confirm that my understanding is correct. To support the snowflake in sql instrumentation, we can add an new API likeaddDetector(), if you don't mind, could you help submit a PR for it? We can review and add unit testing for the changes.

amanangira commented 4 months ago

Hello @wangzlei , I don't mind. I sure can try and respond to the review changes as they are reviewed. Before moving forward I wanted to confirm if there was no existing API to do the same.

Are there any instructions to keep in mind when working on a new PR? Thanks!