1package ctxkit_test
2
3import (
4	"context"
5
6	"github.com/grpc-ecosystem/go-grpc-middleware/logging/kit/ctxkit"
7	grpc_ctxtags "github.com/grpc-ecosystem/go-grpc-middleware/tags"
8	pb_testproto "github.com/grpc-ecosystem/go-grpc-middleware/testing/testproto"
9)
10
11// Simple unary handler that adds custom fields to the requests's context. These will be used for all log statements.
12func ExampleExtract_unary() {
13	_ = func(ctx context.Context, ping *pb_testproto.PingRequest) (*pb_testproto.PingResponse, error) {
14		// Add fields the ctxtags of the request which will be added to all extracted loggers.
15		grpc_ctxtags.Extract(ctx).Set("custom_tags.string", "something").Set("custom_tags.int", 1337)
16
17		// Extract a single request-scoped log.Logger and log messages.
18		l := ctxkit.Extract(ctx)
19		l.Log("msg", "some ping")
20		l.Log("msg", "another ping")
21		return &pb_testproto.PingResponse{Value: ping.Value}, nil
22	}
23}
24