-
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.
- Loading branch information
Showing
4 changed files
with
109 additions
and
2 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 |
---|---|---|
@@ -1,2 +1,106 @@ | ||
# jaeger-middleware | ||
An extensively configurable Go web middleware that integrates Jaeger for distributed tracing. | ||
|
||
## Usage | ||
|
||
### Installation | ||
|
||
```bash | ||
go get github.com/makonike/jaeger-middleware | ||
``` | ||
|
||
### Example | ||
|
||
#### Server | ||
|
||
```go | ||
func main() { | ||
tp, _ := middleware.TracerProvider("http://localhost:14268/api/traces", false) | ||
otel.SetTracerProvider(tp) | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
// Cleanly shutdown and flush telemetry when the application exits. | ||
defer func(ctx context.Context) { | ||
// Do not make the application hang when it is shutdown. | ||
ctx, cancel = context.WithTimeout(ctx, time.Second*5) | ||
defer cancel() | ||
if err := tp.Shutdown(ctx); err != nil { | ||
fmt.Println("failed to shutdown TracerProvider: ", err) | ||
} | ||
}(ctx) | ||
|
||
server := grpc.NewServer( | ||
grpc.UnaryInterceptor(middleware.NewJaegerServerMiddleware().UnaryInterceptor), | ||
grpc.StreamInterceptor(middleware.NewJaegerServerMiddleware().StreamInterceptor), | ||
) | ||
proto.RegisterTestServiceServer(server, new(test.UserService)) | ||
list, err := net.Listen("tcp", ":50055") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
err = server.Serve(list) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
``` | ||
|
||
#### Client | ||
```go | ||
func main() { | ||
tp, _ := middleware.TracerProvider("http://localhost:14268/api/traces", false) | ||
otel.SetTracerProvider(tp) | ||
var addr string | ||
addr = ":50055" | ||
ctx := context.WithValue(context.Background(), "trace-id", "cdde169b504ec847521a2cf1d1ffa9f9") | ||
req := &proto.GetReq{ | ||
Name: "xxx", | ||
} | ||
conn, err := grpc.Dial(addr, | ||
grpc.WithTransportCredentials(insecure.NewCredentials()), | ||
grpc.WithUnaryInterceptor(middleware.NewJaegerClientMiddleware().UnaryClientInterceptor), | ||
grpc.WithStreamInterceptor(middleware.NewJaegerClientMiddleware().StreamClientInterceptor), | ||
) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer conn.Close() | ||
client := proto.NewTestServiceClient(conn) | ||
resp, err := client.Get(ctx, req) | ||
assert.Nil(t, err) | ||
} | ||
``` | ||
|
||
## Configuration | ||
|
||
At present, configuration exclusively relies on manipulation of environmental variables within the operating system. Hence, it is advisable to operate a distinct application within an individual container. This approach facilitates the accommodation of multiple applications on a single host, each employing distinct customized configurations. | ||
|
||
- CLUSTER_NAME, default default_cluster | ||
- NAMESPACE, default default_namespace | ||
- DEPLOYMENT, default default_deployment | ||
- SERVICE_NAME, default default_hostname | ||
- ENVIRONMENT, default default_pod | ||
- TRACE_HEADER, default trace-id | ||
|
||
The identifying key for the trace_id propagated across the chain of communication. | ||
|
||
- MAX_BOX_SIZE, default 10240 | ||
|
||
If the size of the input body or the returned error message exceeds the MAX_BOX_SIZE, it will not be logged. | ||
|
||
- SERVER_ENABLED, default true | ||
|
||
If configured as 'false,' the server middleware will remain inactive. | ||
|
||
- CLIENT_ENABLED=dev, default true | ||
|
||
If configured as 'false,' the client middleware will remain inactive. | ||
|
||
## Effect | ||
|
||
![img.png](/img/img.png) | ||
|
||
## Reference | ||
|
||
TODO |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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