-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add server and client gRPC trace interceptors
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package interceptors | ||
|
||
import ( | ||
"fmt" | ||
"google.golang.org/grpc" | ||
grpctrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/google.golang.org/grpc" | ||
) | ||
|
||
const ( | ||
datadogServiceServerSuffix = "grpc" | ||
datadogServiceClientSuffix = "grpc-client" | ||
) | ||
|
||
// TracingUnaryServerInterceptor returns a unary server interceptor that will | ||
// trace requests to the given gRPC server. | ||
func TracingUnaryServerInterceptor(applicationName string) grpc.UnaryServerInterceptor { | ||
serviceName := fmt.Sprintf("%s-%s", applicationName, datadogServiceServerSuffix) | ||
return grpctrace.UnaryServerInterceptor(grpctrace.WithServiceName(serviceName)) | ||
} | ||
|
||
// TracingStreamServerInterceptor returns a stream server interceptor that will | ||
// trace streaming requests to the given gRPC server. | ||
func TracingStreamServerInterceptor(applicationName string) grpc.StreamServerInterceptor { | ||
serviceName := fmt.Sprintf("%s-%s", applicationName, datadogServiceServerSuffix) | ||
return grpctrace.StreamServerInterceptor(grpctrace.WithServiceName(serviceName)) | ||
} | ||
|
||
// TracingUnaryClientInterceptor returns a unary client interceptor that will | ||
// trace requests performed by gRPC client. | ||
func TracingUnaryClientInterceptor(applicationName string) grpc.UnaryClientInterceptor { | ||
serviceName := fmt.Sprintf("%s-%s", applicationName, datadogServiceClientSuffix) | ||
return grpctrace.UnaryClientInterceptor(grpctrace.WithServiceName(serviceName)) | ||
} | ||
|
||
// TracingStreamClientInterceptor returns a stream server interceptor that will | ||
// trace streaming requests performed by gRPC client. | ||
func TracingStreamClientInterceptor(applicationName string) grpc.StreamClientInterceptor { | ||
serviceName := fmt.Sprintf("%s-%s", applicationName, datadogServiceClientSuffix) | ||
return grpctrace.StreamClientInterceptor(grpctrace.WithServiceName(serviceName)) | ||
} |