Skip to content

Commit 56248a0

Browse files
committed
context request type and trace id
1 parent 118180c commit 56248a0

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

internal/meta/context.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ import (
66
"google.golang.org/grpc/metadata"
77
)
88

9-
// WithTraceID returns a copy of parent deadline with traceID
9+
// WithTraceID returns a copy of parent context with traceID
1010
func WithTraceID(ctx context.Context, traceID string) context.Context {
1111
return metadata.AppendToOutgoingContext(ctx, HeaderTraceID, traceID)
1212
}
1313

14-
// WithUserAgent returns a copy of parent deadline with custom user-agent info
14+
// WithUserAgent returns a copy of parent context with custom user-agent info
1515
func WithUserAgent(ctx context.Context, userAgent string) context.Context {
1616
return metadata.AppendToOutgoingContext(ctx, HeaderUserAgent, userAgent)
1717
}
18+
19+
// WithRequestType returns a copy of parent context with custom request type
20+
func WithRequestType(ctx context.Context, requestType string) context.Context {
21+
return metadata.AppendToOutgoingContext(ctx, HeaderRequestType, requestType)
22+
}

meta.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package ydb
2+
3+
import (
4+
"context"
5+
6+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/meta"
7+
)
8+
9+
// WithTraceID returns a copy of parent context with traceID
10+
func WithTraceID(ctx context.Context, traceID string) context.Context {
11+
return meta.WithTraceID(ctx, traceID)
12+
}
13+
14+
// WithRequestType returns a copy of parent context with custom request type
15+
func WithRequestType(ctx context.Context, requestType string) context.Context {
16+
return meta.WithRequestType(ctx, requestType)
17+
}

options.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ func WithUserAgent(userAgent string) Option {
6161
}
6262
}
6363

64+
func WithRequestsType(requestsType string) Option {
65+
return func(ctx context.Context, c *connection) error {
66+
c.options = append(c.options, config.WithRequestsType(requestsType))
67+
return nil
68+
}
69+
}
70+
6471
// WithConnectionString accept connection string like 'grpc[s]://{endpoint}/?database={database}'
6572
func WithConnectionString(connectionString string) Option {
6673
return func(ctx context.Context, c *connection) error {

0 commit comments

Comments
 (0)