Skip to content

Commit

Permalink
Merge branch 'v1' into caleb/memcache
Browse files Browse the repository at this point in the history
  • Loading branch information
dd-caleb authored Aug 3, 2018
2 parents 39fa1ff + 888c7c4 commit ff0e63a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions contrib/database/sql/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"log"

sqlite "github.com/mattn/go-sqlite3" // Setup application to use Sqlite
sqltrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
Expand Down Expand Up @@ -54,3 +55,28 @@ func Example_context() {
}
rows.Close()
}

func Example_sqlite() {
// Register the driver that we will be using (in this case Sqlite) under a custom service name.
sqltrace.Register("sqlite", &sqlite.SQLiteDriver{}, sqltrace.WithServiceName("sqlite-example"))

// Open a connection to the DB using the driver we've just registered with tracing.
db, err := sqltrace.Open("sqlite", "./test.db")
if err != nil {
log.Fatal(err)
}

// Create a root span, giving name, server and resource.
_, ctx := tracer.StartSpanFromContext(context.Background(), "my-query",
tracer.SpanType("example"),
tracer.ServiceName("sqlite-example"),
tracer.ResourceName("initial-access"),
)

// Subsequent spans inherit their parent from context.
rows, err := db.QueryContext(ctx, "SELECT * FROM city LIMIT 5")
if err != nil {
log.Fatal(err)
}
rows.Close()
}

0 comments on commit ff0e63a

Please sign in to comment.