-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve tracing feature and document it. fix #298
- Loading branch information
Showing
7 changed files
with
117 additions
and
4 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
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ Welcome to Pitaya's documentation! | |
configuration | ||
API | ||
examples | ||
tracing | ||
|
||
|
||
Indices and tables | ||
|
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,57 @@ | ||
Tracing | ||
======= | ||
|
||
Pitaya supports tracing using [OpenTracing](http://opentracing.io/). | ||
|
||
### Using Jaeger tracing | ||
|
||
First set the required environment variables: | ||
|
||
```bash | ||
export JAEGER_DISABLED=false | ||
export JAEGER_SERVICE_NAME=my-pitaya-server | ||
export JAEGER_SAMPLER_PARAM=1 #Ajust accordingly | ||
``` | ||
|
||
With these environment variables set, you can use the following code to configure Jaeger: | ||
|
||
```go | ||
func configureJaeger(config *viper.Viper, logger logrus.FieldLogger) { | ||
cfg, err := jaegercfg.FromEnv() | ||
if cfg.ServiceName == "" { | ||
logger.Error("Could not init jaeger tracer without ServiceName, either set environment JAEGER_SERVICE_NAME or cfg.ServiceName = \"my-api\"") | ||
return | ||
} | ||
if err != nil { | ||
logger.Error("Could not parse Jaeger env vars: %s", err.Error()) | ||
return | ||
} | ||
options := jaeger.Options{ // import "github.com/topfreegames/pitaya/v2/tracing/jaeger" | ||
Disabled: cfg.Disabled, | ||
Probability: cfg.Sampler.Param, | ||
ServiceName: cfg.ServiceName, | ||
} | ||
jaeger.Configure(options) | ||
} | ||
``` | ||
|
||
Then in your main function: | ||
|
||
```go | ||
func main() { | ||
// ... | ||
configureJaeger(config, logger) | ||
// ... | ||
} | ||
``` | ||
|
||
Ensure to run this Jaeger initialization code in all your server types. Only changing the "JAEGER_SERVICE_NAME" env var between different types. | ||
|
||
### Testing Locally | ||
```bash | ||
make run-jaeger-aio | ||
make run-cluster-example-frontend-tracing | ||
make run-cluster-example-backend-tracing | ||
``` | ||
|
||
Then access Jaeger UI at http://localhost:16686 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: '3.7' | ||
services: | ||
jaeger: | ||
image: jaegertracing/all-in-one:latest | ||
ports: | ||
- "16686:16686" | ||
- "14268:14268" | ||
- "6831:6831/udp" | ||
- "6832:6832/udp" | ||
environment: | ||
- COLLECTOR_OTLP_ENABLED=true | ||
- LOG_LEVEL=debug |
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