-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instrument with open tracing (#6347)
* add tracing of bootstrap phase * Added tracing of plugin and API calls * added opentracing-zipkin * remove commented tags * add tracing to actions to be propogated to onCreateNode * added cli option for open tracing config file * remove console log * use api-runner instance to store parentSpan * added build phase tracing * finish build-node-types span * added tracer util * added stop tracer functionality * added docs on how to use tracing * doc fixes * remove custom tracing section * remove activity boolean tag * general cleanup before PR * address linter issues * fixed failing test cases including jest update * added tracing image example * npm run format * merge tracerStop ifs into &&
- Loading branch information
1 parent
554d8ec
commit d863bcb
Showing
20 changed files
with
429 additions
and
90 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
title: "Performance tracing" | ||
--- | ||
|
||
Gatsby allows a build to be traced, enabling you to find which plugins or parts of the build are taking the longest. The trace information can be viewed in any [open tracing](http://opentracing.io/) compatible tool such as [https://www.jaegertracing.io/](https://www.jaegertracing.io/). You can also use Zipkin compatible tools such as [Zipkin](https://zipkin.io/) or [Honeycomb](https://www.honeycomb.io/). | ||
|
||
![Example Zipkin Trace](./images/zipkin-trace.png) | ||
|
||
## Running Gatsby with tracing turned on | ||
|
||
Gatsby code is instrumented with Open Tracing, which is a general tracing API that is implementation agnostic. Therefore, you'll need to include and configure an open tracing compatible library in your application, as well as a backend to collect the trace data. | ||
|
||
The steps required to add tracing are below. Including an [example](/docs/performance-tracing/#local-zipkin-with-docker) of how to get tracing working with zipkin locally using docker | ||
|
||
### 1. Library dependency | ||
|
||
Add an [open-tracing compatible library](https://github.com/opentracing) to your site's `package.json` dependencies. | ||
|
||
### 2. Library configuration file | ||
|
||
Each open tracing library must be configured. For example, what is the URL of the tracing backend? How often should spans be sent to the backend? What service name should the trace be recorded under? Etc. | ||
|
||
The configuration file is a javascript file that exports two functions. `create` and `stop` | ||
|
||
- **create**: Create and return an [open tracing compatible Tracer](https://github.com/opentracing/opentracing-javascript/blob/master/src/tracer.ts). It is called at the start of the build | ||
- **stop**: Called at the end of the build. Any cleanup required by the tracer should be performed here. Such as clearing out any span queues and sending them to the tracing backend. | ||
|
||
### 3. Start Gatsby with tracing turned on | ||
|
||
The above configuration file can be passed to Gatsby with the `--open-tracing-config-file` command-line option. When Gatsby is started with this option, it will load the supplied tracing configuration file, and call its `create` function. The returned Tracer will be used for tracing the build. Once the build has stopped, the configuration file's `stop` method will be called, allowing the tracing implementation to perform any cleanup. | ||
|
||
## Tracing backend examples | ||
|
||
There are many open tracing compatible backends available. Below is an example of how to hook zipkin into Gatsby | ||
|
||
### local Zipkin with Docker | ||
|
||
[Zipkin](https://zipkin.io/) is an open source Tracing system that can be run locally using docker. | ||
|
||
1. Add following dependencies to your site's `package.json` | ||
|
||
- [zipkin](https://www.npmjs.com/package/zipkin) | ||
- [zipkin-javascript-opentracing](https://www.npmjs.com/package/zipkin-javascript-opentracing) | ||
- [zipkin-transport-http](https://www.npmjs.com/package/zipkin-transport-http) | ||
|
||
2. Run Zipkin all-in-one docker instance with `docker run -d -p 9411:9411 openzipkin/zipkin`. See [Zipkin Getting Started](https://zipkin.io/pages/quickstart.html) for more information. | ||
|
||
3. Start Gatsby `build` or `develop` with `--open-tracing-config-file` pointing at the Zipkin configuration file. An example file is provided in the gatsby project under `node_modules/gatsby/dist/utils/tracer/zipkin-local.js` that will send tracing spans to your local docker instance. E.g | ||
|
||
``` | ||
gatsby build --open-tracing-config-file node_modules/gatsby/dist/utils/tracer/zipkin-local.js | ||
``` | ||
4. Once the build is complete, view your tracing information at [http://localhost:9411](http://localhost:9411) |
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
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
Oops, something went wrong.