@@ -17,25 +17,30 @@ Package `ydb-go-sdk` provides usage `database/sql` API also.
1717 * [ Over ` sql.Tx ` ] ( #retry-tx )
18186 . [ Query args types] ( #arg-types )
19197 . [ Get native driver from ` *sql.DB ` ] ( #unwrap )
20+ 8 . [ Logging SDK's events] ( #logs )
21+ 9 . [ Add metrics about SDK's events] ( #metrics )
22+ 10 . [ Add ` Jaeger ` traces about driver events] ( #jaeger )
2023
2124## Initialization of ` database/sql ` driver <a name =" init " ></a >
2225
2326### Configure driver with ` ydb.Connector ` (recommended way) <a name =" init-connector " ></a >
2427``` go
2528import (
29+ " database/sql"
30+
2631 " github.com/ydb-platform/ydb-go-sdk/v3"
2732)
2833
2934func main () {
3035 // init native ydb-go-sdk driver
3136 nativeDriver , err := ydb.Open (context.TODO (), " grpcs://localhost:2135/local" ,
32- // See many ydb.Option's for configure driver
37+ // See many ydb.Option's for configure driver https://pkg.go.dev/github.com/ydb-platform/ydb-go-sdk/v3#Option
3338 )
3439 if err != nil {
3540 // fallback on error
3641 }
3742 connector , err := ydb.Connector (nativeDriver,
38- // See ydb.ConnectorOption's for configure connector
43+ // See ydb.ConnectorOption's for configure connector https://pkg.go.dev/github.com/ydb-platform/ydb-go-sdk/v3#ConnectorOption
3944 )
4045 if err != nil {
4146 // fallback on error
@@ -46,6 +51,8 @@ func main() {
4651### Configure driver only with data source name (connection string) <a name =" init-dsn " ></a >
4752``` go
4853import (
54+ " database/sql"
55+
4956 _ " github.com/ydb-platform/ydb-go-sdk/v3"
5057)
5158
@@ -259,7 +266,7 @@ err := retry.DoTx(context.TODO(), db, func(ctx context.Context, tx *sql.Tx) erro
259266 ```
260267## Get native driver from ` *sql.DB ` <a name =" unwrap " ></a >
261268
262- ```
269+ ``` go
263270db , err := sql.Open (" ydb" , " grpcs://localhost:2135/local" )
264271if err != nil {
265272 t.Fatal (err)
@@ -273,3 +280,78 @@ nativeDriver.Table().Do(ctx, func(ctx context.Context, s table.Session) error {
273280 return nil
274281})
275282```
283+
284+ ## Logging driver events <a name =" logging " ></a >
285+
286+ Adding a logging driver events allowed only if connection to ` YDB ` opens over [ connector] ( ##init-connector ) .
287+ Adding of logging provides with [ debug adapters] ( README.md#debug ) and wrotes in [ migration notes] ( MIGRATION_v2_v3.md#logs )
288+ Example of adding ` zap ` logging:
289+ ``` go
290+ import (
291+ " github.com/ydb-platform/ydb-go-sdk/v3/trace"
292+ ydbZap " github.com/ydb-platform/ydb-go-sdk-zap"
293+ )
294+ ...
295+ nativeDriver , err := ydb.Open (ctx, connectionString,
296+ ...
297+ ydbZap.WithTraces (log, trace.DetailsAll ),
298+ )
299+ if err != nil {
300+ // fallback on error
301+ }
302+ connector , err := ydb.Connector (nativeDriver)
303+ if err != nil {
304+ // fallback on error
305+ }
306+ db := sql.OpenDB (connector)
307+ ```
308+
309+ ## Add metrics about SDK's events <a name =" metrics " ></a >
310+
311+ Adding of driver events monitoring allowed only if connection to ` YDB ` opens over [ connector] ( ##init-connector ) .
312+ Monitoring of driver events provides with [ debug adapters] ( README.md#debug ) and wrotes in [ migration notes] ( MIGRATION_v2_v3.md#metrics )
313+ Example of adding ` Prometheus ` monitoring:
314+ ``` go
315+ import (
316+ " github.com/ydb-platform/ydb-go-sdk/v3/trace"
317+ ydbMetrics " github.com/ydb-platform/ydb-go-sdk-prometheus"
318+ )
319+ ...
320+ nativeDriver , err := ydb.Open (ctx, connectionString,
321+ ...
322+ ydbMetrics.WithTraces (registry, ydbMetrics.WithDetails (trace.DetailsAll )),
323+ )
324+ if err != nil {
325+ // fallback on error
326+ }
327+ connector , err := ydb.Connector (nativeDriver)
328+ if err != nil {
329+ // fallback on error
330+ }
331+ db := sql.OpenDB (connector)
332+ ```
333+
334+ ## Add ` Jaeger ` traces about driver events <a name =" jaeger " ></a >
335+
336+ Adding of ` Jaeger ` traces about driver events allowed only if connection to ` YDB ` opens over [ connector] ( ##init-connector ) .
337+ ` Jaeger ` tracing provides with [ debug adapters] ( README.md#debug ) and wrotes in [ migration notes] ( MIGRATION_v2_v3.md#jaeger )
338+ Example of adding ` Jaeger ` tracing:
339+ ``` go
340+ import (
341+ " github.com/ydb-platform/ydb-go-sdk/v3/trace"
342+ ydbOpentracing " github.com/ydb-platform/ydb-go-sdk-opentracing"
343+ )
344+ ...
345+ nativeDriver , err := ydb.Open (ctx, connectionString,
346+ ...
347+ ydbOpentracing.WithTraces (trace.DriverConnEvents | trace.DriverClusterEvents | trace.DriverRepeaterEvents | trace.DiscoveryEvents ),
348+ )
349+ if err != nil {
350+ // fallback on error
351+ }
352+ connector , err := ydb.Connector (nativeDriver)
353+ if err != nil {
354+ // fallback on error
355+ }
356+ db := sql.OpenDB (connector)
357+ ```
0 commit comments